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 return_default_category() { logIn(); propertyDefinitions.addComponent(PropertyDefinition.builder("foo").build(), "default"); propertyDefinitions.addComponent(PropertyDefinition.builder("foo").category("").build(), "default"); ListDefinitionsWsResponse result = executeRequest(); assertThat(result.getDefinitionsList()).hasSize(1); assertThat(result.getDefinitions(0).getCategory()).isEqualTo("default"); assertThat(result.getDefinitions(0).getSubCategory()).isEqualTo("default"); }
public static List<PropertyDefinition> properties() { return Collections.singletonList( PropertyDefinition.builder(REPORT_PATHS_PROPERTY_KEY) .name("Issues report paths") .description("List of comma-separated paths (absolute or relative) containing report with issues created by external rule engines.") .category(CoreProperties.CATEGORY_EXTERNAL_ISSUES) .onQualifiers(Qualifiers.PROJECT) .build()); }
@Test public void fail_when_view_property_when_on_projects_only() { definitions.addComponent(PropertyDefinition .builder("my.key") .name("foo") .description("desc") .category("cat") .subCategory("subCat") .type(PropertyType.STRING) .defaultValue("default") .onQualifiers(Qualifiers.PROJECT) .build()); ComponentDto view = db.components().insertComponent(newView(db.getDefaultOrganization(), "view-uuid")); i18n.put("qualifier." + Qualifiers.VIEW, "View"); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Setting 'my.key' cannot be set on a View"); logInAsProjectAdministrator(view); callForProjectSettingByKey("my.key", "My Value", view.getDbKey()); }
@Test public void fail_when_data_and_login_type_with_invalid_logIn() { definitions.addComponent(PropertyDefinition .builder("my.key") .name("foo") .description("desc") .category("cat") .subCategory("subCat") .type(PropertyType.USER_LOGIN) .defaultValue("default") .multiValues(true) .build()); db.users().insertUser(newUserDto().setLogin("login.1")); db.users().insertUser(newUserDto().setLogin("login.2").setActive(false)); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Error when validating login setting with key 'my.key' and values [login.1, login.2]. A value is not a valid login."); callForMultiValueGlobalSetting("my.key", newArrayList("login.1", "login.2")); }
@Test public void should_group_by_category() { PropertyDefinitions def = new PropertyDefinitions( PropertyDefinition.builder("global1").name("Global1").category("catGlobal1").build(), PropertyDefinition.builder("global2").name("Global2").category("catGlobal1").build(), PropertyDefinition.builder("global3").name("Global3").category("catGlobal2").build(), PropertyDefinition.builder("project").name("Project").category("catProject").onlyOnQualifiers(Qualifiers.PROJECT).build(), PropertyDefinition.builder("module").name("Module").category("catModule").onlyOnQualifiers(Qualifiers.MODULE).build(), PropertyDefinition.builder("view").name("View").category("catView").onlyOnQualifiers(Qualifiers.VIEW).build(), PropertyDefinition.builder("app").name("Application").category("catApp").onlyOnQualifiers(Qualifiers.APP).build()); assertThat(def.propertiesByCategory(null).keySet()).contains(new Category("catGlobal1"), new Category("catGlobal2")); assertThat(def.propertiesByCategory(Qualifiers.PROJECT).keySet()).containsOnly(new Category("catProject")); assertThat(def.propertiesByCategory(Qualifiers.MODULE).keySet()).containsOnly(new Category("catModule")); assertThat(def.propertiesByCategory(Qualifiers.VIEW).keySet()).containsOnly(new Category("catView")); assertThat(def.propertiesByCategory(Qualifiers.APP).keySet()).containsOnly(new Category("catApp")); assertThat(def.propertiesByCategory("Unkown").keySet()).isEmpty(); }
@Test public void persist_multi_value_with_type_logIn() { definitions.addComponent(PropertyDefinition .builder("my.key") .name("foo") .description("desc") .category("cat") .subCategory("subCat") .type(PropertyType.USER_LOGIN) .defaultValue("default") .multiValues(true) .build()); db.users().insertUser(newUserDto().setLogin("login.1")); db.users().insertUser(newUserDto().setLogin("login.2")); callForMultiValueGlobalSetting("my.key", newArrayList("login.1", "login.2")); assertGlobalSetting("my.key", "login.1,login.2"); }
@Test public void fail_when_global_with_property_only_on_projects() { definitions.addComponent(PropertyDefinition .builder("my.key") .name("foo") .description("desc") .category("cat") .subCategory("subCat") .type(PropertyType.INTEGER) .defaultValue("default") .onlyOnQualifiers(Qualifiers.PROJECT) .build()); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Setting 'my.key' cannot be global"); callForGlobalSetting("my.key", "42"); }
@Test public void fail_when_data_and_type_do_not_match() { definitions.addComponent(PropertyDefinition .builder("my.key") .name("foo") .description("desc") .category("cat") .subCategory("subCat") .type(PropertyType.INTEGER) .defaultValue("default") .build()); i18n.put("property.error.notInteger", "Not an integer error message"); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Not an integer error message"); callForGlobalSetting("my.key", "My Value"); }
@Test public void persist_global_property_with_deprecated_key() { definitions.addComponent(PropertyDefinition .builder("my.key") .deprecatedKey("my.old.key") .name("foo") .description("desc") .category("cat") .subCategory("subCat") .type(PropertyType.STRING) .defaultValue("default") .build()); callForGlobalSetting("my.old.key", "My Value"); assertGlobalSetting("my.key", "My Value"); }
@Test public void fail_when_data_and_type_do_not_match_with_unknown_error_key() { definitions.addComponent(PropertyDefinition .builder("my.key") .name("foo") .description("desc") .category("cat") .subCategory("subCat") .type(PropertyType.INTEGER) .defaultValue("default") .build()); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Error when validating setting with key 'my.key' and value [My Value, My Other Value]"); callForMultiValueGlobalSetting("my.key", newArrayList("My Value", "My Other Value")); }
@Test public void fail_when_single_definition_and_multi_value_provided() { definitions.addComponent(PropertyDefinition .builder("my.key") .name("foo") .description("desc") .category("cat") .type(PropertyType.STRING) .multiValues(false) .build()); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Parameter 'value' must be used for single value setting. Parameter 'values' must be used for multi value setting."); callForMultiValueGlobalSetting("my.key", newArrayList("My Value")); }
@Test public void fail_when_multi_definition_and_single_value_provided() { definitions.addComponent(PropertyDefinition .builder("my.key") .name("foo") .description("desc") .category("cat") .type(PropertyType.STRING) .multiValues(true) .build()); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Parameter 'value' must be used for single value setting. Parameter 'values' must be used for multi value setting."); callForGlobalSetting("my.key", "My Value"); }
@Test @UseDataProvider("allMethodsToAddExtension") public void install_adds_PropertyDefinition_with_extension_name_as_default_category(BiConsumer<CoreExtension.Context, Collection<Object>> extensionAdder) { PropertyDefinition propertyDefinitionNoCategory = PropertyDefinition.builder("fooKey").build(); PropertyDefinition propertyDefinitionWithCategory = PropertyDefinition.builder("barKey").category("donut").build(); List<Object> extensions = ImmutableList.of(propertyDefinitionNoCategory, propertyDefinitionWithCategory); CoreExtension coreExtension = newCoreExtension(context -> extensionAdder.accept(context, extensions)); when(coreExtensionRepository.loadedCoreExtensions()).thenReturn(Stream.of(coreExtension)); ComponentContainer container = new ComponentContainer(); underTest.install(container, noExtensionFilter(), noAdditionalSideFilter()); assertAddedExtensions(container, 0); assertPropertyDefinitions(container, coreExtension, propertyDefinitionNoCategory, propertyDefinitionWithCategory); }
@Test public void should_group_by_subcategory() { PropertyDefinitions def = new PropertyDefinitions( PropertyDefinition.builder("global1").name("Global1").category("catGlobal1").subCategory("sub1").build(), PropertyDefinition.builder("global2").name("Global2").category("catGlobal1").subCategory("sub2").build(), PropertyDefinition.builder("global3").name("Global3").category("catGlobal1").build(), PropertyDefinition.builder("global4").name("Global4").category("catGlobal2").build()); assertThat(def.propertiesByCategory(null).get(new Category("catGlobal1")).keySet()).containsOnly(new SubCategory("catGlobal1"), new SubCategory("sub1"), new SubCategory("sub2")); assertThat(def.propertiesByCategory(null).get(new Category("catGlobal2")).keySet()).containsOnly(new SubCategory("catGlobal2")); }
@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 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(); }
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 definitions_are_ordered_by_category_then_index_then_name_case_insensitive() { logIn(); propertyDefinitions.addComponent(PropertyDefinition.builder("sonar.prop.11").category("cat-1").index(1).name("prop 1").build()); propertyDefinitions.addComponent(PropertyDefinition.builder("sonar.prop.12").category("cat-1").index(2).name("prop 2").build()); propertyDefinitions.addComponent(PropertyDefinition.builder("sonar.prop.13").category("CAT-1").index(1).name("prop 3").build()); propertyDefinitions.addComponent(PropertyDefinition.builder("sonar.prop.41").category("cat-0").index(25).name("prop 1").build()); ListDefinitionsWsResponse result = executeRequest(); assertThat(result.getDefinitionsList()).extracting(Definition::getKey) .containsExactly("sonar.prop.41", "sonar.prop.11", "sonar.prop.13", "sonar.prop.12"); }
public static ImmutableList<PropertyDefinition> properties() { return ImmutableList.of( PropertyDefinition.builder(REPORT_PATHS_PROPERTY_KEY) .name("Coverage report paths") .description("List of comma-separated paths (absolute or relative) containing coverage report.") .category(CATEGORY_CODE_COVERAGE) .onQualifiers(Qualifiers.PROJECT) .multiValues(true) .deprecatedKey(OLD_COVERAGE_REPORT_PATHS_PROPERTY_KEY) .build()); }