CAMEL-9273:Support all free api methods (solved ids problem)
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2f3392df Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2f3392df Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2f3392df Branch: refs/heads/master Commit: 2f3392df44ecb0bdc79e76c6b3722fd148b1aed7 Parents: cd6c3d7 Author: Arno Noordover <a...@noordover.net> Authored: Mon May 23 22:46:54 2016 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Wed May 25 16:54:34 2016 +0200 ---------------------------------------------------------------------- .../camel/component/weather/WeatherComponent.java | 8 ++++++++ .../component/weather/WeatherConfiguration.java | 17 ++++++++++++++++- .../weather/CurrentWeatherConsumerXmlTest.java | 2 +- .../camel/component/weather/WeatherQueryTest.java | 15 +++++---------- 4 files changed, 30 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/2f3392df/components/camel-weather/src/main/java/org/apache/camel/component/weather/WeatherComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-weather/src/main/java/org/apache/camel/component/weather/WeatherComponent.java b/components/camel-weather/src/main/java/org/apache/camel/component/weather/WeatherComponent.java index 557af0f..884a16a 100644 --- a/components/camel-weather/src/main/java/org/apache/camel/component/weather/WeatherComponent.java +++ b/components/camel-weather/src/main/java/org/apache/camel/component/weather/WeatherComponent.java @@ -16,6 +16,7 @@ */ package org.apache.camel.component.weather; +import java.util.Iterator; import java.util.Map; import org.apache.camel.CamelContext; @@ -51,6 +52,13 @@ public class WeatherComponent extends UriEndpointComponent { protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { WeatherConfiguration configuration = new WeatherConfiguration(this); + String ids = getAndRemoveParameter(parameters, "ids", String.class); + Iterator<?> it = ObjectHelper.createIterator(ids); + while (it.hasNext()) { + String id = (String) it.next(); + configuration.addId(id); + } + // and then override from parameters setProperties(configuration, parameters); http://git-wip-us.apache.org/repos/asf/camel/blob/2f3392df/components/camel-weather/src/main/java/org/apache/camel/component/weather/WeatherConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-weather/src/main/java/org/apache/camel/component/weather/WeatherConfiguration.java b/components/camel-weather/src/main/java/org/apache/camel/component/weather/WeatherConfiguration.java index df8f9df..9613c1f 100644 --- a/components/camel-weather/src/main/java/org/apache/camel/component/weather/WeatherConfiguration.java +++ b/components/camel-weather/src/main/java/org/apache/camel/component/weather/WeatherConfiguration.java @@ -16,6 +16,8 @@ */ package org.apache.camel.component.weather; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Scanner; @@ -364,7 +366,20 @@ public class WeatherConfiguration { } public List<String> getIds() { - return ids; + return (List<String>) ids; + } + + public void addId(String id) { + if (ids == null) { + ids = new ArrayList<>(); + } + ids.add(id); + } + /** + * List of id's of city/stations + */ + public void setIds(String... ids) { + this.ids = Arrays.asList(ids); } /** http://git-wip-us.apache.org/repos/asf/camel/blob/2f3392df/components/camel-weather/src/test/java/org/apache/camel/component/weather/CurrentWeatherConsumerXmlTest.java ---------------------------------------------------------------------- diff --git a/components/camel-weather/src/test/java/org/apache/camel/component/weather/CurrentWeatherConsumerXmlTest.java b/components/camel-weather/src/test/java/org/apache/camel/component/weather/CurrentWeatherConsumerXmlTest.java index 4798d18..7e6976b 100644 --- a/components/camel-weather/src/test/java/org/apache/camel/component/weather/CurrentWeatherConsumerXmlTest.java +++ b/components/camel-weather/src/test/java/org/apache/camel/component/weather/CurrentWeatherConsumerXmlTest.java @@ -33,7 +33,7 @@ public class CurrentWeatherConsumerXmlTest extends BaseWeatherConsumerTest { return new RouteBuilder() { @Override public void configure() throws Exception { - from("weather:foo?mode=XML&appid=9162755b2efa555823cfe0451d7fff38").to("mock:result"); + from("weather:foo?mode=XML&appid=9162755b2efa555823cfe0451d7fff38&ids=2747373").to("mock:result"); } }; } http://git-wip-us.apache.org/repos/asf/camel/blob/2f3392df/components/camel-weather/src/test/java/org/apache/camel/component/weather/WeatherQueryTest.java ---------------------------------------------------------------------- diff --git a/components/camel-weather/src/test/java/org/apache/camel/component/weather/WeatherQueryTest.java b/components/camel-weather/src/test/java/org/apache/camel/component/weather/WeatherQueryTest.java index af9dcec..910f5f8 100644 --- a/components/camel-weather/src/test/java/org/apache/camel/component/weather/WeatherQueryTest.java +++ b/components/camel-weather/src/test/java/org/apache/camel/component/weather/WeatherQueryTest.java @@ -113,8 +113,7 @@ public class WeatherQueryTest { @Test public void testSingleIdQuery() throws Exception { WeatherConfiguration weatherConfiguration = new WeatherConfiguration(new WeatherComponent()); - List<String> ids = Arrays.asList("524901"); - weatherConfiguration.setIds(ids); + weatherConfiguration.setIds("524901"); weatherConfiguration.setMode(WeatherMode.XML); weatherConfiguration.setLanguage(WeatherLanguage.nl); weatherConfiguration.setAppid(APPID); @@ -127,8 +126,7 @@ public class WeatherQueryTest { @Test public void testSingleIdDailyForecastQuery() throws Exception { WeatherConfiguration weatherConfiguration = new WeatherConfiguration(new WeatherComponent()); - List<String> ids = Arrays.asList("524901"); - weatherConfiguration.setIds(ids); + weatherConfiguration.setIds("524901"); weatherConfiguration.setMode(WeatherMode.XML); weatherConfiguration.setLanguage(WeatherLanguage.nl); weatherConfiguration.setAppid(APPID); @@ -142,8 +140,7 @@ public class WeatherQueryTest { @Test public void testSingleIdHourlyForecastQuery() throws Exception { WeatherConfiguration weatherConfiguration = new WeatherConfiguration(new WeatherComponent()); - List<String> ids = Arrays.asList("524901"); - weatherConfiguration.setIds(ids); + weatherConfiguration.setIds("524901"); weatherConfiguration.setMode(WeatherMode.XML); weatherConfiguration.setLanguage(WeatherLanguage.nl); weatherConfiguration.setAppid(APPID); @@ -158,8 +155,7 @@ public class WeatherQueryTest { @Test public void testSingleIdStationQuery() throws Exception { WeatherConfiguration weatherConfiguration = new WeatherConfiguration(new WeatherComponent()); - List<String> ids = Arrays.asList("52"); - weatherConfiguration.setIds(ids); + weatherConfiguration.setIds("52"); weatherConfiguration.setMode(WeatherMode.JSON); weatherConfiguration.setLanguage(WeatherLanguage.nl); weatherConfiguration.setAppid(APPID); @@ -173,8 +169,7 @@ public class WeatherQueryTest { @Test public void testMultiIdQuery() throws Exception { WeatherConfiguration weatherConfiguration = new WeatherConfiguration(new WeatherComponent()); - List<String> ids = Arrays.asList("524901", "703448"); - weatherConfiguration.setIds(ids); + weatherConfiguration.setIds("524901", "703448"); weatherConfiguration.setMode(WeatherMode.JSON); weatherConfiguration.setLanguage(WeatherLanguage.nl); weatherConfiguration.setAppid(APPID);