JAL-2489 JAL-2371 reinstate calls to
[jalview.git] / test / jalview / io / JSONFileTest.java
index 4e4abe9..acde68d 100644 (file)
@@ -130,13 +130,14 @@ public class JSONFileTest
       expectedSeqs.put(seq.getName(), seq);
     }
 
-    // create and add sequence groups
-    ArrayList<SequenceI> grpSeqs = new ArrayList<SequenceI>();
+    // create and add a sequence group
+    List<SequenceI> grpSeqs = new ArrayList<SequenceI>();
     grpSeqs.add(seqs[1]);
     grpSeqs.add(seqs[2]);
     grpSeqs.add(seqs[3]);
     grpSeqs.add(seqs[4]);
-    SequenceGroup seqGrp = new SequenceGroup(grpSeqs, "JGroup:1883305585",
+    SequenceGroup seqGrp = new SequenceGroup(grpSeqs,
+            "JGroup:1883305585",
             null, true, true, false, 21, 29);
     ColourSchemeI scheme = ColourSchemeMapper.getJalviewColourScheme(
             "zappo", seqGrp);
@@ -340,11 +341,12 @@ public class JSONFileTest
             "Zappo colour scheme expected!");
   }
 
-  @Test(groups = { "Functional" })
   /**
-   * Test for bug JAL-2489, NPE when exporting BioJSON with global colour scheme set as 'None'
+   * Test for bug JAL-2489, NPE when exporting BioJSON with global colour
+   * scheme, and a group colour scheme, set as 'None'
    */
-  public void testBioJSONRoundTripWithGlobalColourSchemeSetAsNone()
+  @Test(groups = { "Functional" })
+  public void testBioJSONRoundTripWithColourSchemeNone()
   {
     AppletFormatAdapter formatAdapter = new AppletFormatAdapter();
 
@@ -359,7 +361,14 @@ public class JSONFileTest
               bioJsonFile.getHiddenSequences(),
               bioJsonFile.getColumnSelection(), AlignFrame.DEFAULT_WIDTH,
               AlignFrame.DEFAULT_HEIGHT);
-      // Change colour scheme to 'None' and perform round trip
+
+      /*
+       * Create a group on the alignment;
+       * Change global and group colour scheme to 'None' and perform round trip
+       */
+      SequenceGroup sg = new SequenceGroup();
+      sg.addSequence(_alignment.getSequenceAt(0), false);
+      sg.setColourScheme(null);
       ColourSchemeI cs = ColourSchemeMapper.getJalviewColourScheme(
               ResidueColourScheme.NONE, _alignment);
       alignFrame.changeColour(cs);
@@ -556,4 +565,47 @@ public class JSONFileTest
     // System.out.println(">>>>>>>>>>>>>> features matched : " + matched);
     return matched;
   }
+
+  /**
+   * Test group roundtrip with null (None) group colour scheme
+   * 
+   * @throws IOException
+   */
+  @Test(groups = { "Functional" })
+  public void testGrpParsed_colourNone() throws IOException
+  {
+    AlignmentI copy = new Alignment(testAlignment);
+    SequenceGroup sg = testAlignment.getGroups().get(0);
+    SequenceGroup copySg = new SequenceGroup(new ArrayList<SequenceI>(),
+            sg.getName(),
+            null, sg.getDisplayBoxes(), sg.getDisplayText(),
+            sg.getColourText(), sg.getStartRes(), sg.getEndRes());
+    for (SequenceI seq : sg.getSequences())
+    {
+      int seqIndex = testAlignment.findIndex(seq);
+      copySg.addSequence(copy.getSequenceAt(seqIndex), false);
+    }
+    copy.addGroup(copySg);
+
+    AlignFrame af = new AlignFrame(copy, copy.getWidth(), copy.getHeight());
+    AppletFormatAdapter formatAdapter = new AppletFormatAdapter(
+            af.alignPanel);
+    String jsonOutput = formatAdapter.formatSequences(FileFormat.Json,
+            copy, false);
+    formatAdapter = new AppletFormatAdapter();
+    AlignmentI newAlignment = formatAdapter.readFile(jsonOutput,
+            DataSourceType.PASTE, FileFormat.Json);
+
+    Assert.assertNotNull(newAlignment.getGroups());
+    for (SequenceGroup seqGrp : newAlignment.getGroups())
+    {
+      SequenceGroup expectedGrp = expectedGrps.get(seqGrp.getName());
+      AssertJUnit.assertTrue(
+              "Failed SequenceGroup Test for >>> " + seqGrp.getName(),
+              isGroupMatched(expectedGrp, seqGrp));
+      passedCount++;
+    }
+    AssertJUnit.assertEquals("Some SequenceGroups did not pass the test",
+            TEST_GRP_HEIGHT, passedCount);
+  }
 }