|
38 | 38 | import org.springframework.context.ApplicationEventPublisher;
|
39 | 39 | import org.springframework.data.domain.AfterDomainEventPublication;
|
40 | 40 | import org.springframework.data.domain.DomainEvents;
|
| 41 | +import org.springframework.data.domain.Page; |
| 42 | +import org.springframework.data.domain.PageImpl; |
| 43 | +import org.springframework.data.domain.PageRequest; |
| 44 | +import org.springframework.data.domain.Pageable; |
| 45 | +import org.springframework.data.domain.ScrollPosition; |
| 46 | +import org.springframework.data.domain.Window; |
41 | 47 | import org.springframework.data.repository.CrudRepository;
|
42 | 48 | import org.springframework.data.repository.core.RepositoryInformation;
|
43 | 49 | import org.springframework.data.repository.core.support.EventPublishingRepositoryProxyPostProcessor.EventPublishingMethod;
|
|
50 | 56 | * @author Mark Paluch
|
51 | 57 | * @author Yuki Yoshida
|
52 | 58 | * @author Réda Housni Alaoui
|
| 59 | + * @author Yanming Zhou |
53 | 60 | * @soundtrack Henrik Freischlader Trio - Nobody Else To Blame (Openness)
|
54 | 61 | */
|
55 | 62 | @ExtendWith(MockitoExtension.class)
|
@@ -199,6 +206,36 @@ void publishesEventsForCallToSaveWithIterable() throws Throwable {
|
199 | 206 | verify(publisher).publishEvent(any(SomeEvent.class));
|
200 | 207 | }
|
201 | 208 |
|
| 209 | + @Test |
| 210 | + void publishesEventsForCallToSaveWithIterableAndWindowAsParameter() throws Throwable { |
| 211 | + |
| 212 | + var event = new SomeEvent(); |
| 213 | + var sample = MultipleEvents.of(Collections.singletonList(event)); |
| 214 | + Window<MultipleEvents> window = Window.from(List.of(sample), ScrollPosition::offset); |
| 215 | + mockInvocation(invocation, SampleRepository.class.getMethod("saveAll", Iterable.class), window); |
| 216 | + |
| 217 | + EventPublishingMethodInterceptor// |
| 218 | + .of(EventPublishingMethod.of(MultipleEvents.class), publisher)// |
| 219 | + .invoke(invocation); |
| 220 | + |
| 221 | + verify(publisher).publishEvent(any(SomeEvent.class)); |
| 222 | + } |
| 223 | + |
| 224 | + @Test |
| 225 | + void publishesEventsForCallToSaveWithIterableAndPageAsParameter() throws Throwable { |
| 226 | + |
| 227 | + var event = new SomeEvent(); |
| 228 | + var sample = MultipleEvents.of(Collections.singletonList(event)); |
| 229 | + Page<MultipleEvents> page = new PageImpl<>(List.of(sample), Pageable.ofSize(10), 1); |
| 230 | + mockInvocation(invocation, SampleRepository.class.getMethod("saveAll", Iterable.class), page); |
| 231 | + |
| 232 | + EventPublishingMethodInterceptor// |
| 233 | + .of(EventPublishingMethod.of(MultipleEvents.class), publisher)// |
| 234 | + .invoke(invocation); |
| 235 | + |
| 236 | + verify(publisher).publishEvent(any(SomeEvent.class)); |
| 237 | + } |
| 238 | + |
202 | 239 | @Test // DATACMNS-1663
|
203 | 240 | void publishesEventsForCallToDeleteWithIterable() throws Throwable {
|
204 | 241 |
|
|
0 commit comments