b228ba10492205d8582bda0ceed06b256d660ea5
[jalview.git] / test / jalview / gui / AlignmentPanelTest.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.bin.Jalview;
27 import jalview.datamodel.Sequence;
28 import jalview.datamodel.SequenceI;
29 import jalview.io.DataSourceType;
30 import jalview.io.FileLoader;
31 import jalview.viewmodel.ViewportRanges;
32
33 import org.testng.annotations.BeforeMethod;
34 import org.testng.annotations.Test;
35
36 public class AlignmentPanelTest
37 {
38   SequenceI seq1 = new Sequence(
39           "Seq1",
40           "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
41
42   SequenceI seq2 = new Sequence(
43           "Seq2",
44           "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
45
46   SequenceI seq3 = new Sequence(
47           "Seq3",
48           "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
49
50   SequenceI seq4 = new Sequence(
51           "Seq4",
52           "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
53
54   SequenceI seq5 = new Sequence(
55           "Seq5",
56           "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
57
58   SequenceI seq6 = new Sequence(
59           "Seq6",
60           "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
61
62   SequenceI seq7 = new Sequence(
63           "Seq7",
64           "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
65
66   SequenceI seq8 = new Sequence(
67           "Seq8",
68           "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
69
70   SequenceI seq9 = new Sequence(
71           "Seq9",
72           "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
73
74   SequenceI seq10 = new Sequence(
75           "Seq10",
76           "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
77
78   SequenceI seq11 = new Sequence(
79           "Seq11",
80           "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
81
82   SequenceI seq12 = new Sequence(
83           "Seq12",
84           "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
85
86   SequenceI seq13 = new Sequence(
87           "Seq13",
88           "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
89
90   SequenceI seq14 = new Sequence(
91           "Seq14",
92           "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
93
94   SequenceI seq15 = new Sequence(
95           "Seq15",
96           "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
97
98   SequenceI seq16 = new Sequence(
99           "Seq16",
100           "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
101
102   SequenceI seq17 = new Sequence(
103           "Seq17",
104           "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
105
106   SequenceI seq18 = new Sequence(
107           "Seq18",
108           "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
109
110   SequenceI seq19 = new Sequence(
111           "Seq19",
112           "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
113
114   SequenceI seq20 = new Sequence(
115           "Seq20",
116           "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
117
118   SequenceI seq21 = new Sequence(
119           "Seq21",
120           "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
121
122   SequenceI seq22 = new Sequence(
123           "Seq22",
124           "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
125
126   SequenceI seq23 = new Sequence(
127           "Seq23",
128           "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
129
130   AlignFrame af;
131
132   @BeforeMethod(alwaysRun = true)
133   public void setUp()
134   {
135     Jalview.main(new String[] { "-nonews", "-props",
136         "test/jalview/testProps.jvprops" });
137
138     Cache.applicationProperties.setProperty("SHOW_IDENTITY",
139             Boolean.TRUE.toString());
140     af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa",
141             DataSourceType.FILE);
142
143     /*
144      * wait for Consensus thread to complete
145      */
146     synchronized (this)
147     {
148       while (af.getViewport().getConsensusSeq() == null)
149       {
150         try
151         {
152           wait(50);
153         } catch (InterruptedException e)
154         {
155         }
156       }
157     }
158   }
159
160
161   /**
162    * Test side effect that end residue is set correctly by setScrollValues, with
163    * or without hidden columns
164    */
165   @Test(groups = "Functional")
166   public void TestSetScrollValues()
167   {
168     ViewportRanges ranges = af.getViewport().getRanges();
169     af.alignPanel.setScrollValues(0, 0);
170
171     int oldres = ranges.getEndRes();
172     af.alignPanel.setScrollValues(-1, 5);
173
174     // setting -ve x value does not change residue
175     assertEquals(ranges.getEndRes(), oldres);
176
177     af.alignPanel.setScrollValues(0, 5);
178
179     // setting 0 as x value does not change residue
180     assertEquals(ranges.getEndRes(), oldres);
181
182     af.alignPanel.setScrollValues(5, 5);
183     // setting x value to 5 extends endRes by 5 residues
184     assertEquals(ranges.getEndRes(), oldres + 5);
185
186     // scroll to position after hidden columns sets endres to oldres (width) +
187     // position
188     int scrollpos = 60;
189     af.getViewport().hideColumns(30, 50);
190     af.alignPanel.setScrollValues(scrollpos, 5);
191     assertEquals(ranges.getEndRes(), oldres + scrollpos);
192
193     // scroll to position within hidden columns, still sets endres to oldres +
194     // position
195     // not sure if this is actually correct behaviour but this is what Jalview
196     // currently does
197     scrollpos = 40;
198     af.getViewport().showAllHiddenColumns();
199     af.getViewport().hideColumns(30, 50);
200     af.alignPanel.setScrollValues(scrollpos, 5);
201     assertEquals(ranges.getEndRes(), oldres + scrollpos);
202
203     // scroll to position within <width> distance of the end of the alignment
204     // endRes should be set to width of alignment - 1
205     scrollpos = 130;
206     af.getViewport().showAllHiddenColumns();
207     af.alignPanel.setScrollValues(scrollpos, 5);
208     assertEquals(ranges.getEndRes(), af.getViewport()
209             .getAlignment().getWidth() - 1);
210
211     // now hide some columns, and scroll to position within <width>
212     // distance of the end of the alignment
213     // endRes should be set to width of alignment - 1 - the number of hidden
214     // columns
215     af.getViewport().hideColumns(30, 50);
216     af.alignPanel.setScrollValues(scrollpos, 5);
217     assertEquals(ranges.getEndRes(), af.getViewport()
218             .getAlignment().getWidth() - 1 - 21); // 21 is the number of hidden
219                                                   // columns
220   }
221 }