4 import java.util.HashSet;
7 import org.testng.Assert;
8 import org.testng.annotations.AfterClass;
9 import org.testng.annotations.AfterMethod;
10 import org.testng.annotations.BeforeClass;
11 import org.testng.annotations.DataProvider;
12 import org.testng.annotations.Test;
14 import jalview.gui.AlignFrame;
15 import jalview.gui.Desktop;
16 import jalview.gui.JvOptionPane;
17 import jalview.util.ArrayUtils;
19 @Test(singleThreaded = true)
20 public class CommandsTest
22 @BeforeClass(alwaysRun = true)
23 public static void setUpBeforeClass() throws Exception
25 Cache.loadProperties("test/jalview/gui/quitProps.jvprops");
26 Date oneHourFromNow = new Date(
27 System.currentTimeMillis() + 3600 * 1000);
28 Cache.setDateProperty("JALVIEW_NEWS_RSS_LASTMODIFIED", oneHourFromNow);
31 @AfterClass(alwaysRun = true)
32 public static void resetProps()
34 Cache.loadProperties("test/jalview/testProps.jvprops");
37 @BeforeClass(alwaysRun = true)
38 public void setUpJvOptionPane()
40 JvOptionPane.setInteractiveMode(false);
41 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
44 @AfterMethod(alwaysRun = true)
45 public void tearDown()
47 if (Desktop.instance != null)
48 Desktop.instance.closeAll_actionPerformed(null);
51 @Test(groups = "Functional", dataProvider = "cmdLines")
52 public void commandsOpenTest(String cmdLine, boolean cmdArgs,
53 int numFrames, String[] sequences)
55 String[] args = cmdLine.split("\\s+");
57 Commands cmds = Jalview.getInstance().getCommands();
58 Assert.assertNotNull(cmds);
59 Assert.assertEquals(cmds.commandArgsProvided(), cmdArgs,
60 "Commands were not provided in the args");
61 Assert.assertEquals(cmds.argsWereParsed(), cmdArgs,
62 "Overall command parse and operation is false");
64 Assert.assertEquals(Desktop.getAlignFrames().length, numFrames);
66 if (sequences != null)
68 Set<String> openedSequenceNames = new HashSet<>();
69 AlignFrame[] afs = Desktop.getAlignFrames();
70 for (AlignFrame af : afs)
73 .addAll(af.getViewport().getAlignment().getSequenceNames());
75 for (String sequence : sequences)
77 Assert.assertTrue(openedSequenceNames.contains(sequence),
78 "Sequence '" + sequence
79 + "' was not found in opened alignment files: "
80 + cmdLine + ".\nOpened sequence names are:\n"
81 + String.join("\n", openedSequenceNames));
86 lookForSequenceName("THIS_SEQUENCE_ID_DOESN'T_EXIST"));
89 @DataProvider(name = "cmdLines")
90 public Object[][] cmdLines()
92 String[] someUniref50Seqs = new String[] { "FER_CAPAA", "FER_CAPAN",
93 "FER1_MAIZE", "FER1_SPIOL", "O80429_MAIZE" };
94 String[] t1 = new String[] { "TEST1" };
95 String[] t2 = new String[] { "TEST2" };
96 String[] t3 = new String[] { "TEST3" };
97 return new Object[][] {
98 { "--open=examples/uniref50.fa", true, 1, someUniref50Seqs },
99 { "--open examples/uniref50.fa", true, 1, someUniref50Seqs },
100 { "--open=examples/uniref50*.fa", true, 1, someUniref50Seqs },
101 // NOTE we cannot use shell expansion in tests, so list all files!
102 { "--open examples/uniref50.fa examples/uniref50_mz.fa", true, 1,
104 { "--open=[new]examples/uniref50*.fa", true, 2, someUniref50Seqs },
105 { "--opennew=examples/uniref50*.fa", true, 2, someUniref50Seqs },
106 { "examples/uniref50.fa", true, 1, someUniref50Seqs },
107 { "examples/uniref50.fa test/jalview/bin/argparser/testfiles/test1.fa",
108 true, 2, ArrayUtils.concatArrays(someUniref50Seqs, t1) },
109 { "examples/uniref50.fa test/jalview/bin/argparser/testfiles/test1.fa",
111 { "--argfile=test/jalview/bin/argparser/testfiles/argfile0.txt",
112 true, 1, ArrayUtils.concatArrays(t1, t3) },
113 { "--argfile=test/jalview/bin/argparser/testfiles/argfile*.txt",
114 true, 4, ArrayUtils.concatArrays(t1, t2, t3) },
115 { "--argfile=test/jalview/bin/argparser/testfiles/argfile.autocounter",
116 true, 3, ArrayUtils.concatArrays(t1, t2) } };
119 public static boolean lookForSequenceName(String sequenceName)
121 AlignFrame[] afs = Desktop.getAlignFrames();
122 for (AlignFrame af : afs)
124 for (String name : af.getViewport().getAlignment().getSequenceNames())
126 if (sequenceName.equals(name))