X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fproject%2FJalview2xmlTests.java;h=a0f1f6d4190e227d3f89a4919359123ef227504c;hb=716b7ed46ecee85d5a5ced3e2c0cf65523b278ae;hp=f0fc3fd639c79a7f8dfaa713a10920411d75eb7b;hpb=bd75c84346a9d63341d2cf3826ce99a2b37bcace;p=jalview.git diff --git a/test/jalview/project/Jalview2xmlTests.java b/test/jalview/project/Jalview2xmlTests.java index f0fc3fd..a0f1f6d 100644 --- a/test/jalview/project/Jalview2xmlTests.java +++ b/test/jalview/project/Jalview2xmlTests.java @@ -27,6 +27,7 @@ import static org.testng.Assert.assertNull; import static org.testng.Assert.assertSame; import static org.testng.Assert.assertTrue; +import jalview.analysis.scoremodels.SimilarityParams; import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.api.FeatureColourI; @@ -49,6 +50,7 @@ import jalview.gui.AlignmentPanel; import jalview.gui.Desktop; import jalview.gui.FeatureRenderer; import jalview.gui.JvOptionPane; +import jalview.gui.PCAPanel; import jalview.gui.PopupMenu; import jalview.gui.SliderPanel; import jalview.io.DataSourceType; @@ -77,6 +79,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.swing.JInternalFrame; + import org.testng.Assert; import org.testng.AssertJUnit; import org.testng.annotations.BeforeClass; @@ -1038,4 +1042,120 @@ public class Jalview2xmlTests extends Jalview2xmlBase addFeature(seq, featureType, score++); addFeature(seq, featureType, score); } + + /** + * pre 2.11 - jalview 2.10 erroneously created new dataset entries for each + * view (JAL-3171) this test ensures we can import and merge those views + */ + @Test(groups = { "Functional" }) + public void testMergeDatasetsforViews() throws IOException + { + // simple project - two views on one alignment + AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded( + "examples/testdata/projects/twoViews.jvp", DataSourceType.FILE); + assertNotNull(af); + assertTrue(af.getAlignPanels().size() > 1); + verifyDs(af); + } + + /** + * pre 2.11 - jalview 2.10 erroneously created new dataset entries for each + * view (JAL-3171) this test ensures we can import and merge those views This + * is a more complex project + */ + @Test(groups = { "Functional" }) + public void testMergeDatasetsforManyViews() throws IOException + { + Desktop.instance.closeAll_actionPerformed(null); + + // complex project - one dataset, several views on several alignments + AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded( + "examples/testdata/projects/manyViews.jvp", + DataSourceType.FILE); + assertNotNull(af); + + AlignmentI ds = null; + for (AlignFrame alignFrame : Desktop.getAlignFrames()) + { + if (ds == null) + { + ds = verifyDs(alignFrame); + } + else + { + // check that this frame's dataset matches the last + assertTrue(ds == verifyDs(alignFrame)); + } + } + } + + private AlignmentI verifyDs(AlignFrame af) + { + AlignmentI ds = null; + for (AlignmentViewPanel ap : af.getAlignPanels()) + { + if (ds == null) + { + ds = ap.getAlignment().getDataset(); + } + else + { + assertTrue(ap.getAlignment().getDataset() == ds, + "Dataset was not the same for imported 2.10.5 project with several alignment views"); + } + } + return ds; + } + + @Test(groups = "Functional") + public void testPcaViewAssociation() throws IOException + { + Desktop.instance.closeAll_actionPerformed(null); + final String PCAVIEWNAME = "With PCA"; + // create a new tempfile + File tempfile = File.createTempFile("jvPCAviewAssoc", "jvp"); + + { + String exampleFile = "examples/uniref50.fa"; + AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(exampleFile, + DataSourceType.FILE); + assertNotNull(af, "Didn't read in the example file correctly."); + AlignmentPanel newview = af.newView(PCAVIEWNAME, true); + // create another for good measure + af.newView("Not the PCA View", true); + PCAPanel pcaPanel = new PCAPanel(newview, "BLOSUM62", + new SimilarityParams(true, true, true, false)); + + // we're in the test exec thread, so we can just run synchronously here + pcaPanel.run(); + + assertTrue(pcaPanel.getAlignViewport() == newview.getAlignViewport(), + "PCA should be associated with 'With PCA' view: test is broken"); + + // now save and reload project + Jalview2XML jv2xml = new jalview.project.Jalview2XML(false); + tempfile.delete(); + jv2xml.saveState(tempfile); + assertTrue(jv2xml.errorMessage == null, + "Failed to save dummy project with PCA: test broken"); + } + + // load again. + Desktop.instance.closeAll_actionPerformed(null); + AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( + tempfile.getCanonicalPath(), DataSourceType.FILE); + JInternalFrame[] frames = Desktop.instance.getAllFrames(); + // PCA and the tabbed alignment view should be the only two windows on the + // desktop + assertEquals(frames.length, 2, + "PCA and the tabbed alignment view should be the only two windows on the desktop"); + PCAPanel pcaPanel = (PCAPanel) frames[frames[0] == af ? 1 : 0]; + + AlignmentViewPanel restoredNewView = af.getAlignPanels().get(1); + assertEquals(restoredNewView.getViewName(), PCAVIEWNAME); + assertTrue( + restoredNewView.getAlignViewport() == pcaPanel + .getAlignViewport(), + "Didn't restore correct view association for the PCA view"); + } }