I am working on Spring Boot application which uses Spring Integration and Mqtt support. Here we have a test to check if the application context is started properly.
class ApplicationTests {
private @Autowired transient ApplicationContext applicationContext;
@Test
void mainMethodTest() {
Application.main(new String[] {});
Assertions.assertNotNull(this.applicationContext);
}
}
but this test will if the Mqtt Broker is not running.
@Bean
@ConfigurationProperties(prefix = "mqtt")
public MqttConnectionOptions mqttConnectOptions() {
return new MqttConnectionOptions();
}
@Bean
@DependsOn("mqttConnectOptions")
public MessageHandler mqttOutbound() {
Mqttv5PahoMessageHandler mqttv5PahoMessageHandler =
new Mqttv5PahoMessageHandler(mqttConnectOptions(), QueueConfigs.CLIENT_ID);
mqttv5PahoMessageHandler.setAsync(true);
return mqttv5PahoMessageHandler;
}
@Bean
public IntegrationFlow simulatorReadingsOutFlow() {
return flow -> flow.handle(mqttOutbound());
}
tests will fail because the above beans will not be created during the testing without an mqtt broker running in the environment. is there a way to skip the integration flow related beans or mock them during the testing of ApplicationContext.