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