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