Eli
Eli

Reputation: 117

How to test IntegrationFlow with FileReadingMessageSource and HttpRequestExecutingMessageHandler in spring integration

I have an integration flow to poll json files from some folder and send them to a rest http endpoint. Below my code:

@Bean
public IntegrationFlow jsonFileToRestFlow() {
    return IntegrationFlows
            .from("fileInputChannel")
            .transform(new FileToStringTransformer())
            .enrichHeaders(s -> s.header("Content-Type", "application/json; charset=utf8"))
            .handle(httpRequestExecutingMessageHandler())
            .get();
}

After receiving response from http endpoint i will move my files to successful or failure channel. Now i want to test my code. What is the best way to test this code. My idea is to put some json Files in my inputChannel and then mock my http response and check if expected message is in successChannel or failure. But I don't know how to start. Can anyone give me some tips? thanks

Upvotes: 2

Views: 1078

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121542

Please, take a look into the Spring Integration Testing Framework. So, your httpRequestExecutingMessageHandler can be replaces with the MockIntegration.mockMessageHandler() where you really can produce any possible mocked reply in the handleNextAndReply().

Another option is like a MockMvc and its MockMvcClientHttpRequestFactory to be injected into the RestTemplate for the HttpRequestExecutingMessageHandler.

Success or failure can be achieved with the ExpressionEvaluatingRequestHandlerAdvice applied on the .handle(httpRequestExecutingMessageHandler()) endpoint.

Upvotes: 1

Related Questions