e8fa9f16a5dfa7938a5491dcc903f77fb7cfa1a4
[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, int idWidth1min,
91           int idWidth1max, int manualWidth, String structureFilename,
92           String paeFilename, boolean secondaryStructureView,
93           TFType temperatureFactorType, ViewerType viewerType,
94           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, "idWidth (" + idWidth
114             + ") is not less wide than" + idWidth1max);
115
116     AlignmentI al = av.getAlignment();
117     SequenceI s = al.getSequenceAt(0);
118     AlignmentPanel ap = af.alignPanel;
119
120     File structureFile = new File(structureFilename);
121     File paeFile = new File(paeFilename);
122
123     StructureViewer sv = StructureChooser.openStructureFileForSequence(null,
124             null, ap, s, false, structureFile.getAbsolutePath(),
125             temperatureFactorType, paeFile.getAbsolutePath(), true,
126             secondaryStructureView, false, viewerType);
127     // give time for annotations to open
128     try
129     {
130       Thread.sleep(200); // to allow alignment annotations to open
131     } catch (InterruptedException e)
132     {
133       // TODO Auto-generated catch block
134       e.printStackTrace();
135     }
136
137     idWidth = av.getIdWidth();
138     assertTrue(idWidth > idWidth2min,
139             "idWidth (" + idWidth + ") is not greater than " + idWidth2min);
140     assertTrue(idWidth < idWidth2max, "idWidth (" + idWidth
141             + ") is not less wide than" + idWidth2max);
142   }
143
144   @Test(
145     groups =
146     { "Functional", "testTask1" },
147     dataProvider = "openFilesWithIdWidthChanges")
148   public void testIdWidthNoChanges(String alignmentFilename,
149           int idWidth1min, int idWidth1max, int manualWidth,
150           String structureFilename, String paeFilename,
151           boolean secondaryStructureView, TFType temperatureFactorType,
152           ViewerType viewerType, int idWidth2min, int idWidth2max)
153   {
154     AlignFrame af = new FileLoader()
155             .LoadFileWaitTillLoaded(alignmentFilename, DataSourceType.FILE);
156     try
157     {
158       Thread.sleep(200); // to allow alignment annotations to open
159     } catch (InterruptedException e)
160     {
161       // TODO Auto-generated catch block
162       e.printStackTrace();
163     }
164     AlignViewport av = af.getCurrentView();
165
166     int idWidth = 0;
167
168     idWidth = av.getIdWidth();
169     assertTrue(idWidth > idWidth1min,
170             "idWidth (" + idWidth + ") is not greater than " + idWidth1min);
171     assertTrue(idWidth < idWidth1max, "idWidth (" + idWidth
172             + ") is not less wide than" + idWidth1max);
173
174     AlignmentI al = av.getAlignment();
175     SequenceI s = al.getSequenceAt(0);
176     AlignmentPanel ap = af.alignPanel;
177
178     // set width manually
179     av.setIdWidth(manualWidth);
180     ap.validateAnnotationDimensions(false);
181     ap.paintAlignment(true, false);
182     ap.getIdPanel().getIdCanvas().setManuallyAdjusted(true);
183
184     idWidth = av.getIdWidth();
185     assertEquals(idWidth, manualWidth,
186             "idWidth is not set to the manually set width " + manualWidth);
187
188     File structureFile = new File(structureFilename);
189     File paeFile = new File(paeFilename);
190
191     StructureViewer sv = StructureChooser.openStructureFileForSequence(null,
192             null, ap, s, false, structureFile.getAbsolutePath(),
193             temperatureFactorType, paeFile.getAbsolutePath(), false,
194             secondaryStructureView, false, viewerType);
195
196     idWidth = ap.getIdPanel().getWidth();// av.getIdWidth();
197     idWidth = av.getIdWidth();
198     assertEquals(idWidth, manualWidth,
199             "idWidth is not set to the manually set width " + manualWidth
200                     + " after adding structure annotations");
201     assertFalse(idWidth > idWidth2min,
202             "idWidth (" + idWidth + ") is greater than " + idWidth2min);
203   }
204
205   @DataProvider(name = "openFilesWithIdWidthChanges")
206   public Object[][] openFilesWithIdWidthChanges()
207   {
208     /*
209       String alignmentFilename,
210       int idWidth1min,
211       int idWidth1max,
212       int manualWidth, // ignored by testIdWidthChanges()
213       String structureFilename,
214       String paeFilename,
215       boolean secondaryStructureView,
216       TFType temperatureFactorType,
217       ViewerType viewerType,
218       int idWidth2min,
219       int idWidth2max,
220      */
221     return new Object[][] {
222         //
223         /*
224          */
225         {
226             //
227             "./test/files/annotation_label_width/sample.a2m", 50, 70, 100,
228             "./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb",
229             "./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3_scores.json",
230             true, TFType.PLDDT, null, 115, 130
231         //
232         },
233         /*
234          */
235     };
236   }
237
238 }