3 import static org.testng.AssertJUnit.assertEquals;
4 import static org.testng.AssertJUnit.assertNotNull;
5 import static org.testng.AssertJUnit.assertSame;
6 import static org.testng.AssertJUnit.assertTrue;
8 import jalview.datamodel.AlignedCodonFrame;
9 import jalview.datamodel.Alignment;
10 import jalview.datamodel.AlignmentI;
11 import jalview.datamodel.PDBEntry;
12 import jalview.datamodel.PDBEntry.Type;
13 import jalview.datamodel.Sequence;
14 import jalview.datamodel.SequenceI;
15 import jalview.io.FileLoader;
16 import jalview.io.FormatAdapter;
17 import jalview.structure.StructureSelectionManager;
19 import java.util.LinkedHashSet;
22 import org.testng.annotations.BeforeClass;
23 import org.testng.annotations.BeforeMethod;
24 import org.testng.annotations.Test;
26 public class AlignViewportTest
32 @BeforeClass(alwaysRun = true)
33 public static void setUpBeforeClass() throws Exception
35 jalview.bin.Jalview.main(new String[] { "-props",
36 "test/jalview/testProps.jvprops" });
39 @BeforeMethod(alwaysRun = true)
42 SequenceI seq1 = new Sequence("Seq1", "ABC");
43 SequenceI seq2 = new Sequence("Seq2", "ABC");
44 SequenceI seq3 = new Sequence("Seq3", "ABC");
45 SequenceI[] seqs = new SequenceI[]
47 al = new Alignment(seqs);
49 testee = new AlignViewport(al);
52 @Test(groups ={ "Functional" })
53 public void testCollateForPdb()
56 * Set up sequence pdb ids
58 PDBEntry pdb1 = new PDBEntry("1ABC", "A", Type.PDB, "1ABC.pdb");
59 PDBEntry pdb2 = new PDBEntry("2ABC", "A", Type.PDB, "2ABC.pdb");
60 PDBEntry pdb3 = new PDBEntry("3ABC", "A", Type.PDB, "3ABC.pdb");
63 * seq1 and seq3 refer to 1ABC, seq2 to 2ABC, none to 3ABC
65 al.getSequenceAt(0).getDatasetSequence()
67 new PDBEntry("1ABC", "B", Type.PDB, "1ABC.pdb"));
68 al.getSequenceAt(2).getDatasetSequence()
70 new PDBEntry("1ABC", "B", Type.PDB, "1ABC.pdb"));
71 al.getSequenceAt(1).getDatasetSequence()
73 new PDBEntry("2ABC", "C", Type.PDB, "2ABC.pdb"));
75 * Add a second chain PDB xref to Seq2 - should not result in a duplicate in
78 al.getSequenceAt(1).getDatasetSequence()
79 .addPDBId(new PDBEntry("2ABC", "D", Type.PDB, "2ABC.pdb"));
81 * Seq3 refers to 3abc - this does not match 3ABC (as the code stands)
83 al.getSequenceAt(2).getDatasetSequence()
84 .addPDBId(new PDBEntry("3abc", "D", Type.PDB, "3ABC.pdb"));
87 * run method under test
89 SequenceI[][] seqs = testee.collateForPDB(new PDBEntry[]
90 { pdb1, pdb2, pdb3 });
92 // seq1 and seq3 refer to PDBEntry[0]
93 assertEquals(2, seqs[0].length);
94 assertSame(al.getSequenceAt(0), seqs[0][0]);
95 assertSame(al.getSequenceAt(2), seqs[0][1]);
97 // seq2 refers to PDBEntry[1]
98 assertEquals(1, seqs[1].length);
99 assertSame(al.getSequenceAt(1), seqs[1][0]);
101 // no sequence refers to PDBEntry[2]
102 assertEquals(0, seqs[2].length);
106 * Test that a mapping is not deregistered when a second view is closed but
107 * the first still holds a reference to the mapping
109 @Test(groups ={ "Functional" })
110 public void testDeregisterMapping_onCloseView()
113 * alignment with reference to mappings
115 AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
116 ">Seq1\nCAGT\n", FormatAdapter.PASTE);
118 AlignedCodonFrame acf1 = new AlignedCodonFrame();
119 AlignedCodonFrame acf2 = new AlignedCodonFrame();
121 Set<AlignedCodonFrame> mappings = new LinkedHashSet<AlignedCodonFrame>();
124 af1.getViewport().getAlignment().setCodonFrames(mappings);
125 af1.newView_actionPerformed(null);
128 * Verify that creating the alignment for the new View has registered the
131 StructureSelectionManager ssm = StructureSelectionManager
132 .getStructureSelectionManager(Desktop.instance);
133 assertEquals(2, ssm.seqmappings.size());
134 assertTrue(ssm.seqmappings.contains(acf1));
135 assertTrue(ssm.seqmappings.contains(acf2));
138 * Close the second view. Verify that mappings are not removed as the first
139 * view still holds a reference to them.
141 af1.closeMenuItem_actionPerformed(false);
142 assertEquals(2, ssm.seqmappings.size());
143 assertTrue(ssm.seqmappings.contains(acf1));
144 assertTrue(ssm.seqmappings.contains(acf2));
148 * Test that a mapping is not deregistered if an alignment holds a reference
151 @Test(groups ={ "Functional" })
152 public void testDeregisterMapping_withAlignmentReference()
154 Desktop d = Desktop.instance;
158 * alignment with reference to mappings
160 AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
161 ">Seq1\nCAGT\n", FormatAdapter.PASTE);
163 AlignedCodonFrame acf1 = new AlignedCodonFrame();
164 AlignedCodonFrame acf2 = new AlignedCodonFrame();
166 Set<AlignedCodonFrame> mappings = new LinkedHashSet<AlignedCodonFrame>();
169 af1.getViewport().getAlignment().setCodonFrames(mappings);
170 StructureSelectionManager ssm = StructureSelectionManager
171 .getStructureSelectionManager(Desktop.instance);
174 * Add one and remove it.
176 ssm.registerMapping(acf1);
177 ssm.deregisterMapping(acf1);
178 assertEquals(1, ssm.seqmappings.size());
179 assertTrue(ssm.seqmappings.contains(acf1));
183 * Test that a mapping is deregistered if no alignment holds a reference to it
185 @Test(groups ={ "Functional" })
186 public void testDeregisterMapping_withNoReference()
188 Desktop d = Desktop.instance;
192 * alignment with reference to mappings
194 AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
195 ">Seq1\nCAGT\n", FormatAdapter.PASTE);
197 AlignedCodonFrame acf1 = new AlignedCodonFrame();
198 AlignedCodonFrame acf2 = new AlignedCodonFrame();
200 Set<AlignedCodonFrame> mappings = new LinkedHashSet<AlignedCodonFrame>();
202 af1.getViewport().getAlignment().setCodonFrames(mappings);
203 StructureSelectionManager ssm = StructureSelectionManager
204 .getStructureSelectionManager(Desktop.instance);
207 * Add one and remove it.
209 ssm.registerMapping(acf1);
210 assertEquals(1, ssm.seqmappings.size());
211 assertTrue(ssm.seqmappings.contains(acf1));
212 ssm.deregisterMapping(acf1);
213 assertEquals(0, ssm.seqmappings.size());