ae14c1ae922737c78e2cadb2210efb6a8f5a3f0b
[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     while (Desktop.instance != null
69             && Desktop.instance.operationsAreInProgress())
70     {
71       try
72       {
73         // sleep for slow build server to open annotations and viewer windows
74         Thread.sleep(viewerNum * 50);
75       } catch (InterruptedException e)
76       {
77         e.printStackTrace();
78       }
79     }
80     ;
81
82     AlignFrame[] afs = Desktop.getAlignFrames();
83     Assert.assertNotNull(afs);
84     Assert.assertTrue(afs.length > 0);
85
86     AlignFrame af = afs[0];
87     Assert.assertNotNull(af);
88
89     AlignmentPanel ap = af.alignPanel;
90     Assert.assertNotNull(ap);
91
92     AlignmentI al = ap.getAlignment();
93     Assert.assertNotNull(al);
94
95     List<SequenceI> seqs = al.getSequences();
96     Assert.assertNotNull(seqs);
97
98     Assert.assertEquals(seqs.size(), seqNum, "Wrong number of sequences");
99
100     AlignViewportI av = ap.getAlignViewport();
101     Assert.assertNotNull(av);
102
103     AlignmentAnnotation[] aas = al.getAlignmentAnnotation();
104     int visibleAnn = 0;
105     int dcount = 0;
106     for (AlignmentAnnotation aa : aas)
107     {
108       if (aa.visible)
109         visibleAnn++;
110     }
111
112     Assert.assertEquals(visibleAnn, annNum,
113             "Wrong number of visible annotations");
114
115     if (viewerNum > -1)
116     {
117       List<StructureViewerBase> openViewers = Desktop.instance
118               .getStructureViewers(ap, null);
119       Assert.assertNotNull(openViewers);
120       int count = 0;
121       for (StructureViewerBase svb : openViewers)
122       {
123         if (svb.isVisible())
124           count++;
125       }
126       Assert.assertEquals(count, viewerNum,
127               "Wrong number of structure viewers opened");
128     }
129   }
130
131   @DataProvider(name = "structureOpeningArgsParams")
132   public Object[][] structureOpeningArgsParams()
133   {
134     /*
135       String cmdLine,
136       int seqNum,
137       int annNum,
138       int structureViewerNum,
139      */
140     return new Object[][] {
141         //
142         /*
143          */
144         { "--gui --nonews --nosplash --debug "
145                 + "--append=examples/uniref50.fa "
146                 + "--colour=gecos-flower "
147                 + "--structure=[seqid=FER1_SPIOL]examples/AlphaFold/AF-P00221-F1-model_v4.cif "
148                 + "--paematrix=examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
149                 + "--props=test/jalview/bin/commandsTest2.jvprops1 ",
150             15, 7, 1 },
151         { "--gui --nonews --nosplash --debug "
152                 + "--append=examples/uniref50.fa "
153                 + "--colour=gecos-flower "
154                 + "--structure=[seqid=FER1_SPIOL]examples/AlphaFold/AF-P00221-F1-model_v4.cif "
155                 + "--paematrix=examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
156                 + "--props=test/jalview/bin/commandsTest2.jvprops2 ",
157             15, 4, 1 },
158         { "--gui --nonews --nosplash --debug "
159                 + "--append=examples/uniref50.fa "
160                 + "--colour=gecos-flower "
161                 + "--structure=[seqid=FER1_SPIOL]examples/AlphaFold/AF-P00221-F1-model_v4.cif "
162                 + "--paematrix=examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
163                 + "--noshowssannotations "
164                 + "--props=test/jalview/bin/commandsTest2.jvprops1 ",
165             15, 4, 1 },
166         { "--gui --nonews --nosplash --debug "
167                 + "--append=examples/uniref50.fa "
168                 + "--colour=gecos-flower "
169                 + "--structure=[seqid=FER1_SPIOL]examples/AlphaFold/AF-P00221-F1-model_v4.cif "
170                 + "--paematrix=examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
171                 + "--noshowannotations "
172                 + "--props=test/jalview/bin/commandsTest2.jvprops1 ",
173             15, 3, 1 },
174         { "--gui --nonews --nosplash --debug "
175                 + "--append=examples/uniref50.fa "
176                 + "--colour=gecos-flower "
177                 + "--structure=[seqid=FER1_SPIOL]examples/AlphaFold/AF-P00221-F1-model_v4.cif "
178                 + "--paematrix=examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
179                 + "--noshowannotations " + "--noshowssannotations "
180                 + "--props=test/jalview/bin/commandsTest2.jvprops1 ",
181             15, 0, 1 },
182         { "--gui --nonews --nosplash --debug "
183                 + "--append=examples/uniref50.fa "
184                 + "--colour=gecos-flower "
185                 + "--structure=[seqid=FER1_SPIOL]examples/AlphaFold/AF-P00221-F1-model_v4.cif "
186                 + "--paematrix=examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
187                 + "--noshowannotations " + "--noshowssannotations "
188                 + "--props=test/jalview/bin/commandsTest2.jvprops1 ",
189             15, 0, 1 },
190         { "--gui --nonews --nosplash --debug --nowebservicediscovery --props=test/jalview/bin/commandsTest.jvprops --argfile=test/jalview/bin/commandsTest2.argfile1 ",
191             16, 19, 3 },
192         { "--gui --nonews --nosplash --debug --nowebservicediscovery --props=test/jalview/bin/commandsTest.jvprops --argfile=test/jalview/bin/commandsTest2.argfile2 ",
193             16, 0, 2 },
194         { "--gui --nonews --nosplash --debug --nowebservicediscovery --props=test/jalview/bin/commandsTest.jvprops --open=./examples/test_fab41.result/sample.a2m "
195                 + "--allstructures "
196                 + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb "
197                 + "--structureviewer=none "
198                 + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_2_model_4.pdb "
199                 + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_3_model_2.pdb",
200             16, 10, 0 },
201         { "--gui --nonews --nosplash --debug --nowebservicediscovery --props=test/jalview/bin/commandsTest.jvprops --open=./examples/test_fab41.result/sample.a2m "
202                 + "--allstructures "
203                 + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb "
204                 + "--noallstructures " + "--structureviewer=none "
205                 + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_2_model_4.pdb "
206                 + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_3_model_2.pdb",
207             16, 10, 2 },
208         /*
209          */
210         //
211     };
212   }
213 }