INT-1008 Additional test for outbound tcp gateway.

This commit is contained in:
Gary Russell
2010-05-06 15:33:45 +00:00
parent f0590ed578
commit 37ac39b19c
2 changed files with 37 additions and 10 deletions

View File

@@ -2,17 +2,26 @@
<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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd">
xmlns:ip="http://www.springframework.org/schema/integration/ip"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.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
http://www.springframework.org/schema/integration/spring-integration.xsd">
<import resource="SimpleTcpNetInboundGatewayTests-context.xml" />
<bean id="tcpOutGateway" class="org.springframework.integration.ip.tcp.SimpleTcpNetOutboundGateway">
<constructor-arg value="localhost"/>
<constructor-arg value="#{gatewayCrLf.port}"/>
<!-- <property name="" value=""/>-->
</bean>
<ip:outbound-gateway id="tcpOutGateway"
host="localhost"
port="#{gatewayCrLf.port}"
message-format="crlf"
request-channel="requestChannel"
reply-channel="replyChannel"
/>
<int:channel id="replyChannel" >
<int:queue />
</int:channel>
</beans>

View File

@@ -19,6 +19,8 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.channel.PollableChannel;
import org.springframework.integration.channel.SubscribableChannel;
import org.springframework.integration.core.Message;
import org.springframework.integration.message.MessageBuilder;
import org.springframework.test.context.ContextConfiguration;
@@ -30,7 +32,7 @@ import static org.junit.Assert.assertEquals;
* @author Gary Russell
*
*/
@ContextConfiguration(locations="SimpleTcpNetInboundGatewayTests-context.xml")
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class SimpleTcpNetOutboundGatewayTests {
@@ -49,6 +51,14 @@ public class SimpleTcpNetOutboundGatewayTests {
@Autowired
@Qualifier("gatewayCustom")
private SimpleTcpNetInboundGateway inboundGatewayCustom;
@Autowired
@Qualifier("requestChannel")
SubscribableChannel requestChannel;
@Autowired
@Qualifier("replyChannel")
PollableChannel replyChannel;
@Test
public void testOutboundCrLf() throws Exception {
@@ -91,4 +101,12 @@ public class SimpleTcpNetOutboundGatewayTests {
byte[] bytes = (byte[]) gateway.handleRequestMessage(message);
assertEquals("echo:test", new String(bytes).trim());
}
@Test
public void testOutboundUsingConfig() {
Message<String> message = MessageBuilder.withPayload("test").build();
requestChannel.send(message);
byte[] bytes = (byte[]) replyChannel.receive().getPayload();
assertEquals("echo:test", new String(bytes).trim());
}
}