256e62ff2328747c31030b4970c0fb3b3f46ddec
[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/testProps.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" },
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     AlignFrame[] afs = Desktop.getAlignFrames();
70     Assert.assertNotNull(afs);
71     Assert.assertTrue(afs.length > 0);
72
73     AlignFrame af = afs[0];
74     Assert.assertNotNull(af);
75
76     AlignmentPanel ap = af.alignPanel;
77     Assert.assertNotNull(ap);
78
79     AlignmentI al = ap.getAlignment();
80     Assert.assertNotNull(al);
81
82     List<SequenceI> seqs = al.getSequences();
83     Assert.assertNotNull(seqs);
84
85     Assert.assertEquals(seqs.size(), seqNum, "Wrong number of sequences");
86
87     AlignViewportI av = ap.getAlignViewport();
88     Assert.assertNotNull(av);
89
90     AlignmentAnnotation[] aas = al.getAlignmentAnnotation();
91     int visibleAnn = 0;
92     for (AlignmentAnnotation aa : aas)
93     {
94       if (aa.visible)
95         visibleAnn++;
96     }
97
98     Assert.assertEquals(visibleAnn, annNum,
99             "Wrong number of visible annotations");
100
101     if (viewerNum > -1)
102     {
103       try
104       {
105         // sleep for slow build server to open viewer window
106         Thread.sleep(5000);
107       } catch (InterruptedException e)
108       {
109         e.printStackTrace();
110       }
111       List<StructureViewerBase> openViewers = Desktop.instance
112               .getStructureViewers(ap, null);
113       Assert.assertNotNull(openViewers);
114       Assert.assertEquals(openViewers.size(), viewerNum,
115               "Wrong number of structure viewers opened");
116     }
117   }
118
119   @DataProvider(name = "structureOpeningArgsParams")
120   public Object[][] structureOpeningArgsParams()
121   {
122     /*
123       String cmdLine,
124       int seqNum,
125       int annNum,
126       int viewerNum,
127       String propsFile
128      */
129     return new Object[][] {
130         //
131         /*
132          */
133         { "--nonews --nosplash --debug " + "--append=examples/uniref50.fa "
134                 + "--colour=gecos:flower "
135                 + "--structure=[seqid=FER1_SPIOL]examples/AlphaFold/AF-P00221-F1-model_v4.cif "
136                 + "--paematrix=examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
137                 + "--props=test/jalview/bin/commandsTest2.jvprops1 ",
138             15, 7, 1 },
139         { "--nonews --nosplash --debug " + "--append=examples/uniref50.fa "
140                 + "--colour=gecos:flower "
141                 + "--structure=[seqid=FER1_SPIOL]examples/AlphaFold/AF-P00221-F1-model_v4.cif "
142                 + "--paematrix=examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
143                 + "--props=test/jalview/bin/commandsTest2.jvprops2 ",
144             15, 4, 1 },
145         { "--nonews --nosplash --debug " + "--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                 + "--nossannotations "
150                 + "--props=test/jalview/bin/commandsTest2.jvprops1 ",
151             15, 4, 1 },
152         { "--nonews --nosplash --debug " + "--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                 + "--noannotations "
157                 + "--props=test/jalview/bin/commandsTest2.jvprops1 ",
158             15, 3, 1 },
159         { "--nonews --nosplash --debug " + "--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                 + "--noannotations " + "--nossannotations "
164                 + "--props=test/jalview/bin/commandsTest2.jvprops1 ",
165             15, 0, 1 },
166         { "--nonews --nosplash --debug " + "--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                 + "--noannotations " + "--nossannotations "
171                 + "--props=test/jalview/bin/commandsTest2.jvprops1 ",
172             15, 0, 1 },
173         { "--argfile=test/jalview/bin/commandsTest2.argfile1 ", 16, 19, 3 },
174         { "--argfile=test/jalview/bin/commandsTest2.argfile2 ", 16, 0, 2 },
175         //
176     };
177   }
178 }