From: tcofoegbu Date: Tue, 25 Apr 2017 14:14:29 +0000 (+0100) Subject: JAL-2489 Unit test for bug X-Git-Tag: Release_2_10_2~3^2~126 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=169e40289232178ce2b1a379212c17ff69e3654c;p=jalview.git JAL-2489 Unit test for bug --- diff --git a/test/jalview/io/JSONFileTest.java b/test/jalview/io/JSONFileTest.java index a8611cc..c98e99e 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.getHiddenColumns().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 Null + */ + 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(),