@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); } }
.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);
@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); } }
.hasNoResourceId() .hasTextValue("bar") .hasCreatedAt(DATE_1); assertThatPropertiesRow(id2) .hasKey("new_name") .hasNoUserId() .hasTextValue("doc1") .hasCreatedAt(DATE_1); assertThatPropertiesRow(id3) .hasKey("new_name") .hasNoUserId() .hasTextValue("doc2") .hasCreatedAt(DATE_1); assertThatPropertiesRow(id4) .hasKey("new_name") .hasNoUserId() .hasTextValue("doc3") .hasCreatedAt(DATE_1); assertThatPropertiesRow(id5) .hasKey("new_name") .hasUserId(100) .hasTextValue("doc4") .hasCreatedAt(DATE_1); assertThatPropertiesRow(id6) .hasKey("new_name")
.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);
.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) .hasClobValue(VALUE_SIZE_4001) .hasCreatedAt(DATE_5);