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