65162f3f51f9ba404f71ad2bc60fc106ced7ec51
[jalview.git] / test / jalview / bin / CommandsTest.java
1 package jalview.bin;
2
3 import java.util.Date;
4
5 import org.testng.Assert;
6 import org.testng.annotations.AfterMethod;
7 import org.testng.annotations.BeforeClass;
8 import org.testng.annotations.DataProvider;
9 import org.testng.annotations.Test;
10
11 import jalview.gui.AlignFrame;
12 import jalview.gui.Desktop;
13 import jalview.gui.JvOptionPane;
14
15 @Test(singleThreaded = true)
16 public class CommandsTest
17 {
18   @BeforeClass(alwaysRun = true)
19   public static void setUpBeforeClass() throws Exception
20   {
21     Cache.loadProperties("test/jalview/gui/quitProps.jvprops");
22     Date oneHourFromNow = new Date(
23             System.currentTimeMillis() + 3600 * 1000);
24     Cache.setDateProperty("JALVIEW_NEWS_RSS_LASTMODIFIED", oneHourFromNow);
25   }
26
27   @BeforeClass(alwaysRun = true)
28   public void setUpJvOptionPane()
29   {
30     JvOptionPane.setInteractiveMode(false);
31     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
32   }
33
34   @AfterMethod(alwaysRun = true)
35   public void tearDown()
36   {
37     Desktop.instance.closeAll_actionPerformed(null);
38   }
39
40   @Test(groups = "Functional", dataProvider = "cmdLines")
41   public void commandsOpenTest(String cmdLine, String sequence)
42   {
43     String[] args = cmdLine.split("\\s+");
44     Jalview.main(args);
45     Commands cmds = Jalview.getInstance().getCommands();
46     Assert.assertNotNull(cmds);
47     Assert.assertTrue(cmds.commandArgsProvided(),
48             "Commands were not provided in the args");
49     Assert.assertTrue(cmds.argsWereParsed(),
50             "Overall command parse and operation is false");
51
52     if (sequence != null)
53     {
54       Assert.assertTrue(lookForSequenceName(sequence),
55               "Sequence '" + sequence
56                       + "' was not found in opened alignment files: "
57                       + cmdLine);
58     }
59
60     System.out.println("##### GOT TO END");
61   }
62
63   public static boolean lookForSequenceName(String sequenceName)
64   {
65     AlignFrame[] afs = Desktop.getAlignFrames();
66     for (AlignFrame af : afs)
67     {
68       for (String name : af.getViewport().getAlignment().getSequenceNames())
69       {
70         if (sequenceName.equals(name))
71         {
72           return true;
73         }
74       }
75     }
76     return false;
77   }
78
79   @DataProvider(name = "cmdLines")
80   public Object[][] cmdLines()
81   {
82     return new Object[][] { { "--open=examples/uniref50.fa", "FER1_SPIOL" },
83         { "--argfile=test/jalview/bin/argparser/argfile0.txt", null } };
84   }
85
86 }