JAL-3746 apply copyright to tests
[jalview.git] / test / jalview / gui / AnnotationRowFilterTest.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 org.testng.Assert.assertEquals;
24
25 import jalview.bin.Cache;
26 import jalview.datamodel.AlignmentAnnotation;
27 import jalview.datamodel.AlignmentI;
28 import jalview.datamodel.SequenceI;
29 import jalview.io.DataSourceType;
30 import jalview.io.FileLoader;
31
32 import java.util.Vector;
33
34 import org.testng.annotations.BeforeClass;
35 import org.testng.annotations.Test;
36
37 /**
38  * Tests for methods of base class of annotation column or colour chooser
39  */
40 public class AnnotationRowFilterTest
41 {
42   AlignFrame af;
43
44   private AnnotationRowFilter testee;
45
46   @BeforeClass(alwaysRun = true)
47   public void setUp()
48   {
49     Cache.loadProperties("test/jalview/io/testProps.jvprops");
50     Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
51             Boolean.TRUE.toString());
52     Cache.applicationProperties.setProperty(Preferences.SHOW_AUTOCALC_ABOVE,
53             Boolean.TRUE.toString());
54     af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa",
55             DataSourceType.FILE);
56     testee = new AnnotationRowFilter(af.viewport, af.alignPanel)
57     {
58       @Override
59       public void valueChanged(boolean updateAllAnnotation)
60       {
61       }
62
63       @Override
64       public void updateView()
65       {
66       }
67
68       @Override
69       public void reset()
70       {
71       }
72     };
73   }
74
75   /**
76    * Test the method that builds the drop-down list of annotations to choose
77    * from for colour by annotation or select columns by annotation
78    */
79   @Test(groups = "Functional")
80   public void testGetAnnotationItems()
81   {
82     AlignmentI al = af.getViewport().getAlignment();
83     SequenceI seq1 = al.findSequenceMatch("FER_CAPAA")[0];
84     SequenceI seq2 = al.findSequenceMatch("FER_BRANA")[0];
85
86     AlignmentAnnotation ann1 = new AlignmentAnnotation("ann1Label", "ann1",
87             null);
88     al.addAnnotation(ann1);
89     AlignmentAnnotation ann2 = new AlignmentAnnotation("Significance",
90             "ann2", null);
91     al.addAnnotation(ann2);
92     /*
93      * a second Significance alignment annotation
94      */
95     AlignmentAnnotation ann2a = new AlignmentAnnotation("Significance",
96             "ann2", null);
97     al.addAnnotation(ann2a);
98
99     AlignmentAnnotation ann3 = new AlignmentAnnotation("Jronn", "Jronn",
100             null);
101     ann3.setSequenceRef(seq1);
102     al.addAnnotation(ann3);
103     AlignmentAnnotation ann4 = new AlignmentAnnotation("Jronn", "Jronn",
104             null);
105     ann4.setSequenceRef(seq2);
106     al.addAnnotation(ann4);
107     AlignmentAnnotation ann5 = new AlignmentAnnotation("Jnet", "Jnet",
108             null);
109     ann5.setSequenceRef(seq2);
110     al.addAnnotation(ann5);
111     /*
112      * a second Jnet annotation for FER_BRANA
113      */
114     AlignmentAnnotation ann6 = new AlignmentAnnotation("Jnet", "Jnet",
115             null);
116     ann6.setSequenceRef(seq2);
117     al.addAnnotation(ann6);
118
119     /*
120      * drop-down items with 'Per-sequence only' not checked
121      */
122     Vector<String> items = testee.getAnnotationItems(false);
123     assertEquals(items.toString(),
124             "[Conservation, Quality, Consensus, Occupancy, ann1Label, Significance, Significance_1, Jronn_FER_CAPAA, Jronn_FER_BRANA, Jnet_FER_BRANA, Jnet_FER_BRANA_2]");
125     assertEquals(testee.getAnnotationMenuLabel(ann1), "ann1Label");
126     assertEquals(testee.getAnnotationMenuLabel(ann2), "Significance");
127     assertEquals(testee.getAnnotationMenuLabel(ann2a), "Significance_1");
128     assertEquals(testee.getAnnotationMenuLabel(ann3), "Jronn_FER_CAPAA");
129     assertEquals(testee.getAnnotationMenuLabel(ann4), "Jronn_FER_BRANA");
130     assertEquals(testee.getAnnotationMenuLabel(ann5), "Jnet_FER_BRANA");
131     assertEquals(testee.getAnnotationMenuLabel(ann6), "Jnet_FER_BRANA_2");
132
133     /*
134      * drop-down items with 'Per-sequence only' checked
135      */
136     items = testee.getAnnotationItems(true);
137     assertEquals(items.toString(), "[Jronn, Jnet]");
138     // the first annotation of the type is associated with the menu item
139     assertEquals(testee.getAnnotationMenuLabel(ann3), "Jronn");
140     assertEquals(testee.getAnnotationMenuLabel(ann5), "Jnet");
141   }
142 }