JAL-629 teardown in 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.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     ArgParser argparser = new ArgParser(args);
46     boolean commandsSuccess = Commands.processArgs(argparser, false);
47     Assert.assertTrue(commandsSuccess, "Overall commandsSuccess is false");
48
49     if (sequence != null)
50     {
51       AlignFrame[] afs = Desktop.getAlignFrames();
52       boolean found = false;
53       ALIGNFRAME: for (AlignFrame af : afs)
54       {
55         for (String name : af.getViewport().getAlignment()
56                 .getSequenceNames())
57         {
58           if (sequence.equals(name))
59           {
60             found = true;
61             break ALIGNFRAME;
62           }
63         }
64       }
65       Assert.assertTrue(found, "Sequence '" + sequence
66               + "' was not found in opened alignment files: " + cmdLine);
67     }
68   }
69
70   @DataProvider(name = "cmdLines")
71   public Object[][] cmdLines()
72   {
73     return new Object[][] { { "--open=examples/uniref50.fa", "FER1_SPIOL" },
74         { "--argfile=test/jalview/bin/argparser/argfile0.txt", null } };
75   }
76
77 }