From: Mateusz Warowny Date: Fri, 8 Sep 2023 14:46:48 +0000 (+0200) Subject: Merge branch 'mmw/JAL-4199-web-services-testing' into mmw/bug/JAL-4241-annotation... X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=4df015be529a2e1b12c6b82b061798e186cc154b;hp=-c;p=jalview.git Merge branch 'mmw/JAL-4199-web-services-testing' into mmw/bug/JAL-4241-annotation-alignment-fix-slivka --- 4df015be529a2e1b12c6b82b061798e186cc154b diff --combined test/jalview/ws2/actions/alignment/AlignmentActionTest.java index b4a1388,1725045..d7ef20b --- a/test/jalview/ws2/actions/alignment/AlignmentActionTest.java +++ b/test/jalview/ws2/actions/alignment/AlignmentActionTest.java @@@ -1,6 -1,5 +1,6 @@@ package jalview.ws2.actions.alignment; +import static jalview.testutils.Matchers.matchesSequenceString; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.hasProperty; @@@ -23,6 -22,9 +23,6 @@@ import java.util.concurrent.TimeUnit import javax.help.UnsupportedOperationException; -import org.hamcrest.Description; -import org.hamcrest.Matcher; -import org.hamcrest.TypeSafeMatcher; import org.mockito.ArgumentCaptor; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; @@@ -34,7 -36,6 +34,7 @@@ import jalview.datamodel.SequenceI import jalview.gui.AlignViewport; import jalview.viewmodel.AlignmentViewport; import jalview.ws.params.ParamDatastoreI; +import jalview.ws2.actions.PollingTaskExecutor; import jalview.ws2.actions.api.TaskEventListener; import jalview.ws2.api.Credentials; import jalview.ws2.api.JobStatus; @@@ -50,7 -51,7 +50,7 @@@ public class AlignmentActionTes protected WebServiceJobHandle jobRef; - @BeforeMethod + @BeforeMethod(alwaysRun = true) public void setupMockClient() throws IOException { jobRef = new WebServiceJobHandle( @@@ -64,7 -65,7 +64,7 @@@ doThrow(new UnsupportedOperationException()).when(mockClient).cancel(any()); } - @BeforeMethod(dependsOnMethods = { "setupMockClient" }) + @BeforeMethod(alwaysRun = true, dependsOnMethods = { "setupMockClient" }) public void setupActionBuilder() throws IOException { actionBuilder = AlignmentAction.newBuilder(mockClient); @@@ -136,9 -137,9 +136,9 @@@ verify(mockClient).submit(argument.capture(), eq(List.of()), eq(Credentials.empty())); assertThat(argument.getValue(), contains( - matchesSequence("ASTVLITOPDCMMQEGGST"), - matchesSequence("ASCGLITOMMQEGGST"), - matchesSequence("ASTVLOPDTMMQEL"))); + matchesSequenceString("ASTVLITOPDCMMQEGGST"), + matchesSequenceString("ASCGLITOMMQEGGST"), + matchesSequenceString("ASTVLOPDTMMQEL"))); } @Test( @@@ -157,9 -158,9 +157,9 @@@ verify(mockClient).submit(argument.capture(), eq(List.of()), eq(Credentials.empty())); assertThat(argument.getValue(), contains( - matchesSequence("----ASTVLITOPDCMMQEGGST-"), - matchesSequence("-ASCGLITO------MMQEGGST-"), - matchesSequence("AS--TVL--OPDTMMQEL------"))); + matchesSequenceString("----ASTVLITOPDCMMQEGGST-"), + matchesSequenceString("-ASCGLITO------MMQEGGST-"), + matchesSequenceString("AS--TVL--OPDTMMQEL------"))); } @Test( @@@ -178,9 -179,36 +178,9 @@@ verify(mockListener).taskCompleted(any(), argument.capture()); var alignmentResult = argument.getValue().getAlignment(); assertThat(alignmentResult, hasProperty("sequences", contains( - matchesSequence("ASTV-LITOPDCMMQEGGST----"), - matchesSequence("ASC-GLITO---MMQEGGST----"), - matchesSequence("ASTV-L--OPDTMMQE--L-----")))); - } - - protected static Matcher matchesSequence(String sequence) - { - return new TypeSafeMatcher() - { - @Override - public boolean matchesSafely(SequenceI obj) - { - if (!(obj instanceof SequenceI)) - return false; - var seq = (SequenceI) obj; - return seq.getSequenceAsString().equals(sequence); - } - - @Override - public void describeTo(Description description) - { - description.appendText("a sequence ").appendValue(sequence); - } - - @Override - public void describeMismatchSafely(SequenceI item, Description description) - { - description.appendText("was ").appendValue(item.getSequenceAsString()); - } - }; + matchesSequenceString("ASTV-LITOPDCMMQEGGST----"), + matchesSequenceString("ASC-GLITO---MMQEGGST----"), + matchesSequenceString("ASTV-L--OPDTMMQE--L-----")))); } protected TaskEventListener performAction( @@@ -194,16 -222,12 +194,16 @@@ return null; }) .when(listener).taskCompleted(any(), any()); - action.perform(viewport, List.of(), Credentials.empty(), listener); + var executor = PollingTaskExecutor.fromPool(viewport.getServiceExecutor()); + var task = action.createTask(viewport, List.of(), Credentials.empty()); + task.addTaskEventListener(listener); + var cancellable = executor.submit(task); try { latch.await(100, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { + cancellable.cancel(true); } return listener; } @@@ -213,7 -237,7 +213,7 @@@ class AlignmentActionListenerNotifiedTe { private AlignViewport viewport; - @BeforeMethod + @BeforeMethod(alwaysRun = true) public void setupViewport() { viewport = new AlignViewport(new Alignment(new SequenceI[] { diff --combined test/jalview/ws2/client/slivka/SlivkaWSDiscovererTest.java index 6824a10,b8d0a31..1611b6f --- a/test/jalview/ws2/client/slivka/SlivkaWSDiscovererTest.java +++ b/test/jalview/ws2/client/slivka/SlivkaWSDiscovererTest.java @@@ -1,7 -1,15 +1,7 @@@ package jalview.ws2.client.slivka; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.allOf; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasProperty; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; -import static org.hamcrest.Matchers.typeCompatibleWith; +import static org.hamcrest.Matchers.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@@ -50,7 -58,7 +50,7 @@@ public class SlivkaWSDiscovererTes Console.initLogger(); } - @BeforeMethod + @BeforeMethod(alwaysRun = true) public void setupDiscoverer() throws IOException { clientMock = mock(SlivkaClient.class);