From 9f67f658a0f2028646b8189c57c03ffac709f27c Mon Sep 17 00:00:00 2001 From: Mateusz Warowny Date: Tue, 17 Oct 2023 13:23:37 +0200 Subject: [PATCH] JAL-1601 Test alignment submitted to service --- test/jalview/testutils/ScopeFunctions.java | 20 ++++ .../secstructpred/SecStructPredTaskTest.java | 120 ++++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 test/jalview/testutils/ScopeFunctions.java create mode 100644 test/jalview/ws2/actions/secstructpred/SecStructPredTaskTest.java diff --git a/test/jalview/testutils/ScopeFunctions.java b/test/jalview/testutils/ScopeFunctions.java new file mode 100644 index 0000000..d118d3d --- /dev/null +++ b/test/jalview/testutils/ScopeFunctions.java @@ -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 run(Supplier func) + { + return func.get(); + } + + public static T apply(T context, Consumer 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 index 0000000..f46fae2 --- /dev/null +++ b/test/jalview/ws2/actions/secstructpred/SecStructPredTaskTest.java @@ -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 expectedInput) throws Exception + { + var task = new SecStructPredTask(mockClient, List.of(), Credentials.empty(), + viewport); + var jobs = task.prepareJobs(); + List> seqMatchers = new ArrayList<>( + expectedInput.size()); + for (var seqStr : expectedInput) + seqMatchers.add(matchesSequenceString(seqStr)); + assertThat(jobs.get(0).getInputSequences(), + Matchers. contains(seqMatchers)); + } +} -- 1.7.10.2