2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertFalse;
25 import static org.testng.AssertJUnit.assertTrue;
27 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
28 import jalview.bin.Cache;
29 import jalview.datamodel.AlignmentAnnotation;
30 import jalview.datamodel.AlignmentI;
31 import jalview.datamodel.Annotation;
32 import jalview.datamodel.SequenceGroup;
33 import jalview.datamodel.SequenceI;
34 import jalview.io.AppletFormatAdapter;
35 import jalview.util.MessageManager;
37 import java.awt.BorderLayout;
38 import java.awt.Checkbox;
39 import java.awt.Component;
40 import java.awt.Container;
41 import java.awt.FlowLayout;
42 import java.awt.event.ItemEvent;
43 import java.io.IOException;
44 import java.util.List;
46 import javax.swing.JButton;
47 import javax.swing.JPanel;
49 import org.testng.annotations.BeforeClass;
50 import org.testng.annotations.BeforeMethod;
51 import org.testng.annotations.Test;
54 * Unit tests for AnnotationChooser
59 public class AnnotationChooserTest
62 @BeforeClass(alwaysRun = true)
63 public void setUpJvOptionPane()
65 JvOptionPane.setInteractiveMode(false);
66 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
69 // 4 sequences x 13 positions
70 final static String TEST_DATA = ">FER_CAPAA Ferredoxin\n"
72 + ">FER_CAPAN Ferredoxin, chloroplast precursor\n"
74 + ">FER1_SOLLC Ferredoxin-1, chloroplast precursor\n"
75 + "TIETHKEEELTA-\n" + ">Q93XJ9_SOLTU Ferredoxin I precursor\n"
78 AnnotationChooser testee;
80 AlignmentPanel parentPanel;
84 @BeforeMethod(alwaysRun = true)
85 public void setUp() throws IOException
87 Cache.loadProperties("test/jalview/io/testProps.jvprops");
88 // pin down annotation sort order for test
89 Cache.applicationProperties.setProperty(Preferences.SORT_ANNOTATIONS,
90 SequenceAnnotationOrder.NONE.name());
91 final String TRUE = Boolean.TRUE.toString();
92 Cache.applicationProperties.setProperty(
93 Preferences.SHOW_AUTOCALC_ABOVE, TRUE);
94 Cache.applicationProperties.setProperty("SHOW_QUALITY", TRUE);
95 Cache.applicationProperties.setProperty("SHOW_CONSERVATION", TRUE);
96 Cache.applicationProperties.setProperty("SHOW_IDENTITY", TRUE);
98 AlignmentI al = new jalview.io.FormatAdapter().readFile(TEST_DATA,
99 AppletFormatAdapter.PASTE, "FASTA");
100 af = new AlignFrame(al, 700, 500);
101 parentPanel = new AlignmentPanel(af, af.getViewport());
106 * Add 4 annotations, 3 of them sequence-specific.
109 * ann1 - for sequence 0 - label 'IUPRED'
110 * ann2 - not sequence related - label 'Beauty'
111 * ann3 - for sequence 3 - label 'JMol'
112 * ann4 - for sequence 2 - label 'IUPRED'
113 * ann5 - for sequence 1 - label 'JMol'
115 private void addAnnotations()
117 Annotation an = new Annotation(2f);
118 Annotation[] anns = new Annotation[] { an, an, an };
119 AlignmentAnnotation ann0 = new AlignmentAnnotation("IUPRED", "", anns);
120 AlignmentAnnotation ann1 = new AlignmentAnnotation("Beauty", "", anns);
121 AlignmentAnnotation ann2 = new AlignmentAnnotation("JMol", "", anns);
122 AlignmentAnnotation ann3 = new AlignmentAnnotation("IUPRED", "", anns);
123 AlignmentAnnotation ann4 = new AlignmentAnnotation("JMol", "", anns);
124 SequenceI[] seqs = parentPanel.getAlignment().getSequencesArray();
125 ann0.setSequenceRef(seqs[0]);
126 ann2.setSequenceRef(seqs[3]);
127 ann3.setSequenceRef(seqs[2]);
128 ann4.setSequenceRef(seqs[1]);
129 parentPanel.getAlignment().addAnnotation(ann0);
130 parentPanel.getAlignment().addAnnotation(ann1);
131 parentPanel.getAlignment().addAnnotation(ann2);
132 parentPanel.getAlignment().addAnnotation(ann3);
133 parentPanel.getAlignment().addAnnotation(ann4);
137 * Test creation of panel with OK and Cancel buttons
139 @Test(groups = { "Functional" })
140 public void testBuildActionButtonsPanel()
142 testee = new AnnotationChooser(parentPanel);
143 JPanel jp = testee.buildActionButtonsPanel();
144 assertTrue("Wrong layout", jp.getLayout() instanceof FlowLayout);
146 Component[] comps = jp.getComponents();
147 assertEquals("Not 2 action buttons", 2, comps.length);
149 final Component jb1 = comps[0];
150 final Component jb2 = comps[1];
152 assertEquals("Not 'OK' button", MessageManager.getString("action.ok"),
153 ((JButton) jb1).getText());
154 assertEquals("Wrong button font", JvSwingUtils.getLabelFont(),
157 assertEquals("Not 'Cancel' button",
158 MessageManager.getString("action.cancel"),
159 ((JButton) jb2).getText());
160 assertEquals("Wrong button font", JvSwingUtils.getLabelFont(),
165 * Test 'Apply to' has 3 radio buttons enabled, 'Selected Sequences' selected,
166 * when there is a current selection group.
168 @Test(groups = { "Functional" })
169 public void testBuildApplyToOptionsPanel_withSelectionGroup()
171 selectSequences(0, 2, 3);
172 testee = new AnnotationChooser(parentPanel);
174 JPanel jp = testee.buildApplyToOptionsPanel();
175 Component[] comps = jp.getComponents();
176 assertEquals("Not 3 radio buttons", 3, comps.length);
178 final Checkbox cb1 = (Checkbox) comps[0];
179 final Checkbox cb2 = (Checkbox) comps[1];
180 final Checkbox cb3 = (Checkbox) comps[2];
182 assertTrue("Not enabled", cb1.isEnabled());
183 assertTrue("Not enabled", cb2.isEnabled());
184 assertTrue("Not enabled", cb3.isEnabled());
185 assertEquals("Option not selected", cb2, cb2.getCheckboxGroup()
186 .getSelectedCheckbox());
188 // check state variables match checkbox selection
189 assertTrue(testee.isApplyToSelectedSequences());
190 assertFalse(testee.isApplyToUnselectedSequences());
194 * Add a sequence group to the alignment with the specified sequences (base 0)
200 private void selectSequences(int... selected)
202 SequenceI[] seqs = parentPanel.getAlignment().getSequencesArray();
203 SequenceGroup sg = new SequenceGroup();
204 for (int i : selected)
206 sg.addSequence(seqs[i], false);
208 parentPanel.av.setSelectionGroup(sg);
212 * Test 'Apply to' has 1 radio button enabled, 'All Sequences' selected, when
213 * there is no current selection group.
215 @Test(groups = { "Functional" })
216 public void testBuildApplyToOptionsPanel_noSelectionGroup()
218 testee = new AnnotationChooser(parentPanel);
219 JPanel jp = testee.buildApplyToOptionsPanel();
220 verifyApplyToOptionsPanel_noSelectionGroup(jp);
223 protected void verifyApplyToOptionsPanel_noSelectionGroup(JPanel jp)
225 assertTrue("Wrong layout", jp.getLayout() instanceof FlowLayout);
226 Component[] comps = jp.getComponents();
227 assertEquals("Not 3 radio buttons", 3, comps.length);
229 final Checkbox cb1 = (Checkbox) comps[0];
230 final Checkbox cb2 = (Checkbox) comps[1];
231 final Checkbox cb3 = (Checkbox) comps[2];
233 assertTrue("Not enabled", cb1.isEnabled());
234 assertFalse("Enabled", cb2.isEnabled());
235 assertFalse("Enabled", cb3.isEnabled());
236 assertEquals("Not selected", cb1, cb1.getCheckboxGroup()
237 .getSelectedCheckbox());
239 // check state variables match checkbox selection
240 assertTrue(testee.isApplyToSelectedSequences());
241 assertTrue(testee.isApplyToUnselectedSequences());
243 assertEquals("Wrong text",
244 MessageManager.getString("label.all_sequences"), cb1.getLabel());
245 assertEquals("Wrong text",
246 MessageManager.getString("label.selected_sequences"),
248 assertEquals("Wrong text",
249 MessageManager.getString("label.except_selected_sequences"),
254 * Test Show and Hide radio buttons created, with Hide initially selected.
256 @Test(groups = { "Functional" })
257 public void testBuildShowHidePanel()
259 testee = new AnnotationChooser(parentPanel);
260 JPanel jp = testee.buildShowHidePanel();
261 verifyShowHidePanel(jp);
265 protected void verifyShowHidePanel(JPanel jp)
267 assertTrue("Wrong layout", jp.getLayout() instanceof FlowLayout);
268 Component[] comps = jp.getComponents();
269 assertEquals("Not 2 radio buttons", 2, comps.length);
271 final Checkbox cb1 = (Checkbox) comps[0];
272 final Checkbox cb2 = (Checkbox) comps[1];
274 assertTrue("Show not enabled", cb1.isEnabled());
275 assertTrue("Hide not enabled", cb2.isEnabled());
277 // Hide (button 2) selected; note this may change to none (null)
278 assertEquals("Not selected", cb2, cb2.getCheckboxGroup()
279 .getSelectedCheckbox());
281 assertTrue("Show is flagged", !testee.isShowSelected());
283 assertEquals("Wrong text",
284 MessageManager.getString("label.show_selected_annotations"),
286 assertEquals("Wrong text",
287 MessageManager.getString("label.hide_selected_annotations"),
292 * Test construction of panel containing two sub-panels
294 @Test(groups = { "Functional" })
295 public void testBuildShowHideOptionsPanel()
297 testee = new AnnotationChooser(parentPanel);
298 JPanel jp = testee.buildShowHideOptionsPanel();
299 assertTrue("Wrong layout", jp.getLayout() instanceof BorderLayout);
300 Component[] comps = jp.getComponents();
301 assertEquals("Not 2 sub-panels", 2, comps.length);
303 verifyShowHidePanel((JPanel) comps[0]);
304 verifyApplyToOptionsPanel_noSelectionGroup((JPanel) comps[1]);
308 * Test that annotation types are (uniquely) identified.
311 @Test(groups = { "Functional" })
312 public void testGetAnnotationTypes()
315 testee = new AnnotationChooser(parentPanel);
316 // selection group should make no difference to the result
317 // as all annotation types for the alignment are considered
319 List<String> types = AnnotationChooser.getAnnotationTypes(
320 parentPanel.getAlignment(), true);
321 assertEquals("Not two annotation types", 2, types.size());
322 assertTrue("IUPRED missing", types.contains("IUPRED"));
323 assertTrue("JMol missing", types.contains("JMol"));
325 types = AnnotationChooser.getAnnotationTypes(
326 parentPanel.getAlignment(), false);
327 assertEquals("Not six annotation types", 6, types.size());
328 assertTrue("IUPRED missing", types.contains("IUPRED"));
329 assertTrue("JMol missing", types.contains("JMol"));
330 assertTrue("Beauty missing", types.contains("Beauty"));
331 // These are added by viewmodel.AlignViewport.initAutoAnnotation():
332 assertTrue("Consensus missing", types.contains("Consensus"));
333 assertTrue("Quality missing", types.contains("Quality"));
334 assertTrue("Conservation missing", types.contains("Conservation"));
338 * Test result of selecting an annotation type, with 'Hide for all sequences'.
340 * We expect all annotations of that type to be set hidden. Other annotations
341 * should be left visible.
343 @Test(groups = { "Functional" })
344 public void testSelectType_hideForAll()
346 selectSequences(1, 2);
347 testee = new AnnotationChooser(parentPanel);
348 final Checkbox hideCheckbox = (Checkbox) getComponent(testee, 1, 0, 1);
349 setSelected(hideCheckbox, true);
351 final Checkbox allSequencesCheckbox = (Checkbox) getComponent(testee,
353 setSelected(allSequencesCheckbox, true);
355 AlignmentAnnotation[] anns = parentPanel.getAlignment()
356 .getAlignmentAnnotation();
358 assertTrue(anns[5].visible); // JMol for seq3
359 assertTrue(anns[7].visible); // JMol for seq1
361 setSelected(getTypeCheckbox("JMol"), true);
362 assertTrue(anns[0].visible); // Conservation
363 assertTrue(anns[1].visible); // Quality
364 assertTrue(anns[2].visible); // Consensus
365 assertTrue(anns[3].visible); // IUPred for seq0
366 assertTrue(anns[4].visible); // Beauty
367 assertFalse(anns[5].visible); // JMol for seq3 - not selected but hidden
368 assertTrue(anns[6].visible); // IUPRED for seq2
369 assertFalse(anns[7].visible); // JMol for seq1 - selected and hidden
373 * Test result of selecting an annotation type, with 'Hide for selected
376 * We expect the annotations of that type, linked to the sequence group, to be
377 * set hidden. Other annotations should be left visible.
379 @Test(groups = { "Functional" })
380 public void testSelectType_hideForSelected()
382 selectSequences(1, 2);
383 testee = new AnnotationChooser(parentPanel);
384 final Checkbox hideCheckbox = (Checkbox) getComponent(testee, 1, 0, 1);
385 setSelected(hideCheckbox, true);
388 * Don't set the 'selected sequences' radio button since this would trigger
389 * an update, including unselected sequences / annotation types
391 // setSelected(getSelectedSequencesCheckbox());
393 AlignmentAnnotation[] anns = parentPanel.getAlignment()
394 .getAlignmentAnnotation();
396 assertTrue(anns[7].visible); // JMol for seq1
398 setSelected(getTypeCheckbox("JMol"), true);
399 assertTrue(anns[0].visible); // Conservation
400 assertTrue(anns[1].visible); // Quality
401 assertTrue(anns[2].visible); // Consensus
402 assertTrue(anns[3].visible); // IUPred for seq0
403 assertTrue(anns[4].visible); // Beauty
404 assertTrue(anns[5].visible); // JMol for seq3 not in selection group
405 assertTrue(anns[6].visible); // IUPRED for seq2
406 assertFalse(anns[7].visible); // JMol for seq1 in selection group
410 * Test result of deselecting an annotation type, with 'Hide for all
413 * We expect all annotations of that type to be set visible. Other annotations
414 * should be left unchanged.
416 @Test(groups = { "Functional" })
417 public void testDeselectType_hideForAll()
419 selectSequences(1, 2);
420 testee = new AnnotationChooser(parentPanel);
422 final Checkbox hideCheckbox = (Checkbox) getComponent(testee, 1, 0, 1);
423 setSelected(hideCheckbox, true);
425 final Checkbox allSequencesCheckbox = (Checkbox) getComponent(testee,
427 setSelected(allSequencesCheckbox, true);
429 AlignmentAnnotation[] anns = parentPanel.getAlignment()
430 .getAlignmentAnnotation();
432 final Checkbox typeCheckbox = getTypeCheckbox("JMol");
434 // select JMol - all hidden
435 setSelected(typeCheckbox, true);
436 assertFalse(anns[5].visible); // JMol for seq3
437 assertFalse(anns[7].visible); // JMol for seq1
439 // deselect JMol - all unhidden
440 setSelected(typeCheckbox, false);
441 assertTrue(anns[0].visible); // Conservation
442 assertTrue(anns[1].visible); // Quality
443 assertTrue(anns[2].visible); // Consensus
444 assertTrue(anns[3].visible); // IUPred for seq0
445 assertTrue(anns[4].visible); // Beauty
446 assertTrue(anns[5].visible); // JMol for seq3
447 assertTrue(anns[6].visible); // IUPRED for seq2
448 assertTrue(anns[7].visible); // JMol for seq1
452 * Test result of deselecting an annotation type, with 'Hide for selected
455 * We expect the annotations of that type, linked to the sequence group, to be
456 * set visible. Other annotations should be left unchanged.
458 @Test(groups = { "Functional" })
459 public void testDeselectType_hideForSelected()
461 selectSequences(1, 2);
462 testee = new AnnotationChooser(parentPanel);
463 final Checkbox hideCheckbox = (Checkbox) getComponent(testee, 1, 0, 1);
464 setSelected(hideCheckbox, true);
467 * Don't set the 'selected sequences' radio button since this would trigger
468 * an update, including unselected sequences / annotation types
470 // setSelected(getSelectedSequencesCheckbox());
472 setSelected(getTypeCheckbox("JMol"), true);
473 setSelected(getTypeCheckbox("JMol"), false);
475 AlignmentAnnotation[] anns = parentPanel.getAlignment()
476 .getAlignmentAnnotation();
477 assertTrue(anns[0].visible); // Conservation
478 assertTrue(anns[1].visible); // Quality
479 assertTrue(anns[2].visible); // Consensus
480 assertTrue(anns[3].visible); // IUPred for seq0
481 assertTrue(anns[4].visible); // Beauty
482 assertTrue(anns[5].visible); // JMol for seq3 not in selection group
483 assertTrue(anns[6].visible); // IUPRED for seq2
484 assertTrue(anns[7].visible); // JMol for seq1 in selection group
488 * Test result of selecting an annotation type, with 'Show for all sequences'.
490 * We expect all annotations of that type to be set visible. Other annotations
491 * should be left unchanged
493 @Test(groups = { "Functional" })
494 public void testSelectType_showForAll()
496 selectSequences(1, 2);
497 testee = new AnnotationChooser(parentPanel);
498 final Checkbox showCheckbox = (Checkbox) getComponent(testee, 1, 0, 0);
499 final Checkbox hideCheckbox = (Checkbox) getComponent(testee, 1, 0, 1);
501 final Checkbox allSequencesCheckbox = (Checkbox) getComponent(testee,
504 AlignmentAnnotation[] anns = parentPanel.getAlignment()
505 .getAlignmentAnnotation();
507 // hide all JMol annotations
508 setSelected(allSequencesCheckbox, true);
509 setSelected(hideCheckbox, true);
510 setSelected(getTypeCheckbox("JMol"), true);
511 assertFalse(anns[5].visible); // JMol for seq3
512 assertFalse(anns[7].visible); // JMol for seq1
513 // ...now show them...
514 setSelected(showCheckbox, true);
515 assertTrue(anns[0].visible); // Conservation
516 assertTrue(anns[1].visible); // Quality
517 assertTrue(anns[2].visible); // Consensus
518 assertTrue(anns[3].visible); // IUPred for seq0
519 assertTrue(anns[4].visible); // Beauty
520 assertTrue(anns[5].visible); // JMol for seq3
521 assertTrue(anns[6].visible); // IUPRED for seq2
522 assertTrue(anns[7].visible); // JMol for seq1
526 * Test result of selecting an annotation type, with 'Show for selected
529 * We expect all annotations of that type, linked to the sequence group, to be
530 * set visible. Other annotations should be left unchanged
532 @Test(groups = { "Functional" })
533 public void testSelectType_showForSelected()
535 // sequences 1 and 2 have annotations IUPred and Jmol
536 selectSequences(1, 2);
537 testee = new AnnotationChooser(parentPanel);
538 final Checkbox showCheckbox = (Checkbox) getComponent(testee, 1, 0, 0);
539 final Checkbox hideCheckbox = (Checkbox) getComponent(testee, 1, 0, 1);
541 final Checkbox selectedSequencesCheckbox = (Checkbox) getComponent(
544 AlignmentAnnotation[] anns = parentPanel.getAlignment()
545 .getAlignmentAnnotation();
547 // hide all JMol annotations in the selection region (== annotation 7)
548 setSelected(selectedSequencesCheckbox, true);
549 setSelected(hideCheckbox, true);
550 setSelected(getTypeCheckbox("JMol"), true);
552 assertTrue(anns[5].visible); // JMol for seq3
553 assertFalse(anns[7].visible); // JMol for seq1
554 // ...now show them...
555 setSelected(showCheckbox, true);
557 assertTrue(anns[0].visible); // Conservation
558 assertTrue(anns[1].visible); // Quality
559 assertTrue(anns[2].visible); // Consensus
560 assertTrue(anns[3].visible); // IUPred for seq0
561 assertTrue(anns[4].visible); // Beauty
562 assertTrue(anns[5].visible); // JMol for seq3
563 assertTrue(anns[6].visible); // IUPRED for seq2
564 assertTrue(anns[7].visible); // JMol for seq1
568 * Test result of deselecting an annotation type, with 'Show for all
571 * We expect all annotations of that type to be set hidden. Other annotations
572 * should be left unchanged.
574 @Test(groups = { "Functional" })
575 public void testDeselectType_showForAll()
577 selectSequences(1, 2);
578 testee = new AnnotationChooser(parentPanel);
580 final Checkbox showCheckbox = (Checkbox) getComponent(testee, 1, 0, 0);
581 setSelected(showCheckbox, true);
583 final Checkbox allSequencesCheckbox = (Checkbox) getComponent(testee,
585 setSelected(allSequencesCheckbox, true);
587 AlignmentAnnotation[] anns = parentPanel.getAlignment()
588 .getAlignmentAnnotation();
590 final Checkbox typeCheckbox = getTypeCheckbox("JMol");
591 // select JMol - all shown
592 setSelected(typeCheckbox, true);
593 assertTrue(anns[5].visible); // JMol for seq3
594 assertTrue(anns[7].visible); // JMol for seq1
596 // deselect JMol - all hidden
597 setSelected(typeCheckbox, false);
598 assertTrue(anns[0].visible); // Conservation
599 assertTrue(anns[1].visible); // Quality
600 assertTrue(anns[2].visible); // Consensus
601 assertTrue(anns[3].visible); // IUPred for seq0
602 assertTrue(anns[4].visible); // Beauty
603 assertFalse(anns[5].visible); // JMol for seq3
604 assertTrue(anns[6].visible); // IUPRED for seq2
605 assertFalse(anns[7].visible); // JMol for seq1
609 * Test result of deselecting an annotation type, with 'Show for selected
612 * We expect the annotations of that type, linked to the sequence group, to be
613 * set hidden. Other annotations should be left unchanged.
615 @Test(groups = { "Functional" })
616 public void testDeselectType_showForSelected()
618 selectSequences(1, 2);
619 testee = new AnnotationChooser(parentPanel);
620 final Checkbox showCheckbox = (Checkbox) getComponent(testee, 1, 0, 0);
621 setSelected(showCheckbox, true);
624 * Don't set the 'selected sequences' radio button since this would trigger
625 * an update, including unselected sequences / annotation types
627 // setSelected(getSelectedSequencesCheckbox());
629 AlignmentAnnotation[] anns = parentPanel.getAlignment()
630 .getAlignmentAnnotation();
632 // select JMol - should remain visible
633 setSelected(getTypeCheckbox("JMol"), true);
634 assertTrue(anns[5].visible); // JMol for seq3
635 assertTrue(anns[7].visible); // JMol for seq1
637 // deselect JMol - should be hidden for selected sequences only
638 setSelected(getTypeCheckbox("JMol"), false);
639 assertTrue(anns[0].visible); // Conservation
640 assertTrue(anns[1].visible); // Quality
641 assertTrue(anns[2].visible); // Consensus
642 assertTrue(anns[3].visible); // IUPred for seq0
643 assertTrue(anns[4].visible); // Beauty
644 assertTrue(anns[5].visible); // JMol for seq3 not in selection group
645 assertTrue(anns[6].visible); // IUPRED for seq2
646 assertFalse(anns[7].visible); // JMol for seq1 in selection group
650 * Helper method to drill down to a sub-component in a Container hierarchy.
658 public static Component getComponent(Container cont, int... positions)
660 Component comp = cont;
661 for (int i : positions)
663 comp = ((Container) comp).getComponent(i);
669 * Helper method to set or unset a checkbox and fire its action listener.
674 protected void setSelected(Checkbox cb, boolean select)
676 // TODO refactor to a test utility class
678 // have to manually fire the action listener
679 cb.getItemListeners()[0].itemStateChanged(new ItemEvent(cb,
680 ItemEvent.ITEM_STATE_CHANGED, cb, select ? ItemEvent.SELECTED
681 : ItemEvent.DESELECTED));
685 * Helper method to drill down to the 'Annotation type' checkbox with given
690 private Checkbox getTypeCheckbox(String forLabel)
692 Component[] cbs = ((JPanel) testee.getComponent(0)).getComponents();
693 for (Component comp : cbs)
695 final Checkbox cb = (Checkbox) comp;
696 if (cb.getLabel().equals(forLabel))
705 * Test isInActionScope for the case where the scope is selected sequences.
706 * Test cases include sequences in the selection group, and others not in the
709 @Test(groups = { "Functional" })
710 public void testIsInActionScope_selectedScope()
712 // sequences 1 and 2 have annotations 4 and 3 respectively
713 selectSequences(1, 2);
714 testee = new AnnotationChooser(parentPanel);
716 final Checkbox selectedSequencesCheckbox = (Checkbox) getComponent(
718 setSelected(selectedSequencesCheckbox, true);
720 AlignmentAnnotation[] anns = parentPanel.getAlignment()
721 .getAlignmentAnnotation();
722 // remember 3 annotations to skip (Conservation/Quality/Consensus)
723 assertFalse(testee.isInActionScope(anns[3]));
724 assertFalse(testee.isInActionScope(anns[4]));
725 assertFalse(testee.isInActionScope(anns[5]));
726 assertTrue(testee.isInActionScope(anns[6]));
727 assertTrue(testee.isInActionScope(anns[7]));
731 * Test isInActionScope for the case where the scope is unselected sequences.
732 * Test cases include sequences in the selection group, and others not in the
735 @Test(groups = { "Functional" })
736 public void testIsInActionScope_unselectedScope()
738 // sequences 1 and 2 have annotations 4 and 3 respectively
739 selectSequences(1, 2);
740 testee = new AnnotationChooser(parentPanel);
742 final Checkbox unselectedSequencesCheckbox = (Checkbox) getComponent(
744 setSelected(unselectedSequencesCheckbox, true);
746 AlignmentAnnotation[] anns = parentPanel.getAlignment()
747 .getAlignmentAnnotation();
748 // remember 3 annotations to skip (Conservation/Quality/Consensus)
749 assertTrue(testee.isInActionScope(anns[3]));
750 assertTrue(testee.isInActionScope(anns[4]));
751 assertTrue(testee.isInActionScope(anns[5]));
752 assertFalse(testee.isInActionScope(anns[6]));
753 assertFalse(testee.isInActionScope(anns[7]));
757 * Test that the reset method restores previous visibility flags.
759 @Test(groups = { "Functional" })
760 public void testResetOriginalState()
762 testee = new AnnotationChooser(parentPanel);
764 AlignmentAnnotation[] anns = parentPanel.getAlignment()
765 .getAlignmentAnnotation();
767 for (int i = 0; i < anns.length; i++)
769 assertTrue(i + "'th sequence not visible", anns[i].visible);
773 * check options to hide JMol and IUPRED annotations for all sequences
775 final Checkbox hideCheckbox = (Checkbox) getComponent(testee, 1, 0, 1);
776 setSelected(hideCheckbox, true);
778 final Checkbox allSequencesCheckbox = (Checkbox) getComponent(testee,
780 setSelected(allSequencesCheckbox, true);
782 setSelected(getTypeCheckbox("JMol"), true);
783 setSelected(getTypeCheckbox("IUPRED"), true);
785 assertTrue(anns[0].visible); // Conservation
786 assertTrue(anns[1].visible); // Quality
787 assertTrue(anns[2].visible); // Consensus
788 assertFalse(anns[3].visible); // IUPRED
789 assertTrue(anns[4].visible); // Beauty (not seq-related)
790 assertFalse(anns[5].visible); // JMol
791 assertFalse(anns[6].visible); // IUPRED
792 assertFalse(anns[7].visible); // JMol
794 // reset - should all be visible
795 testee.resetOriginalState();
796 for (int i = 0; i < anns.length; i++)
798 assertTrue(i + "'th sequence not visible", anns[i].visible);