X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=test%2Fjalview%2Fio%2FJSONFileTest.java;fp=test%2Fjalview%2Fio%2FJSONFileTest.java;h=108122306f535708aa0c56d9c067471b7ac308ec;hb=bd2190024b6988cc7a371e932ef5c46de0d9df3b;hp=191709726accd57e0d0e417468d205a2bce48759;hpb=d4c27a996e22436dd4c4d8f64f6341d5315ff621;p=jalview.git diff --git a/test/jalview/io/JSONFileTest.java b/test/jalview/io/JSONFileTest.java index 1917097..1081223 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 { @@ -193,7 +196,7 @@ public class JSONFileTest TEST_ANOT_HEIGHT = expectedAnnots.size(); TEST_CS_HEIGHT = expectedColSel.getHiddenRegions().size(); - AlignExportSettingI exportSettings = new AlignExportSettingI() + exportSettings = new AlignExportSettingI() { @Override public boolean isExportHiddenSequences() @@ -338,6 +341,50 @@ public class JSONFileTest } @Test(groups = { "Functional" }) + /** + * Test for bug JAL-2489, NPE when exporting BioJSON with global colour scheme set as 'None' + */ + public void testBioJSONRoundTripWithGlobalColourSchemeSetAsNone() + { + 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.getColumnSelection(), AlignFrame.DEFAULT_WIDTH, + AlignFrame.DEFAULT_HEIGHT); + // Change colour scheme to 'None' and perform round trip + 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() { Assert.assertTrue(testJsonFile.isShowSeqFeatures(),