Search in sources :

Example 1 with BeforeConvertEvent

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();
}
Also used : AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) BeforeConvertEvent(org.springframework.data.mongodb.core.mapping.event.BeforeConvertEvent) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 AbstractApplicationContext (org.springframework.context.support.AbstractApplicationContext)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1 MongoMappingContext (org.springframework.data.mongodb.core.mapping.MongoMappingContext)1 BeforeConvertEvent (org.springframework.data.mongodb.core.mapping.event.BeforeConvertEvent)1