Merge branch 'releases/Release_2_10_4_Branch' into develop
[jalview.git] / test / jalview / gui / PopupMenuTest.java
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.assertTrue;
28
29 import jalview.bin.Cache;
30 import jalview.datamodel.AlignmentAnnotation;
31 import jalview.datamodel.AlignmentI;
32 import jalview.datamodel.Annotation;
33 import jalview.datamodel.ColumnSelection;
34 import jalview.datamodel.DBRefEntry;
35 import jalview.datamodel.DBRefSource;
36 import jalview.datamodel.HiddenColumns;
37 import jalview.datamodel.Sequence;
38 import jalview.datamodel.SequenceFeature;
39 import jalview.datamodel.SequenceGroup;
40 import jalview.datamodel.SequenceI;
41 import jalview.io.DataSourceType;
42 import jalview.io.FileFormat;
43 import jalview.io.FormatAdapter;
44 import jalview.urls.api.UrlProviderFactoryI;
45 import jalview.urls.desktop.DesktopUrlProviderFactory;
46 import jalview.util.MessageManager;
47 import jalview.util.UrlConstants;
48
49 import java.awt.Component;
50 import java.io.IOException;
51 import java.util.ArrayList;
52 import java.util.Collections;
53 import java.util.Iterator;
54 import java.util.List;
55
56 import javax.swing.JMenu;
57 import javax.swing.JMenuItem;
58 import javax.swing.JPopupMenu;
59 import javax.swing.JSeparator;
60
61 import org.testng.annotations.BeforeClass;
62 import org.testng.annotations.BeforeMethod;
63 import org.testng.annotations.Test;
64
65 public class PopupMenuTest
66 {
67
68   @BeforeClass(alwaysRun = true)
69   public void setUpJvOptionPane()
70   {
71     JvOptionPane.setInteractiveMode(false);
72     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
73   }
74
75   // 4 sequences x 13 positions
76   final static String TEST_DATA = ">FER_CAPAA Ferredoxin\n"
77           + "TIETHKEAELVG-\n"
78           + ">FER_CAPAN Ferredoxin, chloroplast precursor\n"
79           + "TIETHKEAELVG-\n"
80           + ">FER1_SOLLC Ferredoxin-1, chloroplast precursor\n"
81           + "TIETHKEEELTA-\n" + ">Q93XJ9_SOLTU Ferredoxin I precursor\n"
82           + "TIETHKEEELTA-\n";
83
84   AlignmentI alignment;
85
86   AlignmentPanel parentPanel;
87
88   PopupMenu testee = null;
89
90   @BeforeMethod(alwaysRun = true)
91   public void setUp() throws IOException
92   {
93     Cache.loadProperties("test/jalview/io/testProps.jvprops");
94     String inMenuString = ("EMBL-EBI Search | http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$"
95             + SEQUENCE_ID
96             + "$"
97             + "|"
98             + "UNIPROT | http://www.uniprot.org/uniprot/$" + DB_ACCESSION + "$")
99             + "|"
100             + ("INTERPRO | http://www.ebi.ac.uk/interpro/entry/$"
101                     + DB_ACCESSION + "$")
102             + "|"
103             +
104             // Gene3D entry tests for case (in)sensitivity
105             ("Gene3D | http://gene3d.biochem.ucl.ac.uk/Gene3D/search?sterm=$"
106                     + DB_ACCESSION + "$&mode=protein");
107
108     UrlProviderFactoryI factory = new DesktopUrlProviderFactory(
109             UrlConstants.DEFAULT_LABEL, inMenuString, "");
110     Preferences.sequenceUrlLinks = factory.createUrlProvider();
111
112     alignment = new FormatAdapter().readFile(TEST_DATA,
113             DataSourceType.PASTE, FileFormat.Fasta);
114     AlignFrame af = new AlignFrame(alignment, 700, 500);
115     parentPanel = new AlignmentPanel(af, af.getViewport());
116     testee = new PopupMenu(parentPanel, null, null);
117     int i = 0;
118     for (SequenceI seq : alignment.getSequences())
119     {
120       final AlignmentAnnotation annotation = new AlignmentAnnotation(
121               "label" + i, "desc" + i, i);
122       annotation.setCalcId("calcId" + i);
123       seq.addAlignmentAnnotation(annotation);
124       annotation.setSequenceRef(seq);
125     }
126   }
127
128   @Test(groups = { "Functional" })
129   public void testConfigureReferenceAnnotationsMenu_noSequenceSelected()
130   {
131     JMenuItem menu = new JMenuItem();
132     List<SequenceI> seqs = new ArrayList<>();
133     testee.configureReferenceAnnotationsMenu(menu, seqs);
134     assertFalse(menu.isEnabled());
135     // now try null list
136     menu.setEnabled(true);
137     testee.configureReferenceAnnotationsMenu(menu, null);
138     assertFalse(menu.isEnabled());
139   }
140
141   /**
142    * Test building the 'add reference annotations' menu for the case where there
143    * are no reference annotations to add to the alignment. The menu item should
144    * be disabled.
145    */
146   @Test(groups = { "Functional" })
147   public void testConfigureReferenceAnnotationsMenu_noReferenceAnnotations()
148   {
149     JMenuItem menu = new JMenuItem();
150
151     /*
152      * Initial state is that sequences have annotations, and have dataset
153      * sequences, but the dataset sequences have no annotations. Hence nothing
154      * to add.
155      */
156     List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
157
158     testee.configureReferenceAnnotationsMenu(menu, seqs);
159     assertFalse(menu.isEnabled());
160   }
161
162   /**
163    * Test building the 'add reference annotations' menu for the case where all
164    * reference annotations are already on the alignment. The menu item should be
165    * disabled.
166    */
167   @Test(groups = { "Functional" })
168   public void testConfigureReferenceAnnotationsMenu_alreadyAdded()
169   {
170     JMenuItem menu = new JMenuItem();
171     List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
172
173     // make up new annotations and add to dataset sequences, sequences and
174     // alignment
175     attachReferenceAnnotations(seqs, true, true);
176
177     testee.configureReferenceAnnotationsMenu(menu, seqs);
178     assertFalse(menu.isEnabled());
179   }
180
181   /**
182    * Test building the 'add reference annotations' menu for the case where
183    * several reference annotations are on the dataset but not on the sequences.
184    * The menu item should be enabled, and acquire a tooltip which lists the
185    * annotation sources (calcIds) and type (labels).
186    */
187   @Test(groups = { "Functional" })
188   public void testConfigureReferenceAnnotationsMenu()
189   {
190     JMenuItem menu = new JMenuItem();
191     List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
192
193     // make up new annotations and add to dataset sequences
194     attachReferenceAnnotations(seqs, false, false);
195
196     testee.configureReferenceAnnotationsMenu(menu, seqs);
197     assertTrue(menu.isEnabled());
198     String s = MessageManager.getString("label.add_annotations_for");
199     String expected = "<html><style> p.ttip {width: 350; text-align: justify; word-wrap: break-word;}</style><p class=\"ttip\">"
200             + s + "<br/>Jmol/secondary structure<br/>PDB/Temp</p></html>";
201     assertEquals(expected, menu.getToolTipText());
202   }
203
204   /**
205    * Test building the 'add reference annotations' menu for the case where
206    * several reference annotations are on the dataset and the sequences but not
207    * on the alignment. The menu item should be enabled, and acquire a tooltip
208    * which lists the annotation sources (calcIds) and type (labels).
209    */
210   @Test(groups = { "Functional" })
211   public void testConfigureReferenceAnnotationsMenu_notOnAlignment()
212   {
213     JMenuItem menu = new JMenuItem();
214     List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
215
216     // make up new annotations and add to dataset sequences and sequences
217     attachReferenceAnnotations(seqs, true, false);
218
219     testee.configureReferenceAnnotationsMenu(menu, seqs);
220     assertTrue(menu.isEnabled());
221     String s = MessageManager.getString("label.add_annotations_for");
222     String expected = "<html><style> p.ttip {width: 350; text-align: justify; word-wrap: break-word;}</style><p class=\"ttip\">"
223             + s + "<br/>Jmol/secondary structure<br/>PDB/Temp</p></html>";
224     assertEquals(expected, menu.getToolTipText());
225   }
226
227   /**
228    * Generate annotations and add to dataset sequences and (optionally)
229    * sequences and/or alignment
230    * 
231    * @param seqs
232    * @param addToSequence
233    * @param addToAlignment
234    */
235   private void attachReferenceAnnotations(List<SequenceI> seqs,
236           boolean addToSequence, boolean addToAlignment)
237   {
238     // PDB.secondary structure on Sequence0
239     AlignmentAnnotation annotation = new AlignmentAnnotation(
240             "secondary structure", "", 0);
241     annotation.setCalcId("PDB");
242     seqs.get(0).getDatasetSequence().addAlignmentAnnotation(annotation);
243     if (addToSequence)
244     {
245       seqs.get(0).addAlignmentAnnotation(annotation);
246     }
247     if (addToAlignment)
248     {
249       this.alignment.addAnnotation(annotation);
250     }
251
252     // PDB.Temp on Sequence1
253     annotation = new AlignmentAnnotation("Temp", "", 0);
254     annotation.setCalcId("PDB");
255     seqs.get(1).getDatasetSequence().addAlignmentAnnotation(annotation);
256     if (addToSequence)
257     {
258       seqs.get(1).addAlignmentAnnotation(annotation);
259     }
260     if (addToAlignment)
261     {
262       this.alignment.addAnnotation(annotation);
263     }
264
265     // JMOL.secondary structure on Sequence0
266     annotation = new AlignmentAnnotation("secondary structure", "", 0);
267     annotation.setCalcId("Jmol");
268     seqs.get(0).getDatasetSequence().addAlignmentAnnotation(annotation);
269     if (addToSequence)
270     {
271       seqs.get(0).addAlignmentAnnotation(annotation);
272     }
273     if (addToAlignment)
274     {
275       this.alignment.addAnnotation(annotation);
276     }
277   }
278
279   /**
280    * Test building the 'add reference annotations' menu for the case where there
281    * are two alignment views:
282    * <ul>
283    * <li>in one view, reference annotations have been added (are on the
284    * datasets, sequences and alignment)</li>
285    * <li>in the current view, reference annotations are on the dataset and
286    * sequence, but not the alignment</li>
287    * </ul>
288    * The menu item should be enabled, and acquire a tooltip which lists the
289    * annotation sources (calcIds) and type (labels).
290    */
291   @Test(groups = { "Functional" })
292   public void testConfigureReferenceAnnotationsMenu_twoViews()
293   {
294   }
295
296   /**
297    * Test for building menu options including 'show' and 'hide' annotation
298    * types.
299    */
300   @Test(groups = { "Functional" })
301   public void testBuildAnnotationTypesMenus()
302   {
303     JMenu showMenu = new JMenu();
304     JMenu hideMenu = new JMenu();
305     List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
306
307     // make up new annotations and add to sequences and to the alignment
308
309     // PDB.secondary structure on Sequence0
310     AlignmentAnnotation annotation = new AlignmentAnnotation(
311             "secondary structure", "", new Annotation[] {});
312     annotation.setCalcId("PDB");
313     annotation.visible = true;
314     seqs.get(0).addAlignmentAnnotation(annotation);
315     parentPanel.getAlignment().addAnnotation(annotation);
316
317     // JMOL.secondary structure on Sequence0 - hidden
318     annotation = new AlignmentAnnotation("secondary structure", "",
319             new Annotation[] {});
320     annotation.setCalcId("JMOL");
321     annotation.visible = false;
322     seqs.get(0).addAlignmentAnnotation(annotation);
323     parentPanel.getAlignment().addAnnotation(annotation);
324
325     // Jpred.SSP on Sequence0 - hidden
326     annotation = new AlignmentAnnotation("SSP", "", new Annotation[] {});
327     annotation.setCalcId("JPred");
328     annotation.visible = false;
329     seqs.get(0).addAlignmentAnnotation(annotation);
330     parentPanel.getAlignment().addAnnotation(annotation);
331
332     // PDB.Temp on Sequence1
333     annotation = new AlignmentAnnotation("Temp", "", new Annotation[] {});
334     annotation.setCalcId("PDB");
335     annotation.visible = true;
336     seqs.get(1).addAlignmentAnnotation(annotation);
337     parentPanel.getAlignment().addAnnotation(annotation);
338
339     /*
340      * Expect menu options to show "secondary structure" and "SSP", and to hide
341      * "secondary structure" and "Temp". Tooltip should be calcId.
342      */
343     testee.buildAnnotationTypesMenus(showMenu, hideMenu, seqs);
344
345     assertTrue(showMenu.isEnabled());
346     assertTrue(hideMenu.isEnabled());
347
348     Component[] showOptions = showMenu.getMenuComponents();
349     Component[] hideOptions = hideMenu.getMenuComponents();
350
351     assertEquals(4, showOptions.length); // includes 'All' and separator
352     assertEquals(4, hideOptions.length);
353     String all = MessageManager.getString("label.all");
354     assertEquals(all, ((JMenuItem) showOptions[0]).getText());
355     assertTrue(showOptions[1] instanceof JPopupMenu.Separator);
356     assertEquals(JSeparator.HORIZONTAL,
357             ((JSeparator) showOptions[1]).getOrientation());
358     assertEquals("secondary structure",
359             ((JMenuItem) showOptions[2]).getText());
360     assertEquals("JMOL", ((JMenuItem) showOptions[2]).getToolTipText());
361     assertEquals("SSP", ((JMenuItem) showOptions[3]).getText());
362     assertEquals("JPred", ((JMenuItem) showOptions[3]).getToolTipText());
363
364     assertEquals(all, ((JMenuItem) hideOptions[0]).getText());
365     assertTrue(hideOptions[1] instanceof JPopupMenu.Separator);
366     assertEquals(JSeparator.HORIZONTAL,
367             ((JSeparator) hideOptions[1]).getOrientation());
368     assertEquals("secondary structure",
369             ((JMenuItem) hideOptions[2]).getText());
370     assertEquals("PDB", ((JMenuItem) hideOptions[2]).getToolTipText());
371     assertEquals("Temp", ((JMenuItem) hideOptions[3]).getText());
372     assertEquals("PDB", ((JMenuItem) hideOptions[3]).getToolTipText());
373   }
374
375   /**
376    * Test for building menu options with only 'hide' annotation types enabled.
377    */
378   @Test(groups = { "Functional" })
379   public void testBuildAnnotationTypesMenus_showDisabled()
380   {
381     JMenu showMenu = new JMenu();
382     JMenu hideMenu = new JMenu();
383     List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
384
385     // make up new annotations and add to sequences and to the alignment
386
387     // PDB.secondary structure on Sequence0
388     AlignmentAnnotation annotation = new AlignmentAnnotation(
389             "secondary structure", "", new Annotation[] {});
390     annotation.setCalcId("PDB");
391     annotation.visible = true;
392     seqs.get(0).addAlignmentAnnotation(annotation);
393     parentPanel.getAlignment().addAnnotation(annotation);
394
395     // PDB.Temp on Sequence1
396     annotation = new AlignmentAnnotation("Temp", "", new Annotation[] {});
397     annotation.setCalcId("PDB");
398     annotation.visible = true;
399     seqs.get(1).addAlignmentAnnotation(annotation);
400     parentPanel.getAlignment().addAnnotation(annotation);
401
402     /*
403      * Expect menu options to hide "secondary structure" and "Temp". Tooltip
404      * should be calcId. 'Show' menu should be disabled.
405      */
406     testee.buildAnnotationTypesMenus(showMenu, hideMenu, seqs);
407
408     assertFalse(showMenu.isEnabled());
409     assertTrue(hideMenu.isEnabled());
410
411     Component[] showOptions = showMenu.getMenuComponents();
412     Component[] hideOptions = hideMenu.getMenuComponents();
413
414     assertEquals(2, showOptions.length); // includes 'All' and separator
415     assertEquals(4, hideOptions.length);
416     String all = MessageManager.getString("label.all");
417     assertEquals(all, ((JMenuItem) showOptions[0]).getText());
418     assertTrue(showOptions[1] instanceof JPopupMenu.Separator);
419     assertEquals(JSeparator.HORIZONTAL,
420             ((JSeparator) showOptions[1]).getOrientation());
421
422     assertEquals(all, ((JMenuItem) hideOptions[0]).getText());
423     assertTrue(hideOptions[1] instanceof JPopupMenu.Separator);
424     assertEquals(JSeparator.HORIZONTAL,
425             ((JSeparator) hideOptions[1]).getOrientation());
426     assertEquals("secondary structure",
427             ((JMenuItem) hideOptions[2]).getText());
428     assertEquals("PDB", ((JMenuItem) hideOptions[2]).getToolTipText());
429     assertEquals("Temp", ((JMenuItem) hideOptions[3]).getText());
430     assertEquals("PDB", ((JMenuItem) hideOptions[3]).getToolTipText());
431   }
432
433   /**
434    * Test for building menu options with only 'show' annotation types enabled.
435    */
436   @Test(groups = { "Functional" })
437   public void testBuildAnnotationTypesMenus_hideDisabled()
438   {
439     JMenu showMenu = new JMenu();
440     JMenu hideMenu = new JMenu();
441     List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
442
443     // make up new annotations and add to sequences and to the alignment
444
445     // PDB.secondary structure on Sequence0
446     AlignmentAnnotation annotation = new AlignmentAnnotation(
447             "secondary structure", "", new Annotation[] {});
448     annotation.setCalcId("PDB");
449     annotation.visible = false;
450     seqs.get(0).addAlignmentAnnotation(annotation);
451     parentPanel.getAlignment().addAnnotation(annotation);
452
453     // PDB.Temp on Sequence1
454     annotation = new AlignmentAnnotation("Temp", "", new Annotation[] {});
455     annotation.setCalcId("PDB2");
456     annotation.visible = false;
457     seqs.get(1).addAlignmentAnnotation(annotation);
458     parentPanel.getAlignment().addAnnotation(annotation);
459
460     /*
461      * Expect menu options to show "secondary structure" and "Temp". Tooltip
462      * should be calcId. 'hide' menu should be disabled.
463      */
464     testee.buildAnnotationTypesMenus(showMenu, hideMenu, seqs);
465
466     assertTrue(showMenu.isEnabled());
467     assertFalse(hideMenu.isEnabled());
468
469     Component[] showOptions = showMenu.getMenuComponents();
470     Component[] hideOptions = hideMenu.getMenuComponents();
471
472     assertEquals(4, showOptions.length); // includes 'All' and separator
473     assertEquals(2, hideOptions.length);
474     String all = MessageManager.getString("label.all");
475     assertEquals(all, ((JMenuItem) showOptions[0]).getText());
476     assertTrue(showOptions[1] instanceof JPopupMenu.Separator);
477     assertEquals(JSeparator.HORIZONTAL,
478             ((JSeparator) showOptions[1]).getOrientation());
479     assertEquals("secondary structure",
480             ((JMenuItem) showOptions[2]).getText());
481     assertEquals("PDB", ((JMenuItem) showOptions[2]).getToolTipText());
482     assertEquals("Temp", ((JMenuItem) showOptions[3]).getText());
483     assertEquals("PDB2", ((JMenuItem) showOptions[3]).getToolTipText());
484
485     assertEquals(all, ((JMenuItem) hideOptions[0]).getText());
486     assertTrue(hideOptions[1] instanceof JPopupMenu.Separator);
487     assertEquals(JSeparator.HORIZONTAL,
488             ((JSeparator) hideOptions[1]).getOrientation());
489   }
490
491   /**
492    * Test for adding feature links
493    */
494   @Test(groups = { "Functional" })
495   public void testAddFeatureLinks()
496   {
497     // sequences from the alignment
498     List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
499
500     // create list of links and list of DBRefs
501     List<String> links = new ArrayList<>();
502     List<DBRefEntry> refs = new ArrayList<>();
503
504     // links as might be added into Preferences | Connections dialog
505     links.add("EMBL-EBI Search | http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$"
506             + SEQUENCE_ID + "$");
507     links.add("UNIPROT | http://www.uniprot.org/uniprot/$" + DB_ACCESSION
508             + "$");
509     links.add("INTERPRO | http://www.ebi.ac.uk/interpro/entry/$"
510             + DB_ACCESSION + "$");
511     // Gene3D entry tests for case (in)sensitivity
512     links.add("Gene3D | http://gene3d.biochem.ucl.ac.uk/Gene3D/search?sterm=$"
513             + DB_ACCESSION + "$&mode=protein");
514
515     // make seq0 dbrefs
516     refs.add(new DBRefEntry(DBRefSource.UNIPROT, "1", "P83527"));
517     refs.add(new DBRefEntry("INTERPRO", "1", "IPR001041"));
518     refs.add(new DBRefEntry("INTERPRO", "1", "IPR006058"));
519     refs.add(new DBRefEntry("INTERPRO", "1", "IPR012675"));
520     
521     // make seq1 dbrefs
522     refs.add(new DBRefEntry(DBRefSource.UNIPROT, "1", "Q9ZTS2"));
523     refs.add(new DBRefEntry("GENE3D", "1", "3.10.20.30"));
524
525     // add all the dbrefs to the sequences: Uniprot 1 each, Interpro all 3 to
526     // seq0, Gene3D to seq1
527     SequenceI seq = seqs.get(0);
528     seq.addDBRef(refs.get(0));
529
530     seq.addDBRef(refs.get(1));
531     seq.addDBRef(refs.get(2));
532     seq.addDBRef(refs.get(3));
533     
534     seqs.get(1).addDBRef(refs.get(4));
535     seqs.get(1).addDBRef(refs.get(5));
536     
537     // get the Popup Menu for first sequence
538     List<SequenceFeature> noFeatures = Collections.<SequenceFeature> emptyList();
539     testee = new PopupMenu(parentPanel, seq, noFeatures);
540     Component[] seqItems = testee.sequenceMenu.getMenuComponents();
541     JMenu linkMenu = (JMenu) seqItems[6];
542     Component[] linkItems = linkMenu.getMenuComponents();
543     
544     // check the number of links are the expected number
545     assertEquals(5, linkItems.length);
546
547     // first entry is EMBL-EBI which just uses sequence id not accession id?
548     assertEquals("EMBL-EBI Search", ((JMenuItem) linkItems[0]).getText());
549
550     // sequence id for each link should match corresponding DB accession id
551     for (int i = 1; i < 4; i++)
552     {
553       String msg = seq.getName() + " link[" + i + "]";
554       assertEquals(msg, refs.get(i - 1).getSource(),
555               ((JMenuItem) linkItems[i])
556               .getText().split("\\|")[0]);
557       assertEquals(msg, refs.get(i - 1).getAccessionId(),
558               ((JMenuItem) linkItems[i])
559               .getText().split("\\|")[1]);
560     }
561
562     // get the Popup Menu for second sequence
563     seq = seqs.get(1);
564     testee = new PopupMenu(parentPanel, seq, noFeatures);
565     seqItems = testee.sequenceMenu.getMenuComponents();
566     linkMenu = (JMenu) seqItems[6];
567     linkItems = linkMenu.getMenuComponents();
568     
569     // check the number of links are the expected number
570     assertEquals(3, linkItems.length);
571
572     // first entry is EMBL-EBI which just uses sequence id not accession id?
573     assertEquals("EMBL-EBI Search", ((JMenuItem) linkItems[0]).getText());
574
575     // sequence id for each link should match corresponding DB accession id
576     for (int i = 1; i < 3; i++)
577     {
578       String msg = seq.getName() + " link[" + i + "]";
579       assertEquals(msg, refs.get(i + 3).getSource(),
580               ((JMenuItem) linkItems[i])
581               .getText().split("\\|")[0].toUpperCase());
582       assertEquals(msg, refs.get(i + 3).getAccessionId(),
583               ((JMenuItem) linkItems[i]).getText().split("\\|")[1]);
584     }
585
586     // if there are no valid links the Links submenu is disabled
587     List<String> nomatchlinks = new ArrayList<>();
588     nomatchlinks.add("NOMATCH | http://www.uniprot.org/uniprot/$"
589             + DB_ACCESSION + "$");
590
591     testee = new PopupMenu(parentPanel, seq, noFeatures);
592     seqItems = testee.sequenceMenu.getMenuComponents();
593     linkMenu = (JMenu) seqItems[6];
594     assertFalse(linkMenu.isEnabled());
595
596   }
597
598   /**
599    * Test for adding feature links
600    */
601   @Test(groups = { "Functional" })
602   public void testHideInsertions()
603   {
604     // get sequences from the alignment
605     List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
606     
607     // add our own seqs to avoid problems with changes to existing sequences
608     // (gap at end of sequences varies depending on how tests are run!)
609     Sequence seqGap1 = new Sequence("GappySeq",
610             "AAAA----AA-AAAAAAA---AAA-----------AAAAAAAAAA--");
611     seqGap1.createDatasetSequence();
612     seqs.add(seqGap1);
613     Sequence seqGap2 = new Sequence("LessGappySeq",
614             "AAAAAA-AAAAA---AAA--AAAAA--AAAAAAA-AAAAAA");
615     seqGap2.createDatasetSequence();
616     seqs.add(seqGap2);
617     Sequence seqGap3 = new Sequence("AnotherGapSeq",
618             "AAAAAA-AAAAAA--AAAAAA-AAAAAAAAAAA---AAAAAAAA");
619     seqGap3.createDatasetSequence();
620     seqs.add(seqGap3);
621     Sequence seqGap4 = new Sequence("NoGaps",
622             "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
623     seqGap4.createDatasetSequence();
624     seqs.add(seqGap4);
625
626     ColumnSelection sel = new ColumnSelection();
627     parentPanel.av.getAlignment().getHiddenColumns()
628             .revealAllHiddenColumns(sel);
629
630     // get the Popup Menu for 7th sequence - no insertions
631     testee = new PopupMenu(parentPanel, seqs.get(7), null);
632     testee.hideInsertions_actionPerformed(null);
633     
634     HiddenColumns hidden = parentPanel.av.getAlignment().getHiddenColumns();
635     Iterator<int[]> it = hidden.iterator();
636     assertFalse(it.hasNext());
637
638     // get the Popup Menu for GappySeq - this time we have insertions
639     testee = new PopupMenu(parentPanel, seqs.get(4), null);
640     testee.hideInsertions_actionPerformed(null);
641     hidden = parentPanel.av.getAlignment().getHiddenColumns();
642     it = hidden.iterator();
643
644     assertTrue(it.hasNext());
645     int[] region = it.next();
646     assertEquals(region[0], 4);
647     assertEquals(region[1], 7);
648
649     assertTrue(it.hasNext());
650     region = it.next();
651     assertEquals(region[0], 10);
652     assertEquals(region[1], 10);
653
654     assertTrue(it.hasNext());
655     region = it.next();
656     assertEquals(region[0], 18);
657     assertEquals(region[1], 20);
658
659     assertTrue(it.hasNext());
660     region = it.next();
661     assertEquals(region[0], 24);
662     assertEquals(region[1], 34);
663
664     assertTrue(it.hasNext());
665     region = it.next();
666     assertEquals(region[0], 45);
667     assertEquals(region[1], 46);
668
669     assertFalse(it.hasNext());
670
671     sel = new ColumnSelection();
672     hidden.revealAllHiddenColumns(sel);
673
674     // make a sequence group and hide insertions within the group
675     SequenceGroup sg = new SequenceGroup();
676     sg.setStartRes(8);
677     sg.setEndRes(42);
678     sg.addSequence(seqGap2, false);
679     sg.addSequence(seqGap3, false);
680     parentPanel.av.setSelectionGroup(sg);
681
682     // hide columns outside and within selection
683     // only hidden columns outside the collection will be retained (unless also
684     // gaps in the selection)
685     hidden.hideColumns(1, 10);
686     hidden.hideColumns(31, 40);
687
688     // get the Popup Menu for LessGappySeq in the sequence group
689     testee = new PopupMenu(parentPanel, seqs.get(5), null);
690     testee.hideInsertions_actionPerformed(null);
691     hidden = parentPanel.av.getAlignment().getHiddenColumns();
692     it = hidden.iterator();
693
694     assertTrue(it.hasNext());
695     region = it.next();
696     assertEquals(region[0], 1);
697     assertEquals(region[1], 7);
698
699     assertTrue(it.hasNext());
700     region = it.next();
701     assertEquals(region[0], 13);
702     assertEquals(region[1], 14);
703
704     assertTrue(it.hasNext());
705     region = it.next();
706     assertEquals(region[0], 34);
707     assertEquals(region[1], 34);
708   }
709
710 }