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