X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=test%2Fjalview%2Fgui%2FAnnotationChooserTest.java;h=f3c0dee6eecac20ceada348ae1d031a44ac82d02;hb=6ceab6a05ff1bb43ac3d9225c3c3cd932ff003dd;hp=6621a9434beb848f1bcd3c5bc45e5a965955658b;hpb=a4da7308cd43dcd4bddd773453007c916735d68a;p=jalview.git diff --git a/test/jalview/gui/AnnotationChooserTest.java b/test/jalview/gui/AnnotationChooserTest.java index 6621a94..f3c0dee 100644 --- a/test/jalview/gui/AnnotationChooserTest.java +++ b/test/jalview/gui/AnnotationChooserTest.java @@ -31,7 +31,9 @@ import jalview.datamodel.AlignmentI; import jalview.datamodel.Annotation; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; -import jalview.io.AppletFormatAdapter; +import jalview.io.DataSourceType; +import jalview.io.FileFormat; +import jalview.io.FormatAdapter; import jalview.util.MessageManager; import java.awt.BorderLayout; @@ -46,6 +48,7 @@ import java.util.List; import javax.swing.JButton; import javax.swing.JPanel; +import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -57,6 +60,14 @@ import org.testng.annotations.Test; */ public class AnnotationChooserTest { + + @BeforeClass(alwaysRun = true) + public void setUpJvOptionPane() + { + JvOptionPane.setInteractiveMode(false); + JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); + } + // 4 sequences x 13 positions final static String TEST_DATA = ">FER_CAPAA Ferredoxin\n" + "TIETHKEAELVG-\n" @@ -80,14 +91,14 @@ public class AnnotationChooserTest Cache.applicationProperties.setProperty(Preferences.SORT_ANNOTATIONS, SequenceAnnotationOrder.NONE.name()); final String TRUE = Boolean.TRUE.toString(); - Cache.applicationProperties.setProperty( - Preferences.SHOW_AUTOCALC_ABOVE, TRUE); + Cache.applicationProperties.setProperty(Preferences.SHOW_AUTOCALC_ABOVE, + TRUE); Cache.applicationProperties.setProperty("SHOW_QUALITY", TRUE); Cache.applicationProperties.setProperty("SHOW_CONSERVATION", TRUE); Cache.applicationProperties.setProperty("SHOW_IDENTITY", TRUE); - AlignmentI al = new jalview.io.FormatAdapter().readFile(TEST_DATA, - AppletFormatAdapter.PASTE, "FASTA"); + AlignmentI al = new FormatAdapter().readFile(TEST_DATA, + DataSourceType.PASTE, FileFormat.Fasta); af = new AlignFrame(al, 700, 500); parentPanel = new AlignmentPanel(af, af.getViewport()); addAnnotations(); @@ -97,11 +108,9 @@ public class AnnotationChooserTest * Add 4 annotations, 3 of them sequence-specific. * *
- * ann1 - for sequence 0 - label 'IUPRED' - * ann2 - not sequence related - label 'Beauty' - * ann3 - for sequence 3 - label 'JMol' - * ann4 - for sequence 2 - label 'IUPRED' - * ann5 - for sequence 1 - label 'JMol' + * ann1 - for sequence 0 - label 'IUPRED' ann2 - not sequence related - label + * 'Beauty' ann3 - for sequence 3 - label 'JMol' ann4 - for sequence 2 - label + * 'IUPRED' ann5 - for sequence 1 - label 'JMol' */ private void addAnnotations() { @@ -173,8 +182,8 @@ public class AnnotationChooserTest assertTrue("Not enabled", cb1.isEnabled()); assertTrue("Not enabled", cb2.isEnabled()); assertTrue("Not enabled", cb3.isEnabled()); - assertEquals("Option not selected", cb2, cb2.getCheckboxGroup() - .getSelectedCheckbox()); + assertEquals("Option not selected", cb2, + cb2.getCheckboxGroup().getSelectedCheckbox()); // check state variables match checkbox selection assertTrue(testee.isApplyToSelectedSequences()); @@ -224,15 +233,16 @@ public class AnnotationChooserTest assertTrue("Not enabled", cb1.isEnabled()); assertFalse("Enabled", cb2.isEnabled()); assertFalse("Enabled", cb3.isEnabled()); - assertEquals("Not selected", cb1, cb1.getCheckboxGroup() - .getSelectedCheckbox()); + assertEquals("Not selected", cb1, + cb1.getCheckboxGroup().getSelectedCheckbox()); // check state variables match checkbox selection assertTrue(testee.isApplyToSelectedSequences()); assertTrue(testee.isApplyToUnselectedSequences()); assertEquals("Wrong text", - MessageManager.getString("label.all_sequences"), cb1.getLabel()); + MessageManager.getString("label.all_sequences"), + cb1.getLabel()); assertEquals("Wrong text", MessageManager.getString("label.selected_sequences"), cb2.getLabel()); @@ -266,8 +276,8 @@ public class AnnotationChooserTest assertTrue("Hide not enabled", cb2.isEnabled()); // Hide (button 2) selected; note this may change to none (null) - assertEquals("Not selected", cb2, cb2.getCheckboxGroup() - .getSelectedCheckbox()); + assertEquals("Not selected", cb2, + cb2.getCheckboxGroup().getSelectedCheckbox()); assertTrue("Show is flagged", !testee.isShowSelected()); @@ -307,15 +317,15 @@ public class AnnotationChooserTest // selection group should make no difference to the result // as all annotation types for the alignment are considered - Listtypes = AnnotationChooser.getAnnotationTypes( - parentPanel.getAlignment(), true); + List types = AnnotationChooser + .getAnnotationTypes(parentPanel.getAlignment(), true); assertEquals("Not two annotation types", 2, types.size()); assertTrue("IUPRED missing", types.contains("IUPRED")); assertTrue("JMol missing", types.contains("JMol")); - types = AnnotationChooser.getAnnotationTypes( - parentPanel.getAlignment(), false); - assertEquals("Not six annotation types", 6, types.size()); + types = AnnotationChooser.getAnnotationTypes(parentPanel.getAlignment(), + false); + assertEquals("Not six annotation types", 7, types.size()); assertTrue("IUPRED missing", types.contains("IUPRED")); assertTrue("JMol missing", types.contains("JMol")); assertTrue("Beauty missing", types.contains("Beauty")); @@ -323,6 +333,7 @@ public class AnnotationChooserTest assertTrue("Consensus missing", types.contains("Consensus")); assertTrue("Quality missing", types.contains("Quality")); assertTrue("Conservation missing", types.contains("Conservation")); + assertTrue("Occupancy missing", types.contains("Occupancy")); } /** @@ -339,25 +350,27 @@ public class AnnotationChooserTest final Checkbox hideCheckbox = (Checkbox) getComponent(testee, 1, 0, 1); setSelected(hideCheckbox, true); - final Checkbox allSequencesCheckbox = (Checkbox) getComponent(testee, - 1, 1, 0); + final Checkbox allSequencesCheckbox = (Checkbox) getComponent(testee, 1, + 1, 0); setSelected(allSequencesCheckbox, true); AlignmentAnnotation[] anns = parentPanel.getAlignment() .getAlignmentAnnotation(); - assertTrue(anns[5].visible); // JMol for seq3 - assertTrue(anns[7].visible); // JMol for seq1 + int autocalc = countAutocalc(anns); + assertTrue(anns[autocalc + 2].visible); // JMol for seq3 + assertTrue(anns[autocalc + 4].visible); // JMol for seq1 setSelected(getTypeCheckbox("JMol"), true); assertTrue(anns[0].visible); // Conservation assertTrue(anns[1].visible); // Quality assertTrue(anns[2].visible); // Consensus - assertTrue(anns[3].visible); // IUPred for seq0 - assertTrue(anns[4].visible); // Beauty - assertFalse(anns[5].visible); // JMol for seq3 - not selected but hidden - assertTrue(anns[6].visible); // IUPRED for seq2 - assertFalse(anns[7].visible); // JMol for seq1 - selected and hidden + assertTrue(anns[3].visible); // Occupancy + assertTrue(anns[4].visible); // IUPred for seq0 + assertTrue(anns[5].visible); // Beauty + assertFalse(anns[6].visible); // JMol for seq3 - not selected but hidden + assertTrue(anns[7].visible); // IUPRED for seq2 + assertFalse(anns[8].visible); // JMol for seq1 - selected and hidden } /** @@ -384,17 +397,19 @@ public class AnnotationChooserTest AlignmentAnnotation[] anns = parentPanel.getAlignment() .getAlignmentAnnotation(); - assertTrue(anns[7].visible); // JMol for seq1 + int autocalc = countAutocalc(anns); + assertTrue(anns[autocalc + 4].visible); // JMol for seq1 setSelected(getTypeCheckbox("JMol"), true); assertTrue(anns[0].visible); // Conservation assertTrue(anns[1].visible); // Quality assertTrue(anns[2].visible); // Consensus - assertTrue(anns[3].visible); // IUPred for seq0 - assertTrue(anns[4].visible); // Beauty - assertTrue(anns[5].visible); // JMol for seq3 not in selection group - assertTrue(anns[6].visible); // IUPRED for seq2 - assertFalse(anns[7].visible); // JMol for seq1 in selection group + assertTrue(anns[3].visible); // Occupancy + assertTrue(anns[4].visible); // IUPred for seq0 + assertTrue(anns[5].visible); // Beauty + assertTrue(anns[6].visible); // JMol for seq3 not in selection group + assertTrue(anns[7].visible); // IUPRED for seq2 + assertFalse(anns[8].visible); // JMol for seq1 in selection group } /** @@ -413,8 +428,8 @@ public class AnnotationChooserTest final Checkbox hideCheckbox = (Checkbox) getComponent(testee, 1, 0, 1); setSelected(hideCheckbox, true); - final Checkbox allSequencesCheckbox = (Checkbox) getComponent(testee, - 1, 1, 0); + final Checkbox allSequencesCheckbox = (Checkbox) getComponent(testee, 1, + 1, 0); setSelected(allSequencesCheckbox, true); AlignmentAnnotation[] anns = parentPanel.getAlignment() @@ -424,19 +439,35 @@ public class AnnotationChooserTest // select JMol - all hidden setSelected(typeCheckbox, true); - assertFalse(anns[5].visible); // JMol for seq3 - assertFalse(anns[7].visible); // JMol for seq1 + int autocalc = countAutocalc(anns); + assertFalse(anns[autocalc + 2].visible); // JMol for seq3 + assertFalse(anns[autocalc + 4].visible); // JMol for seq1 // deselect JMol - all unhidden setSelected(typeCheckbox, false); - assertTrue(anns[0].visible); // Conservation - assertTrue(anns[1].visible); // Quality - assertTrue(anns[2].visible); // Consensus - assertTrue(anns[3].visible); // IUPred for seq0 - assertTrue(anns[4].visible); // Beauty - assertTrue(anns[5].visible); // JMol for seq3 - assertTrue(anns[6].visible); // IUPRED for seq2 - assertTrue(anns[7].visible); // JMol for seq1 + for (AlignmentAnnotation ann : anns) + { + assertTrue(ann.visible); + } + } + + /** + * Returns a count of autocalculated annotations in the set provided + * + * @param anns + * @return + */ + private int countAutocalc(AlignmentAnnotation[] anns) + { + int count = 0; + for (AlignmentAnnotation ann : anns) + { + if (ann.autoCalculated) + { + count++; + } + } + return count; } /** @@ -489,8 +520,8 @@ public class AnnotationChooserTest final Checkbox showCheckbox = (Checkbox) getComponent(testee, 1, 0, 0); final Checkbox hideCheckbox = (Checkbox) getComponent(testee, 1, 0, 1); - final Checkbox allSequencesCheckbox = (Checkbox) getComponent(testee, - 1, 1, 0); + final Checkbox allSequencesCheckbox = (Checkbox) getComponent(testee, 1, + 1, 0); AlignmentAnnotation[] anns = parentPanel.getAlignment() .getAlignmentAnnotation(); @@ -499,18 +530,15 @@ public class AnnotationChooserTest setSelected(allSequencesCheckbox, true); setSelected(hideCheckbox, true); setSelected(getTypeCheckbox("JMol"), true); - assertFalse(anns[5].visible); // JMol for seq3 - assertFalse(anns[7].visible); // JMol for seq1 + int autocalc = countAutocalc(anns); + assertFalse(anns[autocalc + 2].visible); // JMol for seq3 + assertFalse(anns[autocalc + 4].visible); // JMol for seq1 // ...now show them... setSelected(showCheckbox, true); - assertTrue(anns[0].visible); // Conservation - assertTrue(anns[1].visible); // Quality - assertTrue(anns[2].visible); // Consensus - assertTrue(anns[3].visible); // IUPred for seq0 - assertTrue(anns[4].visible); // Beauty - assertTrue(anns[5].visible); // JMol for seq3 - assertTrue(anns[6].visible); // IUPRED for seq2 - assertTrue(anns[7].visible); // JMol for seq1 + for (AlignmentAnnotation ann : anns) + { + assertTrue(ann.visible); + } } /** @@ -540,19 +568,16 @@ public class AnnotationChooserTest setSelected(hideCheckbox, true); setSelected(getTypeCheckbox("JMol"), true); - assertTrue(anns[5].visible); // JMol for seq3 - assertFalse(anns[7].visible); // JMol for seq1 + int autocalc = countAutocalc(anns); + assertTrue(anns[autocalc + 2].visible); // JMol for seq3 + assertFalse(anns[autocalc + 4].visible); // JMol for seq1 // ...now show them... setSelected(showCheckbox, true); - assertTrue(anns[0].visible); // Conservation - assertTrue(anns[1].visible); // Quality - assertTrue(anns[2].visible); // Consensus - assertTrue(anns[3].visible); // IUPred for seq0 - assertTrue(anns[4].visible); // Beauty - assertTrue(anns[5].visible); // JMol for seq3 - assertTrue(anns[6].visible); // IUPRED for seq2 - assertTrue(anns[7].visible); // JMol for seq1 + for (AlignmentAnnotation ann : anns) + { + assertTrue(ann.visible); + } } /** @@ -571,8 +596,8 @@ public class AnnotationChooserTest final Checkbox showCheckbox = (Checkbox) getComponent(testee, 1, 0, 0); setSelected(showCheckbox, true); - final Checkbox allSequencesCheckbox = (Checkbox) getComponent(testee, - 1, 1, 0); + final Checkbox allSequencesCheckbox = (Checkbox) getComponent(testee, 1, + 1, 0); setSelected(allSequencesCheckbox, true); AlignmentAnnotation[] anns = parentPanel.getAlignment() @@ -581,19 +606,21 @@ public class AnnotationChooserTest final Checkbox typeCheckbox = getTypeCheckbox("JMol"); // select JMol - all shown setSelected(typeCheckbox, true); - assertTrue(anns[5].visible); // JMol for seq3 - assertTrue(anns[7].visible); // JMol for seq1 + int autocalc = countAutocalc(anns); + assertTrue(anns[autocalc + 2].visible); // JMol for seq3 + assertTrue(anns[autocalc + 4].visible); // JMol for seq1 // deselect JMol - all hidden setSelected(typeCheckbox, false); assertTrue(anns[0].visible); // Conservation assertTrue(anns[1].visible); // Quality assertTrue(anns[2].visible); // Consensus - assertTrue(anns[3].visible); // IUPred for seq0 - assertTrue(anns[4].visible); // Beauty - assertFalse(anns[5].visible); // JMol for seq3 - assertTrue(anns[6].visible); // IUPRED for seq2 - assertFalse(anns[7].visible); // JMol for seq1 + assertTrue(anns[3].visible); // Occupancy + assertTrue(anns[4].visible); // IUPred for seq0 + assertTrue(anns[5].visible); // Beauty + assertFalse(anns[6].visible); // JMol for seq3 + assertTrue(anns[7].visible); // IUPRED for seq2 + assertFalse(anns[8].visible); // JMol for seq1 } /** @@ -622,19 +649,21 @@ public class AnnotationChooserTest // select JMol - should remain visible setSelected(getTypeCheckbox("JMol"), true); - assertTrue(anns[5].visible); // JMol for seq3 - assertTrue(anns[7].visible); // JMol for seq1 + int autocalc = countAutocalc(anns); + assertTrue(anns[autocalc + 2].visible); // JMol for seq3 + assertTrue(anns[autocalc + 4].visible); // JMol for seq1 // deselect JMol - should be hidden for selected sequences only setSelected(getTypeCheckbox("JMol"), false); assertTrue(anns[0].visible); // Conservation assertTrue(anns[1].visible); // Quality assertTrue(anns[2].visible); // Consensus - assertTrue(anns[3].visible); // IUPred for seq0 - assertTrue(anns[4].visible); // Beauty - assertTrue(anns[5].visible); // JMol for seq3 not in selection group - assertTrue(anns[6].visible); // IUPRED for seq2 - assertFalse(anns[7].visible); // JMol for seq1 in selection group + assertTrue(anns[3].visible); // Occupancy + assertTrue(anns[4].visible); // IUPred for seq0 + assertTrue(anns[5].visible); // Beauty + assertTrue(anns[6].visible); // JMol for seq3 not in selection group + assertTrue(anns[7].visible); // IUPRED for seq2 + assertFalse(anns[8].visible); // JMol for seq1 in selection group } /** @@ -667,9 +696,9 @@ public class AnnotationChooserTest // TODO refactor to a test utility class cb.setState(select); // have to manually fire the action listener - cb.getItemListeners()[0].itemStateChanged(new ItemEvent(cb, - ItemEvent.ITEM_STATE_CHANGED, cb, select ? ItemEvent.SELECTED - : ItemEvent.DESELECTED)); + cb.getItemListeners()[0].itemStateChanged( + new ItemEvent(cb, ItemEvent.ITEM_STATE_CHANGED, cb, + select ? ItemEvent.SELECTED : ItemEvent.DESELECTED)); } /** @@ -710,12 +739,12 @@ public class AnnotationChooserTest AlignmentAnnotation[] anns = parentPanel.getAlignment() .getAlignmentAnnotation(); - // remember 3 annotations to skip (Conservation/Quality/Consensus) - assertFalse(testee.isInActionScope(anns[3])); - assertFalse(testee.isInActionScope(anns[4])); - assertFalse(testee.isInActionScope(anns[5])); - assertTrue(testee.isInActionScope(anns[6])); - assertTrue(testee.isInActionScope(anns[7])); + int autocalc = countAutocalc(anns); + assertFalse(testee.isInActionScope(anns[autocalc])); + assertFalse(testee.isInActionScope(anns[autocalc + 1])); + assertFalse(testee.isInActionScope(anns[autocalc + 2])); + assertTrue(testee.isInActionScope(anns[autocalc + 3])); + assertTrue(testee.isInActionScope(anns[autocalc + 4])); } /** @@ -736,12 +765,12 @@ public class AnnotationChooserTest AlignmentAnnotation[] anns = parentPanel.getAlignment() .getAlignmentAnnotation(); - // remember 3 annotations to skip (Conservation/Quality/Consensus) - assertTrue(testee.isInActionScope(anns[3])); - assertTrue(testee.isInActionScope(anns[4])); - assertTrue(testee.isInActionScope(anns[5])); - assertFalse(testee.isInActionScope(anns[6])); - assertFalse(testee.isInActionScope(anns[7])); + int autocalc = countAutocalc(anns); + assertTrue(testee.isInActionScope(anns[autocalc])); + assertTrue(testee.isInActionScope(anns[autocalc + 1])); + assertTrue(testee.isInActionScope(anns[autocalc + 2])); + assertFalse(testee.isInActionScope(anns[autocalc + 3])); + assertFalse(testee.isInActionScope(anns[autocalc + 4])); } /** @@ -766,8 +795,8 @@ public class AnnotationChooserTest final Checkbox hideCheckbox = (Checkbox) getComponent(testee, 1, 0, 1); setSelected(hideCheckbox, true); - final Checkbox allSequencesCheckbox = (Checkbox) getComponent(testee, - 1, 1, 0); + final Checkbox allSequencesCheckbox = (Checkbox) getComponent(testee, 1, + 1, 0); setSelected(allSequencesCheckbox, true); setSelected(getTypeCheckbox("JMol"), true); @@ -776,11 +805,12 @@ public class AnnotationChooserTest assertTrue(anns[0].visible); // Conservation assertTrue(anns[1].visible); // Quality assertTrue(anns[2].visible); // Consensus - assertFalse(anns[3].visible); // IUPRED - assertTrue(anns[4].visible); // Beauty (not seq-related) - assertFalse(anns[5].visible); // JMol - assertFalse(anns[6].visible); // IUPRED - assertFalse(anns[7].visible); // JMol + assertTrue(anns[3].visible); // Occupancy + assertFalse(anns[4].visible); // IUPRED + assertTrue(anns[5].visible); // Beauty (not seq-related) + assertFalse(anns[6].visible); // JMol + assertFalse(anns[7].visible); // IUPRED + assertFalse(anns[8].visible); // JMol // reset - should all be visible testee.resetOriginalState();