@Test public void header_has_empty_value_if_present_in_request_without_value() { when(source.getHeader("Accept")).thenReturn(""); assertThat(underTest.header("Accept")).hasValue(""); }
private void verifyBooleanTrue(String value) { underTest.put("foo", value); assertThat(underTest.getBoolean("foo")).hasValue(true); }
public PropertyDbTester verifyInternal(String key, @Nullable String expectedValue) { Optional<String> value = dbClient.internalPropertiesDao().selectByKey(dbSession, key); if (expectedValue == null) { assertThat(value).isEmpty(); } else { assertThat(value).hasValue(expectedValue); } return this; }
@Test public void member_can_be_referenced_multiple_times() { underTest.setTimedOut(member); underTest.setAnswer(member, "foo"); IOException exception = new IOException(); underTest.setFailed(member, exception); assertThat(underTest.hasTimedOut(member)).isTrue(); assertThat(underTest.getAnswer(member)).hasValue("foo"); assertThat(underTest.getFailed(member)).hasValue(exception); }
/** * SONAR-8216 System info page fails when a setting is defined both in sonar.properties and in DB */ @Test public void getProperties_does_not_fail_on_duplicated_key() { insertPropertyIntoDb("foo", "from_db"); underTest = create(ImmutableMap.of("foo", "from_system")); assertThat(underTest.get("foo")).hasValue("from_system"); assertThat(underTest.getProperties().get("foo")).isEqualTo("from_system"); }
@Test public void can_not_remove_system_property_if_no_cache() { underTest = create(ImmutableMap.of("foo", "bar")); underTest.remove("foo"); assertThat(underTest.get("foo")).hasValue("bar"); }
private void test(@Nullable QualityGateEvaluator.Measure measure, Condition.Operator operator, String errorThreshold, EvaluatedCondition.EvaluationStatus expectedStatus, @Nullable String expectedValue) { Condition condition = new Condition("foo", operator, errorThreshold); EvaluatedCondition result = ConditionEvaluator.evaluate(condition, new FakeMeasures(measure)); assertThat(result.getStatus()).isEqualTo(expectedStatus); if (expectedValue == null) { assertThat(result.getValue()).isNotPresent(); } else { assertThat(result.getValue()).hasValue(expectedValue); } }
@Test public void overwritten_system_settings_have_precedence_over_system_and_databse() { underTest = create(ImmutableMap.of("foo", "from system")); underTest.setSystemProperty("foo", "donut"); assertThat(underTest.get("foo")).hasValue("donut"); }
@Test public void test_setAnswer() { underTest.setAnswer(member, "foo"); assertThat(underTest.getAnswer(member)).hasValue("foo"); assertThat(underTest.hasTimedOut(member)).isFalse(); assertThat(underTest.getFailed(member)).isEmpty(); }
@Test public void password_cant_be_empty_string() { Credentials underTest = new Credentials("foo", ""); assertThat(underTest.getPassword()).isEmpty(); underTest = new Credentials("foo", null); assertThat(underTest.getPassword()).isEmpty(); underTest = new Credentials("foo", " "); assertThat(underTest.getPassword()).hasValue(" "); underTest = new Credentials("foo", "bar"); assertThat(underTest.getPassword()).hasValue("bar"); }
@Test public void return_global_settings() { settings.setProperty("key", "value"); Configuration config = underTest.newProjectConfiguration(PROJECT_KEY, new DefaultBranchImpl()); assertThat(config.get("key")).hasValue("value"); }
@Test public void load_system_properties() { underTest = create(ImmutableMap.of("foo", "1", "bar", "2")); assertThat(underTest.get("foo")).hasValue("1"); assertThat(underTest.get("missing")).isNotPresent(); assertThat(underTest.getProperties()).containsOnly(entry("foo", "1"), entry("bar", "2")); }
@Test public void add_property_to_cache() { underTest = create(Collections.emptyMap()); underTest.load(); underTest.set("foo", "bar"); assertThat(underTest.get("foo")).hasValue("bar"); underTest.unload(); // no more cache assertThat(underTest.get("foo")).isNotPresent(); }
@Test public void project_settings_are_cached_to_avoid_db_access() { ComponentDto project = db.components().insertPrivateProject(); insertProjectProperty(project, "key", "value"); analysisMetadataHolder.setProject(Project.from(project)); Configuration config = underTest.getConfiguration(); assertThat(config.get("key")).hasValue("value"); db.executeUpdateSql("delete from properties"); db.commit(); assertThat(config.get("key")).hasValue("value"); }
@Test public void getDefaultValues() { Configuration config = new DefaultConfiguration(new PropertyDefinitions(Arrays.asList( PropertyDefinition.builder("single").multiValues(false).defaultValue("default").build(), PropertyDefinition.builder("multiA").multiValues(true).defaultValue("foo,bar").build())), new Encryption(null), ImmutableMap.of()) { }; assertThat(config.get("multiA")).hasValue("foo,bar"); assertThat(config.getStringArray("multiA")).containsExactly("foo", "bar"); assertThat(config.get("single")).hasValue("default"); assertThat(config.getStringArray("single")).containsExactly("default"); }
@Test public void get_project_settings_from_db() { ComponentDto project = db.components().insertPrivateProject(); analysisMetadataHolder.setProject(Project.from(project)); insertProjectProperty(project, "key", "value"); Configuration config = underTest.getConfiguration(); assertThat(config.get("key")).hasValue("value"); }
@Test public void legacy_branch() { ComponentDto project = db.components().insertMainBranch(); db.properties().insertProperties(newComponentPropertyDto(project).setKey("sonar.leak.period").setValue("1")); Branch branch = createBranch("legacy", true); when(branch.isLegacyFeature()).thenReturn(true); Configuration config = underTest.newProjectConfiguration(project.getKey(), createBranch(branch.getName(), true)); assertThat(config.get("sonar.leak.period")).hasValue("1"); }
@Test public void branch_settings_contains_project_settings() { ComponentDto project = db.components().insertMainBranch(); db.properties().insertProperties(newComponentPropertyDto(project).setKey("key").setValue("value")); ComponentDto branch = db.components().insertProjectBranch(project); db.properties().insertProperties(newComponentPropertyDto(branch).setKey("sonar.leak.period").setValue("1")); Configuration config = underTest.newProjectConfiguration(project.getKey(), createBranch(branch.getBranch(), false)); assertThat(config.get("key")).hasValue("value"); assertThat(config.get("sonar.leak.period")).hasValue("1"); }
@Test public void project_settings_override_global_settings() { settings.setProperty("key", "value"); ComponentDto project = db.components().insertPrivateProject(); db.properties().insertProperties(newComponentPropertyDto(project).setKey("key").setValue("value2")); Configuration projectConfig = underTest.newProjectConfiguration(project.getDbKey(), new DefaultBranchImpl()); assertThat(projectConfig.get("key")).hasValue("value2"); }
@Test public void branch_settings_override_project_settings() { ComponentDto project = db.components().insertMainBranch(); db.properties().insertProperties(newComponentPropertyDto(project).setKey("sonar.leak.period").setValue("1")); ComponentDto branch = db.components().insertProjectBranch(project); db.properties().insertProperties(newComponentPropertyDto(branch).setKey("sonar.leak.period").setValue("2")); Configuration config = underTest.newProjectConfiguration(project.getKey(), createBranch(branch.getBranch(), false)); assertThat(config.get("sonar.leak.period")).hasValue("2"); }