JAL-1601 Patch JPred4 service tests.
authorMateusz Warowny <mmzwarowny@dundee.ac.uk>
Fri, 19 Jan 2024 14:43:05 +0000 (15:43 +0100)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Fri, 19 Jan 2024 14:43:05 +0000 (15:43 +0100)
src/jalview/ws2/actions/secstructpred/SecStructPredPDBSearchTask.java
src/jalview/ws2/client/jpred4/JPred4WSClient.java
test/jalview/ws2/actions/secstructpred/SecStructPredPDBSearchTaskTest.java

index 0cb5150..fc7a772 100644 (file)
@@ -53,11 +53,13 @@ public class SecStructPredPDBSearchTask extends
           throws ServiceInputInvalidException
   {
     SeqCigar[] msf = alignmentView.getSequences();
-    SequenceI seq = msf[0].getSeq('-');
-    int[] delMap = alignmentView.getVisibleContigMapFor(seq.gapMap());
     if (msf.length > 1)
       throw new ServiceInputInvalidException(MessageManager.getString(
               "error.implementation_error_multiple_single_sequence_prediction_jobs_not_supported"));
+    SequenceI seq = msf[0].getSeq('-');
+    if (seq == null)
+      throw new ServiceInputInvalidException("Missing sequence.");
+    int[] delMap = alignmentView.getVisibleContigMapFor(seq.gapMap());
     var seqInfo = SeqsetUtils.SeqCharacterHash(seq);
     seq.setSequence(AlignSeq.extractGaps(Comparison.GapChars,
             alignmentView.getASequenceString('-', 0)));
index db1a6e4..3782723 100644 (file)
@@ -53,7 +53,7 @@ public class JPred4WSClient implements SecStructPredWebServiceClientI
     var input = mode == JPredRequest.Mode.MSA
         ? FileFormat.Fasta
             .getWriter(null)
-            .print(sequences.toArray(SequenceI[]::new), false)
+            .print(sequences.toArray(new SequenceI[sequences.size()]), false)
         : sequences.get(0).getSequenceAsString();
 
     JPredRequest request = JPredRequest
index 2f9cc3b..ca88cf3 100644 (file)
@@ -2,8 +2,10 @@ package jalview.ws2.actions.secstructpred;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.equalTo;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.List;
 
 import static org.mockito.Mockito.mock;
@@ -15,6 +17,9 @@ import static jalview.testutils.Matchers.matchesSequenceString;
 import jalview.io.DataSourceType;
 import jalview.io.FastaFile;
 import jalview.io.JPredFile;
+
+import org.hamcrest.Matcher;
+import org.hamcrest.Matchers;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
@@ -23,9 +28,12 @@ import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.HiddenColumns;
 import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceI;
 import jalview.gui.AlignViewport;
 import jalview.ws2.actions.ServiceInputInvalidException;
 import jalview.ws2.api.Credentials;
+import jalview.ws2.api.JobStatus;
+import jalview.ws2.api.WebServiceJobHandle;
 import jalview.ws2.client.api.SecStructPredWebServiceClientI;
 import static java.lang.String.format;
 
@@ -87,7 +95,8 @@ public class SecStructPredPDBSearchTaskTest
   @DataProvider
   public Object[][] viewportWithTooShortSequence()
   {
-    return new Object[][] { { new AlignViewport(createAlignment("")) },
+    return new Object[][] {
+        { new AlignViewport(createAlignment("")) },
         { new AlignViewport(createAlignment("A")) },
         { new AlignViewport(createAlignment("AAAAAAAAAAAAAAAAAAA")) },
         { new AlignViewport(createAlignment("AAAAACCCCCAAAAA-----CC")) },
@@ -125,12 +134,38 @@ public class SecStructPredPDBSearchTaskTest
     };
   }
 
-  @Test(
-      groups = { "Functional" }
-  )
-  public void testCollectResult(AlignViewport viewport, String alnFileName, String predFileName) throws Exception
+  @Test(groups = { "Functional" }, dataProvider = "collectResultDataset")
+  public void testCollectResult(AlignViewport viewport, String alnFileName,
+          String predFileName) throws Exception
   {
     var alnFile = new FastaFile(alnFileName, DataSourceType.FILE);
     var predFile = new JPredFile(predFileName, DataSourceType.FILE);
+    when(mockClient.getPredictionFile(any())).thenReturn(predFile);
+    when(mockClient.getAlignmentFile(any())).thenReturn(alnFile);
+    when(mockClient.getStatus(any())).thenReturn(JobStatus.COMPLETED);
+    when(mockClient.submit(any(), any(), any()))
+            .thenReturn(new WebServiceJobHandle("mock", "mock",
+                    "http://example.org", "0"));
+
+    var task = new SecStructPredPDBSearchTask(mockClient, List.of(),
+            Credentials.empty(), viewport);
+    task.init();
+    task.poll();
+    task.complete();
+    var resultAlignment = task.getResult();
+    var sequences = resultAlignment.getSequences();
+
+    {
+      List<Matcher<? super SequenceI>> matchers = new ArrayList<>();
+      for (var seq : alnFile.getSeqs())
+        matchers.add(matchesSequenceString(seq));
+      assertThat(sequences, Matchers.contains(matchers));
+    }
+
+    {
+      var originalHidden = viewport.getAlignment().getHiddenColumns();
+      var resultHidden = resultAlignment.getHiddenColumns();
+      assertThat(resultHidden, equalTo(originalHidden));
+    }
   }
 }