X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fstructure%2FStructureSelectionManagerTest.java;h=3cbdbad37d46d5f59a3d5c04ed9eebd05e8aef25;hb=e81459b192f4d635c1cd96befa7b14992d12ee5e;hp=e3612a5425baddb9c8669bbb5100e18196ea4f45;hpb=28fda83cbef0c9c82cd09a343af4e1721085c104;p=jalview.git diff --git a/test/jalview/structure/StructureSelectionManagerTest.java b/test/jalview/structure/StructureSelectionManagerTest.java index e3612a5..3cbdbad 100644 --- a/test/jalview/structure/StructureSelectionManagerTest.java +++ b/test/jalview/structure/StructureSelectionManagerTest.java @@ -1,13 +1,20 @@ package jalview.structure; import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertNotNull; import static org.testng.AssertJUnit.assertTrue; import jalview.datamodel.AlignedCodonFrame; +import jalview.gui.AlignFrame; +import jalview.gui.Desktop; +import jalview.io.FileLoader; +import jalview.io.FormatAdapter; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Set; +import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -15,6 +22,13 @@ public class StructureSelectionManagerTest { private StructureSelectionManager ssm; + @BeforeClass(alwaysRun = true) + public static void setUpBeforeClass() throws Exception + { + jalview.bin.Jalview.main(new String[] { "-props", + "test/jalview/testProps.jvprops" }); + } + @BeforeMethod(alwaysRun = true) public void setUp() { @@ -22,45 +36,31 @@ public class StructureSelectionManagerTest } @Test(groups ={ "Functional" }) - public void testAddMapping() + public void testRegisterMapping() { AlignedCodonFrame acf1 = new AlignedCodonFrame(); AlignedCodonFrame acf2 = new AlignedCodonFrame(); - /* - * One mapping only. - */ - ssm.addMapping(acf1); + ssm.registerMapping(acf1); assertEquals(1, ssm.seqmappings.size()); assertTrue(ssm.seqmappings.contains(acf1)); - assertEquals(1, ssm.seqMappingRefCounts.size()); - assertEquals(1, ssm.seqMappingRefCounts.get(acf1).intValue()); - /* - * A second mapping. - */ - ssm.addMapping(acf2); + ssm.registerMapping(acf2); assertEquals(2, ssm.seqmappings.size()); assertTrue(ssm.seqmappings.contains(acf1)); assertTrue(ssm.seqmappings.contains(acf2)); - assertEquals(2, ssm.seqMappingRefCounts.size()); - assertEquals(1, ssm.seqMappingRefCounts.get(acf1).intValue()); - assertEquals(1, ssm.seqMappingRefCounts.get(acf2).intValue()); /* - * A second reference to the first mapping. + * Re-adding the first mapping does nothing */ - ssm.addMapping(acf1); + ssm.registerMapping(acf1); assertEquals(2, ssm.seqmappings.size()); assertTrue(ssm.seqmappings.contains(acf1)); assertTrue(ssm.seqmappings.contains(acf2)); - assertEquals(2, ssm.seqMappingRefCounts.size()); - assertEquals(2, ssm.seqMappingRefCounts.get(acf1).intValue()); - assertEquals(1, ssm.seqMappingRefCounts.get(acf2).intValue()); } @Test(groups ={ "Functional" }) - public void testAddMappings() + public void testRegisterMappings() { AlignedCodonFrame acf1 = new AlignedCodonFrame(); AlignedCodonFrame acf2 = new AlignedCodonFrame(); @@ -74,103 +74,123 @@ public class StructureSelectionManagerTest set2.add(acf3); /* - * Adding both sets adds acf2 twice and acf1 and acf3 once each. + * Add both sets twice; each mapping should be added once only */ - ssm.addMappings(set1); - ssm.addMappings(set2); + ssm.registerMappings(set1); + ssm.registerMappings(set1); + ssm.registerMappings(set2); + ssm.registerMappings(set2); assertEquals(3, ssm.seqmappings.size()); assertTrue(ssm.seqmappings.contains(acf1)); assertTrue(ssm.seqmappings.contains(acf2)); assertTrue(ssm.seqmappings.contains(acf3)); - assertEquals(3, ssm.seqMappingRefCounts.size()); - assertEquals(1, ssm.seqMappingRefCounts.get(acf1).intValue()); - assertEquals(2, ssm.seqMappingRefCounts.get(acf2).intValue()); - assertEquals(1, ssm.seqMappingRefCounts.get(acf3).intValue()); } + /** + * Test that a mapping is not deregistered if an alignment holds a reference + * to it + */ @Test(groups ={ "Functional" }) - public void testRemoveMapping() + public void testDeregisterMapping_withAlignmentReference() { + Desktop d = Desktop.instance; + assertNotNull(d); + + /* + * alignment with reference to mappings + */ + AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded( + ">Seq1\nCAGT\n", FormatAdapter.PASTE); + AlignedCodonFrame acf1 = new AlignedCodonFrame(); AlignedCodonFrame acf2 = new AlignedCodonFrame(); - ssm.addMapping(acf1); + + Set mappings = new LinkedHashSet(); + mappings.add(acf1); + mappings.add(acf2); + af1.getViewport().getAlignment().setCodonFrames(mappings); /* * Add one and remove it. */ - ssm.removeMapping(acf1); - ssm.removeMapping(acf2); - assertEquals(0, ssm.seqmappings.size()); - assertEquals(0, ssm.seqMappingRefCounts.size()); + ssm.registerMapping(acf1); + ssm.deregisterMapping(acf1); + assertEquals(1, ssm.seqmappings.size()); + assertTrue(ssm.seqmappings.contains(acf1)); + } + /** + * Test that a mapping is deregistered if no alignment holds a reference to it + */ + @Test(groups ={ "Functional" }) + public void testDeregisterMapping_withNoReference() + { + Desktop d = Desktop.instance; + assertNotNull(d); + /* - * Add one twice and remove it once. + * alignment with reference to mappings */ - ssm.addMapping(acf1); - ssm.addMapping(acf2); - ssm.addMapping(acf1); - ssm.removeMapping(acf1); - assertEquals(2, ssm.seqmappings.size()); - assertTrue(ssm.seqmappings.contains(acf1)); - assertTrue(ssm.seqmappings.contains(acf2)); - assertEquals(2, ssm.seqMappingRefCounts.size()); - assertEquals(1, ssm.seqMappingRefCounts.get(acf1).intValue()); - assertEquals(1, ssm.seqMappingRefCounts.get(acf2).intValue()); - + AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded( + ">Seq1\nCAGT\n", FormatAdapter.PASTE); + + AlignedCodonFrame acf1 = new AlignedCodonFrame(); + AlignedCodonFrame acf2 = new AlignedCodonFrame(); + + Set mappings = new LinkedHashSet(); + mappings.add(acf2); + af1.getViewport().getAlignment().setCodonFrames(mappings); + /* - * Remove both once more to clear the set. + * Add one and remove it. */ - ssm.removeMapping(acf1); - ssm.removeMapping(acf2); + ssm.registerMapping(acf1); + assertEquals(1, ssm.seqmappings.size()); + assertTrue(ssm.seqmappings.contains(acf1)); + ssm.deregisterMapping(acf1); assertEquals(0, ssm.seqmappings.size()); - assertEquals(0, ssm.seqMappingRefCounts.size()); } + /** + * Test that a mapping is not deregistered when a second view is closed but + * the first still holds a reference to the mapping + */ @Test(groups ={ "Functional" }) - public void testRemoveMappings() + public void testDeregisterMapping_onCloseView() { - AlignedCodonFrame acf1 = new AlignedCodonFrame(); - AlignedCodonFrame acf2 = new AlignedCodonFrame(); - AlignedCodonFrame acf3 = new AlignedCodonFrame(); - /* - * Initial ref counts are 3/2/1: + * alignment with reference to mappings */ - ssm.addMapping(acf1); - ssm.addMapping(acf1); - ssm.addMapping(acf1); - ssm.addMapping(acf2); - ssm.addMapping(acf2); - ssm.addMapping(acf3); - - Set set1 = new HashSet(); - set1.add(acf1); - set1.add(acf2); - Set set2 = new HashSet(); - set2.add(acf2); - set2.add(acf3); + AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded( + ">Seq1\nCAGT\n", FormatAdapter.PASTE); + + AlignedCodonFrame acf1 = new AlignedCodonFrame(); + AlignedCodonFrame acf2 = new AlignedCodonFrame(); + + Set mappings = new LinkedHashSet(); + mappings.add(acf1); + mappings.add(acf2); + af1.getViewport().getAlignment().setCodonFrames(mappings); + af1.newView_actionPerformed(null); /* - * Remove one ref each to acf1, acf2, counts are now 2/1/1: + * Verify that creating the alignment for the new View has registered the + * mappings */ - ssm.removeMappings(set1); - assertEquals(3, ssm.seqmappings.size()); + ssm = StructureSelectionManager + .getStructureSelectionManager(Desktop.instance); + assertEquals(2, ssm.seqmappings.size()); assertTrue(ssm.seqmappings.contains(acf1)); assertTrue(ssm.seqmappings.contains(acf2)); - assertTrue(ssm.seqmappings.contains(acf3)); - assertEquals(3, ssm.seqMappingRefCounts.size()); - assertEquals(2, ssm.seqMappingRefCounts.get(acf1).intValue()); - assertEquals(1, ssm.seqMappingRefCounts.get(acf2).intValue()); - assertEquals(1, ssm.seqMappingRefCounts.get(acf3).intValue()); /* - * Remove one ref each to acf2, acf3 - they are removed + * Close the second view. Verify that mappings are not removed as the first + * view still holds a reference to them. */ - ssm.removeMappings(set2); - assertEquals(1, ssm.seqmappings.size()); + af1.closeMenuItem_actionPerformed(false); + assertEquals(2, ssm.seqmappings.size()); assertTrue(ssm.seqmappings.contains(acf1)); - assertEquals(1, ssm.seqMappingRefCounts.size()); - assertEquals(2, ssm.seqMappingRefCounts.get(acf1).intValue()); + assertTrue(ssm.seqmappings.contains(acf2)); } }