9c763e19b48d4e73b04189c8a36b84ea93daadc3
[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.BeforeClass;
7 import org.testng.annotations.DataProvider;
8 import org.testng.annotations.Test;
9
10 import jalview.gui.AlignFrame;
11 import jalview.gui.Desktop;
12 import jalview.gui.JvOptionPane;
13
14 @Test(singleThreaded = true)
15 public class CommandsTest
16 {
17   @BeforeClass(alwaysRun = true)
18   public static void setUpBeforeClass() throws Exception
19   {
20     Cache.loadProperties("test/jalview/gui/quitProps.jvprops");
21     Date oneHourFromNow = new Date(
22             System.currentTimeMillis() + 3600 * 1000);
23     Cache.setDateProperty("JALVIEW_NEWS_RSS_LASTMODIFIED", oneHourFromNow);
24   }
25
26   @BeforeClass(alwaysRun = true)
27   public void setUpJvOptionPane()
28   {
29     JvOptionPane.setInteractiveMode(false);
30     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
31   }
32
33   @Test(groups = "Functional", dataProvider = "cmdLines")
34   public void commandsOpenTest(String cmdLine, String sequence)
35   {
36     String[] args = cmdLine.split("\\s+");
37     Jalview.main(args);
38     ArgParser argparser = new ArgParser(args);
39     boolean commandsSuccess = Commands.processArgs(argparser, false);
40     Assert.assertTrue(commandsSuccess, "Overall commandsSuccess is false");
41
42     if (sequence != null)
43     {
44       AlignFrame[] afs = Desktop.getAlignFrames();
45       boolean found = false;
46       ALIGNFRAME: for (AlignFrame af : afs)
47       {
48         for (String name : af.getViewport().getAlignment()
49                 .getSequenceNames())
50         {
51           if (sequence.equals(name))
52           {
53             found = true;
54             break ALIGNFRAME;
55           }
56         }
57       }
58       Assert.assertTrue(found, "Sequence '" + sequence
59               + "' was not found in opened alignment files: " + cmdLine);
60     }
61   }
62
63   @DataProvider(name = "cmdLines")
64   public Object[][] cmdLines()
65   {
66     return new Object[][] { { "--open=examples/uniref50.fa", "FER1_SPIOL" },
67         { "--argfile=test/jalview/bin/argparser/argfile0.txt", null } };
68   }
69
70 }