X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=test%2Fjalview%2Fio%2FJSONFileTest.java;h=2aff5ccd88dccc92e1978ac41cf0e54e116a00f8;hb=0125cee3edfa0ba5584631bae3ad9c808ec0b30d;hp=957343bf474f4a44e3381d36e406648b1d344f47;hpb=d1707d4c26db76cfeb640f0dbeb3e3427fd40eb7;p=jalview.git diff --git a/test/jalview/io/JSONFileTest.java b/test/jalview/io/JSONFileTest.java index 957343b..2aff5cc 100644 --- a/test/jalview/io/JSONFileTest.java +++ b/test/jalview/io/JSONFileTest.java @@ -36,6 +36,7 @@ import jalview.gui.AlignFrame; import jalview.gui.JvOptionPane; import jalview.json.binding.biojson.v1.ColourSchemeMapper; import jalview.schemes.ColourSchemeI; +import jalview.schemes.ResidueColourScheme; import java.io.IOException; import java.util.ArrayList; @@ -90,6 +91,8 @@ public class JSONFileTest private JSONFile jf; + private AlignExportSettingI exportSettings; + @BeforeTest(alwaysRun = true) public void setup() throws Exception { @@ -127,13 +130,14 @@ public class JSONFileTest expectedSeqs.put(seq.getName(), seq); } - // create and add sequence groups - ArrayList grpSeqs = new ArrayList(); + // create and add a sequence group + List grpSeqs = new ArrayList(); 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); @@ -191,9 +195,9 @@ public class JSONFileTest TEST_SEQ_HEIGHT = expectedSeqs.size(); TEST_GRP_HEIGHT = expectedGrps.size(); TEST_ANOT_HEIGHT = expectedAnnots.size(); - TEST_CS_HEIGHT = expectedColSel.getListOfCols().size(); + TEST_CS_HEIGHT = expectedColSel.getHiddenRegions().size(); - AlignExportSettingI exportSettings = new AlignExportSettingI() + exportSettings = new AlignExportSettingI() { @Override public boolean isExportHiddenSequences() @@ -311,11 +315,11 @@ public class JSONFileTest { HiddenColumns cs = testJsonFile.getHiddenColumns(); Assert.assertNotNull(cs); - Assert.assertNotNull(cs.getListOfCols()); - List hiddenCols = cs.getListOfCols(); + Assert.assertNotNull(cs.getHiddenRegions()); + List hiddenCols = cs.getHiddenRegions(); Assert.assertEquals(hiddenCols.size(), TEST_CS_HEIGHT); Assert.assertEquals(hiddenCols.get(0), expectedColSel - .getListOfCols().get(0), + .getHiddenRegions().get(0), "Mismatched hidden columns!"); } @@ -337,6 +341,58 @@ public class JSONFileTest "Zappo colour scheme expected!"); } + /** + * Test for bug JAL-2489, NPE when exporting BioJSON with global colour + * scheme, and a group colour scheme, set as 'None' + */ + @Test(groups = { "Functional" }) + public void testBioJSONRoundTripWithColourSchemeNone() + { + AppletFormatAdapter formatAdapter = new AppletFormatAdapter(); + + Alignment _alignment; + try + { + // load example BioJSON file + _alignment = (Alignment) formatAdapter.readFile(TEST_JSON_FILE, + DataSourceType.FILE, FileFormat.Json); + JSONFile bioJsonFile = (JSONFile) formatAdapter.getAlignFile(); + AlignFrame alignFrame = new AlignFrame(_alignment, + bioJsonFile.getHiddenSequences(), + bioJsonFile.getHiddenColumns(), AlignFrame.DEFAULT_WIDTH, + AlignFrame.DEFAULT_HEIGHT); + + /* + * 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); + alignFrame.getViewport().setFeaturesDisplayed( + bioJsonFile.getDisplayedFeatures()); + formatAdapter = new AppletFormatAdapter(alignFrame.alignPanel, + exportSettings); + // export BioJSON string + String jsonOutput = formatAdapter.formatSequences(FileFormat.Json, + alignFrame.alignPanel.getAlignment(), false); + // read back Alignment from BioJSON string + formatAdapter = new AppletFormatAdapter(); + formatAdapter.readFile(jsonOutput, DataSourceType.PASTE, + FileFormat.Json); + // assert 'None' colour scheme is retained after round trip + JSONFile _bioJsonFile = (JSONFile) formatAdapter.getAlignFile(); + Assert.assertEquals(_bioJsonFile.getGlobalColourScheme(), + ResidueColourScheme.NONE); + } catch (IOException e) + { + e.printStackTrace(); + } + } + @Test(groups = { "Functional" }) public void isShowSeqFeaturesSet() { @@ -509,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(), + 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); + } }