X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fgui%2FAnnotationChooserTest.java;h=fbdda0901945fc7a3db67965499eb4ae3eae6f3b;hb=cb8e52fbbc5f725e3f7f48c672cdddb0690bd978;hp=944ab9c22a569558e36841f35ccb632c5126048f;hpb=b4e0958489010d048a9247dad7b45791e633a1dc;p=jalview.git diff --git a/test/jalview/gui/AnnotationChooserTest.java b/test/jalview/gui/AnnotationChooserTest.java index 944ab9c..fbdda09 100644 --- a/test/jalview/gui/AnnotationChooserTest.java +++ b/test/jalview/gui/AnnotationChooserTest.java @@ -1,14 +1,39 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.gui; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertFalse; +import static org.testng.AssertJUnit.assertTrue; + +import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; +import jalview.bin.Cache; import jalview.datamodel.AlignmentAnnotation; 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; @@ -23,8 +48,9 @@ import java.util.List; import javax.swing.JButton; import javax.swing.JPanel; -import org.junit.Before; -import org.junit.Test; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; /** * Unit tests for AnnotationChooser @@ -34,6 +60,14 @@ import org.junit.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" @@ -49,11 +83,22 @@ public class AnnotationChooserTest AlignFrame af; - @Before + @BeforeMethod(alwaysRun = true) public void setUp() throws IOException { - AlignmentI al = new jalview.io.FormatAdapter().readFile(TEST_DATA, - AppletFormatAdapter.PASTE, "FASTA"); + Cache.loadProperties("test/jalview/io/testProps.jvprops"); + // pin down annotation sort order for test + 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("SHOW_QUALITY", TRUE); + Cache.applicationProperties.setProperty("SHOW_CONSERVATION", TRUE); + Cache.applicationProperties.setProperty("SHOW_IDENTITY", TRUE); + + AlignmentI al = new FormatAdapter().readFile(TEST_DATA, + DataSourceType.PASTE, FileFormat.Fasta); af = new AlignFrame(al, 700, 500); parentPanel = new AlignmentPanel(af, af.getViewport()); addAnnotations(); @@ -72,8 +117,7 @@ public class AnnotationChooserTest private void addAnnotations() { Annotation an = new Annotation(2f); - Annotation[] anns = new Annotation[] - { an, an, an }; + Annotation[] anns = new Annotation[] { an, an, an }; AlignmentAnnotation ann0 = new AlignmentAnnotation("IUPRED", "", anns); AlignmentAnnotation ann1 = new AlignmentAnnotation("Beauty", "", anns); AlignmentAnnotation ann2 = new AlignmentAnnotation("JMol", "", anns); @@ -94,7 +138,7 @@ public class AnnotationChooserTest /** * Test creation of panel with OK and Cancel buttons */ - @Test + @Test(groups = { "Functional" }) public void testBuildActionButtonsPanel() { testee = new AnnotationChooser(parentPanel); @@ -123,7 +167,7 @@ public class AnnotationChooserTest * Test 'Apply to' has 3 radio buttons enabled, 'Selected Sequences' selected, * when there is a current selection group. */ - @Test + @Test(groups = { "Functional" }) public void testBuildApplyToOptionsPanel_withSelectionGroup() { selectSequences(0, 2, 3); @@ -170,7 +214,7 @@ public class AnnotationChooserTest * Test 'Apply to' has 1 radio button enabled, 'All Sequences' selected, when * there is no current selection group. */ - @Test + @Test(groups = { "Functional" }) public void testBuildApplyToOptionsPanel_noSelectionGroup() { testee = new AnnotationChooser(parentPanel); @@ -211,7 +255,7 @@ public class AnnotationChooserTest /** * Test Show and Hide radio buttons created, with Hide initially selected. */ - @Test + @Test(groups = { "Functional" }) public void testBuildShowHidePanel() { testee = new AnnotationChooser(parentPanel); @@ -249,7 +293,7 @@ public class AnnotationChooserTest /** * Test construction of panel containing two sub-panels */ - @Test + @Test(groups = { "Functional" }) public void testBuildShowHideOptionsPanel() { testee = new AnnotationChooser(parentPanel); @@ -266,7 +310,7 @@ public class AnnotationChooserTest * Test that annotation types are (uniquely) identified. * */ - @Test + @Test(groups = { "Functional" }) public void testGetAnnotationTypes() { selectSequences(1); @@ -282,7 +326,7 @@ public class AnnotationChooserTest types = AnnotationChooser.getAnnotationTypes( parentPanel.getAlignment(), false); - assertEquals("Not six annotation types", 6, types.size()); + 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")); @@ -290,6 +334,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")); } /** @@ -298,7 +343,7 @@ public class AnnotationChooserTest * We expect all annotations of that type to be set hidden. Other annotations * should be left visible. */ - @Test + @Test(groups = { "Functional" }) public void testSelectType_hideForAll() { selectSequences(1, 2); @@ -313,18 +358,20 @@ public class AnnotationChooserTest 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 } /** @@ -334,7 +381,7 @@ public class AnnotationChooserTest * We expect the annotations of that type, linked to the sequence group, to be * set hidden. Other annotations should be left visible. */ - @Test + @Test(groups = { "Functional" }) public void testSelectType_hideForSelected() { selectSequences(1, 2); @@ -351,17 +398,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 } /** @@ -371,7 +420,7 @@ public class AnnotationChooserTest * We expect all annotations of that type to be set visible. Other annotations * should be left unchanged. */ - @Test + @Test(groups = { "Functional" }) public void testDeselectType_hideForAll() { selectSequences(1, 2); @@ -391,19 +440,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; } /** @@ -413,7 +478,7 @@ public class AnnotationChooserTest * We expect the annotations of that type, linked to the sequence group, to be * set visible. Other annotations should be left unchanged. */ - @Test + @Test(groups = { "Functional" }) public void testDeselectType_hideForSelected() { selectSequences(1, 2); @@ -448,7 +513,7 @@ public class AnnotationChooserTest * We expect all annotations of that type to be set visible. Other annotations * should be left unchanged */ - @Test + @Test(groups = { "Functional" }) public void testSelectType_showForAll() { selectSequences(1, 2); @@ -466,18 +531,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); + } } /** @@ -487,9 +549,10 @@ public class AnnotationChooserTest * We expect all annotations of that type, linked to the sequence group, to be * set visible. Other annotations should be left unchanged */ - @Test + @Test(groups = { "Functional" }) public void testSelectType_showForSelected() { + // sequences 1 and 2 have annotations IUPred and Jmol selectSequences(1, 2); testee = new AnnotationChooser(parentPanel); final Checkbox showCheckbox = (Checkbox) getComponent(testee, 1, 0, 0); @@ -505,19 +568,17 @@ public class AnnotationChooserTest setSelected(selectedSequencesCheckbox, true); 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); + } } /** @@ -527,7 +588,7 @@ public class AnnotationChooserTest * We expect all annotations of that type to be set hidden. Other annotations * should be left unchanged. */ - @Test + @Test(groups = { "Functional" }) public void testDeselectType_showForAll() { selectSequences(1, 2); @@ -546,19 +607,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 } /** @@ -568,7 +631,7 @@ public class AnnotationChooserTest * We expect the annotations of that type, linked to the sequence group, to be * set hidden. Other annotations should be left unchanged. */ - @Test + @Test(groups = { "Functional" }) public void testDeselectType_showForSelected() { selectSequences(1, 2); @@ -587,19 +650,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 } /** @@ -662,7 +727,7 @@ public class AnnotationChooserTest * Test cases include sequences in the selection group, and others not in the * group. */ - @Test + @Test(groups = { "Functional" }) public void testIsInActionScope_selectedScope() { // sequences 1 and 2 have annotations 4 and 3 respectively @@ -675,12 +740,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])); } /** @@ -688,7 +753,7 @@ public class AnnotationChooserTest * Test cases include sequences in the selection group, and others not in the * group. */ - @Test + @Test(groups = { "Functional" }) public void testIsInActionScope_unselectedScope() { // sequences 1 and 2 have annotations 4 and 3 respectively @@ -701,18 +766,18 @@ 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])); } /** * Test that the reset method restores previous visibility flags. */ - @Test + @Test(groups = { "Functional" }) public void testResetOriginalState() { testee = new AnnotationChooser(parentPanel); @@ -725,6 +790,9 @@ public class AnnotationChooserTest assertTrue(i + "'th sequence not visible", anns[i].visible); } + /* + * check options to hide JMol and IUPRED annotations for all sequences + */ final Checkbox hideCheckbox = (Checkbox) getComponent(testee, 1, 0, 1); setSelected(hideCheckbox, true); @@ -738,11 +806,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();