JAL-629 Test and fix --annotation --ssannotation args. Added a viewerType arg/subval...
[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   public void structureOpeningArgsTest(String cmdLine, int seqNum,
63           int annNum, int viewerNum)
64   {
65     String[] args = cmdLine.split("\\s+");
66
67     Jalview.main(args);
68     AlignFrame[] afs = Desktop.getAlignFrames();
69     Assert.assertNotNull(afs);
70     Assert.assertTrue(afs.length > 0);
71
72     AlignFrame af = afs[0];
73     Assert.assertNotNull(af);
74
75     AlignmentPanel ap = af.alignPanel;
76     Assert.assertNotNull(ap);
77
78     AlignmentI al = ap.getAlignment();
79     Assert.assertNotNull(al);
80
81     List<SequenceI> seqs = al.getSequences();
82     Assert.assertNotNull(seqs);
83
84     Assert.assertEquals(seqs.size(), seqNum, "Wrong number of sequences");
85
86     AlignViewportI av = ap.getAlignViewport();
87     Assert.assertNotNull(av);
88
89     AlignmentAnnotation[] aas = al.getAlignmentAnnotation();
90     int visibleAnn = 0;
91     for (AlignmentAnnotation aa : aas)
92     {
93       if (aa.visible)
94         visibleAnn++;
95     }
96
97     Assert.assertEquals(visibleAnn, annNum,
98             "Wrong number of visible annotations");
99
100     if (viewerNum > -1)
101     {
102       try
103       {
104         Thread.sleep(100);
105       } catch (InterruptedException e)
106       {
107         // TODO Auto-generated catch block
108         e.printStackTrace();
109       }
110       List<StructureViewerBase> openViewers = Desktop.instance
111               .getStructureViewers(ap, null);
112       Assert.assertNotNull(openViewers);
113       Assert.assertEquals(openViewers.size(), viewerNum,
114               "Wrong number of structure viewers opened");
115     }
116   }
117
118   @DataProvider(name = "structureOpeningArgsParams")
119   public Object[][] structureOpeningArgsParams()
120   {
121     /*
122       String cmdLine,
123       int seqNum,
124       int annNum,
125       int viewerNum,
126       String propsFile
127      */
128     return new Object[][] { { "--nonews --nosplash --debug "
129             + "--open=examples/uniref50.fa " + "--colour=gecos:flower "
130             + "--structure=[seqid=FER1_SPIOL]examples/AlphaFold/AF-P00221-F1-model_v4.cif "
131             + "--paematrix=examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
132             + "--props=test/jalview/bin/commandsTest2.jvprops1 ",
133         15, 7, 1 },
134         { "--nonews --nosplash --debug " + "--open=examples/uniref50.fa "
135                 + "--colour=gecos:flower "
136                 + "--structure=[seqid=FER1_SPIOL]examples/AlphaFold/AF-P00221-F1-model_v4.cif "
137                 + "--paematrix=examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
138                 + "--props=test/jalview/bin/commandsTest2.jvprops2 ",
139             15, 4, 1 },
140         { "--nonews --nosplash --debug " + "--open=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                 + "--nossannotations "
145                 + "--props=test/jalview/bin/commandsTest2.jvprops1 ",
146             15, 4, 1 },
147         { "--nonews --nosplash --debug " + "--open=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                 + "--noannotations "
152                 + "--props=test/jalview/bin/commandsTest2.jvprops1 ",
153             15, 3, 1 },
154         { "--nonews --nosplash --debug " + "--open=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                 + "--noannotations " + "--nossannotations "
159                 + "--props=test/jalview/bin/commandsTest2.jvprops1 ",
160             15, 0, 1 },
161         { "--nonews --nosplash --debug " + "--open=examples/uniref50.fa "
162                 + "--colour=gecos:flower "
163                 + "--structure=[seqid=FER1_SPIOL]examples/AlphaFold/AF-P00221-F1-model_v4.cif "
164                 + "--paematrix=examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
165                 + "--noannotations " + "--nossannotations "
166                 + "--props=test/jalview/bin/commandsTest2.jvprops1 ",
167             15, 0, 1 },
168         { "--argfile=test/jalview/bin/commandsTest2.argfile1 ", 16, 19, 3 },
169         { "--argfile=test/jalview/bin/commandsTest2.argfile2 ", 16, 0, 2 },
170         //
171     };
172   }
173 }