@Test public void testArgumentsInTheMiddle() throws Exception { String[] args = new String[]{"-c", "foobar", "-b", "toast"}; CommandLine evaluated = cli.parse(Arrays.asList(args)); assertThat(getBooleanOption(evaluated, "c")).isTrue(); assertThat(getStringOption(evaluated, "b")).isEqualTo("toast"); assertThat(evaluated.allArguments()).contains("foobar").hasSize(1); }
@Test public void testWithOneShortOption() throws CLIException { Option[] options = new Option[]{ new Option().setShortName("f").setLongName("file").setSingleValued(true) }; cli.addOptions(Arrays.asList(options)); CommandLine evaluated = cli.parse(Collections.singletonList("-f=hello.txt")); assertThat(evaluated.cli().getOptions()).hasSize(1); assertThat((String) evaluated.getOptionValue("file")).isEqualTo("hello.txt"); assertThat(evaluated.getOptionValues("f")).containsExactly("hello.txt"); }
@Test public void patterns_can_be_evaluated_with_ignore_case() { List<String> resLeft = JsonPath.parse(JSON_DOCUMENT).read("$.store.book[?(@.category =~ /REFERENCE/)].author"); assertThat(resLeft).isEmpty(); resLeft = JsonPath.parse(JSON_DOCUMENT).read("$.store.book[?(@.category =~ /REFERENCE/i)].author"); assertThat(resLeft).containsExactly("Nigel Rees"); }
@Test public void testUnrecognizedOptionWithBursting() throws Exception { String[] args = new String[]{"-adbtoast", "foo", "bar"}; CommandLine evaluated = cli.parse(Arrays.asList(args)); assertThat(evaluated.allArguments()).contains("-adbtoast", "foo", "bar").hasSize(3); }
@Test public void testDoubleDash1() throws Exception { String[] args = new String[]{ "--copt", "--", "-b", "toast"}; CommandLine evaluated = cli.parse(Arrays.asList(args)); assertThat(getBooleanOption(evaluated, "c")).isTrue(); assertThat(getStringOption(evaluated, "b")).isNull(); assertThat(evaluated.allArguments()).hasSize(2).contains("-b", "toast"); }
@Test public void definition() { WebService.Action action = ws.getDef(); assertThat(action.since()).isEqualTo("4.3"); assertThat(action.isPost()).isTrue(); assertThat(action.isInternal()).isFalse(); assertThat(action.params()) .extracting(WebService.Param::key, WebService.Param::isRequired) .containsExactlyInAnyOrder( tuple("id", true), tuple("organization", false)); }
@Test public void definition() { WebService.Action definition = ws.getDef(); assertThat(definition).isNotNull(); assertThat(definition.isPost()).isFalse(); assertThat(definition.isInternal()).isTrue(); assertThat(definition.params()).hasSize(2).extracting("key").containsOnly( "leftKey", "rightKey"); assertThat(definition.responseExampleAsString()).isNotEmpty(); }
@Test public void load_plugins() { String pluginKey = "test"; when(fs.getInstalledPluginsDir()).thenReturn(new File("src/test/plugins/sonar-test-plugin/target")); underTest.start(); assertThat(underTest.getPluginInfos()).extracting("key").containsOnly(pluginKey); assertThat(underTest.getPluginInfo(pluginKey).getKey()).isEqualTo(pluginKey); assertThat(underTest.getPluginInstance(pluginKey)).isNotNull(); assertThat(underTest.hasPlugin(pluginKey)).isTrue(); }
@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 testMapPrimitiveCharFromNull() { h.createUpdate("insert into someBean (primitiveChar) values (null)").execute(); List<SomeBean> beans = dao.listBeans(); assertThat(beans).extracting(SomeBean::getPrimitiveChar).containsExactly('\000'); }
@Test public void verify_definition() { WebService.Action def = ws.getDef(); assertThat(def.isInternal()).isTrue(); assertThat(def.description()).isEqualTo("Get information concerning organization navigation for the current user"); assertThat(def.since()).isEqualTo("6.3"); assertThat(def.changelog()).extracting(Change::getVersion, Change::getDescription).containsExactlyInAnyOrder( tuple("6.4", "The field 'projectVisibility' is added")); assertThat(def.params()).hasSize(1); WebService.Param organization = def.param("organization"); assertThat(organization.description()).isEqualTo("the organization key"); assertThat(organization.isRequired()).isTrue(); assertThat(organization.exampleValue()).isEqualTo("my-org"); }
@Test public void test_ws_definition() { WebService.Action action = ws.getDef(); assertThat(action).isNotNull(); assertThat(action.isInternal()).isFalse(); assertThat(action.isPost()).isTrue(); assertThat(action.responseExampleAsString()).isNull(); assertThat(action.params()).extracting(Param::key).containsExactlyInAnyOrder("keys", "component", "branch", "pullRequest"); }
@Test public void testOptionAndRequiredOption() throws Exception { String[] args = new String[]{"-a", "-b", "file"}; TypedOption<String> b = new TypedOption<String>().setShortName("b").setLongName("bfile").setSingleValued(true) .setDescription("set the value of [b]").setType(String.class).setRequired(true); cli.removeOption("b").addOption(b); CommandLine evaluated = cli.parse(Arrays.asList(args)); assertThat(getBooleanOption(evaluated, "a")).isTrue(); assertThat(getStringOption(evaluated, "b")).isEqualTo("file"); assertThat(evaluated.allArguments()).isEmpty(); }
@Test public void testWithRequiredOption() throws Exception { String[] args = new String[]{"-b", "file"}; TypedOption<String> b = new TypedOption<String>().setShortName("b").setLongName("bfile").setSingleValued(true) .setDescription("set the value of [b]").setType(String.class).setRequired(true); cli.removeOption("b").addOption(b); CommandLine evaluated = cli.parse(Arrays.asList(args)); assertThat(getBooleanOption(evaluated, "a")).isFalse(); assertThat((String) evaluated.getOptionValue("b")).isEqualTo("file"); assertThat(evaluated.allArguments()).isEmpty(); }
@Test public void testOptionsWithDescription() { CLI cli = CLIConfigurator.define(CommandForDescriptionTest.class); assertThat(cli.getOptions()).hasSize(1); assertThat(find(cli.getOptions(), "option").getDescription()) .isEqualTo("This option is awesome"); }
@Test public void verify_definition() { WebService.Action action = ws.getDef(); assertThat(action.key()).isEqualTo("rename"); assertThat(action.since()).isEqualTo("4.3"); assertThat(action.changelog()).isEmpty(); assertThat(action.params()) .extracting(WebService.Param::key, WebService.Param::isRequired) .containsExactlyInAnyOrder( tuple("id", true), tuple("name", true), tuple("organization", false)); }
private void assertThatProjectChanged(List<QGChangeEvent> events, ComponentDto... projects) { for (ComponentDto p : projects) { assertThat(projectIndexer.hasBeenCalled(p.uuid(), ProjectIndexer.Cause.MEASURE_CHANGE)).isTrue(); } assertThat(events).extracting(e -> e.getProject().uuid()) .containsExactlyInAnyOrder(Arrays.stream(projects).map(ComponentDto::uuid).toArray(String[]::new)); }
@Test public void testWithArgumentReceivingMultipleValues() { CLI cli = new DefaultCLI().setName("test"); cli.addArgument(new Argument().setIndex(0).setArgName("arg").setDescription("argument1")); cli.addArgument(new Argument().setIndex(1).setMultiValued(true).setArgName("m").setDescription("multiple arg")); CommandLine cl = cli.parse(Arrays.asList("a", "b", "c")); assertThat((String) cl.getArgumentValue(0)).isEqualTo("a"); assertThat(cl.getArgumentValues(1)).containsExactly("b", "c"); assertThat((String) cl.getArgumentValue(1)).isEqualTo("b"); StringBuilder builder = new StringBuilder(); cli.usage(builder); assertThat(builder.toString()).contains("test arg m..."); }
@Test public void toSystemInfoSection() { JvmStateSection underTest = new JvmStateSection(PROCESS_NAME); ProtobufSystemInfo.Section section = underTest.toProtobuf(); assertThat(section.getName()).isEqualTo(PROCESS_NAME); assertThat(section.getAttributesCount()).isGreaterThan(0); assertThat(section.getAttributesList()).extracting("key") .contains( "Max Memory (MB)", "Free Memory (MB)", "Heap Max (MB)", "System Load Average", "Threads"); }
@Test public void initialize_does_not_create_Sonar_Way_as_default_if_other_profile_is_defined_as_default() { BuiltInQProfileRepository underTest = new BuiltInQProfileRepositoryImpl( dbClient, new Languages(FOO_LANGUAGE), new DummyProfileDefinition("foo", SONAR_WAY_QP_NAME, false), new DummyProfileDefinition("foo", "goo", true)); underTest.initialize(); assertThat(underTest.get()) .filteredOn(b -> FOO_LANGUAGE.getKey().equals(b.getLanguage())) .filteredOn(BuiltInQProfile::isDefault) .extracting(BuiltInQProfile::getName) .containsExactly("goo"); }