I am new to spring integration and currently stuck on unit testing my integration flow. My flow looks something like this.
and XML file is :
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-ip="http://www.springframework.org/schema/integration/ip"
xmlns:int-aws="http://www.springframework.org/schema/integration/aws"
xmlns:aws-messaging="http://www.springframework.org/schema/cloud/aws/messaging"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/ip
http://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd
http://www.springframework.org/schema/integration/aws
http://www.springframework.org/schema/integration/aws/spring-integration-aws.xsd
http://www.springframework.org/schema/cloud/aws/messaging
https://www.springframework.org/schema/cloud/aws/messaging/spring-cloud-aws-messaging.xsd">
<!-- -->
<!-- receive callbacks -->
<!-- -->
<int-ip:tcp-connection-factory
id="inboundServerTCPFactory1"
deserializer="customSerializerDeserializer"
serializer="customSerializerDeserializer"
type="server"
port="8085"
using-nio="true"
single-use="true"/>
<!-- -->
<!-- receive callbacks -->
<!-- -->
<int-ip:tcp-connection-factory
id="inboundServerTCPFactory2"
deserializer="customSerializerDeserializer"
serializer="customSerializerDeserializer"
type="server"
port="8086"
using-nio="true"
single-use="true"/>
<!-- -->
<!-- Inbound channel adapter -->
<!-- -->
<int-ip:tcp-inbound-channel-adapter id="inboundChannelAdapter1"
channel="inboundReceivingChannel"
connection-factory="inboundServerTCPFactory1"/>
<int-ip:tcp-inbound-channel-adapter id="inboundChannelAdapter2"
channel="inboundReceivingChannel"
connection-factory="inboundServerTCPFactory2"/>
<!-- -->
<!-- Inbound channel adapter -->
<!-- -->
<int:channel id="inboundReceivingChannel">
<int:interceptors>
<int:wire-tap channel="logger"/>
</int:interceptors>
</int:channel>
<!--Transfrom XML message to Json-->
<int:transformer ref="xmlToJsonTransformer" input-channel="inboundReceivingChannel"
method="transform" output-channel="outChannel"/>
<int:channel id="outChannel" />
<!--<aws-messaging:sqs-async-client id="amazonSqs"/>-->
<int-aws:sqs-outbound-channel-adapter id= "out"
sqs="sqs"
channel="outChannel"
queue="SendQueue"/>
</beans>
How do I mock every component and unit test the complete flow?
See Spring Integration testing support documentation: https://docs.spring.io/spring-integration/docs/current/reference/html/testing.html#testing. The framework provides for us a MockIntegrationContext
via @SpringIntegrationTest
marker on the Spring JUnit test class. The MockIntegration
factory lets us to create respective mocks and stub their handling logic. Then you can substitute endpoint beans with your mocks and so.