@Test public void upsert_does_not_update_row_if_values_are_not_changed() { if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) { return; } LiveMeasureDto dto = newLiveMeasure(); underTest.upsert(db.getSession(), dto); // update int count = underTest.upsert(db.getSession(), dto); assertThat(count).isEqualTo(0); verifyPersisted(dto); verifyTableSize(1); }
@Test public void upsert_inserts_or_updates_row() { if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) { return; } // insert LiveMeasureDto dto = newLiveMeasure(); int count = underTest.upsert(db.getSession(), dto); verifyPersisted(dto); verifyTableSize(1); assertThat(count).isEqualTo(1); // update dto.setValue(dto.getValue() + 1); dto.setVariation(dto.getVariation() + 10); dto.setData(dto.getDataAsString() + "_new"); count = underTest.upsert(db.getSession(), dto); assertThat(count).isEqualTo(1); verifyPersisted(dto); verifyTableSize(1); }
@Test public void upsert_updates_row_if_variation_is_removed() { if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) { return; } LiveMeasureDto dto = newLiveMeasure().setVariation(40.0); underTest.upsert(db.getSession(), dto); // update dto.setVariation(null); int count = underTest.upsert(db.getSession(), dto); assertThat(count).isEqualTo(1); verifyPersisted(dto); verifyTableSize(1); }
@Test public void upsert_updates_row_if_variation_is_added() { if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) { return; } LiveMeasureDto dto = newLiveMeasure().setVariation(null); underTest.upsert(db.getSession(), dto); // update dto.setVariation(40.0); int count = underTest.upsert(db.getSession(), dto); assertThat(count).isEqualTo(1); verifyPersisted(dto); verifyTableSize(1); }
@Test public void upsert_updates_row_if_value_is_added() { if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) { return; } LiveMeasureDto dto = newLiveMeasure().setValue(null); underTest.upsert(db.getSession(), dto); // update dto.setValue(40.0); int count = underTest.upsert(db.getSession(), dto); assertThat(count).isEqualTo(1); verifyPersisted(dto); verifyTableSize(1); }
@Test public void upsert_updates_row_if_variation_is_changed() { if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) { return; } LiveMeasureDto dto = newLiveMeasure().setVariation(40.0); underTest.upsert(db.getSession(), dto); // update dto.setVariation(50.0); int count = underTest.upsert(db.getSession(), dto); assertThat(count).isEqualTo(1); verifyPersisted(dto); verifyTableSize(1); }
@Test public void upsert_updates_row_if_value_is_removed() { if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) { return; } LiveMeasureDto dto = newLiveMeasure().setValue(40.0); underTest.upsert(db.getSession(), dto); // update dto.setValue(null); int count = underTest.upsert(db.getSession(), dto); assertThat(count).isEqualTo(1); verifyPersisted(dto); verifyTableSize(1); }
@Test public void upsert_updates_row_if_value_is_changed() { if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) { return; } LiveMeasureDto dto = newLiveMeasure().setValue(40.0); underTest.upsert(db.getSession(), dto); // update dto.setValue(50.0); int count = underTest.upsert(db.getSession(), dto); assertThat(count).isEqualTo(1); verifyPersisted(dto); verifyTableSize(1); }
@Test public void insertOrUpdate() { // insert LiveMeasureDto dto = newLiveMeasure(); underTest.insertOrUpdate(db.getSession(), dto); verifyPersisted(dto); verifyTableSize(1); // update dto.setValue(dto.getValue() + 1); dto.setVariation(dto.getVariation() + 10); dto.setData(dto.getDataAsString() + "_new"); underTest.insertOrUpdate(db.getSession(), dto); verifyPersisted(dto); verifyTableSize(1); }
@Test public void deleteByComponentUuidExcludingMetricIds_with_empty_metrics() { LiveMeasureDto measure1 = newLiveMeasure().setComponentUuid("C1").setMetricId(1); LiveMeasureDto measure2 = newLiveMeasure().setComponentUuid("C1").setMetricId(2); LiveMeasureDto measureOnOtherComponent = newLiveMeasure().setComponentUuid("C2").setMetricId(2); underTest.insertOrUpdate(db.getSession(), measure1); underTest.insertOrUpdate(db.getSession(), measure2); underTest.insertOrUpdate(db.getSession(), measureOnOtherComponent); int count = underTest.deleteByComponentUuidExcludingMetricIds(db.getSession(), "C1", Collections.emptyList()); assertThat(count).isEqualTo(2); verifyTableSize(1); verifyPersisted(measureOnOtherComponent); }
@Test public void deleteByComponentUuidExcludingMetricIds() { LiveMeasureDto measure1 = newLiveMeasure().setComponentUuid("C1").setMetricId(1); LiveMeasureDto measure2 = newLiveMeasure().setComponentUuid("C1").setMetricId(2); LiveMeasureDto measure3 = newLiveMeasure().setComponentUuid("C1").setMetricId(3); LiveMeasureDto measureOtherComponent = newLiveMeasure().setComponentUuid("C2").setMetricId(3); underTest.insertOrUpdate(db.getSession(), measure1); underTest.insertOrUpdate(db.getSession(), measure2); underTest.insertOrUpdate(db.getSession(), measure3); underTest.insertOrUpdate(db.getSession(), measureOtherComponent); int count = underTest.deleteByComponentUuidExcludingMetricIds(db.getSession(), "C1", Arrays.asList(1, 2)); verifyTableSize(3); verifyPersisted(measure1); verifyPersisted(measure2); verifyPersisted(measureOtherComponent); assertThat(count).isEqualTo(1); }