JAL-3423 testNG fix for revised tooltip html format
[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;
200     // word-wrap: break-word;}</style><p class=\"ttip\">"
201     // + s + "<br/>Jmol/secondary structure<br/>PDB/Temp</p></html>";
202     String expected = JvSwingUtils.HTML_PREFIX + s
203             + "<br/>Jmol/secondary structure<br/>PDB/Temp</div></html>";
204     assertEquals(expected, menu.getToolTipText());
205   }
206
207   /**
208    * Test building the 'add reference annotations' menu for the case where
209    * several reference annotations are on the dataset and the sequences but not
210    * on the alignment. The menu item should be enabled, and acquire a tooltip
211    * which lists the annotation sources (calcIds) and type (labels).
212    */
213   @Test(groups = { "Functional" })
214   public void testConfigureReferenceAnnotationsMenu_notOnAlignment()
215   {
216     JMenuItem menu = new JMenuItem();
217     List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
218
219     // make up new annotations and add to dataset sequences and sequences
220     attachReferenceAnnotations(seqs, true, false);
221
222     testee.configureReferenceAnnotationsMenu(menu, seqs);
223     assertTrue(menu.isEnabled());
224     String s = MessageManager.getString("label.add_annotations_for");
225     // String expected = "<html><style> p.ttip {width: 350; text-align: justify;
226     // word-wrap: break-word;}</style><p class=\"ttip\">"
227     // + s + "<br/>Jmol/secondary structure<br/>PDB/Temp</p></html>";
228     String expected = JvSwingUtils.HTML_PREFIX
229             + "Add annotations for<br/>Jmol/secondary structure<br/>PDB/Temp</div></html>";
230     assertEquals(expected, menu.getToolTipText());
231   }
232
233   /**
234    * Generate annotations and add to dataset sequences and (optionally)
235    * sequences and/or alignment
236    * 
237    * @param seqs
238    * @param addToSequence
239    * @param addToAlignment
240    */
241   private void attachReferenceAnnotations(List<SequenceI> seqs,
242           boolean addToSequence, boolean addToAlignment)
243   {
244     // PDB.secondary structure on Sequence0
245     AlignmentAnnotation annotation = new AlignmentAnnotation(
246             "secondary structure", "", 0);
247     annotation.setCalcId("PDB");
248     seqs.get(0).getDatasetSequence().addAlignmentAnnotation(annotation);
249     if (addToSequence)
250     {
251       seqs.get(0).addAlignmentAnnotation(annotation);
252     }
253     if (addToAlignment)
254     {
255       this.alignment.addAnnotation(annotation);
256     }
257
258     // PDB.Temp on Sequence1
259     annotation = new AlignmentAnnotation("Temp", "", 0);
260     annotation.setCalcId("PDB");
261     seqs.get(1).getDatasetSequence().addAlignmentAnnotation(annotation);
262     if (addToSequence)
263     {
264       seqs.get(1).addAlignmentAnnotation(annotation);
265     }
266     if (addToAlignment)
267     {
268       this.alignment.addAnnotation(annotation);
269     }
270
271     // JMOL.secondary structure on Sequence0
272     annotation = new AlignmentAnnotation("secondary structure", "", 0);
273     annotation.setCalcId("Jmol");
274     seqs.get(0).getDatasetSequence().addAlignmentAnnotation(annotation);
275     if (addToSequence)
276     {
277       seqs.get(0).addAlignmentAnnotation(annotation);
278     }
279     if (addToAlignment)
280     {
281       this.alignment.addAnnotation(annotation);
282     }
283   }
284
285   /**
286    * Test building the 'add reference annotations' menu for the case where there
287    * are two alignment views:
288    * <ul>
289    * <li>in one view, reference annotations have been added (are on the
290    * datasets, sequences and alignment)</li>
291    * <li>in the current view, reference annotations are on the dataset and
292    * sequence, but not the alignment</li>
293    * </ul>
294    * The menu item should be enabled, and acquire a tooltip which lists the
295    * annotation sources (calcIds) and type (labels).
296    */
297   @Test(groups = { "Functional" })
298   public void testConfigureReferenceAnnotationsMenu_twoViews()
299   {
300   }
301
302   /**
303    * Test for building menu options including 'show' and 'hide' annotation
304    * types.
305    */
306   @Test(groups = { "Functional" })
307   public void testBuildAnnotationTypesMenus()
308   {
309     JMenu showMenu = new JMenu();
310     JMenu hideMenu = new JMenu();
311     List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
312
313     // make up new annotations and add to sequences and to the alignment
314
315     // PDB.secondary structure on Sequence0
316     AlignmentAnnotation annotation = new AlignmentAnnotation(
317             "secondary structure", "", new Annotation[] {});
318     annotation.setCalcId("PDB");
319     annotation.visible = true;
320     seqs.get(0).addAlignmentAnnotation(annotation);
321     parentPanel.getAlignment().addAnnotation(annotation);
322
323     // JMOL.secondary structure on Sequence0 - hidden
324     annotation = new AlignmentAnnotation("secondary structure", "",
325             new Annotation[] {});
326     annotation.setCalcId("JMOL");
327     annotation.visible = false;
328     seqs.get(0).addAlignmentAnnotation(annotation);
329     parentPanel.getAlignment().addAnnotation(annotation);
330
331     // Jpred.SSP on Sequence0 - hidden
332     annotation = new AlignmentAnnotation("SSP", "", new Annotation[] {});
333     annotation.setCalcId("JPred");
334     annotation.visible = false;
335     seqs.get(0).addAlignmentAnnotation(annotation);
336     parentPanel.getAlignment().addAnnotation(annotation);
337
338     // PDB.Temp on Sequence1
339     annotation = new AlignmentAnnotation("Temp", "", new Annotation[] {});
340     annotation.setCalcId("PDB");
341     annotation.visible = true;
342     seqs.get(1).addAlignmentAnnotation(annotation);
343     parentPanel.getAlignment().addAnnotation(annotation);
344
345     /*
346      * Expect menu options to show "secondary structure" and "SSP", and to hide
347      * "secondary structure" and "Temp". Tooltip should be calcId.
348      */
349     testee.buildAnnotationTypesMenus(showMenu, hideMenu, seqs);
350
351     assertTrue(showMenu.isEnabled());
352     assertTrue(hideMenu.isEnabled());
353
354     Component[] showOptions = showMenu.getMenuComponents();
355     Component[] hideOptions = hideMenu.getMenuComponents();
356
357     assertEquals(4, showOptions.length); // includes 'All' and separator
358     assertEquals(4, hideOptions.length);
359     String all = MessageManager.getString("label.all");
360     assertEquals(all, ((JMenuItem) showOptions[0]).getText());
361     assertTrue(showOptions[1] instanceof JPopupMenu.Separator);
362     assertEquals(JSeparator.HORIZONTAL,
363             ((JSeparator) showOptions[1]).getOrientation());
364     assertEquals("secondary structure",
365             ((JMenuItem) showOptions[2]).getText());
366     assertEquals("JMOL", ((JMenuItem) showOptions[2]).getToolTipText());
367     assertEquals("SSP", ((JMenuItem) showOptions[3]).getText());
368     assertEquals("JPred", ((JMenuItem) showOptions[3]).getToolTipText());
369
370     assertEquals(all, ((JMenuItem) hideOptions[0]).getText());
371     assertTrue(hideOptions[1] instanceof JPopupMenu.Separator);
372     assertEquals(JSeparator.HORIZONTAL,
373             ((JSeparator) hideOptions[1]).getOrientation());
374     assertEquals("secondary structure",
375             ((JMenuItem) hideOptions[2]).getText());
376     assertEquals("PDB", ((JMenuItem) hideOptions[2]).getToolTipText());
377     assertEquals("Temp", ((JMenuItem) hideOptions[3]).getText());
378     assertEquals("PDB", ((JMenuItem) hideOptions[3]).getToolTipText());
379   }
380
381   /**
382    * Test for building menu options with only 'hide' annotation types enabled.
383    */
384   @Test(groups = { "Functional" })
385   public void testBuildAnnotationTypesMenus_showDisabled()
386   {
387     JMenu showMenu = new JMenu();
388     JMenu hideMenu = new JMenu();
389     List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
390
391     // make up new annotations and add to sequences and to the alignment
392
393     // PDB.secondary structure on Sequence0
394     AlignmentAnnotation annotation = new AlignmentAnnotation(
395             "secondary structure", "", new Annotation[] {});
396     annotation.setCalcId("PDB");
397     annotation.visible = true;
398     seqs.get(0).addAlignmentAnnotation(annotation);
399     parentPanel.getAlignment().addAnnotation(annotation);
400
401     // PDB.Temp on Sequence1
402     annotation = new AlignmentAnnotation("Temp", "", new Annotation[] {});
403     annotation.setCalcId("PDB");
404     annotation.visible = true;
405     seqs.get(1).addAlignmentAnnotation(annotation);
406     parentPanel.getAlignment().addAnnotation(annotation);
407
408     /*
409      * Expect menu options to hide "secondary structure" and "Temp". Tooltip
410      * should be calcId. 'Show' menu should be disabled.
411      */
412     testee.buildAnnotationTypesMenus(showMenu, hideMenu, seqs);
413
414     assertFalse(showMenu.isEnabled());
415     assertTrue(hideMenu.isEnabled());
416
417     Component[] showOptions = showMenu.getMenuComponents();
418     Component[] hideOptions = hideMenu.getMenuComponents();
419
420     assertEquals(2, showOptions.length); // includes 'All' and separator
421     assertEquals(4, hideOptions.length);
422     String all = MessageManager.getString("label.all");
423     assertEquals(all, ((JMenuItem) showOptions[0]).getText());
424     assertTrue(showOptions[1] instanceof JPopupMenu.Separator);
425     assertEquals(JSeparator.HORIZONTAL,
426             ((JSeparator) showOptions[1]).getOrientation());
427
428     assertEquals(all, ((JMenuItem) hideOptions[0]).getText());
429     assertTrue(hideOptions[1] instanceof JPopupMenu.Separator);
430     assertEquals(JSeparator.HORIZONTAL,
431             ((JSeparator) hideOptions[1]).getOrientation());
432     assertEquals("secondary structure",
433             ((JMenuItem) hideOptions[2]).getText());
434     assertEquals("PDB", ((JMenuItem) hideOptions[2]).getToolTipText());
435     assertEquals("Temp", ((JMenuItem) hideOptions[3]).getText());
436     assertEquals("PDB", ((JMenuItem) hideOptions[3]).getToolTipText());
437   }
438
439   /**
440    * Test for building menu options with only 'show' annotation types enabled.
441    */
442   @Test(groups = { "Functional" })
443   public void testBuildAnnotationTypesMenus_hideDisabled()
444   {
445     JMenu showMenu = new JMenu();
446     JMenu hideMenu = new JMenu();
447     List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
448
449     // make up new annotations and add to sequences and to the alignment
450
451     // PDB.secondary structure on Sequence0
452     AlignmentAnnotation annotation = new AlignmentAnnotation(
453             "secondary structure", "", new Annotation[] {});
454     annotation.setCalcId("PDB");
455     annotation.visible = false;
456     seqs.get(0).addAlignmentAnnotation(annotation);
457     parentPanel.getAlignment().addAnnotation(annotation);
458
459     // PDB.Temp on Sequence1
460     annotation = new AlignmentAnnotation("Temp", "", new Annotation[] {});
461     annotation.setCalcId("PDB2");
462     annotation.visible = false;
463     seqs.get(1).addAlignmentAnnotation(annotation);
464     parentPanel.getAlignment().addAnnotation(annotation);
465
466     /*
467      * Expect menu options to show "secondary structure" and "Temp". Tooltip
468      * should be calcId. 'hide' menu should be disabled.
469      */
470     testee.buildAnnotationTypesMenus(showMenu, hideMenu, seqs);
471
472     assertTrue(showMenu.isEnabled());
473     assertFalse(hideMenu.isEnabled());
474
475     Component[] showOptions = showMenu.getMenuComponents();
476     Component[] hideOptions = hideMenu.getMenuComponents();
477
478     assertEquals(4, showOptions.length); // includes 'All' and separator
479     assertEquals(2, hideOptions.length);
480     String all = MessageManager.getString("label.all");
481     assertEquals(all, ((JMenuItem) showOptions[0]).getText());
482     assertTrue(showOptions[1] instanceof JPopupMenu.Separator);
483     assertEquals(JSeparator.HORIZONTAL,
484             ((JSeparator) showOptions[1]).getOrientation());
485     assertEquals("secondary structure",
486             ((JMenuItem) showOptions[2]).getText());
487     assertEquals("PDB", ((JMenuItem) showOptions[2]).getToolTipText());
488     assertEquals("Temp", ((JMenuItem) showOptions[3]).getText());
489     assertEquals("PDB2", ((JMenuItem) showOptions[3]).getToolTipText());
490
491     assertEquals(all, ((JMenuItem) hideOptions[0]).getText());
492     assertTrue(hideOptions[1] instanceof JPopupMenu.Separator);
493     assertEquals(JSeparator.HORIZONTAL,
494             ((JSeparator) hideOptions[1]).getOrientation());
495   }
496
497   /**
498    * Test for adding sequence id, dbref and feature links
499    */
500   @Test(groups = { "Functional" })
501   public void testBuildLinkMenu()
502   {
503     List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
504     final SequenceI seq0 = seqs.get(0);
505     final SequenceI seq1 = seqs.get(1);
506     final List<SequenceFeature> noFeatures = Collections
507             .<SequenceFeature> emptyList();
508     final String linkText = MessageManager.getString("action.link");
509
510     seq0.addDBRef(new DBRefEntry(DBRefSource.UNIPROT, "1", "P83527"));
511     seq0.addDBRef(new DBRefEntry("INTERPRO", "1", "IPR001041"));
512     seq0.addDBRef(new DBRefEntry("INTERPRO", "1", "IPR012675"));
513     seq0.addDBRef(new DBRefEntry("INTERPRO", "1", "IPR006058"));
514     seq1.addDBRef(new DBRefEntry(DBRefSource.UNIPROT, "1", "Q9ZTS2"));
515     seq1.addDBRef(new DBRefEntry("GENE3D", "1", "3.10.20.30"));
516     
517     /*
518      * check the Link Menu for the first sequence
519      */
520     JMenu linkMenu = PopupMenu.buildLinkMenu(seq0, noFeatures);
521     assertEquals(linkText, linkMenu.getText());
522     Component[] linkItems = linkMenu.getMenuComponents();
523     
524     /*
525      * menu items are ordered: SEQUENCE_ID search first, then dbrefs in order
526      * of database name (and within that by order of dbref addition)
527      */
528     assertEquals(5, linkItems.length);
529     assertEquals("EMBL-EBI Search", ((JMenuItem) linkItems[0]).getText());
530     assertEquals("INTERPRO|IPR001041",
531             ((JMenuItem) linkItems[1]).getText());
532     assertEquals("INTERPRO|IPR012675",
533             ((JMenuItem) linkItems[2]).getText());
534     assertEquals("INTERPRO|IPR006058",
535             ((JMenuItem) linkItems[3]).getText());
536     assertEquals("UNIPROT|P83527", ((JMenuItem) linkItems[4]).getText());
537
538     /*
539      * check the Link Menu for the second sequence
540      * note dbref GENE3D is matched to link Gene3D, the latter is displayed
541      */
542     linkMenu = PopupMenu.buildLinkMenu(seq1, noFeatures);
543     assertEquals(linkText, linkMenu.getText());
544     linkItems = linkMenu.getMenuComponents();
545     assertEquals(3, linkItems.length);
546     assertEquals("EMBL-EBI Search", ((JMenuItem) linkItems[0]).getText());
547     assertEquals("Gene3D|3.10.20.30", ((JMenuItem) linkItems[1]).getText());
548     assertEquals("UNIPROT|Q9ZTS2", ((JMenuItem) linkItems[2]).getText());
549
550     /*
551      * if there are no valid links the Links submenu is still shown, but
552      * reduced to the EMBL-EBI lookup only (inserted by 
553      * CustomUrlProvider.choosePrimaryUrl())
554      */
555     String unmatched = "NOMATCH|http://www.uniprot.org/uniprot/$"
556             + DB_ACCESSION + "$";
557     UrlProviderFactoryI factory = new DesktopUrlProviderFactory(null,
558             unmatched, "");
559     Preferences.sequenceUrlLinks = factory.createUrlProvider();
560
561     linkMenu = PopupMenu.buildLinkMenu(seq1, noFeatures);
562     assertEquals(linkText, linkMenu.getText());
563     linkItems = linkMenu.getMenuComponents();
564     assertEquals(1, linkItems.length);
565     assertEquals("EMBL-EBI Search", ((JMenuItem) linkItems[0]).getText());
566   }
567
568   @Test(groups = { "Functional" })
569   public void testHideInsertions()
570   {
571     // get sequences from the alignment
572     List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
573     
574     // add our own seqs to avoid problems with changes to existing sequences
575     // (gap at end of sequences varies depending on how tests are run!)
576     Sequence seqGap1 = new Sequence("GappySeq",
577             "AAAA----AA-AAAAAAA---AAA-----------AAAAAAAAAA--");
578     seqGap1.createDatasetSequence();
579     seqs.add(seqGap1);
580     Sequence seqGap2 = new Sequence("LessGappySeq",
581             "AAAAAA-AAAAA---AAA--AAAAA--AAAAAAA-AAAAAA");
582     seqGap2.createDatasetSequence();
583     seqs.add(seqGap2);
584     Sequence seqGap3 = new Sequence("AnotherGapSeq",
585             "AAAAAA-AAAAAA--AAAAAA-AAAAAAAAAAA---AAAAAAAA");
586     seqGap3.createDatasetSequence();
587     seqs.add(seqGap3);
588     Sequence seqGap4 = new Sequence("NoGaps",
589             "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
590     seqGap4.createDatasetSequence();
591     seqs.add(seqGap4);
592
593     ColumnSelection sel = new ColumnSelection();
594     parentPanel.av.getAlignment().getHiddenColumns()
595             .revealAllHiddenColumns(sel);
596
597     // get the Popup Menu for 7th sequence - no insertions
598     testee = new PopupMenu(parentPanel, seqs.get(7), null);
599     testee.hideInsertions_actionPerformed(null);
600     
601     HiddenColumns hidden = parentPanel.av.getAlignment().getHiddenColumns();
602     Iterator<int[]> it = hidden.iterator();
603     assertFalse(it.hasNext());
604
605     // get the Popup Menu for GappySeq - this time we have insertions
606     testee = new PopupMenu(parentPanel, seqs.get(4), null);
607     testee.hideInsertions_actionPerformed(null);
608     hidden = parentPanel.av.getAlignment().getHiddenColumns();
609     it = hidden.iterator();
610
611     assertTrue(it.hasNext());
612     int[] region = it.next();
613     assertEquals(region[0], 4);
614     assertEquals(region[1], 7);
615
616     assertTrue(it.hasNext());
617     region = it.next();
618     assertEquals(region[0], 10);
619     assertEquals(region[1], 10);
620
621     assertTrue(it.hasNext());
622     region = it.next();
623     assertEquals(region[0], 18);
624     assertEquals(region[1], 20);
625
626     assertTrue(it.hasNext());
627     region = it.next();
628     assertEquals(region[0], 24);
629     assertEquals(region[1], 34);
630
631     assertTrue(it.hasNext());
632     region = it.next();
633     assertEquals(region[0], 45);
634     assertEquals(region[1], 46);
635
636     assertFalse(it.hasNext());
637
638     sel = new ColumnSelection();
639     hidden.revealAllHiddenColumns(sel);
640
641     // make a sequence group and hide insertions within the group
642     SequenceGroup sg = new SequenceGroup();
643     sg.setStartRes(8);
644     sg.setEndRes(42);
645     sg.addSequence(seqGap2, false);
646     sg.addSequence(seqGap3, false);
647     parentPanel.av.setSelectionGroup(sg);
648
649     // hide columns outside and within selection
650     // only hidden columns outside the collection will be retained (unless also
651     // gaps in the selection)
652     hidden.hideColumns(1, 10);
653     hidden.hideColumns(31, 40);
654
655     // get the Popup Menu for LessGappySeq in the sequence group
656     testee = new PopupMenu(parentPanel, seqs.get(5), null);
657     testee.hideInsertions_actionPerformed(null);
658     hidden = parentPanel.av.getAlignment().getHiddenColumns();
659     it = hidden.iterator();
660
661     assertTrue(it.hasNext());
662     region = it.next();
663     assertEquals(region[0], 1);
664     assertEquals(region[1], 7);
665
666     assertTrue(it.hasNext());
667     region = it.next();
668     assertEquals(region[0], 13);
669     assertEquals(region[1], 14);
670
671     assertTrue(it.hasNext());
672     region = it.next();
673     assertEquals(region[0], 34);
674     assertEquals(region[1], 34);
675   }
676
677 }