IntegrationTests for Spring IntegrationFlow

I'm having trouble writing test cases for my IntegrationFlow, which uses Spring DSL integration. Below is a snippet of code, and I would like to check out the "transform" part. Please provide some help in mocking part of the pen, or if there is any other way to check this -

public class DmwConfig { @Value("${dmw.url.hostname}") public String hostName; @Bean public MessageChannel dmwGetProductDetailsByEanChannel() { return MessageChannels.direct().get(); } @Bean public IntegrationFlow dmwGetProductDetailsByEan() { return IntegrationFlows .from("input") .channel("dmwGetProductDetailsByEanChannel") .handle(httpMessageHandlerSpec()) .<JsonNode, ProductModel>transform( node -> new ProductModel( node.findValue("name").asText(null), node.findValue("inventory").findValue("orderable").asBoolean(false), node.findValue("stock_level").asInt(0), node.findValue("price").asDouble(0), "", // this url field will be enriched in the controller because the url doesn't contain any data from the response node.findValue("image_groups").findValue("link").asText(null) ) ) .get(); } @Bean public HttpRequestExecutingMessageHandler httpMessageHandlerSpec() { return Http .outboundGateway((Message<DmwPayload> p) -> "foobar url") .charset("UTF-8") .httpMethod(HttpMethod.GET) .expectedResponseType(JsonNode.class).get(); } } 
+6
source share
1 answer

We do not have a mocking framework , but this is really an intention in the near future.

You can use @MockBean from the latest Spring Boot for your HttpRequestExecutingMessageHandler httpMessageHandlerSpec to replace this bean with your desired taunt.

Alternatively, you can simply send a message directly to the input channel for this .transform . Please read this phrase guide:

By default, endpoints connect via DirectChannel, where the bean name is based on the template: [IntegrationFlow.beanName] .channel # [channelNameIndex].

So, the desired channel in your thread has a bean name like: dmwGetProductDetailsByEan.channel#0 , because this is the first unnamed channel in the IntegrationFlow definition.

+1
source

All Articles