示例#1
0
  @Test
  public void testMultipleOptionsWithMainArgAtTheEnd() {
    String[] args = {
      "-arg",
      "-update=green",
      "-version",
      "-headless",
      "-arg",
      "-about",
      "-arg",
      "blah1",
      "blah2",
      "blah3",
      "-noupdate",
      "-arg",
      "blah4",
      "blah5",
      "blah6",
      "-headless",
      "File.jnlp"
    };
    OptionParser parser = new OptionParser(args, OptionsDefinitions.getJavaWsOptions());

    List<String> values = parser.getParams(OptionsDefinitions.OPTIONS.ARG);
    assertEquals(6, values.size());
    assertTrue(parser.mainArgExists());
    assertEquals("File.jnlp", parser.getMainArg());
    assertEquals(0, values.indexOf("blah1"));
    assertEquals(1, values.indexOf("blah2"));
    assertEquals(2, values.indexOf("blah3"));
    assertEquals(3, values.indexOf("blah4"));
    assertEquals(4, values.indexOf("blah5"));
    assertEquals(5, values.indexOf("blah6"));
  }
示例#2
0
  @Test
  public void testMainArgAfterOneArgOption() {
    String[] args = {"-arg", "-red=colour", "-update", "200", "File.jnlp", "-arg", "-grizzly=bear"};
    OptionParser parser = new OptionParser(args, OptionsDefinitions.getJavaWsOptions());

    assertEquals("File.jnlp", parser.getMainArg());
  }
示例#3
0
  @Test
  public void testMultipleMainArgsReturnsFirstMainArg() {
    String[] args = {"File.jnlp", "FileTwo,jnlp", "FileThree.jnlp"};
    OptionParser parser = new OptionParser(args, OptionsDefinitions.getJavaWsOptions());

    assertTrue(parser.mainArgExists());
    assertEquals("File.jnlp", parser.getMainArg());
  }
示例#4
0
  @Test
  public void testSupportedOptionValueNotBeingUsed() {
    String[] args = {};
    OptionParser parser = new OptionParser(args, OptionsDefinitions.getJavaWsOptions());

    List<String> values = parser.getParams(OptionsDefinitions.OPTIONS.ARG);
    assertEquals(0, values.size());
  }
示例#5
0
  @Test
  public void testCheckOptionNotExists() {
    String[] args = {"-run", "fish", "-castle", "cat"};
    OptionParser parser = new OptionParser(args, OptionsDefinitions.getJavaWsOptions());

    boolean value = parser.hasOption(OptionsDefinitions.OPTIONS.HEADLESS);
    assertFalse(value);
  }
示例#6
0
  @Test
  public void testCheckOptionExistsAsNotFirstArg() {
    String[] args = {"-run", "fish", "-castle", "-headless"};
    OptionParser parser = new OptionParser(args, OptionsDefinitions.getJavaWsOptions());

    boolean value = parser.hasOption(OptionsDefinitions.OPTIONS.HEADLESS);
    assertTrue(value);
  }
示例#7
0
  @Test
  public void testOptionWithDashInMiddleWontBeAltered() {
    String[] args = {"ar-g", "blue", "green", "red"};

    OptionParser parser = new OptionParser(args, OptionsDefinitions.getJavaWsOptions());
    List<String> values = parser.getParams(OptionsDefinitions.OPTIONS.ARG);
    assertEquals(values.size(), 0);
  }
示例#8
0
  @Test
  public void testOptionValueWithNoArgument() {
    String[] args = {"-arg"};
    OptionParser parser = new OptionParser(args, OptionsDefinitions.getJavaWsOptions());

    List<String> values = parser.getParams(OptionsDefinitions.OPTIONS.ARG);
    assertEquals(0, values.size());
  }
示例#9
0
  @Test
  public void testMainArgAfterManyArgsOptionIsNotAccepted() {
    String[] args = {"-arg", "-red=colour", "-arg", "200", "File.jnlp", "-arg", "-grizzly=bear"};
    OptionParser parser = new OptionParser(args, OptionsDefinitions.getJavaWsOptions());

    assertFalse(parser.mainArgExists());
    assertNotEquals("File.jnlp", parser.getMainArg());
  }
示例#10
0
  @Test
  public void testGetSingleOptionValue() {
    String[] args = {"-update", "blob"};
    OptionParser parser = new OptionParser(args, OptionsDefinitions.getJavaWsOptions());

    String value = parser.getParam(OptionsDefinitions.OPTIONS.UPDATE);
    assertEquals("blob", value);
  }
示例#11
0
  @Test
  public void testCheckOptionExists() {
    String[] args = {"-headless", "-fish", "-busybee", "boat"};
    OptionParser parser = new OptionParser(args, OptionsDefinitions.getJavaWsOptions());

    boolean value = parser.hasOption(OptionsDefinitions.OPTIONS.HEADLESS);
    assertTrue(value);
  }
示例#12
0
  @Test
  public void testGetParamWithNoParams() {
    String[] args = {"-arg"};
    OptionParser parser = new OptionParser(args, OptionsDefinitions.getJavaWsOptions());

    String value = parser.getParam(OptionsDefinitions.OPTIONS.ARG);
    assertEquals("", value);
  }
示例#13
0
  @Test
  public void testSameTagMultipleTimesWithoutMainArg() {
    String[] args = {"-headless", "-headless", "-headless", "-headless", "-headless"};
    OptionParser parser = new OptionParser(args, OptionsDefinitions.getJavaWsOptions());

    assertFalse(parser.mainArgExists());
    assertEquals("", parser.getMainArg());
    assertTrue(parser.hasOption(OptionsDefinitions.OPTIONS.HEADLESS));
  }
示例#14
0
  @Test
  public void testOptionWithEqualsParamIsValid() {
    String[] args = {"-arg=blue"};
    OptionParser parser = new OptionParser(args, OptionsDefinitions.getJavaWsOptions());

    List<String> values = parser.getParams(OptionsDefinitions.OPTIONS.ARG);
    assertEquals(1, values.size());
    assertEquals(0, values.indexOf("blue"));
  }
示例#15
0
  @Test
  public void testOptionWithMultipleEqualSignsOnlyParsesFirstEquals() {
    String[] args = {"-arg=grizzly=panda=goldfish=mouse"};
    OptionParser parser = new OptionParser(args, OptionsDefinitions.getJavaWsOptions());

    List<String> values = parser.getParams(OptionsDefinitions.OPTIONS.ARG);

    assertEquals(1, values.size());
    assertEquals(0, values.indexOf("grizzly=panda=goldfish=mouse"));
  }
示例#16
0
  @Test
  public void testGetSingleOptionMultipleValues() {
    String[] args = {"-arg", "blob", "meow"};
    OptionParser parser = new OptionParser(args, OptionsDefinitions.getJavaWsOptions());

    List<String> values = parser.getParams(OptionsDefinitions.OPTIONS.ARG);
    assertEquals(0, values.indexOf("blob"));
    assertEquals(1, values.indexOf("meow"));
    assertEquals(2, values.size());
  }
示例#17
0
  @Test
  public void testSameOptionWithEqualsParamMultipleTimesIsValid() {
    String[] args = {"-arg=blue", "-arg=red", "-arg=green"};
    OptionParser parser = new OptionParser(args, OptionsDefinitions.getJavaWsOptions());

    List<String> values = parser.getParams(OptionsDefinitions.OPTIONS.ARG);
    assertEquals(3, values.size());
    assertEquals(0, values.indexOf("blue"));
    assertEquals(1, values.indexOf("red"));
    assertEquals(2, values.indexOf("green"));
  }
示例#18
0
  @Test
  public void testParamsCanHaveDashesAndEqualsSigns() {
    String[] args = {"-arg", "-red=colour", "-koala=animal", "-panda=bear", "-grizzly=bear"};
    OptionParser parser = new OptionParser(args, OptionsDefinitions.getJavaWsOptions());

    List<String> values = parser.getParams(OptionsDefinitions.OPTIONS.ARG);
    assertEquals(4, values.size());
    assertEquals(0, values.indexOf("-red=colour"));
    assertEquals(1, values.indexOf("-koala=animal"));
    assertEquals(2, values.indexOf("-panda=bear"));
    assertEquals(3, values.indexOf("-grizzly=bear"));
  }
示例#19
0
  @Test
  public void testOnlyFirstDashIsAcceptable() {
    String[] args = {"-arg", "blue", "a-rg", "-headless", "-arg", "green", "-ar-g"};

    OptionParser parser = new OptionParser(args, OptionsDefinitions.getJavaWsOptions());
    List<String> values = parser.getParams(OptionsDefinitions.OPTIONS.ARG);
    assertEquals(4, values.size());
    assertEquals(0, values.indexOf("blue"));
    assertEquals(1, values.indexOf("a-rg"));
    assertEquals(2, values.indexOf("green"));
    assertEquals(3, values.indexOf("-ar-g"));
  }
示例#20
0
  @Test
  public void testParamsCanHaveEqualsSigns() {
    String[] args = {"-arg", "colour=red", "height=50", "width=222", "circular=true"};
    OptionParser parser = new OptionParser(args, OptionsDefinitions.getJavaWsOptions());

    List<String> values = parser.getParams(OptionsDefinitions.OPTIONS.ARG);
    assertEquals(4, values.size());
    assertEquals(0, values.indexOf("colour=red"));
    assertEquals(1, values.indexOf("height=50"));
    assertEquals(2, values.indexOf("width=222"));
    assertEquals(3, values.indexOf("circular=true"));
  }
示例#21
0
  @Test
  public void testGetDifferentOptionValues() {
    String[] args = {"-param", "blob", "-arg", "yelp"};
    OptionParser parser = new OptionParser(args, OptionsDefinitions.getJavaWsOptions());

    List<String> values = parser.getParams(OptionsDefinitions.OPTIONS.PARAM);
    assertEquals(0, values.indexOf("blob"));
    assertEquals(1, values.size());

    values = parser.getParams(OptionsDefinitions.OPTIONS.ARG);
    assertEquals(0, values.indexOf("yelp"));
    assertEquals(1, values.size());
  }
示例#22
0
 @Test
 public void testEvenNumberSupportsEqualsChar() {
   String[] args = {"-set", "yes", "no", "blue=red", "green", "orange", "yellow=purple=roseyred"};
   OptionParser parser = new OptionParser(args, OptionsDefinitions.getItwsettingsCommands());
   List<String> values = parser.getParams(OptionsDefinitions.OPTIONS.SET);
   assertEquals("yes", values.get(0));
   assertEquals("no", values.get(1));
   assertEquals("blue", values.get(2));
   assertEquals("red", values.get(3));
   assertEquals("green", values.get(4));
   assertEquals("orange", values.get(5));
   assertEquals("yellow", values.get(6));
   assertEquals("purple=roseyred", values.get(7));
 }
示例#23
0
  @Test
  public void testMultipleOptionsMultipleValues() {
    String[] args = {"-param", "poke", "blob", "-arg", "meep", "feep", "blurp"};
    OptionParser parser = new OptionParser(args, OptionsDefinitions.getJavaWsOptions());

    List<String> values = parser.getParams(OptionsDefinitions.OPTIONS.PARAM);
    assertEquals(2, values.size());
    assertEquals(0, values.indexOf("poke"));
    assertEquals(1, values.indexOf("blob"));
    values = parser.getParams(OptionsDefinitions.OPTIONS.ARG);
    assertEquals(3, values.size());
    assertEquals(0, values.indexOf("meep"));
    assertEquals(1, values.indexOf("feep"));
    assertEquals(2, values.indexOf("blurp"));
  }
示例#24
0
  @Test
  public void testMultipleOptionWithEqualsParamIsValid() {
    String[] args = {"-arg=blue", "-property=red", "-param=green"};
    OptionParser parser = new OptionParser(args, OptionsDefinitions.getJavaWsOptions());

    List<String> values = parser.getParams(OptionsDefinitions.OPTIONS.ARG);
    assertEquals(1, values.size());
    assertEquals(0, values.indexOf("blue"));
    values = parser.getParams(OptionsDefinitions.OPTIONS.PROPERTY);
    assertEquals(1, values.size());
    assertEquals(0, values.indexOf("red"));
    values = parser.getParams(OptionsDefinitions.OPTIONS.PARAM);
    assertEquals(1, values.size());
    assertEquals(0, values.indexOf("green"));
  }
示例#25
0
 @Test
 public void testMultipleArgTagSurroundingMainArgAfterNoArgOption() {
   String[] args = {
     "-arg", "blue", "green", "red", "-headless", "File.jnlp", "-arg", "yellow", "purple"
   };
   OptionParser parser = new OptionParser(args, OptionsDefinitions.getJavaWsOptions());
   List<String> values = parser.getParams(OptionsDefinitions.OPTIONS.ARG);
   assertEquals(0, values.indexOf("blue"));
   assertEquals(1, values.indexOf("green"));
   assertEquals(2, values.indexOf("red"));
   assertEquals(3, values.indexOf("yellow"));
   assertEquals(4, values.indexOf("purple"));
   assertTrue(parser.mainArgExists());
   assertEquals("File.jnlp", parser.getMainArg());
   assertTrue(parser.hasOption(OptionsDefinitions.OPTIONS.HEADLESS));
 }
示例#26
0
 @Test
 public void testMultipleOptionsWithNoArgsCombinedWithMultipleOptions() {
   String[] args = {
     "-arg",
     "-update=green",
     "-version",
     "-arg",
     "-about",
     "-arg",
     "blah1",
     "blah2",
     "blah3",
     "-about",
     "-arg",
     "blah4",
     "blah5",
     "blah6",
     "File.jnlp",
     "-headless",
     "-noupdate"
   };
   OptionParser parser = new OptionParser(args, OptionsDefinitions.getJavaWsOptions());
   assertTrue(parser.hasOption(OptionsDefinitions.OPTIONS.ABOUT));
 }
示例#27
0
 @Test(expected = UnevenParameterException.class)
 public void testEvenNumberSupportsEqualsCharThrowsExceptionWhenParametersIsUneven() {
   String[] args = {"-set", "yes", "no", "blue=red", "green"};
   OptionParser parser = new OptionParser(args, OptionsDefinitions.getItwsettingsCommands());
 }
示例#28
0
 @Test
 public void testGetNumberOfOptionsWithOtherOptions() {
   String[] args = {"-arg", "-version", "-param", "-property", "-update", "-set", "-reset"};
   OptionParser parser = new OptionParser(args, OptionsDefinitions.getJavaWsOptions());
   assertEquals(5, parser.getNumberOfOptions());
 }