use of org.springframework.data.mongodb.core.KAuditableVersionedEntity in project spring-data-mongodb by spring-projects.
the class ReactiveMongoTemplateAuditingTests method auditingSetsLastModifiedDateCorrectlyForImmutableVersionedKotlinEntityOnSave.
// DATAMONGO-2346
@Test
void auditingSetsLastModifiedDateCorrectlyForImmutableVersionedKotlinEntityOnSave() {
KAuditableVersionedEntity entity = new KAuditableVersionedEntity(null, "value", null, null);
//
template.save(entity).delayElement(Duration.ofMillis(500)).flatMap(inserted -> //
template.save(inserted.withValue("changed-value")).map(//
updated -> Tuples.of(inserted, updated))).flatMap(tuple2 -> template.findOne(Query.query(Criteria.where("id").is(tuple2.getT1().getId())), KAuditableVersionedEntity.class).map(//
fetched -> Tuples.of(tuple2.getT1(), tuple2.getT2(), fetched))).as(//
StepVerifier::create).consumeNextWith(tuple3 -> {
assertThat(tuple3.getT2().getModificationDate()).isAfter(tuple3.getT1().getModificationDate());
assertThat(tuple3.getT3().getModificationDate()).isAfter(tuple3.getT1().getModificationDate());
assertThat(tuple3.getT3().getModificationDate()).isEqualTo(tuple3.getT2().getModificationDate().truncatedTo(ChronoUnit.MILLIS));
}).verifyComplete();
}
use of org.springframework.data.mongodb.core.KAuditableVersionedEntity in project spring-data-mongodb by spring-projects.
the class MongoTemplateAuditingTests method auditingSetsLastModifiedDateCorrectlyForImmutableVersionedKotlinEntityOnSave.
// DATAMONGO-2346
@Test
public void auditingSetsLastModifiedDateCorrectlyForImmutableVersionedKotlinEntityOnSave() throws InterruptedException {
template.remove(new Query(), KAuditableVersionedEntity.class);
KAuditableVersionedEntity entity = new KAuditableVersionedEntity("kId-1", "value", null, null);
KAuditableVersionedEntity inserted = template.save(entity);
TimeUnit.MILLISECONDS.sleep(500);
KAuditableVersionedEntity updated = template.save(inserted.withValue("changed-value"));
KAuditableVersionedEntity fetched = template.findOne(Query.query(Criteria.where("id").is(entity.getId())), KAuditableVersionedEntity.class);
assertThat(updated.getModificationDate()).isAfter(inserted.getModificationDate());
assertThat(fetched.getModificationDate()).isAfter(inserted.getModificationDate());
assertThat(fetched.getModificationDate()).isEqualTo(updated.getModificationDate().truncatedTo(ChronoUnit.MILLIS));
}
Aggregations