JAL-4397 Test all fixed on linux. Given leeway to some tests, platform dependent...
[jalview.git] / test / jalview / gui / AnnotationLabelsTest2.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 import static org.testng.Assert.assertFalse;
25 import static org.testng.Assert.assertTrue;
26
27 import java.io.File;
28
29 import org.testng.annotations.AfterMethod;
30 import org.testng.annotations.BeforeClass;
31 import org.testng.annotations.BeforeMethod;
32 import org.testng.annotations.DataProvider;
33 import org.testng.annotations.Test;
34
35 import jalview.bin.Cache;
36 import jalview.bin.Jalview;
37 import jalview.datamodel.AlignmentI;
38 import jalview.datamodel.SequenceI;
39 import jalview.gui.StructureViewer.ViewerType;
40 import jalview.io.DataSourceType;
41 import jalview.io.FileLoader;
42 import jalview.structure.StructureImportSettings.TFType;
43
44 public class AnnotationLabelsTest2
45 {
46   private static double scaling;
47
48   @BeforeClass(alwaysRun = true)
49   public static void setUpBeforeClass() throws Exception
50   {
51     if (Desktop.instance != null)
52       Desktop.instance.closeAll_actionPerformed(null);
53
54     setUpJvOptionPane();
55     /*
56      * use read-only test properties file
57      */
58     Cache.loadProperties("test/jalview/io/testProps.jvprops");
59     Jalview.main(new String[] { "--nonews", "--nosplash", });
60
61     scaling = JvSwingUtilsTest.getScaling(Desktop.instance);
62   }
63
64   @AfterMethod(alwaysRun = true)
65   public void tearDown()
66   {
67     if (Desktop.instance != null)
68       Desktop.instance.closeAll_actionPerformed(null);
69   }
70
71   /**
72    * configure (read-only) properties for test to ensure Consensus is computed
73    * for colour Above PID testing
74    */
75   @BeforeMethod(alwaysRun = true)
76   public void setUp()
77   {
78     Cache.loadProperties("test/jalview/io/testProps.jvprops");
79     Cache.applicationProperties.setProperty("SHOW_IDENTITY",
80             Boolean.TRUE.toString());
81
82   }
83
84   public static void setUpJvOptionPane()
85   {
86     JvOptionPane.setInteractiveMode(false);
87     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
88   }
89
90   @Test(
91     groups =
92     { "Functional", "testTask1" },
93     dataProvider = "openFilesWithIdWidthChanges")
94   public void testIdWidthChanges(String alignmentFilename, boolean wrap,
95           int idWidth1min, int idWidth1max, int manualWidth,
96           String structureFilename, String paeFilename,
97           boolean secondaryStructureView, TFType temperatureFactorType,
98           ViewerType viewerType, int idWidth2min, int idWidth2max)
99   {
100     AlignFrame af = new FileLoader()
101             .LoadFileWaitTillLoaded(alignmentFilename, DataSourceType.FILE);
102
103     try
104     {
105       Thread.sleep(200); // to allow alignment annotations to open
106     } catch (InterruptedException e)
107     {
108       // TODO Auto-generated catch block
109       e.printStackTrace();
110     }
111     AlignViewport av = af.getCurrentView();
112
113     int idWidth = 0;
114
115     idWidth = av.getIdWidth();
116     assertTrue(idWidth > idWidth1min,
117             "idWidth (" + idWidth + ") is not greater than " + idWidth1min);
118     assertTrue(idWidth < idWidth1max,
119             "idWidth (" + idWidth + ") is not narrower than" + idWidth1max);
120
121     // set wrap
122     if (wrap)
123     {
124       af.setWrapFormat(true, false);
125       idWidth = av.getIdWidth();
126       assertTrue(idWidth > idWidth1min, "After wrap idWidth (" + idWidth
127               + ") is not greater than " + idWidth1min);
128       assertTrue(idWidth < idWidth1max, "After wrap idWidth (" + idWidth
129               + ") is not narrower than" + idWidth1max);
130     }
131
132     AlignmentI al = av.getAlignment();
133     SequenceI s = al.getSequenceAt(0);
134     AlignmentPanel ap = af.alignPanel;
135
136     File structureFile = new File(structureFilename);
137     File paeFile = new File(paeFilename);
138
139     StructureViewer sv = StructureChooser.openStructureFileForSequence(null,
140             null, ap, s, false, structureFile.getAbsolutePath(),
141             temperatureFactorType, paeFile.getAbsolutePath(), true,
142             secondaryStructureView, false, viewerType);
143     // give time for annotations to open
144     try
145     {
146       Thread.sleep(200); // to allow alignment annotations to open
147     } catch (InterruptedException e)
148     {
149       // TODO Auto-generated catch block
150       e.printStackTrace();
151     }
152
153     // idWidth = ap.getIdPanel().getWidth();
154     idWidth = av.getIdWidth();
155     assertTrue(idWidth >= idWidth2min,
156             "idWidth (" + idWidth + ") is not greater than " + idWidth2min);
157     assertTrue(idWidth <= idWidth2max,
158             "idWidth (" + idWidth + ") is not narrower than" + idWidth2max);
159   }
160
161   @Test(
162     groups =
163     { "Functional", "testTask1" },
164     dataProvider = "openFilesWithIdWidthChanges")
165   public void testIdWidthNoChanges(String alignmentFilename, boolean wrap,
166           int idWidth1min, int idWidth1max, int manualWidth,
167           String structureFilename, String paeFilename,
168           boolean secondaryStructureView, TFType temperatureFactorType,
169           ViewerType viewerType, int idWidth2min, int idWidth2max)
170   {
171     AlignFrame af = new FileLoader()
172             .LoadFileWaitTillLoaded(alignmentFilename, DataSourceType.FILE);
173     try
174     {
175       Thread.sleep(200); // to allow alignment annotations to open
176     } catch (InterruptedException e)
177     {
178       // TODO Auto-generated catch block
179       e.printStackTrace();
180     }
181     AlignViewport av = af.getCurrentView();
182
183     int idWidth = 0;
184     idWidth = av.getIdWidth();
185     assertTrue(idWidth > idWidth1min,
186             "idWidth (" + idWidth + ") is not greater than " + idWidth1min);
187     assertTrue(idWidth < idWidth1max,
188             "idWidth (" + idWidth + ") is not narrower than" + idWidth1max);
189
190     AlignmentI al = av.getAlignment();
191     SequenceI s = al.getSequenceAt(0);
192     AlignmentPanel ap = af.alignPanel;
193
194     // set width manually
195     av.setIdWidth(manualWidth);
196     ap.validateAnnotationDimensions(false);
197     ap.paintAlignment(true, false);
198     ap.getIdPanel().getIdCanvas().setManuallyAdjusted(true);
199
200     idWidth = av.getIdWidth();
201     assertEquals(idWidth, manualWidth,
202             "idWidth is not set to the manually set width " + manualWidth);
203
204     File structureFile = new File(structureFilename);
205     File paeFile = new File(paeFilename);
206
207     StructureViewer sv = StructureChooser.openStructureFileForSequence(null,
208             null, ap, s, false, structureFile.getAbsolutePath(),
209             temperatureFactorType, paeFile.getAbsolutePath(), false,
210             secondaryStructureView, false, viewerType);
211
212     idWidth = ap.getIdPanel().getWidth();// av.getIdWidth();
213     idWidth = av.getIdWidth();
214     assertEquals(idWidth, manualWidth,
215             "idWidth is not set to the manually set width " + manualWidth
216                     + " after adding structure annotations");
217     assertFalse(idWidth > idWidth2min,
218             "idWidth (" + idWidth + ") is greater than " + idWidth2min);
219   }
220
221   @DataProvider(name = "openFilesWithIdWidthChanges")
222   public Object[][] openFilesWithIdWidthChanges()
223   {
224     /*
225       String alignmentFilename,
226       boolean wrap,
227       int idWidth1min,
228       int idWidth1max,
229       int manualWidth, // ignored by testIdWidthChanges()
230       String structureFilename,
231       String paeFilename,
232       boolean secondaryStructureView,
233       TFType temperatureFactorType,
234       ViewerType viewerType,
235       int idWidth2min,
236       int idWidth2max,
237      */
238     int idWidth2min = scaling == 1.0 ? 114 : 108;
239     int idWidth2max = scaling == 1.0 ? 114 : 114; // was 130
240
241     return new Object[][] {
242         //
243         /*
244          */
245         { "./test/files/annotation_label_width/sample.a2m", false, 50, 70,
246             100,
247             "./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb",
248             "./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3_scores.json",
249             true, TFType.PLDDT, null, idWidth2min, idWidth2max },
250         { "./test/files/annotation_label_width/sample.a2m", true, 50, 70,
251             100,
252             "./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb",
253             "./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3_scores.json",
254             true, TFType.PLDDT, null, idWidth2min, idWidth2max },
255         /*
256          */
257     };
258   }
259
260 }