0

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"));

1 Answers1

1
  1. 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?

  2. "Nothing happens until you subscribe"

    You can add a doOnSubscribe() call and see whether it is triggered and when, when running the test.

Konstantin Kolinko
  • 3,854
  • 1
  • 13
  • 21
  • Just edited the question to provide details regarding the author. `getAuthor()` is mocked and always returns `Mono.just("Author")` – Francisco Aguiar Jul 27 '20 at 10:37
  • Regarding 2, you were correct. I was calling the method that triggered the aspect but i was ignoring the return value, and so there was no subscription. Been banging my head on this for some hours now, thank you. – Francisco Aguiar Jul 27 '20 at 10:42
  • Will mark this answer as correct since it pointed out the possible issues causing this. – Francisco Aguiar Jul 27 '20 at 10:42