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