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();
}
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);
}
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);
}
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);
}
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);
}
Aggregations