Clover icon

Coverage Report

  1. Project Clover database Tue Nov 18 2025 10:51:49 GMT
  2. Package jalview.bin

File CommandsTest2.java

 

Code metrics

18
56
9
1
363
279
20
0.36
6.22
9
2.22

Classes

Class Line # Actions
CommandsTest2 43 56 20
0.951807295.2%
 

Contributing tests

This file is covered by 23 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.bin;
22   
23    import java.util.Date;
24    import java.util.List;
25   
26    import org.testng.Assert;
27    import org.testng.annotations.AfterClass;
28    import org.testng.annotations.AfterMethod;
29    import org.testng.annotations.BeforeClass;
30    import org.testng.annotations.DataProvider;
31    import org.testng.annotations.Test;
32   
33    import jalview.api.AlignViewportI;
34    import jalview.datamodel.AlignmentAnnotation;
35    import jalview.datamodel.AlignmentI;
36    import jalview.datamodel.SequenceI;
37    import jalview.gui.AlignFrame;
38    import jalview.gui.AlignmentPanel;
39    import jalview.gui.Desktop;
40    import jalview.gui.JvOptionPane;
41    import jalview.gui.StructureViewerBase;
42   
 
43    public class CommandsTest2
44    {
 
45  1 toggle @BeforeClass(alwaysRun = true)
46    public static void setUpBeforeClass() throws Exception
47    {
48  1 Cache.loadProperties("test/jalview/bin/commandsTest.jvprops");
49  1 Date oneHourFromNow = new Date(
50    System.currentTimeMillis() + 3600 * 1000);
51  1 Cache.setDateProperty("JALVIEW_NEWS_RSS_LASTMODIFIED", oneHourFromNow);
52  1 if (Desktop.instance != null)
53  1 Desktop.instance.closeAll_actionPerformed(null);
54   
55    }
56   
 
57  1 toggle @AfterClass(alwaysRun = true)
58    public static void resetProps()
59    {
60  1 Cache.loadProperties("test/jalview/testProps.jvprops");
61    }
62   
 
63  1 toggle @BeforeClass(alwaysRun = true)
64    public void setUpJvOptionPane()
65    {
66  1 JvOptionPane.setInteractiveMode(false);
67  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
68    }
69   
 
70  23 toggle @AfterMethod(alwaysRun = true)
71    public void tearDown()
72    {
73  23 Desktop.closeDesktop();
74    }
75   
 
76  20 toggle @Test(
77    groups =
78    { "Functional", "testTask1" },
79    dataProvider = "structureOpeningArgsParams",
80    singleThreaded = true)
81    public void do_structureOpeningArgsTest(String cmdLine, int seqNum,
82    int annNum, int pdbPerSeqNum, int viewerNum)
83    {
84  20 _do_structureOpeningArgsTest(cmdLine, seqNum, annNum, pdbPerSeqNum,
85    viewerNum);
86    }
87   
 
88  3 toggle @Test(
89    groups =
90    { "Network", "testTask1" },
91    dataProvider = "structureOpeningArgsNetworkParams",
92    singleThreaded = true)
93    public void do_network_structureOpeningArgsTest(String cmdLine,
94    int seqNum, int annNum, int pdbPerSeqNum, int viewerNum)
95    {
96  3 _do_structureOpeningArgsTest(cmdLine, seqNum, annNum, pdbPerSeqNum,
97    viewerNum);
98    }
99   
100    /*
101    * Actual test logic - called by different groups with different data providers
102    */
 
103  23 toggle public void _do_structureOpeningArgsTest(String cmdLine, int seqNum,
104    int annNum, int strucPerSeqNum, int viewerNum)
105    {
106  23 String[] args = cmdLine.split("\\s+");
107   
108  23 CommandsTest.callJalviewMain(args);
109  35 while (Desktop.instance != null
110    && Desktop.instance.operationsAreInProgress())
111    {
112  12 try
113    {
114    // sleep for slow build server to open annotations and viewer windows
115  12 Thread.sleep(viewerNum * 50);
116    } catch (InterruptedException e)
117    {
118  0 e.printStackTrace();
119    }
120    }
121  23 ;
122   
123  23 AlignFrame[] afs = Desktop.getDesktopAlignFrames();
124  23 Assert.assertNotNull(afs);
125  23 Assert.assertTrue(afs.length > 0);
126   
127  23 AlignFrame af = afs[0];
128  23 Assert.assertNotNull(af);
129   
130  23 AlignmentPanel ap = af.alignPanel;
131  23 Assert.assertNotNull(ap);
132   
133  23 AlignmentI al = ap.getAlignment();
134  23 Assert.assertNotNull(al);
135   
136  23 List<SequenceI> seqs = al.getSequences();
137  23 Assert.assertNotNull(seqs);
138   
139  23 if (seqNum > -1)
140    {
141  16 Assert.assertEquals(seqs.size(), seqNum, "Wrong number of sequences");
142    }
143   
144  23 AlignViewportI av = ap.getAlignViewport();
145  23 Assert.assertNotNull(av);
146   
147  23 AlignmentAnnotation[] aas = al.getAlignmentAnnotation();
148  23 int visibleAnn = 0;
149  23 int dcount = 0;
150   
151  23 if (strucPerSeqNum > -1)
152    {
153  16 for (AlignmentAnnotation aa : aas)
154    {
155  120 if (aa.visible)
156  104 visibleAnn++;
157  120 if (aa.sequenceRef != null)
158    {
159  44 Assert.assertEquals(
160    aa.sequenceRef.getDatasetSequence().getAllPDBEntries()
161    .size(),
162    strucPerSeqNum,
163    "Unexpected number of structures for sequence");
164    }
165    }
166    }
167   
168  23 if (annNum > -1)
169    {
170  16 Assert.assertEquals(visibleAnn, annNum,
171    "Wrong number of visible annotations");
172    }
173   
174  23 if (viewerNum > -1)
175    {
176  23 List<StructureViewerBase> openViewers = Desktop.instance
177    .getStructureViewers(ap, null);
178  23 Assert.assertNotNull(openViewers);
179  23 int count = 0;
180  23 for (StructureViewerBase svb : openViewers)
181    {
182  30 if (svb.isVisible())
183    {
184  30 count++;
185    }
186    }
187  23 Assert.assertEquals(count, viewerNum,
188    "Wrong number of structure viewers opened");
189    }
190    }
191   
 
192  1 toggle @DataProvider(name = "structureOpeningArgsNetworkParams")
193    public Object[][] structureOpeningArgsNetworkParams()
194    {
195    /*
196    String cmdLine,
197    int seqNum,
198    int annNum,
199    int strucPerSeq,
200    int structureViewerNum,
201    */
202  1 return new Object[][] {
203    //
204    /*
205    * check import of structure and metadata via URL
206    */
207    { "--gui --nonews --nosplash --debug "
208    + "--open https://www.jalview.org/examples/uniref50.fa "
209    + "--colour=gecos-flower "
210    + "--structure=[seqid=FER1_SPIOL]https://www.jalview.org/examples/AlphaFold/AF-P00221-F1-model_v4.cif "
211    + "--paematrix=https://www.jalview.org/examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
212    + "--props=test/jalview/bin/commandsTest2.jvprops1 ",
213    15, 7, 1, 1 },
214    //
215    /*
216    * check URL import via 'open='
217    */
218    { "--gui --nonews --nosplash --debug "
219    + "--open=https://www.jalview.org/examples/uniref50.fa "
220    + "--colour=gecos-flower "
221    + "--structure=[seqid=FER1_SPIOL]https://www.jalview.org/examples/AlphaFold/AF-P00221-F1-model_v4.cif "
222    + "--paematrix=https://www.jalview.org/examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
223    + "--props=test/jalview/bin/commandsTest2.jvprops1 ",
224    15, 7, 1, 1 },
225    //
226    /*
227    * check URL import via 'append='
228    */
229    { "--gui --nonews --nosplash --debug "
230    + "--append=https://www.jalview.org/examples/uniref50.fa "
231    + "--colour=gecos-flower "
232    + "--structure=[seqid=FER1_SPIOL]https://www.jalview.org/examples/AlphaFold/AF-P00221-F1-model_v4.cif "
233    + "--paematrix=https://www.jalview.org/examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
234    + "--props=test/jalview/bin/commandsTest2.jvprops1 ",
235    15, 7, 1, 1 }, };
236    }
237   
 
238  1 toggle @DataProvider(name = "structureOpeningArgsParams")
239    public Object[][] structureOpeningArgsParams()
240    {
241    /*
242    String cmdLine,
243    int seqNum,
244    int annNum,
245    int strucPerSeq,
246    int structureViewerNum,
247    */
248  1 String stdargs = "--gui --nonews --nosplash --debug ";
249  1 String stdargs2 = stdargs
250    + "--nowebservicediscovery --props=test/jalview/bin/commandsTest.jvprops ";
251  1 return new Object[][] {
252    //
253    /*
254    */
255    { stdargs + "--append=examples/uniref50.fa "
256    + "--colour=gecos-flower "
257    + "--structure=[seqid=FER1_SPIOL]examples/AlphaFold/AF-P00221-F1-model_v4.cif "
258    + "--paematrix=examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
259    + "--props=test/jalview/bin/commandsTest2.jvprops1 ",
260    15, 7, 1, 1 },
261    { stdargs + "--append=examples/uniref50.fa "
262    + "--colour=gecos-flower "
263    + "--structure=[seqid=FER1_SPIOL]examples/AlphaFold/AF-P00221-F1-model_v4.cif "
264    + "--paematrix=examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
265    + "--props=test/jalview/bin/commandsTest2.jvprops2 ",
266    15, 4, 1, 1 },
267    { stdargs + "--append=examples/uniref50.fa "
268    + "--colour=gecos-flower "
269    + "--structure=[seqid=FER1_SPIOL]examples/AlphaFold/AF-P00221-F1-model_v4.cif "
270    + "--paematrix=examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
271    + "--noshowssannotations "
272    + "--props=test/jalview/bin/commandsTest2.jvprops1 ",
273    15, 4, 1, 1 },
274    { stdargs + "--append=examples/uniref50.fa "
275    + "--colour=gecos-flower "
276    + "--structure=[seqid=FER1_SPIOL]examples/AlphaFold/AF-P00221-F1-model_v4.cif "
277    + "--paematrix=examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
278    + "--noshowannotations "
279    + "--props=test/jalview/bin/commandsTest2.jvprops1 ",
280    15, 3, 1, 1 },
281    { stdargs + "--append=examples/uniref50.fa "
282    + "--colour=gecos-flower "
283    + "--structure=[seqid=FER1_SPIOL]examples/AlphaFold/AF-P00221-F1-model_v4.cif "
284    + "--paematrix=examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
285    + "--noshowannotations " + "--noshowssannotations "
286    + "--props=test/jalview/bin/commandsTest2.jvprops1 ",
287    15, 0, 1, 1 },
288    { stdargs + "--append=examples/uniref50.fa "
289    + "--colour=gecos-flower "
290    + "--structure=[seqid=FER1_SPIOL]examples/AlphaFold/AF-P00221-F1-model_v4.cif "
291    + "--paematrix=examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
292    + "--noshowannotations " + "--noshowssannotations "
293    + "--props=test/jalview/bin/commandsTest2.jvprops1 ",
294    15, 0, 1, 1 },
295    { stdargs2 + "--argfile=test/jalview/bin/commandsTest2.argfile1 ",
296    16, 19, 5, 3 },
297    { stdargs2 + "--argfile=test/jalview/bin/commandsTest2.argfile2 ",
298    16, 0, 5, 2 },
299    { stdargs2 + "--open=./examples/test_fab41.result/sample.a2m "
300    + "--allstructures "
301    + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb "
302    + "--structureviewer=none "
303    + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_2_model_4.pdb "
304    + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_3_model_2.pdb",
305    16, 10, 3, 0 },
306    { stdargs2 + "--open=./examples/test_fab41.result/sample.a2m "
307    + "--allstructures "
308    + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb "
309    + "--noallstructures " + "--structureviewer=none "
310    + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_2_model_4.pdb "
311    + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_3_model_2.pdb",
312    16, 10, 3, 2 },
313    // these three are to test that multiple annotations files can be
314    // opened
315    { stdargs2 + "--open=./examples/plantfdx.fa ", 15, 4, 0, 0 },
316    { stdargs2 + "--open=./examples/plantfdx.fa "
317    + "--annotations=./examples/testdata/plantfdx.annotations ",
318    15, 10, 0, 0 },
319    { stdargs2 + "--open=./examples/plantfdx.fa "
320    + "--annotations=./examples/testdata/plantfdx.annotations "
321    + "--annotations=./examples/testdata/FER1_SPIOL.plddt "
322    + "--annotations=./examples/testdata/FER1_SPIOL.paematrix ",
323    15, 12, 0, 0 },
324    // these 7 are to test that structure viewers can be shared
325    { stdargs2 + "--open=./examples/uniref50.fa "
326    + "--structure=./examples/AF-P83527-F1-model_v4.cif --seqid=FER_CAPAA "
327    + "--structure=./examples/SM-P83527-FER_CAPAA.pdb --seqid=FER_CAPAA --nosuperpose "
328    + "--structure=./examples/AlphaFold/AF-P00221-F1-model_v4.pdb --seqid=FER1_SPIOL ",
329    -1, -1, -1, 3 },
330    { stdargs2 + "--open=./examples/uniref50.fa "
331    + "--structure=./examples/AF-P83527-F1-model_v4.cif --seqid=FER_CAPAA --viewerid=id1 "
332    + "--structure=./examples/SM-P83527-FER_CAPAA.pdb --seqid=FER_CAPAA --nosuperpose --viewerid=id1 "
333    + "--structure=./examples/AlphaFold/AF-P00221-F1-model_v4.pdb --seqid=FER1_SPIOL ",
334    -1, -1, -1, 2 },
335    { stdargs2 + "--open=./examples/uniref50.fa "
336    + "--structure=./examples/AF-P83527-F1-model_v4.cif --seqid=FER_CAPAA --viewerid=id1 "
337    + "--structure=./examples/SM-P83527-FER_CAPAA.pdb --seqid=FER_CAPAA --nosuperpose --viewerid=id1 "
338    + "--structure=./examples/AlphaFold/AF-P00221-F1-model_v4.pdb --seqid=FER1_SPIOL --viewerid=id2 ",
339    -1, -1, -1, 2 },
340    { stdargs2 + "--open=./examples/uniref50.fa "
341    + "--structure=./examples/AF-P83527-F1-model_v4.cif --seqid=FER_CAPAA --viewerid=id1 "
342    + "--structure=./examples/SM-P83527-FER_CAPAA.pdb --seqid=FER_CAPAA --nosuperpose --viewerid=id1 "
343    + "--structure=./examples/AlphaFold/AF-P00221-F1-model_v4.pdb --seqid=FER1_SPIOL --viewerid=id1 ",
344    -1, -1, -1, 1 },
345    { stdargs2 + "--open=./examples/uniref50.fa "
346    + "--structuresfile=./examples/structuresfile.txt ",
347    -1, -1, -1, 1 },
348    { stdargs2 + "--open=./examples/uniref50.fa "
349    + "--structuresfile=./examples/structuresfile.txt "
350    + "--structure=./examples/SM-P83527-FER_CAPAA.pdb --seqid=FER_CAPAA --nosuperpose --viewerid=id1 "
351    + "--structuresfile=./examples/structuresfile2.txt ",
352    -1, -1, -1, 3 },
353    { stdargs2 + "--open=./examples/uniref50.fa "
354    + "--structuresfile=./examples/structuresfile.txt "
355    + "--structure=./examples/SM-P83527-FER_CAPAA.pdb --seqid=FER_CAPAA --nosuperpose --viewerid=THIS "
356    + "--structuresfile=./examples/structuresfile2.txt ",
357    -1, -1, -1, 2 },
358    /*
359    */
360    //
361    };
362    }
363    }