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