Search in sources :

Example 1 with EntityCallbacks

use of org.springframework.data.mapping.callback.EntityCallbacks in project spring-data-mongodb by spring-projects.

the class AuditingIntegrationTests method enablesAuditingAndSetsPropertiesAccordingly.

// DATAMONGO-577, DATAMONGO-800, DATAMONGO-883, DATAMONGO-2261
@Test
public void enablesAuditingAndSetsPropertiesAccordingly() throws Exception {
    AbstractApplicationContext context = new ClassPathXmlApplicationContext("auditing.xml", getClass());
    MongoMappingContext mappingContext = context.getBean(MongoMappingContext.class);
    mappingContext.getPersistentEntity(Entity.class);
    EntityCallbacks callbacks = EntityCallbacks.create(context);
    Entity entity = new Entity();
    entity = callbacks.callback(BeforeConvertCallback.class, entity, "collection-1");
    assertThat(entity.created).isNotNull();
    assertThat(entity.modified).isEqualTo(entity.created);
    Thread.sleep(10);
    entity.id = 1L;
    entity = callbacks.callback(BeforeConvertCallback.class, entity, "collection-1");
    assertThat(entity.created).isNotNull();
    assertThat(entity.modified).isNotEqualTo(entity.created);
    context.close();
}
Also used : AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) BeforeConvertCallback(org.springframework.data.mongodb.core.mapping.event.BeforeConvertCallback) EntityCallbacks(org.springframework.data.mapping.callback.EntityCallbacks) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) Test(org.junit.jupiter.api.Test)

Example 2 with EntityCallbacks

use of org.springframework.data.mapping.callback.EntityCallbacks in project spring-data-mongodb by spring-projects.

the class MongoTemplateUnitTests method setterForApplicationContextShouldNotOverrideAlreadySetEntityCallbacks.

// DATAMONGO-2261
@Test
void setterForApplicationContextShouldNotOverrideAlreadySetEntityCallbacks() {
    EntityCallbacks callbacks = EntityCallbacks.create();
    ApplicationContext ctx = new StaticApplicationContext();
    template.setEntityCallbacks(callbacks);
    template.setApplicationContext(ctx);
    Assertions.assertThat(ReflectionTestUtils.getField(template, "entityCallbacks")).isSameAs(callbacks);
}
Also used : StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) EntityCallbacks(org.springframework.data.mapping.callback.EntityCallbacks) Test(org.junit.jupiter.api.Test)

Example 3 with EntityCallbacks

use of org.springframework.data.mapping.callback.EntityCallbacks in project spring-data-mongodb by spring-projects.

the class MappingMongoConverterUnitTests method setterForEntityCallbackOverridesContextInitializedOnes.

// DATAMONGO-2479
@Test
void setterForEntityCallbackOverridesContextInitializedOnes() {
    ApplicationContext ctx = new StaticApplicationContext();
    converter.setApplicationContext(ctx);
    EntityCallbacks callbacks = EntityCallbacks.create();
    converter.setEntityCallbacks(callbacks);
    assertThat(ReflectionTestUtils.getField(converter, "entityCallbacks")).isSameAs(callbacks);
}
Also used : StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) EntityCallbacks(org.springframework.data.mapping.callback.EntityCallbacks) Test(org.junit.jupiter.api.Test)

Example 4 with EntityCallbacks

use of org.springframework.data.mapping.callback.EntityCallbacks in project spring-data-mongodb by spring-projects.

the class MongoTemplateUnitTests method setterForEntityCallbackOverridesContextInitializedOnes.

// DATAMONGO-2261
@Test
void setterForEntityCallbackOverridesContextInitializedOnes() {
    ApplicationContext ctx = new StaticApplicationContext();
    template.setApplicationContext(ctx);
    EntityCallbacks callbacks = EntityCallbacks.create();
    template.setEntityCallbacks(callbacks);
    Assertions.assertThat(ReflectionTestUtils.getField(template, "entityCallbacks")).isSameAs(callbacks);
}
Also used : StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) EntityCallbacks(org.springframework.data.mapping.callback.EntityCallbacks) Test(org.junit.jupiter.api.Test)

Example 5 with EntityCallbacks

use of org.springframework.data.mapping.callback.EntityCallbacks in project spring-data-mongodb by spring-projects.

the class MappingMongoConverterUnitTests method setterForApplicationContextShouldNotOverrideAlreadySetEntityCallbacks.

// DATAMONGO-2479
@Test
void setterForApplicationContextShouldNotOverrideAlreadySetEntityCallbacks() {
    EntityCallbacks callbacks = EntityCallbacks.create();
    ApplicationContext ctx = new StaticApplicationContext();
    converter.setEntityCallbacks(callbacks);
    converter.setApplicationContext(ctx);
    assertThat(ReflectionTestUtils.getField(converter, "entityCallbacks")).isSameAs(callbacks);
}
Also used : StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) EntityCallbacks(org.springframework.data.mapping.callback.EntityCallbacks) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)5 EntityCallbacks (org.springframework.data.mapping.callback.EntityCallbacks)5 ApplicationContext (org.springframework.context.ApplicationContext)4 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)4 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)2 AbstractApplicationContext (org.springframework.context.support.AbstractApplicationContext)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1 MongoMappingContext (org.springframework.data.mongodb.core.mapping.MongoMappingContext)1 BeforeConvertCallback (org.springframework.data.mongodb.core.mapping.event.BeforeConvertCallback)1