+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;
+import jalview.util.FileUtils;
+
+public class ArgParserTest
+{
+
+ @Test(groups = "Functional", dataProvider = "argLines")
+ public void parseArgsAndSubValsTest(String commandLineArgs)
+ {
+ 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)));
+ }
+ else if (a == Arg.ARGFILE)
+ {
+ List<File> files = FileUtils.getFilesFromGlob(b.get(a));
+ boolean found = false;
+ for (File f : files)
+ {
+ File fo = new File(other);
+ try
+ {
+ if (fo.getCanonicalPath().equals(f.getCanonicalPath()))
+ {
+ found = true;
+ break;
+ }
+ } catch (IOException e)
+ {
+ }
+ }
+ Assert.assertTrue(found);
+ }
+
+ }
+
+ @Test(groups = "Functional", dataProvider = "argFiles")
+ public void argFilesTest(String commandLineArgs, Arg a)
+ {
+ 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("true".equals(bP.get(Cache.BOOTSTRAP_TEST)));
+ }
+
+ }
+
+ @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/argfile1.txt" } };
+ }
+
+ @DataProvider(name = "argFiles")
+ public Object[][] argFiles()
+ {
+ return new Object[][] {
+ { "--argfile=test/jalview/bin/argparser/argfile0.txt", Arg.OPEN,
+ "test/jalview/bin/argfiles/test1.fa" } };
+ }
+}