+ testee = new PopupMenu(parentPanel, alignment.getSequenceAt(0), null);
+ int i = 0;
+ for (SequenceI seq : alignment.getSequences())
+ {
+ final AlignmentAnnotation annotation = new AlignmentAnnotation(
+ "label" + i, "desc" + i, i);
+ annotation.setCalcId("calcId" + i);
+ seq.addAlignmentAnnotation(annotation);
+ annotation.setSequenceRef(seq);
+ }
+ }
+
+ @Test(groups = { "Functional" })
+ public void testConfigureReferenceAnnotationsMenu_noSequenceSelected()
+ {
+ JMenuItem menu = new JMenuItem();
+ List<SequenceI> seqs = new ArrayList<>();
+ testee.configureReferenceAnnotationsMenu(menu, seqs);
+ assertFalse(menu.isEnabled());
+ // now try null list
+ menu.setEnabled(true);
+ testee.configureReferenceAnnotationsMenu(menu, null);
+ assertFalse(menu.isEnabled());
+ }
+
+ /**
+ * Test building the 'add reference annotations' menu for the case where there
+ * are no reference annotations to add to the alignment. The menu item should
+ * be disabled.
+ */
+ @Test(groups = { "Functional" })
+ public void testConfigureReferenceAnnotationsMenu_noReferenceAnnotations()
+ {
+ JMenuItem menu = new JMenuItem();
+
+ /*
+ * Initial state is that sequences have annotations, and have dataset
+ * sequences, but the dataset sequences have no annotations. Hence nothing
+ * to add.
+ */
+ List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
+
+ testee.configureReferenceAnnotationsMenu(menu, seqs);
+ assertFalse(menu.isEnabled());
+ }
+
+ /**
+ * Test building the 'add reference annotations' menu for the case where all
+ * reference annotations are already on the alignment. The menu item should be
+ * disabled.
+ */
+ @Test(groups = { "Functional" })
+ public void testConfigureReferenceAnnotationsMenu_alreadyAdded()
+ {
+ JMenuItem menu = new JMenuItem();
+ List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
+
+ // make up new annotations and add to dataset sequences, sequences and
+ // alignment
+ attachReferenceAnnotations(seqs, true, true);
+
+ testee.configureReferenceAnnotationsMenu(menu, seqs);
+ assertFalse(menu.isEnabled());
+ }
+
+ /**
+ * Test building the 'add reference annotations' menu for the case where
+ * several reference annotations are on the dataset but not on the sequences.
+ * The menu item should be enabled, and acquire a tooltip which lists the
+ * annotation sources (calcIds) and type (labels).
+ */
+ @Test(groups = { "Functional" })
+ public void testConfigureReferenceAnnotationsMenu()
+ {
+ JMenuItem menu = new JMenuItem();
+ List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
+
+ // make up new annotations and add to dataset sequences
+ attachReferenceAnnotations(seqs, false, false);
+
+ testee.configureReferenceAnnotationsMenu(menu, seqs);
+ assertTrue(menu.isEnabled());
+ String s = MessageManager.getString("label.add_annotations_for");
+ String expected = "<html><style> div.ttip {width:350px;white-space:pre-wrap;padding:2px;overflow-wrap:break-word;}</style>"
+ + "<div class=\"ttip\">" + s
+ + "<br/>Jmol/secondary structure<br/>PDB/Temp </div></html>";
+ assertEquals(expected, menu.getToolTipText());
+ }
+
+ /**
+ * Test building the 'add reference annotations' menu for the case where
+ * several reference annotations are on the dataset and the sequences but not
+ * on the alignment. The menu item should be enabled, and acquire a tooltip
+ * which lists the annotation sources (calcIds) and type (labels).
+ */
+ @Test(groups = { "Functional" })
+ public void testConfigureReferenceAnnotationsMenu_notOnAlignment()
+ {
+ JMenuItem menu = new JMenuItem();
+ List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
+
+ // make up new annotations and add to dataset sequences and sequences
+ attachReferenceAnnotations(seqs, true, false);
+
+ testee.configureReferenceAnnotationsMenu(menu, seqs);
+ assertTrue(menu.isEnabled());
+ String s = MessageManager.getString("label.add_annotations_for");
+ String expected = "<html><style> div.ttip {width:350px;white-space:pre-wrap;padding:2px;overflow-wrap:break-word;}</style>"
+ + "<div class=\"ttip\">" + s
+ + "<br/>Jmol/secondary structure<br/>PDB/Temp </div></html>";
+ assertEquals(expected, menu.getToolTipText());
+ }
+
+ /**
+ * Generate annotations and add to dataset sequences and (optionally)
+ * sequences and/or alignment
+ *
+ * @param seqs
+ * @param addToSequence
+ * @param addToAlignment
+ */
+ private void attachReferenceAnnotations(List<SequenceI> seqs,
+ boolean addToSequence, boolean addToAlignment)
+ {
+ // PDB.secondary structure on Sequence0
+ AlignmentAnnotation annotation = new AlignmentAnnotation(
+ "secondary structure", "", 0);
+ annotation.setCalcId("PDB");
+ seqs.get(0).getDatasetSequence().addAlignmentAnnotation(annotation);
+ if (addToSequence)
+ {
+ seqs.get(0).addAlignmentAnnotation(annotation);
+ }
+ if (addToAlignment)
+ {
+ this.alignment.addAnnotation(annotation);
+ }
+
+ // PDB.Temp on Sequence1
+ annotation = new AlignmentAnnotation("Temp", "", 0);
+ annotation.setCalcId("PDB");
+ seqs.get(1).getDatasetSequence().addAlignmentAnnotation(annotation);
+ if (addToSequence)
+ {
+ seqs.get(1).addAlignmentAnnotation(annotation);
+ }
+ if (addToAlignment)
+ {
+ this.alignment.addAnnotation(annotation);
+ }