.fields(newArrayList( PropertyFieldDefinition.build("firstField") .name("First Field") .type(PropertyType.STRING) .build(), PropertyFieldDefinition.build("secondField") .name("Second Field") .type(PropertyType.STRING) .build())) .build()); ComponentDto project = db.components().insertPrivateProject();
@Test public void return_property_set() { logIn(); propertyDefinitions.addComponent(PropertyDefinition .builder("foo") .type(PropertyType.PROPERTY_SET) .fields( PropertyFieldDefinition.build("boolean").name("Boolean").description("boolean desc").type(PropertyType.BOOLEAN).build(), PropertyFieldDefinition.build("list").name("List").description("list desc").type(PropertyType.SINGLE_SELECT_LIST).options("one", "two").build()) .build()); ListDefinitionsWsResponse result = executeRequest(); assertThat(result.getDefinitionsList()).hasSize(1); Definition definition = result.getDefinitions(0); assertThat(definition.getType()).isEqualTo(PROPERTY_SET); assertThat(definition.getFieldsList()).hasSize(2); assertThat(definition.getFields(0).getKey()).isEqualTo("boolean"); assertThat(definition.getFields(0).getName()).isEqualTo("Boolean"); assertThat(definition.getFields(0).getDescription()).isEqualTo("boolean desc"); assertThat(definition.getFields(0).getType()).isEqualTo(BOOLEAN); assertThat(definition.getFields(0).getOptionsCount()).isZero(); assertThat(definition.getFields(1).getKey()).isEqualTo("list"); assertThat(definition.getFields(1).getName()).isEqualTo("List"); assertThat(definition.getFields(1).getDescription()).isEqualTo("list desc"); assertThat(definition.getFields(1).getType()).isEqualTo(SINGLE_SELECT_LIST); assertThat(definition.getFields(1).getOptionsList()).containsExactly("one", "two"); }
@Test public void should_support_property_sets() { PropertyDefinition def = PropertyDefinition.builder("hello") .name("Hello") .fields( PropertyFieldDefinition.build("first").name("First").description("Description").options("A", "B").build(), PropertyFieldDefinition.build("second").name("Second").type(PropertyType.INTEGER).indicativeSize(5).build()) .build(); assertThat(def.type()).isEqualTo(PropertyType.PROPERTY_SET); assertThat(def.fields()).hasSize(2); assertThat(def.fields().get(0).key()).isEqualTo("first"); assertThat(def.fields().get(0).name()).isEqualTo("First"); assertThat(def.fields().get(0).description()).isEqualTo("Description"); assertThat(def.fields().get(0).type()).isEqualTo(PropertyType.STRING); assertThat(def.fields().get(0).options()).containsOnly("A", "B"); assertThat(def.fields().get(0).indicativeSize()).isEqualTo(20); assertThat(def.fields().get(1).key()).isEqualTo("second"); assertThat(def.fields().get(1).name()).isEqualTo("Second"); assertThat(def.fields().get(1).type()).isEqualTo(PropertyType.INTEGER); assertThat(def.fields().get(1).options()).isEmpty(); assertThat(def.fields().get(1).indicativeSize()).isEqualTo(5); }
.fields( PropertyFieldDefinition.build(RULE_KEY) .name(PROPERTY_RULE_KEY_PATTERN) .description("Pattern to match rules which should be ignored.") .type(PropertyType.STRING) .indicativeSize(LARGE_SIZE) .build(), PropertyFieldDefinition.build(RESOURCE_KEY) .name(PROPERTY_FILE_PATH_PATTERN) .description("Pattern to match files which should be ignored.") .type(PropertyType.STRING) .indicativeSize(LARGE_SIZE) .build() .fields( PropertyFieldDefinition.build(BEGIN_BLOCK_REGEXP) .name("Regular Expression for Start of Block") .description("If this regular expression is found in a file, then following lines are ignored until end of block.") .type(PropertyType.STRING) .indicativeSize(LARGE_SIZE) .build(), PropertyFieldDefinition.build(END_BLOCK_REGEXP) .name("Regular Expression for End of Block") .description("If specified, this regular expression is used to determine the end of code blocks to ignore. If not, then block ends at the end of file.") .type(PropertyType.STRING) .indicativeSize(LARGE_SIZE) .build() .fields(
.fields( PropertyFieldDefinition.build(PROJECT.property()) .name("Project Key") .description("Ex: com.koant.sonar.slack:sonar-slack-notifier-plugin, can use '*' wildcard at the end") .type(PropertyType.STRING) .build(), PropertyFieldDefinition.build(CHANNEL.property()) .name("Slack channel") .description("Channel to send project specific messages to") .type(PropertyType.STRING) .build(), PropertyFieldDefinition.build(QG_FAIL_ONLY.property()) .name("Send on failed Quality Gate") .description("Should notification be sent only if Quality Gate did not pass OK") .type(PropertyType.BOOLEAN) .build()
.fields( PropertyFieldDefinition.build(CoreProperties.LANGUAGE_SPECIFIC_PARAMETERS_LANGUAGE_KEY) .name("Language Key") .description("Ex: java, cs, cpp...") .type(PropertyType.STRING) .build(), PropertyFieldDefinition.build(CoreProperties.LANGUAGE_SPECIFIC_PARAMETERS_MAN_DAYS_KEY) .name("Development cost") .description("If left blank, the generic value defined in this section will be used.") .type(PropertyType.FLOAT) .build()) .build());
public static Builder build(String key) { return new Builder(key); }
public static Builder build(String key) { return new Builder(key); }
static List<PropertyFieldDefinition> create(PropertyField[] fields) { List<PropertyFieldDefinition> definitions = new ArrayList<>(); for (PropertyField field : fields) { definitions.add(PropertyFieldDefinition.build(field.key()) .name(field.name()) .description(field.description()) .indicativeSize(field.indicativeSize()) .type(field.type()) .options(field.options()) .build()); } return definitions; }
static List<PropertyFieldDefinition> create(PropertyField[] fields) { List<PropertyFieldDefinition> definitions = newArrayList(); for (PropertyField field : fields) { definitions.add(PropertyFieldDefinition.build(field.key()) .name(field.name()) .description(field.description()) .indicativeSize(field.indicativeSize()) .type(field.type()) .options(field.options()) .build() ); } return definitions; }
.fields( PropertyFieldDefinition.build(RULE_KEY) .name(PROPERTY_RULE_KEY_PATTERN) .description("Pattern to match rules which should be ignored.") .type(PropertyType.STRING) .indicativeSize(LARGE_SIZE) .build(), PropertyFieldDefinition.build(RESOURCE_KEY) .name(PROPERTY_FILE_PATH_PATTERN) .description("Pattern to match files which should be ignored.") .type(PropertyType.STRING) .indicativeSize(LARGE_SIZE) .build() .fields( PropertyFieldDefinition.build(BEGIN_BLOCK_REGEXP) .name("Regular Expression for Start of Block") .description("If this regular expression is found in a file, then following lines are ignored until end of block.") .type(PropertyType.STRING) .indicativeSize(LARGE_SIZE) .build(), PropertyFieldDefinition.build(END_BLOCK_REGEXP) .name("Regular Expression for End of Block") .description("If specified, this regular expression is used to determine the end of code blocks to ignore. If not, then block ends at the end of file.") .type(PropertyType.STRING) .indicativeSize(LARGE_SIZE) .build() .fields(
.fields( PropertyFieldDefinition.build(CoreProperties.LANGUAGE_SPECIFIC_PARAMETERS_LANGUAGE_KEY) .name("Language Key") .description("Ex: java, cs, cpp...") .type(PropertyType.STRING) .build(), PropertyFieldDefinition.build(CoreProperties.LANGUAGE_SPECIFIC_PARAMETERS_MAN_DAYS_KEY) .name("Development cost") .description("If left blank, the generic value defined in this section will be used.") .type(PropertyType.FLOAT) .build()) .build());
.fields( PropertyFieldDefinition.build("text") .name("Text") .description("Text field description") .type(PropertyType.TEXT) .build(), PropertyFieldDefinition.build("list") .name("List") .description("List field description") .type(PropertyType.SINGLE_SELECT_LIST) .options("value1", "value2") .build()) .build()));
@Test public void fail_when_empty_values_on_one_property_set() { definitions.addComponent(PropertyDefinition .builder("my.key") .name("foo") .description("desc") .category("cat") .subCategory("subCat") .type(PropertyType.PROPERTY_SET) .defaultValue("default") .fields(newArrayList( PropertyFieldDefinition.build("firstField") .name("First Field") .type(PropertyType.STRING) .build(), PropertyFieldDefinition.build("secondField") .name("Second Field") .type(PropertyType.STRING) .build())) .build()); expectedException.expect(BadRequestException.class); expectedException.expectMessage("A non empty value must be provided"); callForGlobalPropertySet("my.key", newArrayList( GSON.toJson(ImmutableMap.of("firstField", "firstValue", "secondField", "secondValue")), GSON.toJson(ImmutableMap.of("firstField", "", "secondField", "")), GSON.toJson(ImmutableMap.of("firstField", "yetFirstValue", "secondField", "yetSecondValue")))); }
@Test public void test_example_json_response() { logIn(); definitions.addComponent(PropertyDefinition .builder("sonar.test.jira") .defaultValue("abc") .build()); definitions.addComponent(PropertyDefinition .builder("sonar.autogenerated") .multiValues(true) .build()); propertyDb.insertProperties(newGlobalPropertyDto().setKey("sonar.autogenerated").setValue("val1,val2,val3")); definitions.addComponent(PropertyDefinition .builder("sonar.demo") .type(PropertyType.PROPERTY_SET) .fields(PropertyFieldDefinition.build("text").name("Text").build(), PropertyFieldDefinition.build("boolean").name("Boolean").build()) .build()); propertyDb.insertPropertySet("sonar.demo", null, ImmutableMap.of("text", "foo", "boolean", "true"), ImmutableMap.of("text", "bar", "boolean", "false")); String result = newTester().newRequest() .setParam("keys", "sonar.test.jira,sonar.autogenerated,sonar.demo") .setMediaType(JSON) .execute() .getInput(); JsonAssert.assertJson(newTester().getDef().responseExampleAsString()).isSimilarTo(result); }
@Test public void test_example_json_response() { logIn(); definitions.addComponent(PropertyDefinition .builder("sonar.test.jira") .defaultValue("abc") .build()); definitions.addComponent(PropertyDefinition .builder("sonar.autogenerated") .multiValues(true) .build()); propertyDb.insertProperties(newGlobalPropertyDto().setKey("sonar.autogenerated").setValue("val1,val2,val3")); definitions.addComponent(PropertyDefinition .builder("sonar.demo") .type(PropertyType.PROPERTY_SET) .fields(PropertyFieldDefinition.build("text").name("Text").build(), PropertyFieldDefinition.build("boolean").name("Boolean").build()) .build()); propertyDb.insertPropertySet("sonar.demo", null, ImmutableMap.of("text", "foo", "boolean", "true"), ImmutableMap.of("text", "bar", "boolean", "false")); String result = ws.newRequest().setMediaType(JSON).execute().getInput(); JsonAssert.assertJson(ws.getDef().responseExampleAsString()).isSimilarTo(result); }
@Test public void do_not_fail_when_only_one_empty_value_on_one_property_set() { definitions.addComponent(PropertyDefinition .builder("my.key") .name("foo") .description("desc") .category("cat") .subCategory("subCat") .type(PropertyType.PROPERTY_SET) .defaultValue("default") .fields(newArrayList( PropertyFieldDefinition.build("firstField") .name("First Field") .type(PropertyType.STRING) .build(), PropertyFieldDefinition.build("secondField") .name("Second Field") .type(PropertyType.STRING) .build())) .build()); callForGlobalPropertySet("my.key", newArrayList( GSON.toJson(ImmutableMap.of("firstField", "firstValue", "secondField", "secondValue")), GSON.toJson(ImmutableMap.of("firstField", "anotherFirstValue", "secondField", "")), GSON.toJson(ImmutableMap.of("firstField", "yetFirstValue", "secondField", "yetSecondValue")))); assertGlobalSetting("my.key", "1,2,3"); }
@Test public void return_no_parent_value() { logInAsProjectUser(); ComponentDto module = componentDb.insertComponent(newModuleDto(project)); ComponentDto subModule = componentDb.insertComponent(newModuleDto(module)); definitions.addComponents(asList( PropertyDefinition.builder("simple").onQualifiers(PROJECT, MODULE).build(), PropertyDefinition.builder("multi").multiValues(true).onQualifiers(PROJECT, MODULE).build(), PropertyDefinition.builder("set") .type(PropertyType.PROPERTY_SET) .onQualifiers(PROJECT, MODULE) .fields(asList( PropertyFieldDefinition.build("key").name("Key").build(), PropertyFieldDefinition.build("size").name("Size").build())) .build())); propertyDb.insertProperties( newComponentPropertyDto(module).setKey("simple").setValue("module"), newComponentPropertyDto(module).setKey("multi").setValue("module1,module2")); propertyDb.insertPropertySet("set", module, ImmutableMap.of("key", "keyM1", "size", "sizeM1")); assertParentValue(executeRequestForComponentProperties(subModule, "simple").getSettings(0), null); assertParentValues(executeRequestForComponentProperties(subModule, "multi").getSettings(0)); assertParentFieldValues(executeRequestForComponentProperties(subModule, "set").getSettings(0)); }