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 should_create_property_with_default_values() { PropertyDefinition def = PropertyDefinition.builder("hello") .name("Hello") .build(); assertThat(def.key()).isEqualTo("hello"); assertThat(def.name()).isEqualTo("Hello"); assertThat(def.defaultValue()).isEmpty(); assertThat(def.category()).isEmpty(); assertThat(def.options()).isEmpty(); assertThat(def.description()).isEmpty(); assertThat(def.type()).isEqualTo(PropertyType.STRING); assertThat(def.global()).isTrue(); assertThat(def.qualifiers()).isEmpty(); assertThat(def.multiValues()).isFalse(); assertThat(def.propertySetKey()).isEmpty(); assertThat(def.fields()).isEmpty(); }
private Setting(PropertyDefinition definition) { this.key = definition.key(); this.value = definition.defaultValue(); this.componentId = null; this.definition = definition; this.propertySets = Collections.emptyList(); this.isDefault = true; }
private PropertyDefinitions add(PropertyDefinition definition, String defaultCategory) { if (!definitions.containsKey(definition.key())) { definitions.put(definition.key(), definition); String category = StringUtils.defaultIfBlank(definition.category(), defaultCategory); categories.put(definition.key(), new Category(category)); String subcategory = StringUtils.defaultIfBlank(definition.subCategory(), category); subcategories.put(definition.key(), new SubCategory(subcategory)); if (!StringUtils.isEmpty(definition.deprecatedKey()) && !definition.deprecatedKey().equals(definition.key())) { deprecatedKeys.put(definition.deprecatedKey(), definition.key()); } } return this; }
public void start() { Loggers.get(RenameDeprecatedPropertyKeys.class).info("Rename deprecated property keys"); for (PropertyDefinition definition : definitions.getAll()) { if (!Strings.isNullOrEmpty(definition.deprecatedKey())) { dao.renamePropertyKey(definition.deprecatedKey(), definition.key()); } } } }
@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 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_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"); }
@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 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_auto_detect_password_type() { PropertyDefinition def = PropertyDefinition.builder("scm.password.secured").name("SCM password").build(); assertThat(def.key()).isEqualTo("scm.password.secured"); assertThat(def.type()).isEqualTo(PropertyType.PASSWORD); }
@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_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 should_override_toString() { PropertyDefinition def = PropertyDefinition.builder("hello").build(); assertThat(def.toString()).isEqualTo("hello"); }
@Test public void return_empty_when_property_def_exists_but_no_value() { logIn(); definitions.addComponent(PropertyDefinition .builder("foo") .build()); ValuesWsResponse result = executeRequestForGlobalProperties("foo"); assertThat(result.getSettingsList()).isEmpty(); }
private void assertPropertyDefinitions(ComponentContainer container, CoreExtension coreExtension, PropertyDefinition... definitions) { PropertyDefinitions propertyDefinitions = container.getComponentByType(PropertyDefinitions.class); if (definitions.length == 0) { assertThat(propertyDefinitions.getAll()).isEmpty(); } else { for (PropertyDefinition definition : definitions) { PropertyDefinition actual = propertyDefinitions.get(definition.key()); assertThat(actual.category()).isEqualTo(definition.category() == null ? coreExtension.getName() : definition.category()); } } }
@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 get_trims_key_before_looking_for_replacement() { Random random = new Random(); String key = RandomStringUtils.randomAlphanumeric(4); String deprecatedKey = RandomStringUtils.randomAlphanumeric(4); PropertyDefinitions underTest = new PropertyDefinitions(singletonList( PropertyDefinition.builder(key) .deprecatedKey(deprecatedKey) .build())); String untrimmedKey = blank(random) + deprecatedKey + blank(random); assertThat(underTest.get(untrimmedKey).key()) .describedAs("expecting key %s being returned for get(%s)", key, untrimmedKey) .isEqualTo(key); }
@Test public void shouldDeclareComponentProperties() { ComponentContainer container = new ComponentContainer(); container.addSingleton(ComponentWithProperty.class); PropertyDefinitions propertyDefinitions = container.getComponentByType(PropertyDefinitions.class); assertThat(propertyDefinitions.get("foo")).isNotNull(); assertThat(propertyDefinitions.get("foo").defaultValue()).isEqualTo("bar"); }
@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)); }