INTSAMPLES-19 Change Return Type to List<> from Array

This commit is contained in:
Gary Russell
2011-02-02 08:18:21 -05:00
parent bfb4f0c4aa
commit 76094d2fab
5 changed files with 21 additions and 16 deletions

View File

@@ -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.
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.

View File

@@ -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<String> result = weatherAndTraffic.getByZip(zip);
System.out.println(result.get(0) + "\r\n" + result.get(1) + "\r\n");
context.close();
System.exit(0);
}

View File

@@ -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<String> getByZip(String zip);
}

View File

@@ -38,7 +38,7 @@
<channel id="aggregatorChannel" />
<aggregator input-channel="aggregatorChannel"
expression="#this.![payload].toArray()"/>
expression="#this.![payload]"/>
<task:executor id="executor" pool-size="10"/>

View File

@@ -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<String> list = new ArrayList<String>();
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<String> results = weatherAndTraffic.getByZip("12345");
assertEquals(2, results.size());
Collections.sort(results);
Iterator<String> result = results.iterator();
assertEquals("Dummy traffic for zip:12345", result.next());
assertEquals("Dummy weather for zip:12345", result.next());
}
}