public InternalPropertyAssert hasCreatedAt(long expected) { isNotNull(); if (!Objects.equals(actual.getCreatedAt(), expected)) { failWithMessage("Expected Internal property to have column CREATED_AT to be <%s> but was <%s>", expected, actual.getCreatedAt()); } return this; }
@Test public void save_persists_value_in_varchar_if_more_than_4000() { when(system2.now()).thenReturn(DATE_2); underTest.save(dbSession, A_KEY, VALUE_SIZE_4001); assertThatInternalProperty(A_KEY) .hasClobValue(VALUE_SIZE_4001) .hasCreatedAt(DATE_2); }
@Test public void save_persists_value_in_varchar_if_less_than_4000() { when(system2.now()).thenReturn(DATE_2); underTest.save(dbSession, A_KEY, VALUE_SMALL); assertThatInternalProperty(A_KEY) .hasTextValue(VALUE_SMALL) .hasCreatedAt(DATE_2); }
private InternalPropertyAssert assertThatInternalProperty(String key) { return new InternalPropertyAssert(dbTester, dbSession, key); }
private InternalPropertyAssert(DbTester dbTester, DbSession dbSession, String internalPropertyKey) { super(asInternalProperty(dbTester, dbSession, internalPropertyKey), InternalPropertyAssert.class); }
public void doesNotExist() { isNull(); }
public InternalPropertyAssert hasClobValue(String expected) { isNotNull(); if (!Objects.equals(actual.getClobValue(), expected)) { failWithMessage("Expected Internal property to have column CLOB_VALUE to be <%s> but was <%s>", true, actual.getClobValue()); } if (actual.getTextValue() != null) { failWithMessage("Expected Internal property to have column TEXT_VALUE to be null but was <%s>", actual.getTextValue()); } if (!Objects.equals(actual.isEmpty(), FALSE)) { failWithMessage("Expected Internal property to have column IS_EMPTY to be <%s> but was <%s>", false, actual.isEmpty()); } return this; }
public InternalPropertyAssert hasTextValue(String expected) { isNotNull(); if (!Objects.equals(actual.getTextValue(), expected)) { failWithMessage("Expected Internal property to have column TEXT_VALUE to be <%s> but was <%s>", true, actual.getTextValue()); } if (actual.getClobValue() != null) { failWithMessage("Expected Internal property to have column CLOB_VALUE to be null but was <%s>", actual.getClobValue()); } if (!Objects.equals(actual.isEmpty(), FALSE)) { failWithMessage("Expected Internal property to have column IS_EMPTY to be <%s> but was <%s>", false, actual.isEmpty()); } return this; }
public InternalPropertyAssert isEmpty() { isNotNull(); if (!Objects.equals(actual.isEmpty(), TRUE)) { failWithMessage("Expected Internal property to have column IS_EMPTY to be <%s> but was <%s>", true, actual.isEmpty()); } if (actual.getTextValue() != null) { failWithMessage("Expected Internal property to have column TEXT_VALUE to be null but was <%s>", actual.getTextValue()); } if (actual.getClobValue() != null) { failWithMessage("Expected Internal property to have column CLOB_VALUE to be null but was <%s>", actual.getClobValue()); } return this; }
@Test public void save_persists_new_value_in_varchar_if_4000_when_old_one_was_in_varchar() { when(system2.now()).thenReturn(DATE_1, DATE_2); underTest.save(dbSession, A_KEY, VALUE_SMALL); assertThatInternalProperty(A_KEY) .hasTextValue(VALUE_SMALL) .hasCreatedAt(DATE_1); underTest.save(dbSession, A_KEY, VALUE_SIZE_4000); assertThatInternalProperty(A_KEY) .hasTextValue(VALUE_SIZE_4000) .hasCreatedAt(DATE_2); }
@Test public void save_persists_value_in_varchar_if_4000() { when(system2.now()).thenReturn(DATE_1); underTest.save(dbSession, A_KEY, VALUE_SIZE_4000); assertThatInternalProperty(A_KEY) .hasTextValue(VALUE_SIZE_4000) .hasCreatedAt(DATE_1); }
private static InternalProperty asInternalProperty(DbTester dbTester, DbSession dbSession, String internalPropertyKey) { Map<String, Object> row = dbTester.selectFirst( dbSession, "select" + " is_empty as \"isEmpty\", text_value as \"textValue\", clob_value as \"clobValue\", created_at as \"createdAt\"" + " from internal_properties" + " where kee='" + internalPropertyKey + "'"); return new InternalProperty( isEmpty(row), (String) row.get("textValue"), (String) row.get("clobValue"), (Long) row.get("createdAt")); }
@Test public void save_persists_new_value_in_clob_if_more_than_4000_when_old_one_was_in_varchar() { when(system2.now()).thenReturn(DATE_1, DATE_2); underTest.save(dbSession, A_KEY, VALUE_SMALL); assertThatInternalProperty(A_KEY) .hasTextValue(VALUE_SMALL) .hasCreatedAt(DATE_1); underTest.save(dbSession, A_KEY, VALUE_SIZE_4001); assertThatInternalProperty(A_KEY) .hasClobValue(VALUE_SIZE_4001) .hasCreatedAt(DATE_2); }
@Test public void save_persists_new_value_in_clob_if_more_than_4000_when_old_one_was_in_clob() { when(system2.now()).thenReturn(DATE_1, DATE_2); String oldValue = VALUE_SIZE_4001 + "blabla"; underTest.save(dbSession, A_KEY, oldValue); assertThatInternalProperty(A_KEY) .hasClobValue(oldValue) .hasCreatedAt(DATE_1); underTest.save(dbSession, A_KEY, VALUE_SIZE_4001); assertThatInternalProperty(A_KEY) .hasClobValue(VALUE_SIZE_4001) .hasCreatedAt(DATE_2); }
@Test public void saveAsEmpty_persist_property_without_textvalue_nor_clob_value() { when(system2.now()).thenReturn(DATE_2); underTest.saveAsEmpty(dbSession, A_KEY); assertThatInternalProperty(A_KEY) .isEmpty() .hasCreatedAt(DATE_2); }
@Test public void saveAsEmpty_persist_property_without_textvalue_nor_clob_value_when_old_value_was_in_varchar() { when(system2.now()).thenReturn(DATE_1, DATE_2); underTest.save(dbSession, A_KEY, VALUE_SMALL); assertThatInternalProperty(A_KEY) .hasTextValue(VALUE_SMALL) .hasCreatedAt(DATE_1); underTest.saveAsEmpty(dbSession, A_KEY); assertThatInternalProperty(A_KEY) .isEmpty() .hasCreatedAt(DATE_2); }
@Test public void save_persists_new_value_in_varchar_if_less_than_4000_when_old_one_was_in_clob() { when(system2.now()).thenReturn(DATE_1, DATE_2); underTest.save(dbSession, A_KEY, VALUE_SIZE_4001); assertThatInternalProperty(A_KEY) .hasClobValue(VALUE_SIZE_4001) .hasCreatedAt(DATE_1); underTest.save(dbSession, A_KEY, VALUE_SMALL); assertThatInternalProperty(A_KEY) .hasTextValue(VALUE_SMALL) .hasCreatedAt(DATE_2); }
@Test public void saveAsEmpty_persist_property_without_textvalue_nor_clob_value_when_old_value_was_in_clob() { when(system2.now()).thenReturn(DATE_2, DATE_1); underTest.save(dbSession, A_KEY, VALUE_SIZE_4001); assertThatInternalProperty(A_KEY) .hasClobValue(VALUE_SIZE_4001) .hasCreatedAt(DATE_2); underTest.saveAsEmpty(dbSession, A_KEY); assertThatInternalProperty(A_KEY) .isEmpty() .hasCreatedAt(DATE_1); }