DATACMNS-928 - Refinements for aggregate root domain event publication.
We now publish events for all methods named "save" on the repository. Fundamentally, that's in place to capture calls to CrudRepository.save(Iterable entities), too. Some minor refactorings to the internal setup of EventPublishingMethodInterceptor. More JavaDoc.
This commit is contained in:
@@ -25,7 +25,6 @@ import lombok.Getter;
|
||||
import lombok.Value;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
@@ -129,14 +128,14 @@ public class EventPublishingRepositoryProxyPostProcessorUnitTests {
|
||||
@Test
|
||||
public void interceptsSaveMethod() throws Throwable {
|
||||
|
||||
Method saveMethod = SampleRepository.class.getMethod("save", Object.class);
|
||||
doReturn(saveMethod).when(invocation).getMethod();
|
||||
doReturn(SampleRepository.class.getMethod("save", Object.class)).when(invocation).getMethod();
|
||||
|
||||
SomeEvent event = new SomeEvent();
|
||||
MultipleEvents sample = MultipleEvents.of(Arrays.asList(event));
|
||||
doReturn(new Object[] { sample }).when(invocation).getArguments();
|
||||
|
||||
new EventPublishingMethodInterceptor(saveMethod, EventPublishingMethod.of(MultipleEvents.class), publisher)
|
||||
EventPublishingMethodInterceptor//
|
||||
.of(EventPublishingMethod.of(MultipleEvents.class), publisher)//
|
||||
.invoke(invocation);
|
||||
|
||||
verify(publisher).publishEvent(event);
|
||||
@@ -148,10 +147,10 @@ public class EventPublishingRepositoryProxyPostProcessorUnitTests {
|
||||
@Test
|
||||
public void doesNotInterceptNonSaveMethod() throws Throwable {
|
||||
|
||||
Method saveMethod = SampleRepository.class.getMethod("save", Object.class);
|
||||
doReturn(SampleRepository.class.getMethod("findOne", Serializable.class)).when(invocation).getMethod();
|
||||
|
||||
new EventPublishingMethodInterceptor(saveMethod, EventPublishingMethod.of(MultipleEvents.class), publisher)
|
||||
EventPublishingMethodInterceptor//
|
||||
.of(EventPublishingMethod.of(MultipleEvents.class), publisher)//
|
||||
.invoke(invocation);
|
||||
|
||||
verify(publisher, never()).publishEvent(any());
|
||||
@@ -189,6 +188,25 @@ public class EventPublishingRepositoryProxyPostProcessorUnitTests {
|
||||
verify(factory, never()).addAdvice(any(Advice.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-928
|
||||
*/
|
||||
@Test
|
||||
public void publishesEventsForCallToSaveWithIterable() throws Throwable {
|
||||
|
||||
SomeEvent event = new SomeEvent();
|
||||
MultipleEvents sample = MultipleEvents.of(Arrays.asList(event));
|
||||
doReturn(new Object[] { Arrays.asList(sample) }).when(invocation).getArguments();
|
||||
|
||||
doReturn(SampleRepository.class.getMethod("save", Iterable.class)).when(invocation).getMethod();
|
||||
|
||||
EventPublishingMethodInterceptor//
|
||||
.of(EventPublishingMethod.of(MultipleEvents.class), publisher)//
|
||||
.invoke(invocation);
|
||||
|
||||
verify(publisher).publishEvent(any(SomeEvent.class));
|
||||
}
|
||||
|
||||
@Value(staticConstructor = "of")
|
||||
static class MultipleEvents {
|
||||
@Getter(onMethod = @__(@DomainEvents)) Collection<? extends Object> events;
|
||||
|
||||
Reference in New Issue
Block a user