I have defined some streams producers (@Output
) and consumers (@Input
) in my spring boot application as long as my rest endpoints. Now I want to test both REST + Streams using
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
First of all I want to know if this is possible. For REST I'm auto wiring the TestRestTemplate and everything goes fine:
@Autowired
private TestRestTemplate restTemplate;
But for streams I'm trying to use:
@ClassRule
public static RabbitTestSupport rabbitTestSupport = new RabbitTestSupport();
Which enables me to recognise if Rabbit is up or not, and this is working fine, but then when I try to
@Autowired
private MessageChannel myProducer;
and send messages, I don't get any error, but the messages are not consumed by my app.
I got the feeling that both producer and consumer are started as part of my app instead of in a decoupled context and for that reason this is not working.
Producers and consumers are working fine in separate apps, so it seems something related with the test configuration.
Any ideas? did someone manage to test both REST and Streams in the same test using @SpringBootTest
because I couldn't find any reference.
I'm adding a reproducer here: https://github.com/Salaboy/test-spring-cloud-streams/
Some pointers: https://github.com/Salaboy/test-spring-cloud-streams/blob/master/src/main/java/org/salaboy/streams/SampleApplication.java#L40
and the test: https://github.com/Salaboy/test-spring-cloud-streams/blob/master/src/test/java/org/salaboy/streams/MyAppStreamsTest.java
Which uses these properties: https://github.com/Salaboy/test-spring-cloud-streams/blob/master/src/test/resources/test-application.properties
I will appreciate any help that you can provide.