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