package jalview.bin; import java.io.File; import java.io.IOException; import java.util.List; import java.util.Properties; import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import jalview.bin.ArgParser.Arg; import jalview.bin.ArgParser.BootstrapArgs; public class ArgParserTest { @Test(groups = "Functional", dataProvider = "argLines") public void parseArgsAndSubValsTest(String commandLineArgs, Arg a, String other) { String[] args = commandLineArgs.split("\\s*"); ArgParser argparser = new ArgParser(args); } @Test(groups = "Functional", dataProvider = "argLines") public void bootstrapArgsTest(String commandLineArgs, Arg a, String other) { String[] args = commandLineArgs.split("\\s+"); BootstrapArgs b = BootstrapArgs.getBootstrapArgs(args); Assert.assertTrue(b.contains(a)); if (a == Arg.PROPS) { Properties bP = Cache.bootstrapProperties(b.get(Arg.PROPS)); Assert.assertTrue(other.equals(bP.get(Cache.BOOTSTRAP_TEST))); Assert.assertFalse(bP.contains("NOT" + Cache.BOOTSTRAP_TEST)); } else if (a == Arg.ARGFILE) { List filenames = b.getList(a); boolean found = false; for (String s : filenames) { File f = new File(s); File fo = new File(other); try { if (fo.getCanonicalPath().equals(f.getCanonicalPath())) { found = true; break; } } catch (IOException e) { } } Assert.assertTrue(found, "File '" + other + "' not found in shell expanded glob '" + commandLineArgs + "'"); } } @Test(groups = "Functional", dataProvider = "argFiles") public void argFilesTest(String commandLineArgs, Arg a, String other) { String[] args = commandLineArgs.split("\\s+"); BootstrapArgs b = BootstrapArgs.getBootstrapArgs(args); Assert.assertTrue(b.contains(a)); Assert.assertFalse(b.contains(Arg.OPEN)); if (a == Arg.PROPS) { Properties bP = Cache.bootstrapProperties(b.get(Arg.PROPS)); Assert.assertTrue("true".equals(bP.get(Cache.BOOTSTRAP_TEST))); } } @DataProvider(name = "argLinesTest") public Object[][] argLinesTest() { return new Object[][] { // can't use this one yet as it doesn't get shell expanded { "--argfile test/jalview/bin/argparser/argfile*.txt", Arg.ARGFILE, "test/jalview/bin/argparser/argfile0.txt" }, }; } @DataProvider(name = "argLines") public Object[][] argLines() { return new Object[][] { { "--debug --open=test/jalview/bin/argparser/test1.fa", Arg.DEBUG, null }, { "--open=test/jalview/bin/argparser/test1.fa --headless", Arg.HEADLESS, null }, { "--open=test/jalview/bin/argparser/test1.fa --props=test/jalview/bin/argparser/testProps.jvprops", Arg.PROPS, "true" }, { "--argfile=test/jalview/bin/argparser/argfile*.txt", Arg.ARGFILE, "test/jalview/bin/argparser/argfile0.txt" }, { "--argfile=test/jalview/bin/argparser/argfile*.txt", Arg.ARGFILE, "test/jalview/bin/argparser/argfile1.txt" }, { "--argfile=test/jalview/bin/argparser/argfile*.txt", Arg.ARGFILE, "test/jalview/bin/argparser/argfile2.txt" } }; } @DataProvider(name = "argFiles") public Object[][] argFiles() { return new Object[][] { { "--argfile=test/jalview/bin/argparser/argfile0.txt --open=shouldntbeabootstrap", Arg.ARGFILE, "test/jalview/bin/argfiles/test1.fa" } }; } }