public static ImmutableList<PropertyDefinition> properties() { return ImmutableList.of( PropertyDefinition.builder(REPORT_PATHS_PROPERTY_KEY) .name("Unit tests results report paths") .description("List of comma-separated paths (absolute or relative) containing unit tests results report.") .category(CATEGORY_CODE_COVERAGE) .onQualifiers(Qualifiers.PROJECT) .multiValues(true) .deprecatedKey(OLD_UNIT_TEST_REPORT_PATHS_PROPERTY_KEY) .build()); }
@Test public void return_settings_definitions() { logIn(); propertyDefinitions.addComponent(PropertyDefinition .builder("foo") .name("Foo") .description("desc") .category("cat") .subCategory("subCat") .type(PropertyType.TEXT) .defaultValue("default") .multiValues(true) .build()); ListDefinitionsWsResponse result = executeRequest(); assertThat(result.getDefinitionsList()).hasSize(1); Definition definition = result.getDefinitions(0); assertThat(definition.getKey()).isEqualTo("foo"); assertThat(definition.getName()).isEqualTo("Foo"); assertThat(definition.getDescription()).isEqualTo("desc"); assertThat(definition.getCategory()).isEqualTo("cat"); assertThat(definition.getSubCategory()).isEqualTo("subCat"); assertThat(definition.getType()).isEqualTo(TEXT); assertThat(definition.getDefaultValue()).isEqualTo("default"); assertThat(definition.getMultiValues()).isTrue(); }
@Test public void should_not_authorise_empty_key() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Key must be set"); PropertyDefinition.builder(null).build(); }
@Test public void does_not_returned_secured_and_license_settings_when_not_authenticated() { propertyDefinitions.addComponents(asList( PropertyDefinition.builder("foo").build(), PropertyDefinition.builder("secret.secured").build(), PropertyDefinition.builder("plugin.license.secured").type(PropertyType.LICENSE).build(), PropertyDefinition.builder("commercial.plugin").type(PropertyType.LICENSE).build())); ListDefinitionsWsResponse result = executeRequest(); assertThat(result.getDefinitionsList()).extracting(Definition::getKey).containsOnly("foo"); }
@Test public void should_validate_boolean() { PropertyDefinition def = PropertyDefinition.builder("foo").name("foo").type(PropertyType.BOOLEAN).build(); assertThat(def.validate(null).isValid()).isTrue(); assertThat(def.validate("").isValid()).isTrue(); assertThat(def.validate(" ").isValid()).isTrue(); assertThat(def.validate("true").isValid()).isTrue(); assertThat(def.validate("false").isValid()).isTrue(); assertThat(def.validate("foo").isValid()).isFalse(); assertThat(def.validate("foo").getErrorKey()).isEqualTo("notBoolean"); }
@Test public void return_project_settings_def_by_project_key() { logInAsProjectUser(); propertyDefinitions.addComponent(PropertyDefinition .builder("foo") .onQualifiers(PROJECT) .build()); ListDefinitionsWsResponse result = executeRequest(project.getDbKey()); assertThat(result.getDefinitionsList()).hasSize(1); }
@Test public void should_create_property() { PropertyDefinition def = PropertyDefinition.builder("hello") .name("Hello") .defaultValue("world") .category("categ") .options("de", "en") .description("desc") .type(PropertyType.FLOAT) .onlyOnQualifiers(Qualifiers.MODULE) .multiValues(true) .propertySetKey("set") .build(); assertThat(def.key()).isEqualTo("hello"); assertThat(def.name()).isEqualTo("Hello"); assertThat(def.defaultValue()).isEqualTo("world"); assertThat(def.category()).isEqualTo("categ"); assertThat(def.options()).containsOnly("de", "en"); assertThat(def.description()).isEqualTo("desc"); assertThat(def.type()).isEqualTo(PropertyType.FLOAT); assertThat(def.global()).isFalse(); assertThat(def.qualifiers()).containsOnly(Qualifiers.MODULE); assertThat(def.multiValues()).isTrue(); assertThat(def.propertySetKey()).isEqualTo("set"); assertThat(def.fields()).isEmpty(); }
@Test public void should_create_hidden_property() { PropertyDefinition def = PropertyDefinition.builder("hello") .name("Hello") .hidden() .build(); assertThat(def.key()).isEqualTo("hello"); assertThat(def.qualifiers()).isEmpty(); assertThat(def.global()).isFalse(); }
@Test public void PropertyDef() { PropertyDefinition def = PropertyDefinition.builder("views.license.secured").name("Views license").build(); assertThat(def.key()).isEqualTo("views.license.secured"); assertThat(def.type()).isEqualTo(PropertyType.LICENSE); }
@Test public void test_default_category() { PropertyDefinitions def = new PropertyDefinitions(); def.addComponent(PropertyDefinition.builder("inCateg").name("In Categ").category("categ").build(), "default"); def.addComponent(PropertyDefinition.builder("noCateg").name("No categ").build(), "default"); assertThat(def.getCategory("inCateg")).isEqualTo("categ"); assertThat(def.getCategory("noCateg")).isEqualTo("default"); }
@Test public void should_override_toString() { PropertyDefinition def = PropertyDefinition.builder("hello").build(); assertThat(def.toString()).isEqualTo("hello"); }
@Test public void test_categories() { PropertyDefinitions def = new PropertyDefinitions( PropertyDefinition.builder("inCateg").name("In Categ").category("categ").build(), PropertyDefinition.builder("noCateg").name("No categ").build()); assertThat(def.getCategory("inCateg")).isEqualTo("categ"); assertThat(def.getCategory("noCateg")).isEmpty(); }
@Test public void set_property_string_array_trims_key() { String key = randomAlphanumeric(3); Settings underTest = new MapSettings(new PropertyDefinitions(singletonList(PropertyDefinition.builder(key).multiValues(true).build()))); Random random = new Random(); String blankBefore = blank(random); String blankAfter = blank(random); underTest.setProperty(blankBefore + key + blankAfter, new String[] {"1", "2"}); assertThat(underTest.hasKey(key)).isTrue(); }
@Test public void return_license_type_in_property_set() { logIn(); propertyDefinitions.addComponent(PropertyDefinition .builder("foo") .type(PropertyType.PROPERTY_SET) .fields(PropertyFieldDefinition.build("license").name("License").type(PropertyType.LICENSE).build()) .build()); ListDefinitionsWsResponse result = executeRequest(); assertThat(result.getDefinitionsList()).hasSize(1); assertThat(result.getDefinitions(0).getFieldsList()).extracting(Settings.Field::getKey, Settings.Field::getType).containsOnly(tuple("license", LICENSE)); }
@Test public void should_validate_string() { PropertyDefinition def = PropertyDefinition.builder("foo").name("foo").type(PropertyType.STRING).build(); assertThat(def.validate(null).isValid()).isTrue(); assertThat(def.validate("").isValid()).isTrue(); assertThat(def.validate(" ").isValid()).isTrue(); assertThat(def.validate("foo").isValid()).isTrue(); }
@Test public void return_nothing_when_unknown_keys() { logIn(); definitions.addComponent(PropertyDefinition .builder("foo") .defaultValue("default") .build()); propertyDb.insertProperties(newGlobalPropertyDto().setKey("bar").setValue("")); ValuesWsResponse result = executeRequestForGlobalProperties("unknown"); assertThat(result.getSettingsList()).isEmpty(); }
public static List getExtensions() { ImmutableList.Builder<Object> extensions = ImmutableList.builder(); extensions.add( PropertyDefinition.builder(REPORT_PATHS_PROPERTY) .defaultValue(REPORT_PATHS_DEFAULT_VALUE) .category(JavaConstants.JAVA_CATEGORY) .subCategory("JaCoCo") .name("JaCoCo Reports") .multiValues(true) .description("Path to the JaCoCo report files containing coverage data by unit tests. The path may be absolute or relative to the project base directory.") .onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE) .build(), JaCoCoSensor.class); return extensions.build(); } }
@Test public void fail_when_user_has_not_project_browse_permission() { userSession.logIn("project-admin").addProjectPermission(CODEVIEWER, project); propertyDefinitions.addComponent(PropertyDefinition.builder("foo").build()); expectedException.expect(ForbiddenException.class); executeRequest(project.getDbKey()); }
static List<PropertyDefinition> all() { return singletonList( PropertyDefinition.builder(CoreProperties.CORE_FORCE_AUTHENTICATION_PROPERTY) .defaultValue(Boolean.toString(CoreProperties.CORE_FORCE_AUTHENTICATION_DEFAULT_VALUE)) .name("Force user authentication") .description( "Forcing user authentication prevents anonymous users from accessing the SonarQube UI, or project data via the Web API. " + "Some specific read-only Web APIs, including those required to prompt authentication, are still available anonymously.") .type(PropertyType.BOOLEAN) .category(CoreProperties.CATEGORY_SECURITY) .build()); } }
@Test public void should_not_authorize_defining_on_qualifiers_and_only_on_qualifiers() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Cannot define both onQualifiers and onlyOnQualifiers"); PropertyDefinition.builder("foo").name("foo").onQualifiers(Qualifiers.MODULE).onlyOnQualifiers(Qualifiers.PROJECT).build(); }