@Test public void saveGlobalProperties_delete_and_insert_new_value_when_property_exists_in_db() throws SQLException { long id = insertProperty("to_be_updated", "old_value", null, null, DATE_1); when(system2.now()).thenReturn(DATE_3); underTest.saveGlobalProperties(ImmutableMap.of("to_be_updated", "new value")); assertThatPropertiesRow(id) .doesNotExist(); assertThatPropertiesRow("to_be_updated") .hasNoResourceId() .hasNoUserId() .hasTextValue("new value") .hasCreatedAt(DATE_3); }
@Test @UseDataProvider("valueUpdatesDataProvider") public void saveProperty_deletes_then_inserts_global_properties_when_they_exist_in_db(@Nullable String oldValue, @Nullable String newValue) throws SQLException { long id = insertProperty("global", oldValue, null, null, DATE_1); when(system2.now()).thenReturn(DATE_4); underTest.saveProperty(new PropertyDto().setKey("global").setValue(newValue)); assertThatPropertiesRow(id) .doesNotExist(); PropertiesRowAssert propertiesRowAssert = assertThatPropertiesRow("global") .hasNoResourceId() .hasNoUserId() .hasCreatedAt(DATE_4); if (newValue == null || newValue.isEmpty()) { propertiesRowAssert.isEmpty(); } else if (newValue.length() > 4000) { propertiesRowAssert.hasClobValue(newValue); } else { propertiesRowAssert.hasTextValue(newValue); } }
@Test @UseDataProvider("valueUpdatesDataProvider") public void saveProperty_deletes_then_inserts_component_properties_when_they_exist_in_db(@Nullable String oldValue, @Nullable String newValue) throws SQLException { long resourceId = 999L; long id = insertProperty("global", oldValue, resourceId, null, DATE_1); when(system2.now()).thenReturn(DATE_4); underTest.saveProperty(new PropertyDto().setKey("global").setResourceId(resourceId).setValue(newValue)); assertThatPropertiesRow(id) .doesNotExist(); PropertiesRowAssert propertiesRowAssert = assertThatPropertiesRow("global") .hasResourceId(resourceId) .hasNoUserId() .hasCreatedAt(DATE_4); if (newValue == null || newValue.isEmpty()) { propertiesRowAssert.isEmpty(); } else if (newValue.length() > 4000) { propertiesRowAssert.hasClobValue(newValue); } else { propertiesRowAssert.hasTextValue(newValue); } }
.hasNoUserId() .isEmpty() .hasCreatedAt(DATE_1); assertThatPropertiesRow("empty_value_property") .hasNoResourceId() .hasNoUserId() .isEmpty() .hasCreatedAt(DATE_2); assertThatPropertiesRow("text_value_property") .hasNoResourceId() .hasNoUserId() .hasTextValue("dfdsfsd") .hasCreatedAt(DATE_3); assertThatPropertiesRow("4000_char_value_property") .hasNoResourceId() .hasNoUserId() .hasTextValue(VALUE_SIZE_4000) .hasCreatedAt(DATE_4); assertThatPropertiesRow("clob_value_property") .hasNoResourceId() .hasNoUserId() .hasClobValue(VALUE_SIZE_4001) .hasCreatedAt(DATE_5);
.hasKey("sonar.profile.java") .hasNoResourceId() .hasNoUserId() .hasTextValue("Sonar Way"); assertThatPropertiesRow(id4) .hasKey("sonar.profile.js") .hasResourceId(1) .hasNoUserId() .hasTextValue("Sonar Way"); assertThatPropertiesRow(id5) .hasKey("sonar.profile.js") .hasResourceId(2) .hasNoUserId() .hasTextValue("Sonar Way"); assertThatPropertiesRow(id6) .hasKey("sonar.profile.js") .hasNoResourceId() .hasNoUserId() .hasTextValue("Sonar Way");
.hasNoUserId() .isEmpty() .hasCreatedAt(DATE_1); assertThatPropertiesRow("global.empty") .hasNoResourceId() .hasNoUserId() .isEmpty() .hasCreatedAt(DATE_2); assertThatPropertiesRow("global.text") .hasNoResourceId() .hasNoUserId() .hasTextValue("some text") .hasCreatedAt(DATE_3); assertThatPropertiesRow("global.4000") .hasNoResourceId() .hasNoUserId() .hasTextValue(VALUE_SIZE_4000) .hasCreatedAt(DATE_4); assertThatPropertiesRow("global.clob") .hasNoResourceId() .hasNoUserId() .hasClobValue(VALUE_SIZE_4001) .hasCreatedAt(DATE_5);
.hasNoUserId() .isEmpty() .hasCreatedAt(DATE_1); assertThatPropertiesRow("component.empty") .hasResourceId(resourceId) .hasNoUserId() .isEmpty() .hasCreatedAt(DATE_2); assertThatPropertiesRow("component.text") .hasResourceId(resourceId) .hasNoUserId() .hasTextValue("some text") .hasCreatedAt(DATE_3); assertThatPropertiesRow("component.4000") .hasResourceId(resourceId) .hasNoUserId() .hasTextValue(VALUE_SIZE_4000) .hasCreatedAt(DATE_4); assertThatPropertiesRow("component.clob") .hasResourceId(resourceId) .hasNoUserId() .hasClobValue(VALUE_SIZE_4001) .hasCreatedAt(DATE_5);
@Test public void deleteGlobalProperty() { // global long id1 = insertProperty("global.key", "new_global", null, null); long id2 = insertProperty("to_be_deleted", "xxx", null, null); // project - do not delete this project property that has the same key long id3 = insertProperty("to_be_deleted", "new_project", 10L, null); // user long id4 = insertProperty("user.key", "new_user", null, 100); underTest.deleteGlobalProperty("to_be_deleted"); assertThatPropertiesRow(id1) .hasKey("global.key") .hasNoUserId() .hasNoResourceId() .hasTextValue("new_global"); assertThatPropertiesRow(id2) .doesNotExist(); assertThatPropertiesRow("to_be_deleted", null, null) .doesNotExist(); assertThatPropertiesRow(id3) .hasKey("to_be_deleted") .hasResourceId(10) .hasNoUserId() .hasTextValue("new_project"); assertThatPropertiesRow(id4) .hasKey("user.key") .hasNoResourceId() .hasUserId(100) .hasTextValue("new_user"); }
.hasNoUserId() .hasNoResourceId() .hasTextValue("bar") .hasKey("new_name") .hasNoResourceId() .hasNoUserId() .hasTextValue("doc1") .hasCreatedAt(DATE_1); .hasKey("new_name") .hasResourceId(15) .hasNoUserId() .hasTextValue("doc2") .hasCreatedAt(DATE_1); .hasKey("new_name") .hasResourceId(16) .hasNoUserId() .hasTextValue("doc3") .hasCreatedAt(DATE_1);
.hasKey("global.one") .hasNoResourceId() .hasNoUserId() .hasTextValue("one"); assertThatPropertiesRow(id2) .hasKey("global.two") .hasNoResourceId() .hasNoUserId() .hasTextValue("two"); assertThatPropertiesRow(id3) .hasKey("commonslang.one") .hasResourceId(projectId2) .hasNoUserId() .hasTextValue("one"); assertThatPropertiesRow(id5) .hasKey("other.one") .hasResourceId(projectId3) .hasNoUserId() .hasTextValue("one");