@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_user_properties_when_they_exist_in_db(@Nullable String oldValue, @Nullable String newValue) throws SQLException { int userId = 90; long id = insertProperty("global", oldValue, null, userId, DATE_1); when(system2.now()).thenReturn(DATE_4); underTest.saveProperty(new PropertyDto().setKey("global").setUserId(userId).setValue(newValue)); assertThatPropertiesRow(id) .doesNotExist(); PropertiesRowAssert propertiesRowAssert = assertThatPropertiesRow("global") .hasNoResourceId() .hasUserId(userId) .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); } }
@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"); }
assertThatPropertiesRow(id1) .doesNotExist(); assertThatPropertiesRow(id2) .doesNotExist(); assertThatPropertiesRow(id3) .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()
"clob_value_property", VALUE_SIZE_4001)); assertThatPropertiesRow("null_value_property") .hasNoResourceId() .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()
assertThatPropertiesRow(id1) .hasKey("global.one") .hasNoResourceId() .hasNoUserId() .hasTextValue("one"); assertThatPropertiesRow(id2) .hasKey("global.two") .hasNoResourceId() .hasNoUserId() .hasTextValue("two"); assertThatPropertiesRow(id3) .doesNotExist(); assertThatPropertiesRow(id4) .hasKey("commonslang.one") .hasResourceId(projectId2) .hasNoUserId() .hasTextValue("one"); assertThatPropertiesRow(id5) .hasKey("user.one") .hasNoResourceId() .hasUserId(100) .hasTextValue("one"); assertThatPropertiesRow(id6) .hasKey("user.two") .hasNoResourceId() .hasUserId(100) .hasTextValue("two"); assertThatPropertiesRow(id7) .hasKey("other.one")
assertThatPropertiesRow(id1) .hasKey("foo") .hasNoUserId() .hasTextValue("bar") .hasCreatedAt(DATE_1); assertThatPropertiesRow(id2) .hasKey("new_name") .hasNoResourceId() .hasTextValue("doc1") .hasCreatedAt(DATE_1); assertThatPropertiesRow(id3) .hasKey("new_name") .hasResourceId(15) .hasTextValue("doc2") .hasCreatedAt(DATE_1); assertThatPropertiesRow(id4) .hasKey("new_name") .hasResourceId(16) .hasTextValue("doc3") .hasCreatedAt(DATE_1); assertThatPropertiesRow(id5) .hasKey("new_name") .hasNoResourceId() .hasTextValue("doc4")
underTest.saveProperty(new PropertyDto().setKey("global.clob").setValue(VALUE_SIZE_4001)); assertThatPropertiesRow("global.null") .hasNoResourceId() .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()
underTest.saveProperty(new PropertyDto().setKey("component.clob").setResourceId(resourceId).setValue(VALUE_SIZE_4001)); assertThatPropertiesRow("component.null") .hasResourceId(resourceId) .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()
underTest.saveProperty(new PropertyDto().setKey("user.clob").setUserId(userId).setValue(VALUE_SIZE_4001)); assertThatPropertiesRow("user.null") .hasNoResourceId() .hasUserId(userId) .isEmpty() .hasCreatedAt(DATE_1); assertThatPropertiesRow("user.empty") .hasNoResourceId() .hasUserId(userId) .isEmpty() .hasCreatedAt(DATE_2); assertThatPropertiesRow("user.text") .hasNoResourceId() .hasUserId(userId) .hasTextValue("some text") .hasCreatedAt(DATE_3); assertThatPropertiesRow("user.4000") .hasNoResourceId() .hasUserId(userId) .hasTextValue(VALUE_SIZE_4000) .hasCreatedAt(DATE_4); assertThatPropertiesRow("user.clob") .hasNoResourceId() .hasUserId(userId)