From: gmungoc Date: Thu, 21 Nov 2019 16:37:49 +0000 (+0000) Subject: JAL-3484 unit test for restoring two views' annotation ordering X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=9e66ffdd391a2467fd6821abf9f8f0ca66e5a18d;p=jalview.git JAL-3484 unit test for restoring two views' annotation ordering --- diff --git a/test/jalview/project/Jalview2xmlTests.java b/test/jalview/project/Jalview2xmlTests.java index 3e7279c..d08ae7d 100644 --- a/test/jalview/project/Jalview2xmlTests.java +++ b/test/jalview/project/Jalview2xmlTests.java @@ -23,6 +23,7 @@ package jalview.project; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNotSame; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertSame; import static org.testng.Assert.assertTrue; @@ -72,6 +73,7 @@ import jalview.schemes.TCoffeeColourScheme; import jalview.structure.StructureImportSettings; import jalview.util.matcher.Condition; import jalview.viewmodel.AlignmentViewport; +import jalview.viewmodel.AlignmentViewport.AutoAnnotation; import java.awt.Color; import java.io.File; @@ -1183,7 +1185,8 @@ public class Jalview2xmlTests extends Jalview2xmlBase } /** - * Test that annotation ordering is faithfully restored + * Tests that annotation ordering is faithfully restored, on project reload or + * New View, even if preference settings have changed * * @throws Exception */ @@ -1289,34 +1292,106 @@ public class Jalview2xmlTests extends Jalview2xmlBase newPanel.closePanel(); /* - * reload the project with Preferences set to not create Occupancy; - * this should still appear, as it is in the saved project + * reload the project with Preferences set to not create Occupancy, but to + * create Quality; annotations should still appear as saved in the project; + * preferences should be left unchanged (after temporary override) */ Desktop.instance.closeAll_actionPerformed(null); Cache.setProperty("SHOW_OCCUPANCY", "false"); + Cache.removeProperty("SHOW_QUALITY"); // will default to true + Map originalPreferences = Cache.getProperties( + AutoAnnotation.OCCUPANCY.preferenceKey, + AutoAnnotation.CONSERVATION.preferenceKey, + AutoAnnotation.QUALITY.preferenceKey, + AutoAnnotation.CONSENSUS.preferenceKey); af = new FileLoader().LoadFileWaitTillLoaded( projectFile.getAbsolutePath(), DataSourceType.FILE); - anns = af.getViewport().getAlignment().getAlignmentAnnotation(); + alignment = af.getViewport().getAlignment(); + anns = alignment.getAlignmentAnnotation(); assertEquals(anns.length, 4); assertEquals(anns[0].label, "Occupancy"); assertEquals(anns[1].label, "hello"); assertEquals(anns[2].label, "Conservation"); assertEquals(anns[3].label, "world"); + Map newPreferences = Cache.getProperties( + AutoAnnotation.OCCUPANCY.preferenceKey, + AutoAnnotation.CONSERVATION.preferenceKey, + AutoAnnotation.QUALITY.preferenceKey, + AutoAnnotation.CONSENSUS.preferenceKey); + assertEquals(originalPreferences, newPreferences); + assertNull(Cache.getProperty(AutoAnnotation.QUALITY.preferenceKey)); + + /* + * make a new view, reorder its annotations, and delete and hide + * a different annotation in each of the two views + */ + newPanel = af.newView("new", true); + af.getViewport().setViewName("Original"); + + /* + * just for interest - new view has the same manual annotation objects, + * but new auto-calculated annotations + */ + AlignmentI newAlignment = newPanel.getAlignment(); + newAnns = newAlignment.getAlignmentAnnotation(); + assertNotSame(anns[0], newAnns[0]); + assertSame(anns[1], newAnns[1]); + assertNotSame(anns[2], newAnns[2]); + assertSame(anns[3], newAnns[3]); + + alignment.deleteAnnotation(anns[2]); // delete Conservation view 1 + anns[1].visible = false; // hide 'hello' view 1 + + tmp = newAnns[0]; + newAnns[0] = newAnns[3]; // 'world' moved to top of new view + newAnns[3] = tmp; // then hello, Conservation, Occupancy + newAnns[0].visible = false; // hide 'world' in new view + newAnns[3].graphHeight = 99; // set height of Occupancy + newAlignment.deleteAnnotation(newAnns[1]); // delete 'hello' in new view /* - * reload the project with Preferences set to create Quality annotation; - * this should not appear, as it is not in the saved project + * save, reload and verify annotations in both views */ + ((AlignViewport) newPanel.getAlignViewport()).setViewName("New View"); + projectFile = File.createTempFile("jvTest", ".jvp"); + new Jalview2XML(false).saveState(projectFile); Desktop.instance.closeAll_actionPerformed(null); - Cache.setProperty("SHOW_OCCUPANCY", "false"); - Cache.setProperty("SHOW_QUALITY", "true"); af = new FileLoader().LoadFileWaitTillLoaded( projectFile.getAbsolutePath(), DataSourceType.FILE); - anns = af.getViewport().getAlignment().getAlignmentAnnotation(); - assertEquals(anns.length, 4); + assertEquals(af.getAlignPanels().size(), 2); + + /* + * check first view + */ + AlignViewportI firstViewport = af.getAlignPanels().get(0) + .getAlignViewport(); + assertEquals(((AlignViewport) firstViewport).getViewName(), "Original"); + alignment = firstViewport.getAlignment(); + anns = alignment.getAlignmentAnnotation(); + assertEquals(anns.length, 3); assertEquals(anns[0].label, "Occupancy"); assertEquals(anns[1].label, "hello"); - assertEquals(anns[2].label, "Conservation"); - assertEquals(anns[3].label, "world"); + assertEquals(anns[2].label, "world"); + assertFalse(anns[0].visible); + assertFalse(anns[1].visible); + assertFalse(anns[2].visible); + + /* + * check second view + */ + AlignViewportI secondViewport = af.getAlignPanels().get(1) + .getAlignViewport(); + assertEquals(((AlignViewport) secondViewport).getViewName(), + "New View"); + alignment = secondViewport.getAlignment(); + anns = alignment.getAlignmentAnnotation(); + assertEquals(anns.length, 3); + assertEquals(anns[0].label, "world"); + assertEquals(anns[1].label, "Conservation"); + assertEquals(anns[2].label, "Occupancy"); + assertFalse(anns[0].visible); + assertTrue(anns[1].visible); + assertFalse(anns[2].visible); + assertEquals(anns[2].graphHeight, 99); } }