Merge branch 'improvement/JAL-4245-return-null-from-getRootDataset' into development...
authorMateusz Warowny <mmzwarowny@dundee.ac.uk>
Mon, 11 Sep 2023 12:14:10 +0000 (14:14 +0200)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Mon, 11 Sep 2023 12:14:10 +0000 (14:14 +0200)
src/jalview/datamodel/SequenceI.java
test/jalview/datamodel/SequenceTest.java
test/jalview/ws2/actions/alignment/AlignmentActionTest.java
test/jalview/ws2/client/slivka/SlivkaWSDiscovererTest.java

index d8a5462..11aa4e6 100755 (executable)
@@ -396,11 +396,16 @@ public interface SequenceI extends ASequenceI
   public SequenceI getDatasetSequence();
 
   /**
-   * Returns the top grandparent in the dataset sequences hierarchy.
+   * Returns the top grandparent in the dataset sequences hierarchy
+   * or null if there is no dataset associated with this sequence.
    */
   public default SequenceI getRootDatasetSequence()
   {
-    var sequence = this;
+    if (getDatasetSequence() == null)
+    {
+      return null;
+    }
+    var sequence = getDatasetSequence();
     while (sequence.getDatasetSequence() != null)
     {
       sequence = sequence.getDatasetSequence();
index 7133455..529c80b 100644 (file)
@@ -1600,6 +1600,43 @@ public class SequenceTest
     assertTrue(found.contains(sfI));
   }
 
+  @Test(groups = { "Functional"} )
+  public void testGetRootDatasetSequence_datasetIsNull_returnNull()
+  {
+    Sequence dseq = new Sequence("test", "ABCDEF");
+    assertNull(dseq.getRootDatasetSequence());
+  }
+
+  @Test(groups = { "Functional" })
+  public void testGetRootDatasetSequence_datasetImplicit_returnDataset()
+  {
+    Sequence seq = new Sequence("test", "--AB-CDEF");
+    SequenceI dseq = seq.createDatasetSequence();
+    assertEquals(seq.getRootDatasetSequence(), dseq);
+  }
+
+  @Test(groups = { "Functional" })
+  public void testGetRootDatasetSequence_datasetExplicit_returnDataset()
+  {
+    Sequence seq = new Sequence("test", "--AB-CDEF");
+    Sequence dseq = new Sequence("test", "ABCDEF");
+    seq.setDatasetSequence(dseq);
+    assertEquals(seq.getRootDatasetSequence(), dseq);
+  }
+
+  @Test(groups = { "Functional" })
+  public void testGetRootDatasetSequence_nestedDatasets_returnLastDataset()
+  {
+    Sequence seq = new Sequence("test", "--AB-CDEFE");
+    Sequence dseq = new Sequence("test", "ABCDEF");
+    seq.setDatasetSequence(dseq);
+    Sequence ddseq = new Sequence("test", "ABCDEF");
+    dseq.setDatasetSequence(ddseq);
+    assertEquals(seq.getDatasetSequence(), dseq);
+    assertEquals(seq.getRootDatasetSequence(), ddseq);
+  }
+
+
   @Test(groups = { "Functional" })
   public void testFindIndex_withCursor()
   {
index e573032..bc43070 100644 (file)
@@ -99,7 +99,9 @@ public class AlignmentActionTest
     };
   }
 
-  @Test(dataProvider = "multipleSequencesUnalignedAndAligned")
+  @Test(
+    groups = { "Functional" },
+    dataProvider = "multipleSequencesUnalignedAndAligned")
   public void submitSequences_verifySequenceNamesUniquified(
       Alignment unaligned, Alignment aligned)
       throws IOException
@@ -117,7 +119,9 @@ public class AlignmentActionTest
             hasProperty("name", is("Sequence2"))));
   }
 
-  @Test(dataProvider = "multipleSequencesUnalignedAndAligned")
+  @Test(
+    groups = { "Functional" },
+    dataProvider = "multipleSequencesUnalignedAndAligned")
   public void submitSequences_submitGapsOff_verifySequencesSubmittedWithoutGaps(Alignment unaligned, Alignment aligned)
       throws IOException
   {
@@ -135,7 +139,9 @@ public class AlignmentActionTest
             matchesSequence("ASTVLOPDTMMQEL")));
   }
 
-  @Test(dataProvider = "multipleSequencesUnalignedAndAligned")
+  @Test(
+    groups = { "Functional" },
+    dataProvider = "multipleSequencesUnalignedAndAligned")
   public void submitSequences_submitGapsOn_verifySequencesSubmittedWithGaps(
       Alignment unaligned, Alignment aligned)
       throws IOException
@@ -154,7 +160,9 @@ public class AlignmentActionTest
             matchesSequence("AS--TVL--OPDTMMQEL------")));
   }
 
-  @Test(dataProvider = "multipleSequencesUnalignedAndAligned")
+  @Test(
+    groups = { "Functional" },
+    dataProvider = "multipleSequencesUnalignedAndAligned")
   public void retrieveResult_verifySequencesAligned(
       Alignment unaligned, Alignment aligned)
       throws IOException
@@ -256,7 +264,7 @@ class AlignmentActionListenerNotifiedTest extends AlignmentActionTest
     };
   }
 
-  @Test
+  @Test(groups = { "Functional" })
   public void allJobsStarted_taskStartedCalled()
       throws IOException
   {
@@ -265,7 +273,7 @@ class AlignmentActionListenerNotifiedTest extends AlignmentActionTest
     verify(mockListener).taskStarted(any(), anyList());
   }
 
-  @Test
+  @Test(groups = { "Functional" })
   public void allJobsStarted_taskStatusChangedCalledWithReadyThenSubmitted()
       throws IOException
   {
@@ -276,7 +284,7 @@ class AlignmentActionListenerNotifiedTest extends AlignmentActionTest
     inOrder.verify(mockListener).taskStatusChanged(any(), eq(JobStatus.SUBMITTED));
   }
 
-  @Test(dataProvider = "jobStatuses")
+  @Test(groups = { "Functional" }, dataProvider = "jobStatuses")
   public void jobStatusChanged_taskStatusChangedCalledWithJobStatus(JobStatus status)
       throws IOException
   {
@@ -287,7 +295,7 @@ class AlignmentActionListenerNotifiedTest extends AlignmentActionTest
     verify(mockListener).taskStatusChanged(any(), eq(status));
   }
 
-  @Test(dataProvider = "jobStatuses")
+  @Test(groups = { "Functional" }, dataProvider = "jobStatuses")
   public void jobStatusChanged_subJobStatusChangedCalledWithJobStatus(JobStatus status)
       throws IOException
   {
index 870acb1..6824a10 100644 (file)
@@ -24,6 +24,7 @@ import org.testng.annotations.Test;
 import jalview.bin.Cache;
 import jalview.bin.Console;
 import jalview.ws.params.ValueConstrainI.ValueType;
+import jalview.ws.params.simple.BooleanOption;
 import jalview.ws.params.simple.DoubleParameter;
 import jalview.ws.params.simple.IntegerParameter;
 import jalview.ws.params.simple.StringParameter;
@@ -55,7 +56,7 @@ public class SlivkaWSDiscovererTest
     clientMock = mock(SlivkaClient.class);
   }
 
-  @Test
+  @Test(groups = { "Functional" })
   public void getStatusForUrl_servicesReturned_statusIsOK() throws Exception
   {
     when(clientMock.getServices())
@@ -67,7 +68,7 @@ public class SlivkaWSDiscovererTest
         is(WebServiceDiscovererI.STATUS_OK));
   }
 
-  @Test
+  @Test(groups = { "Functional" })
   public void getStatusForUrl_noServicesReturned_statusIsNoServices()
       throws Exception
   {
@@ -79,7 +80,7 @@ public class SlivkaWSDiscovererTest
         is(WebServiceDiscovererI.STATUS_NO_SERVICES));
   }
 
-  @Test
+  @Test(groups = { "Functional" })
   public void getStatusForUrl_exceptionThrown_statusIsInvalid()
       throws Exception
   {
@@ -91,7 +92,7 @@ public class SlivkaWSDiscovererTest
         is(WebServiceDiscovererI.STATUS_INVALID));
   }
 
-  @Test
+  @Test(groups = { "Functional" })
   public void testGetUrls_noPropEntry_defaultUrlReturned()
       throws MalformedURLException
   {
@@ -119,7 +120,7 @@ public class SlivkaWSDiscovererTest
             List.of(new URL("http://example.org")) } };
   }
 
-  @Test(dataProvider = "urlPropertyValues")
+  @Test(groups = { "Functional" }, dataProvider = "urlPropertyValues")
   public void testGetUrls_urlsProperlyParsed(String propValue,
       List<URL> expected)
   {
@@ -128,7 +129,7 @@ public class SlivkaWSDiscovererTest
     assertThat(discoverer.getUrls(), equalTo(expected));
   }
 
-  @Test
+  @Test(groups = { "Functional" })
   public void testSetUrls_emptyList_propertyReset()
   {
     Cache.setProperty(URLS_PROPERTY_NAME, "http://www.example.org");
@@ -137,7 +138,7 @@ public class SlivkaWSDiscovererTest
     assertThat(Cache.getProperty(URLS_PROPERTY_NAME), is(nullValue()));
   }
 
-  @Test
+  @Test(groups = { "Functional" })
   public void testSetUrls_null_propertyReset()
   {
     Cache.setProperty(URLS_PROPERTY_NAME, "http://www.example.org");
@@ -159,7 +160,7 @@ public class SlivkaWSDiscovererTest
             "https://www.compbio.dundee.ac.uk/slivka/,http://example.org" }, };
   }
 
-  @Test(dataProvider = "urlsList")
+  @Test(groups = { "Functional" }, dataProvider = "urlsList")
   public void testSetUrls_urlsPropertySet(List<URL> urls, String expected)
       throws MalformedURLException
   {
@@ -168,7 +169,7 @@ public class SlivkaWSDiscovererTest
     assertThat(Cache.getProperty(URLS_PROPERTY_NAME), equalTo(expected));
   }
 
-  @Test
+  @Test(groups = { "Functional" })
   public void testFetchServices_oneService_basicDataMatches()
       throws IOException
   {
@@ -212,7 +213,9 @@ public class SlivkaWSDiscovererTest
 
   }
 
-  @Test(dataProvider = "validMultipleSequenceAlignmentClassifiers")
+  @Test(
+    groups = { "Functional" },
+    dataProvider = "validMultipleSequenceAlignmentClassifiers")
   public void testFetchServices_multipleSequenceAlignmentClassifier_serviceTypeIsMSA(
       String classifier) throws IOException
   {
@@ -257,7 +260,9 @@ public class SlivkaWSDiscovererTest
             List.of(), List.of(), null) };
   }
 
-  @Test(dataProvider = "multipleSequenceAlignmentService")
+  @Test(
+    groups = { "Functional" },
+    dataProvider = "multipleSequenceAlignmentService")
   public void testFetchServices_multipleSequenceAlignmentService_actionTypeIsAlignment(
       SlivkaService service) throws IOException
   {
@@ -271,7 +276,9 @@ public class SlivkaWSDiscovererTest
         typeCompatibleWith(AlignmentAction.class));
   }
 
-  @Test(dataProvider = "multipleSequenceAlignmentService")
+  @Test(
+    groups = { "Functional" },
+    dataProvider = "multipleSequenceAlignmentService")
   public void testFetchServices_multipleSequenceAlignmentService_serviceIsNonInteractive(
       SlivkaService service) throws IOException
   {
@@ -313,7 +320,7 @@ public class SlivkaWSDiscovererTest
             List.of(), List.of(), null), };
   }
 
-  @Test(dataProvider = "clustalFamilyService")
+  @Test(groups = { "Functional" }, dataProvider = "clustalFamilyService")
   public void testFetchService_clustalFamilyService_containsTwoActions(
       SlivkaService service) throws IOException
   {
@@ -362,7 +369,9 @@ public class SlivkaWSDiscovererTest
     return services.iterator();
   }
 
-  @Test(dataProvider = "RNASecondaryStructurePredictionService")
+  @Test(
+    groups = { "Functional" },
+    dataProvider = "RNASecondaryStructurePredictionService")
   public void testFetchServices_RNASecStrPredClassifier_serviceTypeIsRNASecStrPred(
       SlivkaService service) throws IOException
   {
@@ -402,7 +411,9 @@ public class SlivkaWSDiscovererTest
     return services.iterator();
   }
 
-  @Test(dataProvider = "validConservationAnalysisClassifiers")
+  @Test(
+    groups = { "Functional" },
+    dataProvider = "validConservationAnalysisClassifiers")
   public void testFetchServices_conservationAnalysisClassifier_serviceTypeIsConservation(
       String classifier) throws IOException
   {
@@ -427,7 +438,9 @@ public class SlivkaWSDiscovererTest
         "Operation :: Analysis :: Sequence analysis :: Protein sequence analysis", };
   }
 
-  @Test(dataProvider = "validProteinSequenceAnalysisClassifiers")
+  @Test(
+    groups = { "Functional" },
+    dataProvider = "validProteinSequenceAnalysisClassifiers")
   public void testFetchServices_proteinSequenceAnalysisClassifier_serviceTypeIsProtSeqAnalysis(
       String classifier) throws IOException
   {
@@ -460,6 +473,7 @@ public class SlivkaWSDiscovererTest
 
   @Test(
     enabled = false, // sec. str. pred. not implemented for slivka
+    groups = { "Functional" },
     dataProvider = "validProteinSecondaryStructurePredictionClassifiers")
   public void testFetchServices_proteinSecStrPredClassifier_serviceTypeIsProtSecStrPred(
       String classifier) throws IOException
@@ -490,7 +504,7 @@ public class SlivkaWSDiscovererTest
             List.of(), null) };
   }
 
-  @Test(dataProvider = "unrecognisedService")
+  @Test(groups = { "Functional" }, dataProvider = "unrecognisedService")
   public void testFetchServices_unrecognisedService_noServiceDiscovered(
       SlivkaService service) throws IOException
   {
@@ -525,7 +539,7 @@ public class SlivkaWSDiscovererTest
         {
             new Parameter.FlagParameter("param", "Parameter", "Description",
                 true, false, null, Map.of()),
-            StringParameter.class
+            BooleanOption.class
         },
         {
             new Parameter.ChoiceParameter("param", "Parameter", "Description",
@@ -535,7 +549,9 @@ public class SlivkaWSDiscovererTest
     };
   }
 
-  @Test(dataProvider = "serviceParameterAndMappedClass")
+  @Test(
+    groups = { "Functional" },
+    dataProvider = "serviceParameterAndMappedClass")
   public void testServiceParameter_slivkaParameterMappedToJalviewParameter(
       Parameter slivkaParameter, Class<?> expectedClass)
       throws IOException
@@ -593,7 +609,9 @@ public class SlivkaWSDiscovererTest
     };
   }
 
-  @Test(dataProvider = "serviceParametersAndInfoMatcher")
+  @Test(
+    groups = { "Functional" },
+    dataProvider = "serviceParametersAndPropertyMatcher")
   public void testServiceParameters_testBasicParameterProperties(
       Parameter parameter, Matcher<Object> matcher) throws IOException
   {
@@ -638,7 +656,9 @@ public class SlivkaWSDiscovererTest
     };
   }
 
-  @Test(dataProvider = "integerParametersAndPropertyMatcher")
+  @Test(
+    groups = { "Functional" },
+    dataProvider = "integerParametersAndPropertyMatcher")
   public void testServiceParameters_testIntegerProperties(
       Parameter parameter, Matcher<Object> matcher) throws IOException
   {