/* * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.springframework.integration.samples.tcpclientserver; import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory; import org.springframework.integration.ip.util.TestingUtilities; import org.springframework.integration.samples.tcpclientserver.support.CustomTestContextLoader; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * Demonstrates the use of a gateway as an entry point into the integration flow. * The message generated by the gateway is sent over tcp by the outbound gateway * to the inbound gateway. In turn the inbound gateway sends the message to an * echo service and the echoed response comes back over tcp and is returned to * the test case for verification. * * The test uses explicit transformers to convert the byte array payloads to * Strings. * * @author Gary Russell * @author Gunnar Hillert * */ // This one uses transformers @ContextConfiguration(loader=CustomTestContextLoader.class, locations={"/META-INF/spring/integration/tcpClientServerDemo-context.xml"}) @RunWith(SpringJUnit4ClassRunner.class) @DirtiesContext public class TcpClientServerDemoTest { @Autowired SimpleGateway gw; @Autowired AbstractServerConnectionFactory crLfServer; @Before public void setup() { TestingUtilities.waitListening(this.crLfServer, 10000L); } @Test public void testHappyDay() { String result = gw.send("Hello world!"); System.out.println(result); assertEquals("echo:Hello world!", result); } @Test public void testZeroLength() { String result = gw.send(""); System.out.println(result); assertEquals("echo:", result); } @Test public void testFail() { String result = gw.send("FAIL"); System.out.println(result); assertEquals("FAIL:Failure Demonstration", result); } }