0c2071a70923a13a3ec0cdfe66276545179d9ae6
[jalview.git] / test / jalview / bin / CommandsTest2.java
1 package jalview.bin;
2
3 import java.util.Date;
4 import java.util.List;
5
6 import org.testng.Assert;
7 import org.testng.annotations.AfterClass;
8 import org.testng.annotations.AfterMethod;
9 import org.testng.annotations.BeforeClass;
10 import org.testng.annotations.DataProvider;
11 import org.testng.annotations.Test;
12
13 import jalview.api.AlignViewportI;
14 import jalview.datamodel.AlignmentAnnotation;
15 import jalview.datamodel.AlignmentI;
16 import jalview.datamodel.SequenceI;
17 import jalview.gui.AlignFrame;
18 import jalview.gui.AlignmentPanel;
19 import jalview.gui.Desktop;
20 import jalview.gui.JvOptionPane;
21 import jalview.gui.StructureViewerBase;
22
23 @Test
24 public class CommandsTest2
25 {
26   @BeforeClass(alwaysRun = true)
27   public static void setUpBeforeClass() throws Exception
28   {
29     Cache.loadProperties("test/jalview/bin/commandsTest.jvprops");
30     Date oneHourFromNow = new Date(
31             System.currentTimeMillis() + 3600 * 1000);
32     Cache.setDateProperty("JALVIEW_NEWS_RSS_LASTMODIFIED", oneHourFromNow);
33     if (Desktop.instance != null)
34       Desktop.instance.closeAll_actionPerformed(null);
35
36   }
37
38   @AfterClass(alwaysRun = true)
39   public static void resetProps()
40   {
41     Cache.loadProperties("test/jalview/testProps.jvprops");
42   }
43
44   @BeforeClass(alwaysRun = true)
45   public void setUpJvOptionPane()
46   {
47     JvOptionPane.setInteractiveMode(false);
48     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
49   }
50
51   @AfterMethod(alwaysRun = true)
52   public void tearDown()
53   {
54     Desktop.closeDesktop();
55   }
56
57   @Test(
58     groups =
59     { "Functional", "testTask1" },
60     dataProvider = "structureOpeningArgsParams",
61     singleThreaded = true)
62   public void structureOpeningArgsTest(String cmdLine, int seqNum,
63           int annNum, int viewerNum)
64   {
65     String[] args = cmdLine.split("\\s+");
66
67     CommandsTest.callJalviewMain(args);
68     try
69     {
70       // sleep for slow build server to open annotations and viewer windows
71       Thread.sleep(seqNum * 50 + annNum * 50 + viewerNum * 500);
72     } catch (InterruptedException e)
73     {
74       e.printStackTrace();
75     }
76
77     AlignFrame[] afs = Desktop.getAlignFrames();
78     Assert.assertNotNull(afs);
79     Assert.assertTrue(afs.length > 0);
80
81     AlignFrame af = afs[0];
82     Assert.assertNotNull(af);
83
84     AlignmentPanel ap = af.alignPanel;
85     Assert.assertNotNull(ap);
86
87     AlignmentI al = ap.getAlignment();
88     Assert.assertNotNull(al);
89
90     List<SequenceI> seqs = al.getSequences();
91     Assert.assertNotNull(seqs);
92
93     Assert.assertEquals(seqs.size(), seqNum, "Wrong number of sequences");
94
95     AlignViewportI av = ap.getAlignViewport();
96     Assert.assertNotNull(av);
97
98     AlignmentAnnotation[] aas = al.getAlignmentAnnotation();
99     int visibleAnn = 0;
100     int dcount = 0;
101     for (AlignmentAnnotation aa : aas)
102     {
103       if (aa.visible)
104         visibleAnn++;
105     }
106
107     Assert.assertEquals(visibleAnn, annNum,
108             "Wrong number of visible annotations");
109
110     if (viewerNum > -1)
111     {
112       List<StructureViewerBase> openViewers = Desktop.instance
113               .getStructureViewers(ap, null);
114       Assert.assertNotNull(openViewers);
115       int count = 0;
116       for (StructureViewerBase svb : openViewers)
117       {
118         if (svb.isVisible())
119           count++;
120       }
121       Assert.assertEquals(count, viewerNum,
122               "Wrong number of structure viewers opened");
123     }
124   }
125
126   @DataProvider(name = "structureOpeningArgsParams")
127   public Object[][] structureOpeningArgsParams()
128   {
129     /*
130       String cmdLine,
131       int seqNum,
132       int annNum,
133       int structureViewerNum,
134      */
135     return new Object[][] {
136         //
137         /*
138          */
139         { "--gui --nonews --nosplash --debug "
140                 + "--append=examples/uniref50.fa "
141                 + "--colour=gecos-flower "
142                 + "--structure=[seqid=FER1_SPIOL]examples/AlphaFold/AF-P00221-F1-model_v4.cif "
143                 + "--paematrix=examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
144                 + "--props=test/jalview/bin/commandsTest2.jvprops1 ",
145             15, 7, 1 },
146         { "--gui --nonews --nosplash --debug "
147                 + "--append=examples/uniref50.fa "
148                 + "--colour=gecos-flower "
149                 + "--structure=[seqid=FER1_SPIOL]examples/AlphaFold/AF-P00221-F1-model_v4.cif "
150                 + "--paematrix=examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
151                 + "--props=test/jalview/bin/commandsTest2.jvprops2 ",
152             15, 4, 1 },
153         { "--gui --nonews --nosplash --debug "
154                 + "--append=examples/uniref50.fa "
155                 + "--colour=gecos-flower "
156                 + "--structure=[seqid=FER1_SPIOL]examples/AlphaFold/AF-P00221-F1-model_v4.cif "
157                 + "--paematrix=examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
158                 + "--noshowssannotations "
159                 + "--props=test/jalview/bin/commandsTest2.jvprops1 ",
160             15, 4, 1 },
161         { "--gui --nonews --nosplash --debug "
162                 + "--append=examples/uniref50.fa "
163                 + "--colour=gecos-flower "
164                 + "--structure=[seqid=FER1_SPIOL]examples/AlphaFold/AF-P00221-F1-model_v4.cif "
165                 + "--paematrix=examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
166                 + "--noshowannotations "
167                 + "--props=test/jalview/bin/commandsTest2.jvprops1 ",
168             15, 3, 1 },
169         { "--gui --nonews --nosplash --debug "
170                 + "--append=examples/uniref50.fa "
171                 + "--colour=gecos-flower "
172                 + "--structure=[seqid=FER1_SPIOL]examples/AlphaFold/AF-P00221-F1-model_v4.cif "
173                 + "--paematrix=examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
174                 + "--noshowannotations " + "--noshowssannotations "
175                 + "--props=test/jalview/bin/commandsTest2.jvprops1 ",
176             15, 0, 1 },
177         { "--gui --nonews --nosplash --debug "
178                 + "--append=examples/uniref50.fa "
179                 + "--colour=gecos-flower "
180                 + "--structure=[seqid=FER1_SPIOL]examples/AlphaFold/AF-P00221-F1-model_v4.cif "
181                 + "--paematrix=examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
182                 + "--noshowannotations " + "--noshowssannotations "
183                 + "--props=test/jalview/bin/commandsTest2.jvprops1 ",
184             15, 0, 1 },
185         { "--gui --nonews --nosplash --debug --nowebservicediscovery --props=test/jalview/bin/commandsTest.jvprops --argfile=test/jalview/bin/commandsTest2.argfile1 ",
186             16, 19, 3 },
187         { "--gui --nonews --nosplash --debug --nowebservicediscovery --props=test/jalview/bin/commandsTest.jvprops --argfile=test/jalview/bin/commandsTest2.argfile2 ",
188             16, 0, 2 },
189         { "--gui --nonews --nosplash --debug --nowebservicediscovery --props=test/jalview/bin/commandsTest.jvprops --open=./examples/test_fab41.result/sample.a2m "
190                 + "--allstructures "
191                 + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb "
192                 + "--structureviewer=none "
193                 + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_2_model_4.pdb "
194                 + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_3_model_2.pdb",
195             16, 10, 0 },
196         { "--gui --nonews --nosplash --debug --nowebservicediscovery --props=test/jalview/bin/commandsTest.jvprops --open=./examples/test_fab41.result/sample.a2m "
197                 + "--allstructures "
198                 + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb "
199                 + "--noallstructures " + "--structureviewer=none "
200                 + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_2_model_4.pdb "
201                 + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_3_model_2.pdb",
202             16, 10, 2 },
203         /*
204          */
205         //
206     };
207   }
208 }