DATACMNS-1663 - Support domain events for deletions.
Domain events are now also published on calls to CrudRepository.delete(…) and ….deleteAll(…). Original pull request: #436.
This commit is contained in:
committed by
Oliver Drotbohm
parent
00d77d03cd
commit
889ae01c7c
@@ -53,6 +53,7 @@ import org.springframework.data.repository.core.support.EventPublishingRepositor
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
* @author Yuki Yoshida
|
||||
* @author Réda Housni Alaoui
|
||||
* @soundtrack Henrik Freischlader Trio - Nobody Else To Blame (Openness)
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -124,7 +125,20 @@ class EventPublishingRepositoryProxyPostProcessorUnitTests {
|
||||
|
||||
verify(publisher).publishEvent(event);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1663
|
||||
public void interceptsDeleteMethod() throws Throwable {
|
||||
SomeEvent event = new SomeEvent();
|
||||
MultipleEvents sample = MultipleEvents.of(Collections.singletonList(event));
|
||||
mockInvocation(invocation, SampleRepository.class.getMethod("delete", Object.class), sample);
|
||||
|
||||
EventPublishingMethodInterceptor//
|
||||
.of(EventPublishingMethod.of(MultipleEvents.class), publisher)//
|
||||
.invoke(invocation);
|
||||
|
||||
verify(publisher).publishEvent(event);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-928
|
||||
void doesNotInterceptNonSaveMethod() throws Throwable {
|
||||
|
||||
@@ -137,6 +151,18 @@ class EventPublishingRepositoryProxyPostProcessorUnitTests {
|
||||
verify(publisher, never()).publishEvent(any());
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1663
|
||||
public void doesNotInterceptDeleteByIdMethod() throws Throwable {
|
||||
|
||||
doReturn(SampleRepository.class.getMethod("deleteById", Object.class)).when(invocation).getMethod();
|
||||
|
||||
EventPublishingMethodInterceptor//
|
||||
.of(EventPublishingMethod.of(MultipleEvents.class), publisher)//
|
||||
.invoke(invocation);
|
||||
|
||||
verify(publisher, never()).publishEvent(any());
|
||||
}
|
||||
|
||||
@Test // DATACMNS-928
|
||||
void registersAdviceIfDomainTypeExposesEvents() {
|
||||
|
||||
@@ -177,6 +203,20 @@ class EventPublishingRepositoryProxyPostProcessorUnitTests {
|
||||
verify(publisher).publishEvent(any(SomeEvent.class));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1663
|
||||
public void publishesEventsForCallToDeleteWithIterable() throws Throwable {
|
||||
|
||||
SomeEvent event = new SomeEvent();
|
||||
MultipleEvents sample = MultipleEvents.of(Collections.singletonList(event));
|
||||
mockInvocation(invocation, SampleRepository.class.getMethod("deleteAll", Iterable.class), sample);
|
||||
|
||||
EventPublishingMethodInterceptor//
|
||||
.of(EventPublishingMethod.of(MultipleEvents.class), publisher)//
|
||||
.invoke(invocation);
|
||||
|
||||
verify(publisher).publishEvent(any(SomeEvent.class));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-975
|
||||
void publishesEventsAfterSaveInvocation() throws Throwable {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user