use of org.springframework.data.mongodb.core.mapping.event.BeforeConvertEvent in project spring-data-mongodb by spring-projects.
the class AuditingIntegrationTests method enablesAuditingAndSetsPropertiesAccordingly.
// DATAMONGO-577, DATAMONGO-800, DATAMONGO-883
@Test
public void enablesAuditingAndSetsPropertiesAccordingly() throws Exception {
AbstractApplicationContext context = new ClassPathXmlApplicationContext("auditing.xml", getClass());
MongoMappingContext mappingContext = context.getBean(MongoMappingContext.class);
mappingContext.getPersistentEntity(Entity.class);
Entity entity = new Entity();
BeforeConvertEvent<Entity> event = new BeforeConvertEvent<Entity>(entity, "collection-1");
context.publishEvent(event);
assertThat(entity.created, is(notNullValue()));
assertThat(entity.modified, is(entity.created));
Thread.sleep(10);
entity.id = 1L;
event = new BeforeConvertEvent<Entity>(entity, "collection-1");
context.publishEvent(event);
assertThat(entity.created, is(notNullValue()));
assertThat(entity.modified, is(not(entity.created)));
context.close();
}
Aggregations