Merge branch 'mmw/JAL-4199-web-services-testing' into mmw/bug/JAL-4241-annotation...
authorMateusz Warowny <mmzwarowny@dundee.ac.uk>
Fri, 8 Sep 2023 14:46:48 +0000 (16:46 +0200)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Fri, 8 Sep 2023 14:46:48 +0000 (16:46 +0200)
1  2 
test/jalview/ws2/actions/alignment/AlignmentActionTest.java
test/jalview/ws2/client/slivka/SlivkaWSDiscovererTest.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);
      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(
      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(
      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<SequenceI> matchesSequence(String sequence)
 -  {
 -    return new TypeSafeMatcher<SequenceI>()
 -    {
 -      @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<AlignmentResult> performAction(
        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[] {
@@@ -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);