+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
package jalview.io;
-
import static org.testng.AssertJUnit.assertNotNull;
import jalview.api.AlignExportSettingI;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
import jalview.gui.AlignFrame;
+import jalview.gui.JvOptionPane;
+import jalview.json.binding.biojson.v1.ColourSchemeMapper;
import jalview.schemes.ColourSchemeI;
-import jalview.schemes.ZappoColourScheme;
+import jalview.schemes.ResidueColourScheme;
import java.io.IOException;
import java.util.ArrayList;
import org.testng.Assert;
import org.testng.AssertJUnit;
import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class JSONFileTest
{
+ @BeforeClass(alwaysRun = true)
+ public void setUpJvOptionPane()
+ {
+ JvOptionPane.setInteractiveMode(false);
+ JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
+ }
+
private int TEST_SEQ_HEIGHT = 0;
private int TEST_GRP_HEIGHT = 0;
private JSONFile jf;
+ private AlignExportSettingI exportSettings;
+
@BeforeTest(alwaysRun = true)
public void setup() throws Exception
{
seqs[3].addSequenceFeature(seqFeature3);
seqs[4].addSequenceFeature(seqFeature4);
-
for (Sequence seq : seqs)
{
- seq.setDatasetSequence(seq);
+ seq.createDatasetSequence();
expectedSeqs.put(seq.getName(), seq);
}
grpSeqs.add(seqs[2]);
grpSeqs.add(seqs[3]);
grpSeqs.add(seqs[4]);
- ColourSchemeI scheme = JSONFile.getJalviewColorScheme("zappo");
SequenceGroup seqGrp = new SequenceGroup(grpSeqs, "JGroup:1883305585",
- scheme, true, true, false, 21, 29);
+ null, true, true, false, 21, 29);
+ ColourSchemeI scheme = ColourSchemeMapper.getJalviewColourScheme(
+ "zappo", seqGrp);
+ seqGrp.cs.setColourScheme(scheme);
seqGrp.setShowNonconserved(false);
seqGrp.setDescription(null);
TEST_ANOT_HEIGHT = expectedAnnots.size();
TEST_CS_HEIGHT = expectedColSel.getHiddenColumns().size();
- AlignExportSettingI exportSettings = new AlignExportSettingI()
+ exportSettings = new AlignExportSettingI()
{
@Override
public boolean isExportHiddenSequences()
{
return true;
}
+
+ @Override
+ public boolean isCancelled()
+ {
+ return false;
+ }
};
AppletFormatAdapter formatAdapter = new AppletFormatAdapter();
try
{
alignment = (Alignment) formatAdapter.readFile(TEST_JSON_FILE,
- AppletFormatAdapter.FILE, JSONFile.FILE_DESC);
+ DataSourceType.FILE, FileFormat.Json);
jf = (JSONFile) formatAdapter.getAlignFile();
AlignFrame af = new AlignFrame(alignment, jf.getHiddenSequences(),
jf.getColumnSelection(), AlignFrame.DEFAULT_WIDTH,
AlignFrame.DEFAULT_HEIGHT);
af.getViewport().setShowSequenceFeatures(jf.isShowSeqFeatures());
- af.changeColour(jf.getColourScheme());
+ String colourSchemeName = jf.getGlobalColourScheme();
+ ColourSchemeI cs = ColourSchemeMapper.getJalviewColourScheme(
+ colourSchemeName, alignment);
+ af.changeColour(cs);
af.getViewport().setFeaturesDisplayed(jf.getDisplayedFeatures());
-
formatAdapter = new AppletFormatAdapter(af.alignPanel, exportSettings);
- String jsonOutput = formatAdapter.formatSequences(JSONFile.FILE_DESC,
+ String jsonOutput = formatAdapter.formatSequences(FileFormat.Json,
af.alignPanel.getAlignment(), false);
formatAdapter = new AppletFormatAdapter();
testAlignment = formatAdapter.readFile(jsonOutput,
- AppletFormatAdapter.PASTE, JSONFile.FILE_DESC);
+ DataSourceType.PASTE, FileFormat.Json);
testJsonFile = (JSONFile) formatAdapter.getAlignFile();
// System.out.println(jsonOutput);
} catch (IOException e)
}
- @BeforeMethod(alwaysRun = true)
+ @BeforeMethod(alwaysRun = true)
public void methodSetup()
{
passedCount = 0;
}
- @AfterTest
+ @AfterTest(alwaysRun = true)
public void tearDown() throws Exception
{
testJsonFile = null;
jf = null;
}
- @Test(groups ={ "Functional" })
+ @Test(groups = { "Functional" })
public void roundTripTest()
{
assertNotNull("JSON roundtrip test failed!", testJsonFile);
}
- @Test(groups ={ "Functional" })
+ @Test(groups = { "Functional" })
public void testSeqParsed()
{
assertNotNull("Couldn't read supplied alignment data.", testAlignment);
AssertJUnit.assertEquals("Some Sequences did not pass the test",
TEST_SEQ_HEIGHT, passedCount);
}
-
- @Test(groups ={ "Functional" })
+
+ @Test(groups = { "Functional" })
public void hiddenColsTest()
{
ColumnSelection cs = testJsonFile.getColumnSelection();
Assert.assertNotNull(cs.getHiddenColumns());
List<int[]> hiddenCols = cs.getHiddenColumns();
Assert.assertEquals(hiddenCols.size(), TEST_CS_HEIGHT);
- Assert.assertEquals(hiddenCols, expectedColSel.getHiddenColumns(),
+ Assert.assertEquals(hiddenCols.get(0), expectedColSel
+ .getHiddenColumns().get(0),
"Mismatched hidden columns!");
}
- @Test(groups ={ "Functional" })
+ @Test(groups = { "Functional" })
public void hiddenSeqsTest()
{
Assert.assertNotNull(testJsonFile.getHiddenSequences(),
"Hidden sequence Expected but found Null");
Assert.assertEquals(jf.getHiddenSequences().length, 1,
- "Hidden sequece");
+ "Hidden sequence");
}
- @Test(groups ={ "Functional" })
+ @Test(groups = { "Functional" })
public void colorSchemeTest()
{
- Assert.assertNotNull(testJsonFile.getColourScheme(),
+ Assert.assertNotNull(testJsonFile.getGlobalColourScheme(),
"Colourscheme is null, parsing failed!");
- Assert.assertTrue(
- testJsonFile.getColourScheme() instanceof ZappoColourScheme,
+ Assert.assertEquals(testJsonFile.getGlobalColourScheme(), "Zappo",
"Zappo colour scheme expected!");
}
- @Test(groups ={ "Functional" })
+ @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(),
"Sequence feature isDisplayed setting expected to be true");
}
- @Test(groups ={ "Functional" })
+ @Test(groups = { "Functional" })
public void testGrpParsed()
{
Assert.assertNotNull(testAlignment.getGroups());
TEST_GRP_HEIGHT, passedCount);
}
- @Test(groups ={ "Functional" })
+ @Test(groups = { "Functional" })
public void testAnnotationParsed()
{
Assert.assertNotNull(testAlignment.getAlignmentAnnotation());
+ actualGrp.getStartRes());
System.out.println(expectedGrp.getEndRes() + " | "
+ actualGrp.getEndRes());
+ System.out.println(expectedGrp.cs + " | " + actualGrp.cs);
if (expectedGrp.getName().equals(actualGrp.getName())
&& expectedGrp.getColourText() == actualGrp.getColourText()
&& expectedGrp.getDisplayBoxes() == actualGrp.getDisplayBoxes()
&& expectedGrp.getIgnoreGapsConsensus() == actualGrp
.getIgnoreGapsConsensus()
- && expectedGrp.cs.equals(actualGrp.cs)
+ && (expectedGrp.cs.getClass().equals(actualGrp.cs.getClass()))
&& expectedGrp.getSequences().size() == actualGrp
.getSequences().size()
&& expectedGrp.getStartRes() == actualGrp.getStartRes()