Updated Branches: refs/heads/master ea902873b -> f8753c84a
Added producer to camel-weather Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f8753c84 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f8753c84 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f8753c84 Branch: refs/heads/master Commit: f8753c84aab15d47435bc0a04917dd6dda19d59c Parents: ea90287 Author: Claus Ibsen <[email protected]> Authored: Thu Jun 6 11:29:01 2013 +0200 Committer: Claus Ibsen <[email protected]> Committed: Thu Jun 6 11:29:01 2013 +0200 ---------------------------------------------------------------------- .../component/weather/WeatherConfiguration.java | 6 ++-- .../weather/CurrentWeatherMadridProducerTest.java | 19 +++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/f8753c84/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 f0d6499..52d3473 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 @@ -92,8 +92,8 @@ public class WeatherConfiguration { public String getQuery(String location) throws Exception { String answer = "http://api.openweathermap.org/data/2.5/"; - if (isEmpty(location)) { - location = getGeoLocation(); + if (isEmpty(location) || "current".equals(location)) { + location = getCurrentGeoLocation(); } else { // assuming the location is a town or country location = "q=" + location; @@ -118,7 +118,7 @@ public class WeatherConfiguration { return answer; } - private String getGeoLocation() throws Exception { + private String getCurrentGeoLocation() throws Exception { String geoLocation = component.getCamelContext().getTypeConverter().mandatoryConvertTo(String.class, new URL("http://freegeoip.net/json/")); if (isEmpty(geoLocation)) { throw new IllegalStateException("Got the unexpected value '" + geoLocation + "' for the geolocation"); http://git-wip-us.apache.org/repos/asf/camel/blob/f8753c84/components/camel-weather/src/test/java/org/apache/camel/component/weather/CurrentWeatherMadridProducerTest.java ---------------------------------------------------------------------- diff --git a/components/camel-weather/src/test/java/org/apache/camel/component/weather/CurrentWeatherMadridProducerTest.java b/components/camel-weather/src/test/java/org/apache/camel/component/weather/CurrentWeatherMadridProducerTest.java index ec17d00..9592513 100644 --- a/components/camel-weather/src/test/java/org/apache/camel/component/weather/CurrentWeatherMadridProducerTest.java +++ b/components/camel-weather/src/test/java/org/apache/camel/component/weather/CurrentWeatherMadridProducerTest.java @@ -62,6 +62,25 @@ public class CurrentWeatherMadridProducerTest extends BaseWeatherConsumerTest { checkWeatherContent(weather); } + @Test + public void testHeaderOverrideCurrent() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + // as the default delay option is one hour long, we expect exactly one message exchange + mock.expectedMessageCount(1); + + template.sendBodyAndHeader("direct:start", "Hello World", WeatherConstants.WEATHER_LOCATION, "current"); + + mock.assertIsSatisfied(); + + Exchange exchange = mock.getExchanges().get(0); + assertNotNull(exchange); + Message in = exchange.getIn(); + assertNotNull(in); + String weather = assertIsInstanceOf(String.class, in.getBody()); + + checkWeatherContent(weather); + } + @Override protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() {
