Search in sources :

Example 1 with IsNewAwareAuditingHandler

use of org.springframework.data.auditing.IsNewAwareAuditingHandler in project spring-data-mongodb by spring-projects.

the class AuditingEntityCallbackUnitTests method propagatesChangedInstanceToEvent.

// DATAMONGO-2261
@Test
void propagatesChangedInstanceToEvent() {
    ImmutableSample sample = new ImmutableSample();
    ImmutableSample newSample = new ImmutableSample();
    IsNewAwareAuditingHandler handler = mock(IsNewAwareAuditingHandler.class);
    doReturn(newSample).when(handler).markAudited(eq(sample));
    AuditingEntityCallback listener = new AuditingEntityCallback(() -> handler);
    Object result = listener.onBeforeConvert(sample, "foo");
    assertThat(result).isSameAs(newSample);
}
Also used : IsNewAwareAuditingHandler(org.springframework.data.auditing.IsNewAwareAuditingHandler) Test(org.junit.jupiter.api.Test)

Example 2 with IsNewAwareAuditingHandler

use of org.springframework.data.auditing.IsNewAwareAuditingHandler in project spring-data-mongodb by spring-projects.

the class AuditingEventListenerUnitTests method propagatesChangedInstanceToEvent.

// DATAMONGO-1992
@Test
void propagatesChangedInstanceToEvent() {
    ImmutableSample sample = new ImmutableSample();
    BeforeConvertEvent<Object> event = new BeforeConvertEvent<>(sample, "collection");
    ImmutableSample newSample = new ImmutableSample();
    IsNewAwareAuditingHandler handler = mock(IsNewAwareAuditingHandler.class);
    doReturn(newSample).when(handler).markAudited(eq(sample));
    AuditingEventListener listener = new AuditingEventListener(() -> handler);
    listener.onApplicationEvent(event);
    assertThat(event.getSource()).isSameAs(newSample);
}
Also used : IsNewAwareAuditingHandler(org.springframework.data.auditing.IsNewAwareAuditingHandler) Test(org.junit.jupiter.api.Test)

Example 3 with IsNewAwareAuditingHandler

use of org.springframework.data.auditing.IsNewAwareAuditingHandler in project spring-data-mongodb by spring-projects.

the class AuditingEntityCallbackUnitTests method setUp.

@BeforeEach
void setUp() {
    MongoMappingContext mappingContext = new MongoMappingContext();
    mappingContext.getPersistentEntity(Sample.class);
    handler = spy(new IsNewAwareAuditingHandler(new PersistentEntities(Arrays.asList(mappingContext))));
    callback = new AuditingEntityCallback(() -> handler);
}
Also used : IsNewAwareAuditingHandler(org.springframework.data.auditing.IsNewAwareAuditingHandler) PersistentEntities(org.springframework.data.mapping.context.PersistentEntities) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with IsNewAwareAuditingHandler

use of org.springframework.data.auditing.IsNewAwareAuditingHandler in project spring-data-mongodb by spring-projects.

the class AuditingEventListenerUnitTests method setUp.

@BeforeEach
void setUp() {
    MongoMappingContext mappingContext = new MongoMappingContext();
    mappingContext.getPersistentEntity(Sample.class);
    handler = spy(new IsNewAwareAuditingHandler(new PersistentEntities(Arrays.asList(mappingContext))));
    listener = new AuditingEventListener(() -> handler);
}
Also used : IsNewAwareAuditingHandler(org.springframework.data.auditing.IsNewAwareAuditingHandler) PersistentEntities(org.springframework.data.mapping.context.PersistentEntities) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

IsNewAwareAuditingHandler (org.springframework.data.auditing.IsNewAwareAuditingHandler)4 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Test (org.junit.jupiter.api.Test)2 PersistentEntities (org.springframework.data.mapping.context.PersistentEntities)2 MongoMappingContext (org.springframework.data.mongodb.core.mapping.MongoMappingContext)2