Clover icon

Coverage Report

  1. Project Clover database Thu Nov 28 2024 18:06:40 GMT
  2. Package jalview.gui

File AnnotationLabelsTest2.java

 

Code metrics

12
68
7
1
265
180
16
0.24
9.71
7
2.29

Classes

Class Line # Actions
AnnotationLabelsTest2 45 68 16
0.8850574588.5%
 

Contributing tests

This file is covered by 4 tests. .

Source view

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