3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertFalse;
5 import static org.junit.Assert.assertTrue;
6 import jalview.datamodel.AlignmentAnnotation;
7 import jalview.datamodel.AlignmentI;
8 import jalview.datamodel.SequenceI;
9 import jalview.io.AppletFormatAdapter;
10 import jalview.util.MessageManager;
12 import java.io.IOException;
13 import java.util.ArrayList;
14 import java.util.List;
16 import javax.swing.JMenuItem;
18 import org.junit.Before;
19 import org.junit.Test;
21 public class PopupMenuTest
23 // 4 sequences x 13 positions
24 final static String TEST_DATA = ">FER_CAPAA Ferredoxin\n"
26 + ">FER_CAPAN Ferredoxin, chloroplast precursor\n"
28 + ">FER1_SOLLC Ferredoxin-1, chloroplast precursor\n"
29 + "TIETHKEEELTA-\n" + ">Q93XJ9_SOLTU Ferredoxin I precursor\n"
34 AlignmentPanel parentPanel;
36 PopupMenu testee = null;
39 public void setUp() throws IOException
41 alignment = new jalview.io.FormatAdapter().readFile(TEST_DATA,
42 AppletFormatAdapter.PASTE, "FASTA");
43 AlignFrame af = new AlignFrame(alignment, 700, 500);
44 parentPanel = new AlignmentPanel(af, af.getViewport());
45 testee = new PopupMenu(parentPanel, null, null);
47 for (SequenceI seq : alignment.getSequences())
49 final AlignmentAnnotation annotation = new AlignmentAnnotation("label" + i,
51 annotation.setCalcId("calcId" + i);
52 seq.addAlignmentAnnotation(annotation);
53 annotation.setSequenceRef(seq);
58 public void testConfigureReferenceAnnotationsMenu_noSequenceSelected()
60 JMenuItem menu = new JMenuItem();
61 List<SequenceI> seqs = new ArrayList<SequenceI>();
62 testee.configureReferenceAnnotationsMenu(menu, seqs);
63 assertFalse(menu.isEnabled());
65 MessageManager.getString("label.add_reference_annotations"),
68 menu.setEnabled(true);
69 testee.configureReferenceAnnotationsMenu(menu, seqs);
70 assertFalse(menu.isEnabled());
74 * Test building the 'add reference annotations' menu for the case where there
75 * are no reference annotations to add to the alignment. The menu item should
79 public void testConfigureReferenceAnnotationsMenu_noReferenceAnnotations()
81 JMenuItem menu = new JMenuItem();
82 List<SequenceI> seqs = new ArrayList<SequenceI>();
85 * Initial state is that sequences have annotations, and have dataset
86 * sequences, but the dataset sequences have no annotations. Hence nothing
89 seqs = parentPanel.getAlignment().getSequences();
91 testee.configureReferenceAnnotationsMenu(menu, seqs);
92 assertFalse(menu.isEnabled());
96 * Test building the 'add reference annotations' menu for the case where all
97 * reference annotations are already on the alignment. The menu item should be
101 public void testConfigureReferenceAnnotationsMenu_alreadyAdded()
103 JMenuItem menu = new JMenuItem();
104 List<SequenceI> seqs = new ArrayList<SequenceI>();
106 seqs = parentPanel.getAlignment().getSequences();
107 // copy annotation from sequence to dataset
108 seqs.get(1).getDatasetSequence()
109 .addAlignmentAnnotation(seqs.get(1).getAnnotation()[0]);
110 testee.configureReferenceAnnotationsMenu(menu, seqs);
111 assertFalse(menu.isEnabled());
115 * Test building the 'add reference annotations' menu for the case where
116 * several reference annotations are on the dataset but not on the sequences.
117 * The menu item should be enabled, and acquire a tooltip which lists the
118 * annotation sources (calcIds) and type (labels).
121 public void testConfigureReferenceAnnotationsMenu()
123 JMenuItem menu = new JMenuItem();
124 List<SequenceI> seqs = new ArrayList<SequenceI>();
126 seqs = parentPanel.getAlignment().getSequences();
127 // make up new annotations and add to dataset sequences
129 // PDB.secondary structure on Sequence0
130 AlignmentAnnotation annotation = new AlignmentAnnotation(
131 "secondary structure", "", 0);
132 annotation.setCalcId("PBD");
133 seqs.get(0).getDatasetSequence().addAlignmentAnnotation(annotation);
135 // PDB.Temp on Sequence1
136 annotation = new AlignmentAnnotation("Temp", "", 0);
137 annotation.setCalcId("PBD");
138 seqs.get(1).getDatasetSequence().addAlignmentAnnotation(annotation);
140 // JMOL.secondary structure on Sequence0
141 annotation = new AlignmentAnnotation("secondary structure", "", 0);
142 annotation.setCalcId("JMOL");
143 seqs.get(0).getDatasetSequence().addAlignmentAnnotation(annotation);
145 testee.configureReferenceAnnotationsMenu(menu, seqs);
146 assertTrue(menu.isEnabled());
147 String expected = "<html><table width=350 border=0><tr><td>Add annotations for<br/>JMOL/secondary structure<br/>PBD/Temp</td></tr></table></html>";
148 assertEquals(expected, menu.getToolTipText());