JAL-1601 Test alignment submitted to service
authorMateusz Warowny <mmzwarowny@dundee.ac.uk>
Tue, 17 Oct 2023 11:23:37 +0000 (13:23 +0200)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Tue, 17 Oct 2023 11:23:37 +0000 (13:23 +0200)
test/jalview/testutils/ScopeFunctions.java [new file with mode: 0644]
test/jalview/ws2/actions/secstructpred/SecStructPredTaskTest.java [new file with mode: 0644]

diff --git a/test/jalview/testutils/ScopeFunctions.java b/test/jalview/testutils/ScopeFunctions.java
new file mode 100644 (file)
index 0000000..d118d3d
--- /dev/null
@@ -0,0 +1,20 @@
+package jalview.testutils;
+
+import java.util.function.Consumer;
+import java.util.function.Supplier;
+
+public class ScopeFunctions
+{
+  private ScopeFunctions() {}
+  
+  public static <R> R run(Supplier<? extends R> func)
+  {
+    return func.get();
+  }
+  
+  public static <T> T apply(T context, Consumer<? super T> func)
+  {
+    func.accept(context);
+    return context;
+  }
+}
diff --git a/test/jalview/ws2/actions/secstructpred/SecStructPredTaskTest.java b/test/jalview/ws2/actions/secstructpred/SecStructPredTaskTest.java
new file mode 100644 (file)
index 0000000..f46fae2
--- /dev/null
@@ -0,0 +1,120 @@
+package jalview.ws2.actions.secstructpred;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import static jalview.testutils.Matchers.matchesSequenceString;
+import static jalview.testutils.ScopeFunctions.apply;
+import static jalview.testutils.ScopeFunctions.run;
+import org.hamcrest.Matcher;
+import org.hamcrest.Matchers;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyList;
+import static org.hamcrest.Matchers.contains;
+
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.inOrder;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+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.api.Credentials;
+import jalview.ws2.client.api.SecStructPredWebServiceClientI;
+
+import static java.lang.String.format;
+
+public class SecStructPredTaskTest
+{
+  protected SecStructPredWebServiceClientI mockClient;
+
+  @BeforeMethod(alwaysRun = true)
+  public void setupMockClient() throws IOException
+  {
+    mockClient = mock(SecStructPredWebServiceClientI.class);
+    when(mockClient.getUrl()).thenReturn("http://example.org");
+    when(mockClient.getClientName()).thenReturn("mock");
+    when(mockClient.getLog(any())).thenReturn("");
+    when(mockClient.getErrorLog(any())).thenReturn("");
+  }
+
+  @DataProvider
+  public Object[][] alignmentWithExpectedInput()
+  {
+    return new Object[][] {
+        {
+            new AlignViewport(createAlignment("AAAAAAAAAAAA", "AAAAAAAAAAAA",
+                "AAAAAAAAAAAA")),
+            List.of("AAAAAAAAAAAA", "AAAAAAAAAAAA", "AAAAAAAAAAAA") },
+        {
+            new AlignViewport(createAlignment("AAAA--NNNNAAAA",
+                "AA--AANNNNAAAA", "AA--AARRRRAAAA")),
+            List.of("AAAA--NNNNAAAA", "AA--AANNNNAAAA", "AA--AARRRRAAAA") },
+        {
+            new AlignViewport(createAlignment("AAAANNNNAAAA--",
+                "AAAARRRRAAAA--", "AAAARRRRAAAA--")),
+            List.of("AAAANNNNAAAA--", "AAAARRRRAAAA--", "AAAARRRRAAAA--") },
+        {
+            new AlignViewport(createAlignment("AAAA--NNNNAAAA",
+                "AAAA--NNNNAAAA", "AAAA--NNNNAAAA")),
+            List.of("AAAA--NNNNAAAA", "AAAA--NNNNAAAA", "AAAA--NNNNAAAA") },
+        {
+            new AlignViewport(createAlignment("AAAACCCCNNNN", "------------",
+                "AAAADDDDNNNN")),
+            List.of("AAAACCCCNNNN", "AAAADDDDNNNN") },
+        {
+            new AlignViewport(createAlignment("AAAACC--NNNN", "AAAACCDDNNNN"),
+                apply(new HiddenColumns(), it -> it.hideColumns(6, 7))),
+            List.of("AAAACCNNNN", "AAAACCNNNN") },
+        {
+            new AlignViewport(
+                createAlignment("CCAAAACC--MMMM", "--AAAAGGGGMMMM"),
+                apply(new HiddenColumns(), it -> {
+                  it.hideColumns(0, 1);
+                  it.hideColumns(8, 9);
+                })),
+            List.of("AAAACCMMMM", "AAAAGGMMMM") },
+        {
+            new AlignViewport(
+                createAlignment("CCAAAACC--MMMM", "CCAAAACC--MMMM"),
+                apply(new HiddenColumns(), it -> it.hideColumns(2, 5))),
+            List.of("CCCC--MMMM", "CCCC--MMMM") } };
+  }
+
+  public static AlignmentI createAlignment(String... sequences)
+  {
+    var seqArray = new Sequence[sequences.length];
+    for (int i = 0; i < sequences.length; i++)
+      seqArray[i] = new Sequence(format("Seq%d", i), sequences[i]);
+    return new Alignment(seqArray);
+  }
+
+  @Test(groups = { "functional" }, dataProvider = "alignmentWithExpectedInput")
+  public void testPrepareJobs_checkInputSequences(AlignViewport viewport,
+      List<String> expectedInput) throws Exception
+  {
+    var task = new SecStructPredTask(mockClient, List.of(), Credentials.empty(),
+        viewport);
+    var jobs = task.prepareJobs();
+    List<Matcher<? super SequenceI>> seqMatchers = new ArrayList<>(
+        expectedInput.size());
+    for (var seqStr : expectedInput)
+      seqMatchers.add(matchesSequenceString(seqStr));
+    assertThat(jobs.get(0).getInputSequences(),
+        Matchers.<SequenceI> contains(seqMatchers));
+  }
+}