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;
+import static org.hamcrest.Matchers.is;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyList;
+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.net.URL;
import java.util.List;
import javax.help.UnsupportedOperationException;
-import org.hamcrest.BaseMatcher;
-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;
import org.testng.annotations.Test;
import jalview.datamodel.Alignment;
-import jalview.datamodel.AlignmentI;
import jalview.datamodel.Sequence;
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.JobI;
import jalview.ws2.actions.api.TaskEventListener;
import jalview.ws2.api.Credentials;
import jalview.ws2.api.JobStatus;
import jalview.ws2.api.WebServiceJobHandle;
import jalview.ws2.client.api.AlignmentWebServiceClientI;
-import org.mockito.hamcrest.MockitoHamcrest;
-import org.mockito.internal.hamcrest.HamcrestArgumentMatcher;
-
-import static org.mockito.Mockito.*;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.*;
-
public class AlignmentActionTest
{
protected AlignmentWebServiceClientI 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(
--- /dev/null
+package jalview.ws2.actions.annotation;
+
+import static jalview.testutils.Matchers.matchesSequenceString;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.hasSize;
+
+import java.util.List;
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import jalview.datamodel.Alignment;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceGroup;
+
+public class AnnotationJobTest
+{
+ @Test(groups = { "Functional" })
+ public void testCreate_EqualLengthNoGapsSubmitGaps()
+ {
+ var alignment = new Alignment(new Sequence[] {
+ new Sequence("test1", "ACACACACACA"),
+ new Sequence("test2", "AVAVAVAVAVA"),
+ new Sequence("test3", "AVWVAVWVAVW")
+ });
+ var annotJob = AnnotationJob.create(alignment, true, false, false, false, 0);
+ assertThat(annotJob.getInputSequences(), contains(
+ matchesSequenceString("ACACACACACA"),
+ matchesSequenceString("AVAVAVAVAVA"),
+ matchesSequenceString("AVWVAVWVAVW")
+ ));
+ }
+
+ @Test(groups = { "Functional" })
+ public void testCreate_EqualLengthNoGapsNoSubmitGaps()
+ {
+ var alignment = new Alignment(new Sequence[] {
+ new Sequence("test1", "ACACACACACA"),
+ new Sequence("test2", "AVAVAVAVAVA"),
+ new Sequence("test3", "AVWVAVWVAVW")
+ });
+ var annotJob = AnnotationJob.create(alignment, true, true, false, false, 0);
+ assertThat(annotJob.getInputSequences(), contains(
+ matchesSequenceString("ACACACACACA"),
+ matchesSequenceString("AVAVAVAVAVA"),
+ matchesSequenceString("AVWVAVWVAVW")
+ ));
+ }
+
+ @Test(groups = { "Functional" })
+ public void testCreate_UnequalLengthNoGapsNoSubmitGaps()
+ {
+ var alignment = new Alignment(new Sequence[] {
+ new Sequence("test1", "ACACACACACA"),
+ new Sequence("test2", "AVAVAVAVAVAVA"),
+ new Sequence("test3", "AVWVAVWVAVWV")
+ });
+ var annotJob = AnnotationJob.create(alignment, true, false, false, false, 0);
+ assertThat(annotJob.getInputSequences(), contains(
+ matchesSequenceString("ACACACACACA"),
+ matchesSequenceString("AVAVAVAVAVAVA"),
+ matchesSequenceString("AVWVAVWVAVWV")
+ ));
+ }
+
+ @Test(groups = { "Functional" })
+ public void testCreate_UnequalLengthNoGapsSubmitGaps()
+ {
+ var alignment = new Alignment(new Sequence[] {
+ new Sequence("test1", "ACACACACACA"),
+ new Sequence("test2", "AVAVAVAVAVAVA"),
+ new Sequence("test3", "AVWVAVWVAVWV")
+ });
+ var annotJob = AnnotationJob.create(alignment, true, true, false, false, 0);
+ assertThat(annotJob.getInputSequences(), contains(
+ matchesSequenceString("ACACACACACA"),
+ matchesSequenceString("AVAVAVAVAVAVA"),
+ matchesSequenceString("AVWVAVWVAVWV")
+ ));
+ }
+
+ @Test(groups = { "Functional" })
+ public void testCreate_UnequalLengthNoGapsSubmitGapsRequireAligned()
+ {
+ var alignment = new Alignment(new Sequence[] {
+ new Sequence("test1", "ACACACACACA"),
+ new Sequence("test2", "AVAVAVAVAVAVA"),
+ new Sequence("test3", "AVWVAVWVAVWV")
+ });
+ var annotJob = AnnotationJob.create(alignment, true, true, true, false, 0);
+ assertThat(annotJob.getInputSequences(), contains(
+ matchesSequenceString("ACACACACACA--"),
+ matchesSequenceString("AVAVAVAVAVAVA"),
+ matchesSequenceString("AVWVAVWVAVWV-")
+ ));
+ }
+
+ @DataProvider
+ public Object[] alignmentWithShortSequences()
+ {
+ return new Object[] {
+ new Alignment(new Sequence[] {
+ new Sequence("test1", "AAAAA"),
+ new Sequence("test2", "ACAACAAACAAC"),
+ new Sequence("test3", "ACA")
+ }),
+ new Alignment(new Sequence[] {
+ new Sequence("test1", "----AAAAA---"),
+ new Sequence("test2", "ACAACAAACAAC"),
+ new Sequence("test3", "-----ACA----")
+ }),
+ new Alignment(new Sequence[] {
+ new Sequence("test1", "--AAA---AA--"),
+ new Sequence("test2", "ACAACAAACAAC"),
+ new Sequence("test3", "-------ACA--")
+ }),
+ };
+ }
+
+ @Test(groups = { "Functional" }, dataProvider = "alignmentWithShortSequences")
+ public void testCreate_TooShortSequence_ShortSequenceRemoved(Alignment aln)
+ {
+ var annotJob = AnnotationJob.create(aln, true, false, false, false, 0);
+ assertThat(annotJob.getInputSequences(), hasSize(1));
+ }
+
+ @Test(groups = { "Functional" }, dataProvider = "alignmentWithShortSequences")
+ public void testCreate_TooShortSequenceAndSubmitGaps_ShortSeqRemoved(Alignment aln)
+ {
+ var annotJob = AnnotationJob.create(aln, true, true, false, false, 0);
+ assertThat(annotJob.getInputSequences(), hasSize(1));
+ }
+
+ @Test(groups = { "Functional" }, dataProvider = "alignmentWithShortSequences")
+ public void testCreate_TooShortSequenceAndRequireAligned_ShortSeqRemoved(Alignment aln)
+ {
+ var annotJob = AnnotationJob.create(aln, true, true, true, false, 0);
+ assertThat(annotJob.getInputSequences(), hasSize(1));
+ }
+
+ @Test(groups = { "Functional" })
+ public void testCreate_EmptyColumnAndSubmitGaps_ColumnExtruded()
+ {
+ var alignment = new Alignment(new Sequence[] {
+ new Sequence("test1", "ACA-ACAA--CACA"),
+ new Sequence("test2", "AVA-AVAA-AVAVA"),
+ new Sequence("test3", "AVAWAVAA-AVWVA")
+ });
+ var annotJob = AnnotationJob.create(alignment, true, true, false, false, 0);
+ assertThat(annotJob.getInputSequences(), contains(
+ matchesSequenceString("ACA-ACAA-CACA"),
+ matchesSequenceString("AVA-AVAAAVAVA"),
+ matchesSequenceString("AVAWAVAAAVWVA")
+ ));
+ }
+
+ @Test(groups = { "Functional" })
+ public void testCreate_EmptyColumnAndRequireAligned_ColumnExtruded()
+ {
+ var alignment = new Alignment(new Sequence[] {
+ new Sequence("test1", "ACA-ACAA--CACA"),
+ new Sequence("test2", "AVA-AVAA-AVAVA"),
+ new Sequence("test3", "AVAWAVAA-AVWVA")
+ });
+ var annotJob = AnnotationJob.create(alignment, true, true, true, false, 0);
+ assertThat(annotJob.getInputSequences(), contains(
+ matchesSequenceString("ACA-ACAA-CACA"),
+ matchesSequenceString("AVA-AVAAAVAVA"),
+ matchesSequenceString("AVAWAVAAAVWVA")
+ ));
+ }
+
+ @Test(groups = { "Functional"} )
+ public void testCreate_ContainsNonStandardAndNoFilterNonStandard_NonStandardToGap()
+ {
+ var alignment = new Alignment(new Sequence[] {
+ new Sequence("test1", "ACACAOACACAC"),
+ new Sequence("test2", "ABAVAVAVABAV")
+ });
+ var annotJob = AnnotationJob.create(alignment, true, true, true, false, 0);
+ assertThat(annotJob.getInputSequences(), contains(
+ matchesSequenceString("ACACA-ACACAC"),
+ matchesSequenceString("A-AVAVAVA-AV")
+ ));
+ }
+
+ @DataProvider
+ public Object[] alignmentWithNonStandardInColumns()
+ {
+ return new Object[] {
+ new Alignment(new Sequence[] {
+ new Sequence("test1", "A-AAAOAAAAAAAA"),
+ new Sequence("test2", "ABAAA-AAAAAAAA")
+ }),
+ new Alignment(new Sequence[] {
+ new Sequence("test1", "ABAAAOAAAAAAAA"),
+ new Sequence("test2", "ABAAABAAAAAAAA")
+ }),
+ new Alignment(new Sequence[] {
+ new Sequence("test1", "A-AAAOAAAAAAAA"),
+ new Sequence("test2", "A-AAA-AAAAAAAA")
+ })
+ };
+ }
+
+ @Test(groups = { "Functional" }, dataProvider = "alignmentWithNonStandardInColumns")
+ public void testCreate_NonStandardInColumnsAndFilterNonStandard_ColumnsExtruded(Alignment aln)
+ {
+ var annotJob = AnnotationJob.create(aln, true, true, true, true, 0);
+ assertThat(annotJob.getInputSequences(), contains(
+ matchesSequenceString("AAAAAAAAAAAA"),
+ matchesSequenceString("AAAAAAAAAAAA")
+ ));
+ }
+
+ @Test(groups = { "Functional" })
+ public void testCreate_SequenceGroup_RegionSubmitted()
+ {
+ var group = new SequenceGroup(List.of(
+ new Sequence("test1", "CCCCAAATAAATAAATCCC"),
+ new Sequence("test2", "----AAATAAATAAAT---")
+ ));
+ group.setStartRes(4);
+ group.setEndRes(15);
+ var annotJob = AnnotationJob.create(group, true, false, false, false, 0);
+ assertThat(annotJob.getInputSequences(), contains(
+ matchesSequenceString("AAATAAATAAAT"),
+ matchesSequenceString("AAATAAATAAAT")
+ ));
+ }
+
+ @Test(groups = { "Functional" })
+ public void testCreate_RegionIncludingGaps_RegionSubmittedWithoutGaps()
+ {
+ var group = new SequenceGroup(List.of(
+ new Sequence("test1", "CCCC-AAATAAATAAAT--CCC"),
+ new Sequence("test2", "-----AAATAAATAAAT-----")
+ ));
+ group.setStartRes(4);
+ group.setEndRes(18);
+ var annotJob = AnnotationJob.create(group, true, false, false, false, 0);
+ assertThat(annotJob.getInputSequences(), contains(
+ matchesSequenceString("AAATAAATAAAT"),
+ matchesSequenceString("AAATAAATAAAT")
+ ));
+ }
+
+ @Test(groups = { "Functional" })
+ public void testCreate_RegionIncludingGapsAndSubmitGaps_RegionSubmittedGapsExtruded()
+ {
+ var group = new SequenceGroup(List.of(
+ new Sequence("test1", "CCCC-AAATAAATAAAT--CCC"),
+ new Sequence("test2", "-----AAATAAATAAAT-----")
+ ));
+ group.setStartRes(4);
+ group.setEndRes(18);
+ var annotJob = AnnotationJob.create(group, true, true, false, false, 0);
+ assertThat(annotJob.getInputSequences(), contains(
+ matchesSequenceString("AAATAAATAAAT"),
+ matchesSequenceString("AAATAAATAAAT")
+ ));
+ }
+}