@Test public void testWithURL() { final URL url = Converters.create(URL.class, "http://vertx.io"); assertThat(url.toExternalForm()).isEqualToIgnoringCase("http://vertx.io"); }
@Test public void testSystemProperties() throws CLIException { CLI cli = CLIConfigurator.define(command.getClass()); VertxCommandLauncher launcher = new VertxCommandLauncher(); CommandLine evaluatedCLI = parse(cli, "--name=vert.x", "-Dfoo=bar", "--systemProp=x=y"); CLIConfigurator.inject(evaluatedCLI, command); command.setUp(new ExecutionContext(command, launcher, evaluatedCLI)); assertThat(System.getProperty("foo")).isEqualToIgnoringCase("bar"); assertThat(System.getProperty("x")).isEqualToIgnoringCase("y"); command.tearDown(); // System properties are not removed by the tearDown. assertThat(System.getProperty("foo")).isEqualToIgnoringCase("bar"); assertThat(System.getProperty("x")).isEqualToIgnoringCase("y"); }
@Test public void testCreation() { assertThat(new Person4Converter().fromString("bob, morane").first).isEqualToIgnoringCase("bob"); assertThat(new Person4Converter().fromString("bob, morane").last).isEqualToIgnoringCase("morane"); }
@Test public void testInjectionOfString() throws CLIException { HelloClI command = new HelloClI(); CLI cli = CLIConfigurator.define(HelloClI.class); CommandLine evaluatedCLI = cli.parse(Arrays.asList("--name", "vert.x")); CLIConfigurator.inject(evaluatedCLI, command); assertThat(command.run()).isEqualToIgnoringCase("Hello vert.x"); assertThat(command.name).isEqualToIgnoringCase("vert.x"); }
@Test public void shouldReturnResultEqualToBLUE() throws Exception { String code = "import static java.awt.Color.BLUE\n" + "println BL"; //when AutocompleteResult autocomplete = groovyEvaluator.autocomplete(code, code.length()); //then assertThat(autocomplete.getMatches().get(0)).isEqualToIgnoringCase("BLUE"); assertThat(autocomplete.getStartIndex()).isEqualTo(code.length() - 2); }
@Test public void shouldReturnResultEqualToToString() throws Exception { String code = "def v = 'str'\nv.toS"; //when AutocompleteResult autocomplete = groovyEvaluator.autocomplete(code, code.length()); //then assertThat(autocomplete.getMatches().get(0)).isEqualToIgnoringCase("toString"); }
@Test public void shouldReturnResultEqualToParamInt() throws Exception { String code = "int paramInt = 10\n" + "println par"; //when AutocompleteResult autocomplete = groovyEvaluator.autocomplete(code, code.length()); //then assertThat(autocomplete.getMatches().get(0)).isEqualToIgnoringCase("paramInt"); }
@Test public void testHelloCLIFromClass() { CLI command = CLIConfigurator.define(HelloClI.class); assertThat(command.getOptions()).hasSize(1); TypedOption option = (TypedOption) find(command.getOptions(), "name"); assertThat(option.getLongName()).isEqualToIgnoringCase("name"); assertThat(option.getShortName()).isEqualToIgnoringCase("n"); assertThat(option.getType()).isEqualTo(String.class); assertThat(option.getArgName()).isEqualTo("name"); assertThat(option.getDescription()).isEqualToIgnoringCase("your name"); assertThat(option.getDefaultValue()).isNull(); assertThat(option.acceptValue()).isTrue(); assertThat(option.isMultiValued()).isFalse(); assertThat(option.isRequired()).isTrue(); }
@Test public void testMissingValue() throws Exception { String[] args = new String[]{"-b"}; try { CommandLine evaluated = cli.parse(Arrays.asList(args)); fail("Exception expected"); } catch (MissingValueException e) { assertThat(e.getOption().getShortName()).isEqualToIgnoringCase("b"); } }
@Test public void shouldReturnResultEqualToImport() throws Exception { String code = "imp"; //when AutocompleteResult autocomplete = evaluator().autocomplete(code, code.length()); //then assertThat(autocomplete.getMatches().get(0)).isEqualToIgnoringCase("import"); }
@Ignore @Test public void shouldReturnResultEqualToToString() throws Exception { String code = "String v = \"str\";\nv.toS"; //when AutocompleteResult autocomplete = evaluator().autocomplete(code, code.length()); //then assertThat(autocomplete.getMatches().get(0)).isEqualToIgnoringCase("toString"); }
@Test public void testThatArgumentIndexCanBeGenerated() { CLI cli = new DefaultCLI().setName("test"); cli.addArgument(new Argument()); cli.addArgument(new Argument()); cli.addArgument(new Argument().setMultiValued(true)); CommandLine line = cli.parse(Arrays.asList("a", "b", "c", "d")); assertThat((String) line.getArgumentValue(0)).isEqualToIgnoringCase("a"); assertThat((String) line.getArgumentValue(1)).isEqualToIgnoringCase("b"); assertThat(line.getArgumentValues(2)).containsExactly("c", "d"); }
@Test public void testThatArgumentIndexCanBeGeneratedWithPartiallyNumberedArguments() { CLI cli = new DefaultCLI().setName("test"); cli.addArgument(new Argument()); cli.addArgument(new Argument().setIndex(1)); cli.addArgument(new Argument().setMultiValued(true)); CommandLine line = cli.parse(Arrays.asList("a", "b", "c", "d")); assertThat((String) line.getArgumentValue(0)).isEqualToIgnoringCase("a"); assertThat((String) line.getArgumentValue(1)).isEqualToIgnoringCase("b"); assertThat(line.getArgumentValues(2)).containsExactly("c", "d"); }
@Test public void testLongWithUnexpectedArgument2() throws Exception { String[] args = new String[]{"-foobar"}; TypedOption<Boolean> f = new TypedOption<Boolean>().setLongName("foo").setShortName("f").setType(Boolean.class) .setSingleValued(false) // No value accepted here. ; cli.addOption(f); try { CommandLine evaluated = cli.parse(Arrays.asList(args)); fail("Exception expected"); } catch (InvalidValueException e) { assertThat(e.getOption().getShortName()).isEqualToIgnoringCase("f"); assertThat(e.getValue()).isEqualToIgnoringCase("bar"); } }
@Test public void testShortWithUnexpectedArgument() throws Exception { String[] args = new String[]{"-f=bar"}; TypedOption<Boolean> f = new TypedOption<Boolean>().setLongName("foo").setShortName("f").setType(Boolean.class) .setSingleValued(false) // No value accepted here. ; cli.addOption(f); try { CommandLine evaluated = cli.parse(Arrays.asList(args)); fail("Exception expected"); } catch (InvalidValueException e) { assertThat(e.getOption().getShortName()).isEqualToIgnoringCase("f"); assertThat(e.getValue()).isEqualToIgnoringCase("bar"); } }
@Test public void testFlag() { final CLI cli = CLI.create("test") .addOption(new Option().setShortName("f").setFlag(true)) .addOption(new Option().setShortName("x")); final CommandLine evaluated = cli.parse(Arrays.asList("-f", "-x", "foo")); assertThat(evaluated.isFlagEnabled("f")).isTrue(); assertThat((String) evaluated.getOptionValue("x")).isEqualToIgnoringCase("foo"); }
@Test public void testWithConfProvidedAsFile() throws IOException { setManifest("MANIFEST-Launcher-Http-Verticle.MF"); cli.dispatch(new Launcher(), new String[] {"--conf", "target/test-classes/conf.json"}); assertWaitUntil(() -> { try { return getHttpCode() == 200; } catch (IOException e) { return false; } }); assertThat(getContent().getJsonObject("conf").getString("name")).isEqualToIgnoringCase("vertx"); }
@Test public void testMissingFlag() { final CLI cli = CLI.create("test") .addOption(new Option().setShortName("f").setFlag(true)) .addOption(new Option().setShortName("x")); final CommandLine evaluated = cli.parse(Arrays.asList("-x", "foo")); assertThat(evaluated.isFlagEnabled("f")).isFalse(); assertThat((String) evaluated.getOptionValue("x")).isEqualToIgnoringCase("foo"); }
@Test public void testLongWithUnexpectedArgument1() throws Exception { String[] args = new String[]{"--foo=bar"}; TypedOption<Boolean> f = new TypedOption<Boolean>().setLongName("foo").setShortName("f") .setType(Boolean.class) .setSingleValued(false) // No value accepted here. .setFlag(true); cli.addOption(f); try { CommandLine evaluated = cli.parse(Arrays.asList(args)); fail("Exception expected"); } catch (InvalidValueException e) { assertThat(e.getOption().getShortName()).isEqualToIgnoringCase("f"); assertThat(e.getValue()).isEqualToIgnoringCase("bar"); } }
@Test public void testWithBrokenConfProvidedInline() throws IOException { setManifest("MANIFEST-Launcher-Http-Verticle.MF"); // There is a missing `}` in the json fragment. This is normal, as the test check that the configuration is not // read in this case. cli.dispatch(new Launcher(), new String[] {"--conf={\"name\":\"vertx\""}); assertWaitUntil(() -> { try { return getHttpCode() == 200; } catch (IOException e) { return false; } }); assertThat(getContent().getJsonObject("conf").toString()).isEqualToIgnoringCase("{}"); }