JAL-629 null checks for Desktop.instance.closeAll(). Props re-loaded after CommandsTest.
[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.loadProperties("test/jalview/testProps.jvprops");
32   }
33
34   @BeforeClass(alwaysRun = true)
35   public void setUpJvOptionPane()
36   {
37     JvOptionPane.setInteractiveMode(false);
38     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
39   }
40
41   @AfterMethod(alwaysRun = true)
42   public void tearDown()
43   {
44     if (Desktop.instance != null)
45       Desktop.instance.closeAll_actionPerformed(null);
46   }
47
48   @Test(groups = "Functional", dataProvider = "cmdLines")
49   public void commandsOpenTest(String cmdLine, String sequence)
50   {
51     String[] args = cmdLine.split("\\s+");
52     Jalview.main(args);
53     Commands cmds = Jalview.getInstance().getCommands();
54     Assert.assertNotNull(cmds);
55     Assert.assertTrue(cmds.commandArgsProvided(),
56             "Commands were not provided in the args");
57     Assert.assertTrue(cmds.argsWereParsed(),
58             "Overall command parse and operation is false");
59
60     if (sequence != null)
61     {
62       Assert.assertTrue(lookForSequenceName(sequence),
63               "Sequence '" + sequence
64                       + "' was not found in opened alignment files: "
65                       + cmdLine);
66     }
67
68     System.out.println("##### GOT TO END");
69   }
70
71   public static boolean lookForSequenceName(String sequenceName)
72   {
73     AlignFrame[] afs = Desktop.getAlignFrames();
74     for (AlignFrame af : afs)
75     {
76       for (String name : af.getViewport().getAlignment().getSequenceNames())
77       {
78         if (sequenceName.equals(name))
79         {
80           return true;
81         }
82       }
83     }
84     return false;
85   }
86
87   @DataProvider(name = "cmdLines")
88   public Object[][] cmdLines()
89   {
90     return new Object[][] { { "--open=examples/uniref50.fa", "FER1_SPIOL" },
91         { "--argfile=test/jalview/bin/argparser/argfile0.txt", null } };
92   }
93
94 }