I'm trying to test the following code using integration tests:
return ((Mono<Object>) joinPoint.proceed()).then(provider.getAuthor().flatMap((author) -> {
Arrays.stream(joinPoint.getArgs())
.forEach(arg -> javers.commitShallowDeleteById(author, InstanceIdDTO.instanceId(arg.toString(), deletedEntity)));
return Mono.empty();
}));
jointPoint.proceeed()
Always returns a Mono<Void>
so that's why i'm using then()
.
When running the app in debug mode if i place a breakpoint inside the flatmap i can see it passes through there, however if i run it in a @SpringBootTest
in no longer passes inside the flatmap.
Test configuration:
@DirtiesContext
@ActiveProfiles("test")
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
Provider:
when(authorProvider.getAuthor()).thenReturn(Mono.just("Author"));
Maybe provider.getAuthor()
returns no value (a Mono.empty()
) when you run your test?
A flatMap
needs a value to operate on. If there is no value, it won't be called. You can add a doOnComplete()
call and see whether it is triggered when the sequence completes.
Are the web application and the test running with the same data?
"Nothing happens until you subscribe"
You can add a doOnSubscribe()
call and see whether it is triggered and when, when running the test.