X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fio%2FJalview2xmlTests.java;h=52cee59d463e7e921638801065b0e211b98cdbc7;hb=df817465af924ee456d3fd7508cde5acd3512f34;hp=e294616a25727a781d440d606b2cc363a4967a1c;hpb=be1777c33711ef0c9f1014ad6d47c7c2021b2526;p=jalview.git diff --git a/test/jalview/io/Jalview2xmlTests.java b/test/jalview/io/Jalview2xmlTests.java index e294616..52cee59 100644 --- a/test/jalview/io/Jalview2xmlTests.java +++ b/test/jalview/io/Jalview2xmlTests.java @@ -1,29 +1,62 @@ +/* + * 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 . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.io; -import static org.junit.Assert.*; +import static org.testng.AssertJUnit.assertFalse; +import static org.testng.AssertJUnit.assertTrue; + +import jalview.api.AlignmentViewPanel; +import jalview.api.ViewStyleI; +import jalview.bin.Cache; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.gui.AlignFrame; +import jalview.gui.Desktop; +import jalview.gui.Jalview2XML; import jalview.schemes.AnnotationColourGradient; import jalview.schemes.ColourSchemeI; import java.io.File; +import java.util.HashMap; +import java.util.Map; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.testng.Assert; +import org.testng.AssertJUnit; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +@Test(singleThreaded = true) public class Jalview2xmlTests { /** * @throws java.lang.Exception */ - @BeforeClass + @BeforeClass(alwaysRun = true) public static void setUpBeforeClass() throws Exception { - jalview.bin.Jalview.main(new String[] {"-props","test/src/jalview/io/testProps.jvprops"}); + jalview.bin.Jalview.main(new String[] { "-props", + "test/jalview/io/testProps.jvprops" }); } /** @@ -33,12 +66,14 @@ public class Jalview2xmlTests public static void tearDownAfterClass() throws Exception { jalview.gui.Desktop.instance.closeAll_actionPerformed(null); - + } + public int countDsAnn(jalview.viewmodel.AlignmentViewport avp) { - int numdsann=0; - for (SequenceI sq: avp.getAlignment().getDataset().getSequences()) { + int numdsann = 0; + for (SequenceI sq : avp.getAlignment().getDataset().getSequences()) + { if (sq.getAnnotation() != null) { for (AlignmentAnnotation dssa : sq.getAnnotation()) @@ -52,35 +87,52 @@ public class Jalview2xmlTests } return numdsann; } - @Test + + @Test(groups = { "Functional" }) public void testRNAStructureRecovery() throws Exception { String inFile = "examples/RF00031_folded.stk"; - String tfile = File.createTempFile("JalviewTest", ".jvp").getAbsolutePath(); - AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(inFile, FormatAdapter.FILE); - assertTrue("Didn't read input file "+inFile, af!=null); - int olddsann=countDsAnn(af.getViewport()); - assertTrue("Didn't find any dataset annotations",olddsann>0); + String tfile = File.createTempFile("JalviewTest", ".jvp") + .getAbsolutePath(); + AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded( + inFile, FormatAdapter.FILE); + assertTrue("Didn't read input file " + inFile, af != null); + int olddsann = countDsAnn(af.getViewport()); + assertTrue("Didn't find any dataset annotations", olddsann > 0); af.rnahelicesColour_actionPerformed(null); - assertTrue("Couldn't apply RNA helices colourscheme",af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour); - assertTrue("Failed to store as a project.",af.saveAlignment(tfile, "Jalview")); + assertTrue( + "Couldn't apply RNA helices colourscheme", + af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour); + assertTrue("Failed to store as a project.", + af.saveAlignment(tfile, "Jalview")); af.closeMenuItem_actionPerformed(true); - af=null; - af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile, FormatAdapter.FILE); - assertTrue("Failed to import new project", af!=null); - int newdsann=countDsAnn(af.getViewport()); - assertTrue("Differing numbers of dataset sequence annotation\nOriginally "+olddsann+" and now "+newdsann,olddsann==newdsann); - System.out.println("Read in same number of annotations as originally present ("+olddsann+")"); - assertTrue("RNA helices colourscheme was not applied on import.",af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour); + af = null; + af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile, + FormatAdapter.FILE); + assertTrue("Failed to import new project", af != null); + int newdsann = countDsAnn(af.getViewport()); + assertTrue( + "Differing numbers of dataset sequence annotation\nOriginally " + + olddsann + " and now " + newdsann, + olddsann == newdsann); + System.out + .println("Read in same number of annotations as originally present (" + + olddsann + ")"); + assertTrue( + "RNA helices colourscheme was not applied on import.", + af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour); } - @Test + + @Test(groups = { "Functional" }) public void testTCoffeeScores() throws Exception { - String inFile = "examples/uniref50.fa",inAnnot="examples/uniref50.score_ascii"; - String tfile = File.createTempFile("JalviewTest", ".jvp").getAbsolutePath(); - AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(inFile, FormatAdapter.FILE); - assertTrue("Didn't read input file "+inFile, af!=null); - af.loadJalviewDataFile(inAnnot, FormatAdapter.FILE, null,null); + String inFile = "examples/uniref50.fa", inAnnot = "examples/uniref50.score_ascii"; + String tfile = File.createTempFile("JalviewTest", ".jvp") + .getAbsolutePath(); + AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded( + inFile, FormatAdapter.FILE); + assertTrue("Didn't read input file " + inFile, af != null); + af.loadJalviewDataFile(inAnnot, FormatAdapter.FILE, null, null); assertTrue( "Didn't set T-coffee colourscheme", af.getViewport().getGlobalColourScheme().getClass() @@ -92,26 +144,40 @@ public class Jalview2xmlTests jalview.schemes.ColourSchemeProperty.getColourName(af .getViewport().getGlobalColourScheme())) != null); - assertTrue("Failed to store as a project.",af.saveAlignment(tfile, "Jalview")); + assertTrue("Failed to store as a project.", + af.saveAlignment(tfile, "Jalview")); af.closeMenuItem_actionPerformed(true); - af=null; - af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile, FormatAdapter.FILE); - assertTrue("Failed to import new project", af!=null); - assertTrue("Didn't set T-coffee colourscheme for imported project.",af.getViewport().getGlobalColourScheme().getClass().equals(jalview.schemes.TCoffeeColourScheme.class)); - System.out.println("T-Coffee score shading successfully recovered from project."); + af = null; + af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile, + FormatAdapter.FILE); + assertTrue("Failed to import new project", af != null); + assertTrue( + "Didn't set T-coffee colourscheme for imported project.", + af.getViewport().getGlobalColourScheme().getClass() + .equals(jalview.schemes.TCoffeeColourScheme.class)); + System.out + .println("T-Coffee score shading successfully recovered from project."); } - @Test + + @Test(groups = { "Functional" }) public void testColourByAnnotScores() throws Exception { - String inFile = "examples/uniref50.fa",inAnnot="examples/testdata/uniref50_iupred.jva"; - String tfile = File.createTempFile("JalviewTest", ".jvp").getAbsolutePath(); - AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(inFile, FormatAdapter.FILE); - assertTrue("Didn't read input file "+inFile, af!=null); - af.loadJalviewDataFile(inAnnot, FormatAdapter.FILE, null,null); - AlignmentAnnotation[] aa = af.getViewport().getAlignment().getSequenceAt(0).getAnnotation("IUPredWS (Short)"); - assertTrue("Didn't find any IUPred annotation to use to shade alignment.",aa!=null && aa.length>0); - AnnotationColourGradient cs = new jalview.schemes.AnnotationColourGradient(aa[0], null, AnnotationColourGradient.ABOVE_THRESHOLD); - AnnotationColourGradient gcs = new jalview.schemes.AnnotationColourGradient(aa[0], null, AnnotationColourGradient.BELOW_THRESHOLD); + String inFile = "examples/uniref50.fa", inAnnot = "examples/testdata/uniref50_iupred.jva"; + String tfile = File.createTempFile("JalviewTest", ".jvp") + .getAbsolutePath(); + AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded( + inFile, FormatAdapter.FILE); + assertTrue("Didn't read input file " + inFile, af != null); + af.loadJalviewDataFile(inAnnot, FormatAdapter.FILE, null, null); + AlignmentAnnotation[] aa = af.getViewport().getAlignment() + .getSequenceAt(0).getAnnotation("IUPredWS (Short)"); + assertTrue( + "Didn't find any IUPred annotation to use to shade alignment.", + aa != null && aa.length > 0); + AnnotationColourGradient cs = new jalview.schemes.AnnotationColourGradient( + aa[0], null, AnnotationColourGradient.ABOVE_THRESHOLD); + AnnotationColourGradient gcs = new jalview.schemes.AnnotationColourGradient( + aa[0], null, AnnotationColourGradient.BELOW_THRESHOLD); cs.setSeqAssociated(true); gcs.setSeqAssociated(true); af.changeColour(cs); @@ -123,47 +189,355 @@ public class Jalview2xmlTests sg.addSequence(af.getViewport().getAlignment().getSequenceAt(1), false); sg.addSequence(af.getViewport().getAlignment().getSequenceAt(2), true); af.alignPanel.alignmentChanged(); - assertTrue("Failed to store as a project.",af.saveAlignment(tfile, "Jalview")); + assertTrue("Failed to store as a project.", + af.saveAlignment(tfile, "Jalview")); af.closeMenuItem_actionPerformed(true); - af=null; - af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile, FormatAdapter.FILE); - assertTrue("Failed to import new project", af!=null); - + af = null; + af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile, + FormatAdapter.FILE); + assertTrue("Failed to import new project", af != null); + // check for group and alignment colourschemes - - ColourSchemeI _rcs=af.getViewport().getGlobalColourScheme(); - ColourSchemeI _rgcs=af.getViewport().getAlignment().getGroups().get(0).cs; - assertTrue("Didn't recover global colourscheme",_rcs!=null); - assertTrue("Didn't recover annotation colour global scheme",_rcs instanceof AnnotationColourGradient); + + ColourSchemeI _rcs = af.getViewport().getGlobalColourScheme(); + ColourSchemeI _rgcs = af.getViewport().getAlignment().getGroups() + .get(0).cs; + assertTrue("Didn't recover global colourscheme", _rcs != null); + assertTrue("Didn't recover annotation colour global scheme", + _rcs instanceof AnnotationColourGradient); AnnotationColourGradient __rcs = (AnnotationColourGradient) _rcs; - assertTrue("Annotation colourscheme wasn't sequence associated",__rcs.isSeqAssociated()); + assertTrue("Annotation colourscheme wasn't sequence associated", + __rcs.isSeqAssociated()); - - boolean diffseqcols=false,diffgseqcols=false; - SequenceI[] sqs=af.getViewport().getAlignment().getSequencesArray(); - for (int p=0,pSize=af.getViewport().getAlignment().getWidth();p refs = new HashMap(); + int n = 1; + for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid)) + { + // mark representative + SequenceI rep = ap.getAlignment().getSequenceAt( + n++ % ap.getAlignment().getHeight()); + refs.put(ap.getViewName(), rep); + // code from mark/unmark sequence as reference in jalview.gui.PopupMenu + // todo refactor the to an alignment view controller + ap.getAlignViewport().setDisplayReferenceSeq(true); + ap.getAlignViewport().setColourByReferenceSeq(true); + ap.getAlignViewport().getAlignment().setSeqrep(rep); + } + File tfile = File.createTempFile("testStoreAndRecoverReferenceSeq", + ".jvp"); + try + { + new Jalview2XML(false).saveState(tfile); + } catch (Error e) + { + Assert.fail("Didn't save the expanded view state", e); + } catch (Exception e) + { + Assert.fail("Didn't save the expanded view state", e); + } + Desktop.instance.closeAll_actionPerformed(null); + if (Desktop.getAlignFrames() != null) + { + Assert.assertEquals(Desktop.getAlignFrames().length, 0); + } + { + AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded( + tfile.getAbsolutePath(), FormatAdapter.FILE); + afid = af.getViewport().getSequenceSetId(); + } + for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid)) + { + // check representative + SequenceI rep = ap.getAlignment().getSeqrep(); + Assert.assertNotNull(rep, + "Couldn't restore sequence representative from project"); + // can't use a strong equals here, because by definition, the sequence IDs + // will be different. + // could set vamsas session save/restore flag to preserve IDs across + // load/saves. + Assert.assertEquals(refs.get(ap.getViewName()).toString(), + rep.toString(), + "Representative wasn't the same when recovered."); + Assert.assertTrue(ap.getAlignViewport().isDisplayReferenceSeq(), + "Display reference sequence view setting not set."); + Assert.assertTrue(ap.getAlignViewport().isColourByReferenceSeq(), + "Colour By Reference Seq view setting not set."); + } + } + + @Test(groups = { "Functional" }) + public void testIsVersionStringLaterThan() + { + /* + * No version / development / test / autobuild is leniently assumed to be + * compatible + */ + assertTrue(Jalview2XML.isVersionStringLaterThan(null, null)); + assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", null)); + assertTrue(Jalview2XML.isVersionStringLaterThan(null, "2.8.3")); + assertTrue(Jalview2XML.isVersionStringLaterThan(null, + "Development Build")); + assertTrue(Jalview2XML.isVersionStringLaterThan(null, + "DEVELOPMENT BUILD")); + assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", + "Development Build")); + assertTrue(Jalview2XML.isVersionStringLaterThan(null, "Test")); + assertTrue(Jalview2XML.isVersionStringLaterThan(null, "TEST")); + assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "Test")); + assertTrue(Jalview2XML + .isVersionStringLaterThan(null, "Automated Build")); + assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", + "Automated Build")); + assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", + "AUTOMATED BUILD")); + + /* + * same version returns true i.e. compatible + */ + assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8")); + assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3")); + assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3b1")); + assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3B1", "2.8.3b1")); + assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3B1")); + + /* + * later version returns true + */ + assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.4")); + assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9")); + assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.9.2")); + assertTrue(Jalview2XML.isVersionStringLaterThan("2.8", "2.8.3")); + assertTrue(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.3b1")); + + /* + * earlier version returns false + */ + assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8")); + assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.4", "2.8.3")); + assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3b1", "2.8.3")); + assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.3", "2.8.2b1")); + assertFalse(Jalview2XML.isVersionStringLaterThan("2.8.0b2", "2.8.0b1")); } }