Clover icon

Coverage Report

  1. Project Clover database Wed Dec 3 2025 17:03:17 GMT
  2. Package jalview.gui

File PopupMenuTest.java

 

Code metrics

16
329
17
1
773
510
26
0.08
19.35
17
1.53

Classes

Class Line # Actions
PopupMenuTest 69 329 26
1.0100%
 

Contributing tests

This file is covered by 13 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.gui;
22   
23    import static jalview.util.UrlConstants.DB_ACCESSION;
24    import static jalview.util.UrlConstants.SEQUENCE_ID;
25    import static org.testng.AssertJUnit.assertEquals;
26    import static org.testng.AssertJUnit.assertFalse;
27    import static org.testng.AssertJUnit.assertNotNull;
28    import static org.testng.AssertJUnit.assertNull;
29    import static org.testng.AssertJUnit.assertTrue;
30   
31    import java.awt.Component;
32    import java.awt.Container;
33    import java.io.IOException;
34    import java.util.ArrayList;
35    import java.util.Collections;
36    import java.util.Iterator;
37    import java.util.List;
38   
39    import javax.swing.JMenu;
40    import javax.swing.JMenuItem;
41    import javax.swing.JPopupMenu;
42    import javax.swing.JSeparator;
43   
44    import org.testng.annotations.BeforeClass;
45    import org.testng.annotations.BeforeMethod;
46    import org.testng.annotations.Test;
47   
48    import jalview.bin.Cache;
49    import jalview.bin.Console;
50    import jalview.datamodel.AlignmentAnnotation;
51    import jalview.datamodel.AlignmentI;
52    import jalview.datamodel.Annotation;
53    import jalview.datamodel.ColumnSelection;
54    import jalview.datamodel.DBRefEntry;
55    import jalview.datamodel.DBRefSource;
56    import jalview.datamodel.HiddenColumns;
57    import jalview.datamodel.Sequence;
58    import jalview.datamodel.SequenceFeature;
59    import jalview.datamodel.SequenceGroup;
60    import jalview.datamodel.SequenceI;
61    import jalview.io.DataSourceType;
62    import jalview.io.FileFormat;
63    import jalview.io.FormatAdapter;
64    import jalview.urls.api.UrlProviderFactoryI;
65    import jalview.urls.desktop.DesktopUrlProviderFactory;
66    import jalview.util.MessageManager;
67    import jalview.util.UrlConstants;
68   
 
69    public class PopupMenuTest
70    {
71   
 
72  1 toggle @BeforeClass(alwaysRun = true)
73    public void setUpJvOptionPane()
74    {
75  1 JvOptionPane.setInteractiveMode(false);
76  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
77    }
78   
79    // 4 sequences x 13 positions
80    final static String TEST_DATA = ">FER_CAPAA Ferredoxin\n"
81    + "TIETHKEAELVG-\n"
82    + ">FER_CAPAN Ferredoxin, chloroplast precursor\n"
83    + "TIETHKEAELVG-\n"
84    + ">FER1_SOLLC Ferredoxin-1, chloroplast precursor\n"
85    + "TIETHKEEELTA-\n" + ">Q93XJ9_SOLTU Ferredoxin I precursor\n"
86    + "TIETHKEEELTA-\n";
87   
88    AlignmentI alignment;
89   
90    AlignmentPanel parentPanel;
91   
92    PopupMenu testee = null;
93   
 
94  13 toggle @BeforeMethod(alwaysRun = true)
95    public void setUp() throws IOException
96    {
97  13 Cache.loadProperties("test/jalview/io/testProps.jvprops");
98  13 Console.initLogger();
99   
100  13 String inMenuString = ("EMBL-EBI Search | http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$"
101    + SEQUENCE_ID + "$" + "|"
102    + "UNIPROT | http://www.uniprot.org/uniprot/$" + DB_ACCESSION
103    + "$") + "|"
104    + ("INTERPRO | http://www.ebi.ac.uk/interpro/entry/$"
105    + DB_ACCESSION + "$")
106    + "|" +
107    // Gene3D entry tests for case (in)sensitivity
108    ("Gene3D | http://gene3d.biochem.ucl.ac.uk/Gene3D/search?sterm=$"
109    + DB_ACCESSION + "$&mode=protein");
110   
111  13 UrlProviderFactoryI factory = new DesktopUrlProviderFactory(
112    UrlConstants.DEFAULT_LABEL, inMenuString, "");
113  13 Preferences.getInstance().sequenceUrlLinks = factory.createUrlProvider();
114   
115  13 alignment = new FormatAdapter().readFile(TEST_DATA,
116    DataSourceType.PASTE, FileFormat.Fasta);
117  13 AlignFrame af = new AlignFrame(alignment, 700, 500);
118  13 parentPanel = new AlignmentPanel(af, af.getViewport());
119  13 testee = new PopupMenu(parentPanel, alignment.getSequenceAt(0), null);
120  13 int i = 0;
121  13 for (SequenceI seq : alignment.getSequences())
122    {
123  52 final AlignmentAnnotation annotation = new AlignmentAnnotation(
124    "label" + i, "desc" + i, i);
125  52 annotation.setCalcId("calcId" + i);
126  52 seq.addAlignmentAnnotation(annotation);
127  52 annotation.setSequenceRef(seq);
128    }
129    }
130   
 
131  1 toggle @Test(groups = { "Functional" })
132    public void testConfigureReferenceAnnotationsMenu_noSequenceSelected()
133    {
134  1 JMenuItem menu = new JMenuItem();
135  1 List<SequenceI> seqs = new ArrayList<>();
136  1 testee.configureReferenceAnnotationsMenu(menu, seqs);
137  1 assertFalse(menu.isEnabled());
138    // now try null list
139  1 menu.setEnabled(true);
140  1 testee.configureReferenceAnnotationsMenu(menu, null);
141  1 assertFalse(menu.isEnabled());
142    }
143   
144    /**
145    * Test building the 'add reference annotations' menu for the case where there
146    * are no reference annotations to add to the alignment. The menu item should
147    * be disabled.
148    */
 
149  1 toggle @Test(groups = { "Functional" })
150    public void testConfigureReferenceAnnotationsMenu_noReferenceAnnotations()
151    {
152  1 JMenuItem menu = new JMenuItem();
153   
154    /*
155    * Initial state is that sequences have annotations, and have dataset
156    * sequences, but the dataset sequences have no annotations. Hence nothing
157    * to add.
158    */
159  1 List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
160   
161  1 testee.configureReferenceAnnotationsMenu(menu, seqs);
162  1 assertFalse(menu.isEnabled());
163    }
164   
165    /**
166    * Test building the 'add reference annotations' menu for the case where all
167    * reference annotations are already on the alignment. The menu item should be
168    * disabled.
169    */
 
170  1 toggle @Test(groups = { "Functional" })
171    public void testConfigureReferenceAnnotationsMenu_alreadyAdded()
172    {
173  1 JMenuItem menu = new JMenuItem();
174  1 List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
175   
176    // make up new annotations and add to dataset sequences, sequences and
177    // alignment
178  1 attachReferenceAnnotations(seqs, true, true);
179   
180  1 testee.configureReferenceAnnotationsMenu(menu, seqs);
181  1 assertFalse(menu.isEnabled());
182    }
183   
184    /**
185    * Test building the 'add reference annotations' menu for the case where
186    * several reference annotations are on the dataset but not on the sequences.
187    * The menu item should be enabled, and acquire a tooltip which lists the
188    * annotation sources (calcIds) and type (labels).
189    */
 
190  1 toggle @Test(groups = { "Functional" })
191    public void testConfigureReferenceAnnotationsMenu()
192    {
193  1 JMenuItem menu = new JMenuItem();
194  1 List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
195   
196    // make up new annotations and add to dataset sequences
197  1 attachReferenceAnnotations(seqs, false, false);
198   
199  1 testee.configureReferenceAnnotationsMenu(menu, seqs);
200  1 assertTrue(menu.isEnabled());
201  1 String s = MessageManager.getString("label.add_annotations_for");
202    // String expected = "<html><style> div.ttip {width:350px;white-space:pre-wrap;padding:2px;overflow-wrap:break-word;}</style>"
203    // + "<div class=\"ttip\">" + s
204    // + "<br/>Jmol/secondary structure<br/>PDB/Temp </div></html>";
205  1 String expected = "<html>" + s + "<br>Jmol/secondary structure<br>PDB/Temp</html>";
206  1 assertEquals(expected, menu.getToolTipText());
207    }
208   
209    /**
210    * Test building the 'add reference annotations' menu for the case where
211    * several reference annotations are on the dataset and the sequences but not
212    * on the alignment. The menu item should be enabled, and acquire a tooltip
213    * which lists the annotation sources (calcIds) and type (labels).
214    */
 
215  1 toggle @Test(groups = { "Functional" })
216    public void testConfigureReferenceAnnotationsMenu_notOnAlignment()
217    {
218  1 JMenuItem menu = new JMenuItem();
219  1 List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
220   
221    // make up new annotations and add to dataset sequences and sequences
222  1 attachReferenceAnnotations(seqs, true, false);
223   
224  1 testee.configureReferenceAnnotationsMenu(menu, seqs);
225  1 assertTrue(menu.isEnabled());
226  1 String s = MessageManager.getString("label.add_annotations_for");
227    // String expected = "<html><style> div.ttip {width:350px;white-space:pre-wrap;padding:2px;overflow-wrap:break-word;}</style>"
228    // + "<div class=\"ttip\">" + s
229    // + "<br/>Jmol/secondary structure<br/>PDB/Temp</html>";
230  1 String expected = "<html>" + s
231    + "<br>Jmol/secondary structure<br>PDB/Temp</html>";
232  1 s = menu.getToolTipText();
233  1 assertEquals(expected, s);
234    }
235   
236    /**
237    * Generate annotations and add to dataset sequences and (optionally)
238    * sequences and/or alignment
239    *
240    * @param seqs
241    * @param addToSequence
242    * @param addToAlignment
243    */
 
244  3 toggle private void attachReferenceAnnotations(List<SequenceI> seqs,
245    boolean addToSequence, boolean addToAlignment)
246    {
247    // PDB.secondary structure on Sequence0
248  3 AlignmentAnnotation annotation = new AlignmentAnnotation(
249    "secondary structure", "", 0);
250  3 annotation.annotations = new Annotation[] { new Annotation(2f) };
251  3 annotation.setCalcId("PDB");
252  3 seqs.get(0).getDatasetSequence().addAlignmentAnnotation(annotation);
253  3 if (addToSequence)
254    {
255  2 seqs.get(0).addAlignmentAnnotation(annotation);
256    }
257  3 if (addToAlignment)
258    {
259  1 this.alignment.addAnnotation(annotation);
260    }
261   
262    // PDB.Temp on Sequence1
263  3 annotation = new AlignmentAnnotation("Temp", "", 0);
264  3 annotation.setCalcId("PDB");
265  3 annotation.annotations = new Annotation[] { new Annotation(2f) };
266  3 seqs.get(1).getDatasetSequence().addAlignmentAnnotation(annotation);
267  3 if (addToSequence)
268    {
269  2 seqs.get(1).addAlignmentAnnotation(annotation);
270    }
271  3 if (addToAlignment)
272    {
273  1 this.alignment.addAnnotation(annotation);
274    }
275   
276    // JMOL.secondary structure on Sequence0
277  3 annotation = new AlignmentAnnotation("secondary structure", "", 0);
278  3 annotation.setCalcId("Jmol");
279  3 annotation.annotations = new Annotation[] { new Annotation(2f) };
280  3 seqs.get(0).getDatasetSequence().addAlignmentAnnotation(annotation);
281  3 if (addToSequence)
282    {
283  2 seqs.get(0).addAlignmentAnnotation(annotation);
284    }
285  3 if (addToAlignment)
286    {
287  1 this.alignment.addAnnotation(annotation);
288    }
289    }
290   
291    /**
292    * Test building the 'add reference annotations' menu for the case where there
293    * are two alignment views:
294    * <ul>
295    * <li>in one view, reference annotations have been added (are on the
296    * datasets, sequences and alignment)</li>
297    * <li>in the current view, reference annotations are on the dataset and
298    * sequence, but not the alignment</li>
299    * </ul>
300    * The menu item should be enabled, and acquire a tooltip which lists the
301    * annotation sources (calcIds) and type (labels).
302    */
 
303  1 toggle @Test(groups = { "Functional" })
304    public void testConfigureReferenceAnnotationsMenu_twoViews()
305    {
306    }
307   
308    /**
309    * Test for building menu options including 'show' and 'hide' annotation
310    * types.
311    */
 
312  1 toggle @Test(groups = { "Functional" })
313    public void testBuildAnnotationTypesMenus()
314    {
315  1 JMenu showMenu = new JMenu();
316  1 JMenu hideMenu = new JMenu();
317  1 List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
318   
319    // make up new annotations and add to sequences and to the alignment
320   
321    // PDB.secondary structure on Sequence0
322  1 AlignmentAnnotation annotation = new AlignmentAnnotation(
323    "secondary structure", "", new Annotation[] {});
324  1 annotation.setCalcId("PDB");
325  1 annotation.visible = true;
326  1 seqs.get(0).addAlignmentAnnotation(annotation);
327  1 parentPanel.getAlignment().addAnnotation(annotation);
328   
329    // JMOL.secondary structure on Sequence0 - hidden
330  1 annotation = new AlignmentAnnotation("secondary structure", "",
331    new Annotation[] {});
332  1 annotation.setCalcId("JMOL");
333  1 annotation.visible = false;
334  1 seqs.get(0).addAlignmentAnnotation(annotation);
335  1 parentPanel.getAlignment().addAnnotation(annotation);
336   
337    // Jpred.SSP on Sequence0 - hidden
338  1 annotation = new AlignmentAnnotation("SSP", "", new Annotation[] {});
339  1 annotation.setCalcId("JPred");
340  1 annotation.visible = false;
341  1 seqs.get(0).addAlignmentAnnotation(annotation);
342  1 parentPanel.getAlignment().addAnnotation(annotation);
343   
344    // PDB.Temp on Sequence1
345  1 annotation = new AlignmentAnnotation("Temp", "", new Annotation[] {});
346  1 annotation.setCalcId("PDB");
347  1 annotation.visible = true;
348  1 seqs.get(1).addAlignmentAnnotation(annotation);
349  1 parentPanel.getAlignment().addAnnotation(annotation);
350   
351    /*
352    * Expect menu options to show "secondary structure" and "SSP", and to hide
353    * "secondary structure" and "Temp". Tooltip should be calcId.
354    */
355  1 testee.buildAnnotationTypesMenus(showMenu, hideMenu, seqs);
356   
357  1 assertTrue(showMenu.isEnabled());
358  1 assertTrue(hideMenu.isEnabled());
359   
360  1 Component[] showOptions = showMenu.getMenuComponents();
361  1 Component[] hideOptions = hideMenu.getMenuComponents();
362   
363  1 assertEquals(4, showOptions.length); // includes 'All' and separator
364  1 assertEquals(4, hideOptions.length);
365  1 String all = MessageManager.getString("label.all");
366  1 assertEquals(all, ((JMenuItem) showOptions[0]).getText());
367  1 assertTrue(showOptions[1] instanceof JPopupMenu.Separator);
368  1 assertEquals(JSeparator.HORIZONTAL,
369    ((JSeparator) showOptions[1]).getOrientation());
370  1 assertEquals("secondary structure",
371    ((JMenuItem) showOptions[2]).getText());
372  1 assertEquals("JMOL", ((JMenuItem) showOptions[2]).getToolTipText());
373  1 assertEquals("SSP", ((JMenuItem) showOptions[3]).getText());
374  1 assertEquals("JPred", ((JMenuItem) showOptions[3]).getToolTipText());
375   
376  1 assertEquals(all, ((JMenuItem) hideOptions[0]).getText());
377  1 assertTrue(hideOptions[1] instanceof JPopupMenu.Separator);
378  1 assertEquals(JSeparator.HORIZONTAL,
379    ((JSeparator) hideOptions[1]).getOrientation());
380  1 assertEquals("secondary structure",
381    ((JMenuItem) hideOptions[2]).getText());
382  1 assertEquals("PDB", ((JMenuItem) hideOptions[2]).getToolTipText());
383  1 assertEquals("Temp", ((JMenuItem) hideOptions[3]).getText());
384  1 assertEquals("PDB", ((JMenuItem) hideOptions[3]).getToolTipText());
385    }
386   
387    /**
388    * Test for building menu options with only 'hide' annotation types enabled.
389    */
 
390  1 toggle @Test(groups = { "Functional" })
391    public void testBuildAnnotationTypesMenus_showDisabled()
392    {
393  1 JMenu showMenu = new JMenu();
394  1 JMenu hideMenu = new JMenu();
395  1 List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
396   
397    // make up new annotations and add to sequences and to the alignment
398   
399    // PDB.secondary structure on Sequence0
400  1 AlignmentAnnotation annotation = new AlignmentAnnotation(
401    "secondary structure", "", new Annotation[] {});
402  1 annotation.setCalcId("PDB");
403  1 annotation.visible = true;
404  1 seqs.get(0).addAlignmentAnnotation(annotation);
405  1 parentPanel.getAlignment().addAnnotation(annotation);
406   
407    // PDB.Temp on Sequence1
408  1 annotation = new AlignmentAnnotation("Temp", "", new Annotation[] {});
409  1 annotation.setCalcId("PDB");
410  1 annotation.visible = true;
411  1 seqs.get(1).addAlignmentAnnotation(annotation);
412  1 parentPanel.getAlignment().addAnnotation(annotation);
413   
414    /*
415    * Expect menu options to hide "secondary structure" and "Temp". Tooltip
416    * should be calcId. 'Show' menu should be disabled.
417    */
418  1 testee.buildAnnotationTypesMenus(showMenu, hideMenu, seqs);
419   
420  1 assertFalse(showMenu.isEnabled());
421  1 assertTrue(hideMenu.isEnabled());
422   
423  1 Component[] showOptions = showMenu.getMenuComponents();
424  1 Component[] hideOptions = hideMenu.getMenuComponents();
425   
426  1 assertEquals(2, showOptions.length); // includes 'All' and separator
427  1 assertEquals(4, hideOptions.length);
428  1 String all = MessageManager.getString("label.all");
429  1 assertEquals(all, ((JMenuItem) showOptions[0]).getText());
430  1 assertTrue(showOptions[1] instanceof JPopupMenu.Separator);
431  1 assertEquals(JSeparator.HORIZONTAL,
432    ((JSeparator) showOptions[1]).getOrientation());
433   
434  1 assertEquals(all, ((JMenuItem) hideOptions[0]).getText());
435  1 assertTrue(hideOptions[1] instanceof JPopupMenu.Separator);
436  1 assertEquals(JSeparator.HORIZONTAL,
437    ((JSeparator) hideOptions[1]).getOrientation());
438  1 assertEquals("secondary structure",
439    ((JMenuItem) hideOptions[2]).getText());
440  1 assertEquals("PDB", ((JMenuItem) hideOptions[2]).getToolTipText());
441  1 assertEquals("Temp", ((JMenuItem) hideOptions[3]).getText());
442  1 assertEquals("PDB", ((JMenuItem) hideOptions[3]).getToolTipText());
443    }
444   
445    /**
446    * Test for building menu options with only 'show' annotation types enabled.
447    */
 
448  1 toggle @Test(groups = { "Functional" })
449    public void testBuildAnnotationTypesMenus_hideDisabled()
450    {
451  1 JMenu showMenu = new JMenu();
452  1 JMenu hideMenu = new JMenu();
453  1 List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
454   
455    // make up new annotations and add to sequences and to the alignment
456   
457    // PDB.secondary structure on Sequence0
458  1 AlignmentAnnotation annotation = new AlignmentAnnotation(
459    "secondary structure", "", new Annotation[] {});
460  1 annotation.setCalcId("PDB");
461  1 annotation.visible = false;
462  1 seqs.get(0).addAlignmentAnnotation(annotation);
463  1 parentPanel.getAlignment().addAnnotation(annotation);
464   
465    // PDB.Temp on Sequence1
466  1 annotation = new AlignmentAnnotation("Temp", "", new Annotation[] {});
467  1 annotation.setCalcId("PDB2");
468  1 annotation.visible = false;
469  1 seqs.get(1).addAlignmentAnnotation(annotation);
470  1 parentPanel.getAlignment().addAnnotation(annotation);
471   
472    /*
473    * Expect menu options to show "secondary structure" and "Temp". Tooltip
474    * should be calcId. 'hide' menu should be disabled.
475    */
476  1 testee.buildAnnotationTypesMenus(showMenu, hideMenu, seqs);
477   
478  1 assertTrue(showMenu.isEnabled());
479  1 assertFalse(hideMenu.isEnabled());
480   
481  1 Component[] showOptions = showMenu.getMenuComponents();
482  1 Component[] hideOptions = hideMenu.getMenuComponents();
483   
484  1 assertEquals(4, showOptions.length); // includes 'All' and separator
485  1 assertEquals(2, hideOptions.length);
486  1 String all = MessageManager.getString("label.all");
487  1 assertEquals(all, ((JMenuItem) showOptions[0]).getText());
488  1 assertTrue(showOptions[1] instanceof JPopupMenu.Separator);
489  1 assertEquals(JSeparator.HORIZONTAL,
490    ((JSeparator) showOptions[1]).getOrientation());
491  1 assertEquals("secondary structure",
492    ((JMenuItem) showOptions[2]).getText());
493  1 assertEquals("PDB", ((JMenuItem) showOptions[2]).getToolTipText());
494  1 assertEquals("Temp", ((JMenuItem) showOptions[3]).getText());
495  1 assertEquals("PDB2", ((JMenuItem) showOptions[3]).getToolTipText());
496   
497  1 assertEquals(all, ((JMenuItem) hideOptions[0]).getText());
498  1 assertTrue(hideOptions[1] instanceof JPopupMenu.Separator);
499  1 assertEquals(JSeparator.HORIZONTAL,
500    ((JSeparator) hideOptions[1]).getOrientation());
501    }
502   
503    /**
504    * Test for adding sequence id, dbref and feature links
505    */
 
506  1 toggle @Test(groups = { "Functional" })
507    public void testBuildLinkMenu()
508    {
509  1 List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
510  1 final SequenceI seq0 = seqs.get(0);
511  1 final SequenceI seq1 = seqs.get(1);
512  1 final List<SequenceFeature> noFeatures = Collections
513    .<SequenceFeature> emptyList();
514  1 final String linkText = MessageManager.getString("action.link");
515   
516  1 seq0.addDBRef(new DBRefEntry(DBRefSource.UNIPROT, "1", "P83527"));
517  1 seq0.addDBRef(new DBRefEntry("INTERPRO", "1", "IPR001041"));
518  1 seq0.addDBRef(new DBRefEntry("INTERPRO", "1", "IPR012675"));
519  1 seq0.addDBRef(new DBRefEntry("INTERPRO", "1", "IPR006058"));
520  1 seq1.addDBRef(new DBRefEntry(DBRefSource.UNIPROT, "1", "Q9ZTS2"));
521  1 seq1.addDBRef(new DBRefEntry("GENE3D", "1", "3.10.20.30"));
522   
523    /*
524    * check the Link Menu for the first sequence
525    */
526  1 JMenu linkMenu = PopupMenu.buildLinkMenu(seq0, noFeatures);
527  1 assertEquals(linkText, linkMenu.getText());
528  1 Component[] linkItems = linkMenu.getMenuComponents();
529   
530    /*
531    * menu items are ordered: SEQUENCE_ID search first, then dbrefs in order
532    * of database name (and within that by order of dbref addition)
533    */
534  1 assertEquals(5, linkItems.length);
535  1 assertEquals("EMBL-EBI Search", ((JMenuItem) linkItems[0]).getText());
536  1 assertEquals("INTERPRO|IPR001041",
537    ((JMenuItem) linkItems[1]).getText());
538  1 assertEquals("INTERPRO|IPR012675",
539    ((JMenuItem) linkItems[2]).getText());
540  1 assertEquals("INTERPRO|IPR006058",
541    ((JMenuItem) linkItems[3]).getText());
542  1 assertEquals("UNIPROT|P83527", ((JMenuItem) linkItems[4]).getText());
543   
544    /*
545    * check the Link Menu for the second sequence
546    * note dbref GENE3D is matched to link Gene3D, the latter is displayed
547    */
548  1 linkMenu = PopupMenu.buildLinkMenu(seq1, noFeatures);
549  1 linkItems = linkMenu.getMenuComponents();
550  1 assertEquals(3, linkItems.length);
551  1 assertEquals("EMBL-EBI Search", ((JMenuItem) linkItems[0]).getText());
552  1 assertEquals("Gene3D|3.10.20.30", ((JMenuItem) linkItems[1]).getText());
553  1 assertEquals("UNIPROT|Q9ZTS2", ((JMenuItem) linkItems[2]).getText());
554   
555    /*
556    * if there are no valid links the Links submenu is still shown, but
557    * reduced to the EMBL-EBI lookup only (inserted by
558    * CustomUrlProvider.choosePrimaryUrl())
559    */
560  1 String unmatched = "NOMATCH|http://www.uniprot.org/uniprot/$"
561    + DB_ACCESSION + "$";
562  1 UrlProviderFactoryI factory = new DesktopUrlProviderFactory(null,
563    unmatched, "");
564  1 Preferences.getInstance().sequenceUrlLinks = factory.createUrlProvider();
565   
566  1 linkMenu = PopupMenu.buildLinkMenu(seq1, noFeatures);
567  1 linkItems = linkMenu.getMenuComponents();
568  1 assertEquals(1, linkItems.length);
569  1 assertEquals("EMBL-EBI Search", ((JMenuItem) linkItems[0]).getText());
570   
571    /*
572    * if sequence is null, only feature links are shown (alignment popup submenu)
573    */
574  1 linkMenu = PopupMenu.buildLinkMenu(null, noFeatures);
575  1 linkItems = linkMenu.getMenuComponents();
576  1 assertEquals(0, linkItems.length);
577   
578  1 List<SequenceFeature> features = new ArrayList<>();
579  1 SequenceFeature sf = new SequenceFeature("type", "desc", 1, 20, null);
580  1 features.add(sf);
581  1 linkMenu = PopupMenu.buildLinkMenu(null, features);
582  1 linkItems = linkMenu.getMenuComponents();
583  1 assertEquals(0, linkItems.length); // feature has no links
584   
585  1 sf.addLink("Pfam family|http://pfam.xfam.org/family/PF00111");
586  1 linkMenu = PopupMenu.buildLinkMenu(null, features);
587  1 linkItems = linkMenu.getMenuComponents();
588  1 assertEquals(1, linkItems.length);
589  1 JMenuItem item = (JMenuItem) linkItems[0];
590  1 assertEquals("Pfam family", item.getText());
591    // ? no way to verify URL, compiled into link's actionListener
592    }
593   
 
594  1 toggle @Test(groups = { "Functional" })
595    public void testHideInsertions()
596    {
597    // get sequences from the alignment
598  1 List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
599   
600    // add our own seqs to avoid problems with changes to existing sequences
601    // (gap at end of sequences varies depending on how tests are run!)
602  1 Sequence seqGap1 = new Sequence("GappySeq",
603    "AAAA----AA-AAAAAAA---AAA-----------AAAAAAAAAA--");
604  1 seqGap1.createDatasetSequence();
605  1 seqs.add(seqGap1);
606  1 Sequence seqGap2 = new Sequence("LessGappySeq",
607    "AAAAAA-AAAAA---AAA--AAAAA--AAAAAAA-AAAAAA");
608  1 seqGap2.createDatasetSequence();
609  1 seqs.add(seqGap2);
610  1 Sequence seqGap3 = new Sequence("AnotherGapSeq",
611    "AAAAAA-AAAAAA--AAAAAA-AAAAAAAAAAA---AAAAAAAA");
612  1 seqGap3.createDatasetSequence();
613  1 seqs.add(seqGap3);
614  1 Sequence seqGap4 = new Sequence("NoGaps",
615    "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
616  1 seqGap4.createDatasetSequence();
617  1 seqs.add(seqGap4);
618   
619  1 ColumnSelection sel = new ColumnSelection();
620  1 parentPanel.av.getAlignment().getHiddenColumns()
621    .revealAllHiddenColumns(sel);
622   
623    // get the Popup Menu for 7th sequence - no insertions
624  1 testee = new PopupMenu(parentPanel, seqs.get(7), null);
625  1 testee.hideInsertions_actionPerformed(null);
626   
627  1 HiddenColumns hidden = parentPanel.av.getAlignment().getHiddenColumns();
628  1 Iterator<int[]> it = hidden.iterator();
629  1 assertFalse(it.hasNext());
630   
631    // get the Popup Menu for GappySeq - this time we have insertions
632  1 testee = new PopupMenu(parentPanel, seqs.get(4), null);
633  1 testee.hideInsertions_actionPerformed(null);
634  1 hidden = parentPanel.av.getAlignment().getHiddenColumns();
635  1 it = hidden.iterator();
636   
637  1 assertTrue(it.hasNext());
638  1 int[] region = it.next();
639  1 assertEquals(region[0], 4);
640  1 assertEquals(region[1], 7);
641   
642  1 assertTrue(it.hasNext());
643  1 region = it.next();
644  1 assertEquals(region[0], 10);
645  1 assertEquals(region[1], 10);
646   
647  1 assertTrue(it.hasNext());
648  1 region = it.next();
649  1 assertEquals(region[0], 18);
650  1 assertEquals(region[1], 20);
651   
652  1 assertTrue(it.hasNext());
653  1 region = it.next();
654  1 assertEquals(region[0], 24);
655  1 assertEquals(region[1], 34);
656   
657  1 assertTrue(it.hasNext());
658  1 region = it.next();
659  1 assertEquals(region[0], 45);
660  1 assertEquals(region[1], 46);
661   
662  1 assertFalse(it.hasNext());
663   
664  1 sel = new ColumnSelection();
665  1 hidden.revealAllHiddenColumns(sel);
666   
667    // make a sequence group and hide insertions within the group
668  1 SequenceGroup sg = new SequenceGroup();
669  1 sg.setStartRes(8);
670  1 sg.setEndRes(42);
671  1 sg.addSequence(seqGap2, false);
672  1 sg.addSequence(seqGap3, false);
673  1 parentPanel.av.setSelectionGroup(sg);
674   
675    // hide columns outside and within selection
676    // only hidden columns outside the collection will be retained (unless also
677    // gaps in the selection)
678  1 hidden.hideColumns(1, 10);
679  1 hidden.hideColumns(31, 40);
680   
681    // get the Popup Menu for LessGappySeq in the sequence group
682  1 testee = new PopupMenu(parentPanel, seqs.get(5), null);
683  1 testee.hideInsertions_actionPerformed(null);
684  1 hidden = parentPanel.av.getAlignment().getHiddenColumns();
685  1 it = hidden.iterator();
686   
687  1 assertTrue(it.hasNext());
688  1 region = it.next();
689  1 assertEquals(region[0], 1);
690  1 assertEquals(region[1], 7);
691   
692  1 assertTrue(it.hasNext());
693  1 region = it.next();
694  1 assertEquals(region[0], 13);
695  1 assertEquals(region[1], 14);
696   
697  1 assertTrue(it.hasNext());
698  1 region = it.next();
699  1 assertEquals(region[0], 34);
700  1 assertEquals(region[1], 34);
701    }
702   
 
703  1 toggle @Test(groups = { "Functional" })
704    public void testAddFeatureDetails()
705    {
706  1 String menuText = MessageManager.getString("label.feature_details");
707   
708    /*
709    * with no features, sub-menu should not be created
710    */
711  1 List<SequenceFeature> features = new ArrayList<>();
712  1 SequenceI seq = this.alignment.getSequenceAt(0); // FER_CAPAA/1-12
713  1 testee.addFeatureDetails(features, seq, 10);
714  1 JMenu menu = findMenu(testee, menuText);
715  1 assertNull(menu);
716   
717    /*
718    * add some features; the menu item text is wrapped in html, and includes
719    * feature type, position, description, group (if not null)
720    */
721  1 SequenceFeature sf1 = new SequenceFeature("helix", "curly", 2, 6, null);
722  1 SequenceFeature sf2 = new SequenceFeature("chain", "straight", 1, 1,
723    "uniprot");
724  1 features.add(sf1);
725  1 features.add(sf2);
726  1 testee.addFeatureDetails(features, seq, 10);
727  1 menu = findMenu(testee, menuText);
728  1 assertNotNull(menu);
729  1 assertEquals(2, menu.getItemCount());
730  1 JMenuItem item = menu.getItem(0);
731  1 assertEquals("<html>helix 2-6 curly</html>", item.getText());
732  1 item = menu.getItem(1);
733  1 assertEquals("<html>chain 1 straight (uniprot)</html>", item.getText());
734   
735    /*
736    * long feature descriptions are truncated to 40 characters
737    */
738  1 sf1.setDescription("this is a quite extraordinarily long description");
739  1 testee.remove(menu); // don't create the sub-menu twice
740  1 testee.addFeatureDetails(features, seq, 10);
741  1 menu = findMenu(testee, menuText);
742  1 item = menu.getItem(0);
743  1 assertEquals(
744    "<html>helix 2-6 this is a quite extraordinarily long des...</html>",
745    item.getText());
746    }
747   
748    /**
749    * Returns the first component which is a JMenu with the given text
750    *
751    * @param c
752    * @param text
753    * @return
754    */
 
755  3 toggle private JMenu findMenu(Container c, String text)
756    {
757  18 for (int i = 0; i < c.getComponentCount(); i++)
758    {
759  17 Component comp = c.getComponent(i);
760  17 if ((comp instanceof JMenu) && ((JMenu) comp).getText().equals(text))
761    {
762  2 return (JMenu) comp;
763    }
764    }
765  1 return null;
766    }
767   
 
768  1 toggle @Test(groups = { "Functional" })
769    public void testAddFeatureDetails_linkedFeatures()
770    {
771    // todo tests that verify menu items for complement features
772    }
773    }