7b70a4b1687f5b2349811348b130d933576f92d9
[jalview.git] / test / jalview / bin / ArgParserTest.java
1 package jalview.bin;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.util.List;
6 import java.util.Properties;
7
8 import org.testng.Assert;
9 import org.testng.annotations.DataProvider;
10 import org.testng.annotations.Test;
11
12 import jalview.bin.ArgParser.Arg;
13 import jalview.bin.ArgParser.BootstrapArgs;
14 import jalview.util.FileUtils;
15
16 public class ArgParserTest
17 {
18
19   @Test(groups = "Functional", dataProvider = "argLines")
20   public void parseArgsAndSubValsTest(String commandLineArgs)
21   {
22     String[] args = commandLineArgs.split("\\s*");
23     ArgParser argparser = new ArgParser(args);
24   }
25
26   @Test(groups = "Functional", dataProvider = "argLines")
27   public void bootstrapArgsTest(String commandLineArgs, Arg a, String other)
28   {
29     String[] args = commandLineArgs.split("\\s+");
30     BootstrapArgs b = BootstrapArgs.getBootstrapArgs(args);
31
32     Assert.assertTrue(b.contains(a));
33     if (a == Arg.PROPS)
34     {
35       Properties bP = Cache.bootstrapProperties(b.get(Arg.PROPS));
36       Assert.assertTrue(other.equals(bP.get(Cache.BOOTSTRAP_TEST)));
37     }
38     else if (a == Arg.ARGFILE)
39     {
40       List<File> files = FileUtils.getFilesFromGlob(b.get(a));
41       boolean found = false;
42       for (File f : files)
43       {
44         File fo = new File(other);
45         try
46         {
47           if (fo.getCanonicalPath().equals(f.getCanonicalPath()))
48           {
49             found = true;
50             break;
51           }
52         } catch (IOException e)
53         {
54         }
55       }
56       Assert.assertTrue(found);
57     }
58
59   }
60
61   @Test(groups = "Functional", dataProvider = "argFiles")
62   public void argFilesTest(String commandLineArgs, Arg a)
63   {
64     String[] args = commandLineArgs.split("\\s+");
65     BootstrapArgs b = BootstrapArgs.getBootstrapArgs(args);
66
67     Assert.assertTrue(b.contains(a));
68     if (a == Arg.PROPS)
69     {
70       Properties bP = Cache.bootstrapProperties(b.get(Arg.PROPS));
71       Assert.assertTrue("true".equals(bP.get(Cache.BOOTSTRAP_TEST)));
72     }
73
74   }
75
76   @DataProvider(name = "argLines")
77   public Object[][] argLines()
78   {
79     return new Object[][] {
80         { "--debug --open=test/jalview/bin/argparser/test1.fa", Arg.DEBUG,
81             null },
82         { "--open=test/jalview/bin/argparser/test1.fa --headless",
83             Arg.HEADLESS, null },
84         { "--open=test/jalview/bin/argparser/test1.fa --props=test/jalview/bin/argparser/testProps.jvprops",
85             Arg.PROPS, "true" },
86         { "--argfile=test/jalview/bin/argparser/argfile*.txt", Arg.ARGFILE,
87             "test/jalview/bin/argparser/argfile1.txt" } };
88   }
89
90   @DataProvider(name = "argFiles")
91   public Object[][] argFiles()
92   {
93     return new Object[][] {
94         { "--argfile=test/jalview/bin/argparser/argfile0.txt", Arg.OPEN,
95             "test/jalview/bin/argfiles/test1.fa" } };
96   }
97 }