diff --git a/basic/testing-examples/readme.txt b/basic/testing-examples/readme.txt index 5cc30c3a..802166e6 100644 --- a/basic/testing-examples/readme.txt +++ b/basic/testing-examples/readme.txt @@ -28,17 +28,21 @@ as testing it within a Spring Integration flow fragment. ...aggregator.ExternalGatewaySubstitutionTests.java -This example is a little more complex. The application is based on a +This example is a little more complex. The application is simplified version of a travel demo presented at SpringOne in 2010. You do not need to fully understand the application for the purposes of this demonstration. Suffice it to say that a zip code is sent to two outbound gateways (one web service, one http) and the weather and traffic for that zip code are aggregated together. You can run the "real" application by executing the Main class in src/main/java -and entering a valid zip code. +and entering a valid zip code in the console. In many cases, when integrating with external services, we can't rely on those services being available while we test. Consequently, we need a mechanism to stub out those services so we can run the remainder of the flow in a repeatable manner without need for connectivity to the services. This example uses dummy service activators in place of the real outbound -gateways. \ No newline at end of file +gateways. + +This separation of 'infrastructure' from application beans is similar to +the way we separate DataSource, ConnectionFactory beans etc so that the +application can be tested with local versions. \ No newline at end of file diff --git a/basic/testing-examples/src/main/java/org/springframework/integration/samples/testing/externalgateway/Main.java b/basic/testing-examples/src/main/java/org/springframework/integration/samples/testing/externalgateway/Main.java index 7a7610d1..90729a38 100644 --- a/basic/testing-examples/src/main/java/org/springframework/integration/samples/testing/externalgateway/Main.java +++ b/basic/testing-examples/src/main/java/org/springframework/integration/samples/testing/externalgateway/Main.java @@ -17,6 +17,7 @@ package org.springframework.integration.samples.testing.externalgateway; import java.io.BufferedReader; import java.io.InputStreamReader; +import java.util.List; import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -36,8 +37,8 @@ public class Main { BufferedReader console = new BufferedReader(new InputStreamReader(System.in)); String zip = console.readLine().trim(); WeatherAndTraffic weatherAndTraffic = context.getBean("wat", WeatherAndTraffic.class); - String[] result = weatherAndTraffic.getByZip(zip); - System.out.println(result[0] + "\r\n" + result[1] + "\r\n"); + List result = weatherAndTraffic.getByZip(zip); + System.out.println(result.get(0) + "\r\n" + result.get(1) + "\r\n"); context.close(); System.exit(0); } diff --git a/basic/testing-examples/src/main/java/org/springframework/integration/samples/testing/externalgateway/WeatherAndTraffic.java b/basic/testing-examples/src/main/java/org/springframework/integration/samples/testing/externalgateway/WeatherAndTraffic.java index ff62562b..acb3e756 100644 --- a/basic/testing-examples/src/main/java/org/springframework/integration/samples/testing/externalgateway/WeatherAndTraffic.java +++ b/basic/testing-examples/src/main/java/org/springframework/integration/samples/testing/externalgateway/WeatherAndTraffic.java @@ -15,6 +15,8 @@ */ package org.springframework.integration.samples.testing.externalgateway; +import java.util.List; + /** * @author Gary Russell * @since 2.0.2 @@ -22,6 +24,6 @@ package org.springframework.integration.samples.testing.externalgateway; */ public interface WeatherAndTraffic { - public String[] getByZip(String zip); + public List getByZip(String zip); } diff --git a/basic/testing-examples/src/main/resources/META-INF/spring/integration/04-externalgateway/main-integration-context.xml b/basic/testing-examples/src/main/resources/META-INF/spring/integration/04-externalgateway/main-integration-context.xml index f475f75d..9acbcfda 100644 --- a/basic/testing-examples/src/main/resources/META-INF/spring/integration/04-externalgateway/main-integration-context.xml +++ b/basic/testing-examples/src/main/resources/META-INF/spring/integration/04-externalgateway/main-integration-context.xml @@ -38,7 +38,7 @@ + expression="#this.![payload]"/> diff --git a/basic/testing-examples/src/test/java/org/springframework/integration/samples/testing/externalgateway/ExternalGatewaySubstitutionTests.java b/basic/testing-examples/src/test/java/org/springframework/integration/samples/testing/externalgateway/ExternalGatewaySubstitutionTests.java index bf945071..6e7ce226 100644 --- a/basic/testing-examples/src/test/java/org/springframework/integration/samples/testing/externalgateway/ExternalGatewaySubstitutionTests.java +++ b/basic/testing-examples/src/test/java/org/springframework/integration/samples/testing/externalgateway/ExternalGatewaySubstitutionTests.java @@ -17,8 +17,8 @@ package org.springframework.integration.samples.testing.externalgateway; import static org.junit.Assert.assertEquals; -import java.util.ArrayList; import java.util.Collections; +import java.util.Iterator; import java.util.List; import org.junit.Test; @@ -45,14 +45,12 @@ public class ExternalGatewaySubstitutionTests { @Test public void doTest() { - String[] results = weatherAndTraffic.getByZip("12345"); - assertEquals(2, results.length); - List list = new ArrayList(); - list.add(results[0]); - list.add(results[1]); - Collections.sort(list); - assertEquals("Dummy traffic for zip:12345", list.get(0)); - assertEquals("Dummy weather for zip:12345", list.get(1)); + List results = weatherAndTraffic.getByZip("12345"); + assertEquals(2, results.size()); + Collections.sort(results); + Iterator result = results.iterator(); + assertEquals("Dummy traffic for zip:12345", result.next()); + assertEquals("Dummy weather for zip:12345", result.next()); } }