diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleLocationsCurrentWeatherRequester.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleLocationsCurrentWeatherRequester.java index cf428a6..0796908 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleLocationsCurrentWeatherRequester.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleLocationsCurrentWeatherRequester.java @@ -29,8 +29,8 @@ public interface MultipleLocationsCurrentWeatherRequester { MultipleResultCurrentWeatherRequestCustomizer byRectangle(CoordinateRectangle rectangle, int zoom); - MultipleResultCurrentWeatherRequestCustomizer byCitiesInCycle(Coordinate point); + MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer byCitiesInCycle(Coordinate point); - MultipleResultCurrentWeatherRequestCustomizer byCitiesInCycle(Coordinate point, int citiesCount); + MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer byCitiesInCycle(Coordinate point, int citiesCount); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleLocationsCurrentWeatherRequesterImpl.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleLocationsCurrentWeatherRequesterImpl.java index c76e930..d0b085c 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleLocationsCurrentWeatherRequesterImpl.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleLocationsCurrentWeatherRequesterImpl.java @@ -44,21 +44,21 @@ public class MultipleLocationsCurrentWeatherRequesterImpl implements MultipleLoc } @Override - public MultipleResultCurrentWeatherRequestCustomizer byCitiesInCycle(Coordinate point, int citiesCount) { + public MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer byCitiesInCycle(Coordinate point, int citiesCount) { urlBuilder.append("find"); urlBuilder.addRequestParameter("lat", Double.toString(point.getLatitude())); urlBuilder.addRequestParameter("lon", Double.toString(point.getLongitude())); urlBuilder.addRequestParameter("cnt", Integer.toString(citiesCount)); - return new MultipleResultCurrentWeatherRequestCustomizerImpl(urlBuilder); + return new MultipleResultCitiesInCircleCurrentWeatherRequestCustomizerImpl(urlBuilder); } @Override - public MultipleResultCurrentWeatherRequestCustomizer byCitiesInCycle(Coordinate point) { + public MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer byCitiesInCycle(Coordinate point) { urlBuilder.append("find"); urlBuilder.addRequestParameter("lat", Double.toString(point.getLatitude())); urlBuilder.addRequestParameter("lon", Double.toString(point.getLongitude())); - return new MultipleResultCurrentWeatherRequestCustomizerImpl(urlBuilder); + return new MultipleResultCitiesInCircleCurrentWeatherRequestCustomizerImpl(urlBuilder); } } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator.java new file mode 100644 index 0000000..5ddc02f --- /dev/null +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2021 Alexey Zinchenko + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.github.prominence.openweathermap.api.request.weather.multiple; + +import com.github.prominence.openweathermap.api.model.weather.Weather; +import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator; + +import java.util.List; +import java.util.concurrent.CompletableFuture; + +public interface MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator extends AsyncRequestTerminator, String> { + CompletableFuture asXML(); +} diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminatorImpl.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminatorImpl.java new file mode 100644 index 0000000..fadf1cb --- /dev/null +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminatorImpl.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2021 Alexey Zinchenko + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.github.prominence.openweathermap.api.request.weather.multiple; + +import com.github.prominence.openweathermap.api.enums.UnitSystem; +import com.github.prominence.openweathermap.api.model.weather.Weather; +import com.github.prominence.openweathermap.api.request.RequestUrlBuilder; +import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherResponseMapper; +import com.github.prominence.openweathermap.api.utils.RequestUtils; + +import java.util.List; +import java.util.concurrent.CompletableFuture; + +public class MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminatorImpl implements MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator { + + private final RequestUrlBuilder urlBuilder; + private final UnitSystem unitSystem; + + MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) { + this.urlBuilder = urlBuilder; + this.unitSystem = unitSystem; + } + + @Override + public CompletableFuture> asJava() { + return CompletableFuture.supplyAsync(() -> new CurrentWeatherResponseMapper(unitSystem).getList(getRawResponse())); + } + + @Override + public CompletableFuture asJSON() { + return CompletableFuture.supplyAsync(this::getRawResponse); + } + + @Override + public CompletableFuture asXML() { + urlBuilder.addRequestParameter("mode", "xml"); + return CompletableFuture.supplyAsync(this::getRawResponse); + } + + private String getRawResponse() { + return RequestUtils.getResponse(urlBuilder.buildUrl()); + } +} diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer.java new file mode 100644 index 0000000..35646d5 --- /dev/null +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2021 Alexey Zinchenko + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.github.prominence.openweathermap.api.request.weather.multiple; + +import com.github.prominence.openweathermap.api.request.RequestCustomizer; + +public interface MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer extends RequestCustomizer { + + MultipleResultCitiesInCircleCurrentWeatherRequestTerminator retrieve(); + + MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator retrieveAsync(); +} diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherRequestCustomizerImpl.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherRequestCustomizerImpl.java new file mode 100644 index 0000000..10f3939 --- /dev/null +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherRequestCustomizerImpl.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2021 Alexey Zinchenko + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.github.prominence.openweathermap.api.request.weather.multiple; + +import com.github.prominence.openweathermap.api.enums.Language; +import com.github.prominence.openweathermap.api.enums.UnitSystem; +import com.github.prominence.openweathermap.api.request.RequestUrlBuilder; + +public class MultipleResultCitiesInCircleCurrentWeatherRequestCustomizerImpl implements MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer { + + private final RequestUrlBuilder urlBuilder; + + private Language language; + private UnitSystem unitSystem = UnitSystem.STANDARD; + + MultipleResultCitiesInCircleCurrentWeatherRequestCustomizerImpl(RequestUrlBuilder urlBuilder) { + this.urlBuilder = urlBuilder; + } + + @Override + public MultipleResultCitiesInCircleCurrentWeatherRequestTerminator retrieve() { + urlBuilder.applyCustomization(language, unitSystem); + return new MultipleResultCitiesInCircleCurrentWeatherRequestTerminatorImpl(urlBuilder, unitSystem); + } + + @Override + public MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator retrieveAsync() { + urlBuilder.applyCustomization(language, unitSystem); + return new MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminatorImpl(urlBuilder, unitSystem); + } + + @Override + public MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer language(Language language) { + this.language = language; + return this; + } + + @Override + public MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer unitSystem(UnitSystem unitSystem) { + this.unitSystem = unitSystem; + return this; + } +} \ No newline at end of file diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/CurrentWeatherRequestTerminator.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherRequestTerminator.java similarity index 83% rename from src/main/java/com/github/prominence/openweathermap/api/request/weather/CurrentWeatherRequestTerminator.java rename to src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherRequestTerminator.java index 21c6bff..37a490f 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/CurrentWeatherRequestTerminator.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherRequestTerminator.java @@ -20,13 +20,13 @@ * SOFTWARE. */ -package com.github.prominence.openweathermap.api.request.weather; +package com.github.prominence.openweathermap.api.request.weather.multiple; +import com.github.prominence.openweathermap.api.model.weather.Weather; import com.github.prominence.openweathermap.api.request.RequestTerminator; -public interface CurrentWeatherRequestTerminator extends RequestTerminator { +import java.util.List; - S asXML(); - - S asHTML(); +public interface MultipleResultCitiesInCircleCurrentWeatherRequestTerminator extends RequestTerminator, String> { + String asXML(); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherRequestTerminatorImpl.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherRequestTerminatorImpl.java new file mode 100644 index 0000000..e2a1c2c --- /dev/null +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherRequestTerminatorImpl.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2021 Alexey Zinchenko + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.github.prominence.openweathermap.api.request.weather.multiple; + +import com.github.prominence.openweathermap.api.enums.UnitSystem; +import com.github.prominence.openweathermap.api.model.weather.Weather; +import com.github.prominence.openweathermap.api.request.RequestUrlBuilder; +import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherResponseMapper; +import com.github.prominence.openweathermap.api.utils.RequestUtils; + +import java.util.List; + +public class MultipleResultCitiesInCircleCurrentWeatherRequestTerminatorImpl implements MultipleResultCitiesInCircleCurrentWeatherRequestTerminator { + + private final RequestUrlBuilder urlBuilder; + private final UnitSystem unitSystem; + + MultipleResultCitiesInCircleCurrentWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) { + this.urlBuilder = urlBuilder; + this.unitSystem = unitSystem; + } + + @Override + public List asJava() { + return new CurrentWeatherResponseMapper(unitSystem).getList(getRawResponse()); + } + + @Override + public String asJSON() { + return getRawResponse(); + } + + @Override + public String asXML() { + urlBuilder.addRequestParameter("mode", "xml"); + return getRawResponse(); + } + + private String getRawResponse() { + return RequestUtils.getResponse(urlBuilder.buildUrl()); + } +} diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherAsyncRequestTerminator.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherAsyncRequestTerminator.java index e1c39ab..4db7c58 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherAsyncRequestTerminator.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherAsyncRequestTerminator.java @@ -23,10 +23,9 @@ package com.github.prominence.openweathermap.api.request.weather.multiple; import com.github.prominence.openweathermap.api.model.weather.Weather; -import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequestTerminator; +import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator; import java.util.List; -import java.util.concurrent.CompletableFuture; -public interface MultipleResultCurrentWeatherAsyncRequestTerminator extends CurrentWeatherRequestTerminator>, CompletableFuture> { +public interface MultipleResultCurrentWeatherAsyncRequestTerminator extends AsyncRequestTerminator, String> { } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherAsyncRequestTerminatorImpl.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherAsyncRequestTerminatorImpl.java index e071c0b..8edabef 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherAsyncRequestTerminatorImpl.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherAsyncRequestTerminatorImpl.java @@ -51,18 +51,6 @@ public class MultipleResultCurrentWeatherAsyncRequestTerminatorImpl implements M return CompletableFuture.supplyAsync(this::getRawResponse); } - @Override - public CompletableFuture asXML() { - urlBuilder.addRequestParameter("mode", "xml"); - return CompletableFuture.supplyAsync(this::getRawResponse); - } - - @Override - public CompletableFuture asHTML() { - urlBuilder.addRequestParameter("mode", "html"); - return CompletableFuture.supplyAsync(this::getRawResponse); - } - private String getRawResponse() { return RequestUtils.getResponse(urlBuilder.buildUrl()); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherRequestTerminator.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherRequestTerminator.java index 77eaa8b..bab9d52 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherRequestTerminator.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherRequestTerminator.java @@ -23,9 +23,9 @@ package com.github.prominence.openweathermap.api.request.weather.multiple; import com.github.prominence.openweathermap.api.model.weather.Weather; -import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequestTerminator; +import com.github.prominence.openweathermap.api.request.RequestTerminator; import java.util.List; -public interface MultipleResultCurrentWeatherRequestTerminator extends CurrentWeatherRequestTerminator, String> { +public interface MultipleResultCurrentWeatherRequestTerminator extends RequestTerminator, String> { } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherRequestTerminatorImpl.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherRequestTerminatorImpl.java index 852536e..a225467 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherRequestTerminatorImpl.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherRequestTerminatorImpl.java @@ -50,18 +50,6 @@ public class MultipleResultCurrentWeatherRequestTerminatorImpl implements Multip return getRawResponse(); } - @Override - public String asXML() { - urlBuilder.addRequestParameter("mode", "xml"); - return getRawResponse(); - } - - @Override - public String asHTML() { - urlBuilder.addRequestParameter("mode", "html"); - return getRawResponse(); - } - private String getRawResponse() { return RequestUtils.getResponse(urlBuilder.buildUrl()); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleLocationCurrentWeatherRequester.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleLocationCurrentWeatherRequester.java index 83c8600..5235322 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleLocationCurrentWeatherRequester.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleLocationCurrentWeatherRequester.java @@ -30,9 +30,13 @@ public interface SingleLocationCurrentWeatherRequester { SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName, String countryCode); + SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName, String stateCode, String countryCode); + SingleResultCurrentWeatherRequestCustomizer byCityId(long cityId); SingleResultCurrentWeatherRequestCustomizer byCoordinate(Coordinate coordinate); SingleResultCurrentWeatherRequestCustomizer byZipCodeAndCountry(String zipCode, String countryCode); + + SingleResultCurrentWeatherRequestCustomizer byZipCodeInUSA(String zipCode); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleLocationCurrentWeatherRequesterImpl.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleLocationCurrentWeatherRequesterImpl.java index acfcabf..8331a45 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleLocationCurrentWeatherRequesterImpl.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleLocationCurrentWeatherRequesterImpl.java @@ -44,6 +44,12 @@ public class SingleLocationCurrentWeatherRequesterImpl implements SingleLocation return new SingleResultCurrentWeatherRequestCustomizerImpl(urlBuilder); } + @Override + public SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName, String stateCode, String countryCode) { + urlBuilder.addRequestParameter("q", cityName + "," + stateCode + "," + countryCode); + return new SingleResultCurrentWeatherRequestCustomizerImpl(urlBuilder); + } + public SingleResultCurrentWeatherRequestCustomizer byCityId(long cityId) { urlBuilder.addRequestParameter("id", cityId); return new SingleResultCurrentWeatherRequestCustomizerImpl(urlBuilder); @@ -59,4 +65,10 @@ public class SingleLocationCurrentWeatherRequesterImpl implements SingleLocation urlBuilder.addRequestParameter("zip", zipCode + "," + countryCode); return new SingleResultCurrentWeatherRequestCustomizerImpl(urlBuilder); } + + @Override + public SingleResultCurrentWeatherRequestCustomizer byZipCodeInUSA(String zipCode) { + urlBuilder.addRequestParameter("zip", zipCode); + return new SingleResultCurrentWeatherRequestCustomizerImpl(urlBuilder); + } } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherAsyncRequestTerminator.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherAsyncRequestTerminator.java index fac39a9..d9ab9b1 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherAsyncRequestTerminator.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherAsyncRequestTerminator.java @@ -23,9 +23,12 @@ package com.github.prominence.openweathermap.api.request.weather.single; import com.github.prominence.openweathermap.api.model.weather.Weather; -import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequestTerminator; +import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator; import java.util.concurrent.CompletableFuture; -public interface SingleResultCurrentWeatherAsyncRequestTerminator extends CurrentWeatherRequestTerminator, CompletableFuture> { +public interface SingleResultCurrentWeatherAsyncRequestTerminator extends AsyncRequestTerminator { + CompletableFuture asXML(); + + CompletableFuture asHTML(); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherRequestTerminator.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherRequestTerminator.java index 4e738d4..7f89efc 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherRequestTerminator.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherRequestTerminator.java @@ -23,7 +23,10 @@ package com.github.prominence.openweathermap.api.request.weather.single; import com.github.prominence.openweathermap.api.model.weather.Weather; -import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequestTerminator; +import com.github.prominence.openweathermap.api.request.RequestTerminator; -public interface SingleResultCurrentWeatherRequestTerminator extends CurrentWeatherRequestTerminator { +public interface SingleResultCurrentWeatherRequestTerminator extends RequestTerminator { + String asXML(); + + String asHTML(); } diff --git a/src/test/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherIntegrationTest.java b/src/test/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherIntegrationTest.java index 41f17cd..67a5ea5 100644 --- a/src/test/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherIntegrationTest.java +++ b/src/test/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherIntegrationTest.java @@ -39,9 +39,8 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest { - @Test - public void whenGetMultipleCurrentWeatherByCoordinateRequestAsJava_thenReturnNotNull() { + public void whenGetMultipleCurrentWeatherByCoordinateRectangleRequestAsJava_thenReturnNotNull() { final List weatherList = getClient() .currentWeather() .multiple() @@ -52,40 +51,31 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest { .asJava(); Assert.assertNotNull(weatherList); - Assert.assertTrue(weatherList.size() > 0); - System.out.println(weatherList); + for (Weather weather : weatherList) { + Assert.assertNotNull(weather); + Assert.assertNotNull(weather.getState()); + Assert.assertNotNull(weather.getDescription()); + Assert.assertNotNull(weather.getRequestedOn()); + Assert.assertNotNull(weather.getTemperature()); + Assert.assertNotNull(weather.getLocation()); + Assert.assertNotNull(weather.getAtmosphericPressure()); + Assert.assertNotNull(weather.getHumidity()); + Assert.assertNotNull(weather.getWind()); + } } @Test - public void whenGetMultipleCurrentWeatherByCoordinateAndServerClusteringRequestAsJava_thenReturnNotNull() { - final List weatherList = getClient() + public void whenGetMultipleCurrentWeatherByCoordinateRectangleRequestAsJSON_thenReturnNotNull() { + final String weatherJson = getClient() .currentWeather() .multiple() .byRectangle(CoordinateRectangle.forValues(12, 32, 15, 37), 10) .language(Language.ROMANIAN) .unitSystem(UnitSystem.METRIC) .retrieve() - .asJava(); + .asJSON(); - Assert.assertNotNull(weatherList); - Assert.assertTrue(weatherList.size() > 0); - System.out.println(weatherList); - } - - @Test - public void whenGetMultipleCurrentWeatherByCitiesInCycleAndCountRequestAsJava_thenReturnNotNull() { - final List weatherList = getClient() - .currentWeather() - .multiple() - .byCitiesInCycle(Coordinate.forValues(55.5, 37.5), 10) - .language(Language.GERMAN) - .unitSystem(UnitSystem.IMPERIAL) - .retrieve() - .asJava(); - - Assert.assertNotNull(weatherList); - Assert.assertTrue(weatherList.size() > 0); - System.out.println(weatherList); + Assert.assertTrue(weatherJson.startsWith("{")); } @Test @@ -100,13 +90,78 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest { .asJava(); Assert.assertNotNull(weatherList); - Assert.assertTrue(weatherList.size() > 0); - System.out.println(weatherList); + for (Weather weather : weatherList) { + System.out.println(weather); + Assert.assertNotNull(weather); + Assert.assertNotNull(weather.getState()); + Assert.assertNotNull(weather.getDescription()); + Assert.assertNotNull(weather.getRequestedOn()); + Assert.assertNotNull(weather.getTemperature()); + Assert.assertNotNull(weather.getLocation()); + Assert.assertNotNull(weather.getAtmosphericPressure()); + Assert.assertNotNull(weather.getHumidity()); + Assert.assertNotNull(weather.getWind()); + } } @Test - public void whenGetMultipleCurrentWeatherByCitiesInCycleRequestAsJson_thenReturnNotNull() { - final String weather = getClient() + public void whenGetMultipleCurrentWeatherByCitiesInCycleRequestAsJSON_thenReturnNotNull() { + final String weatherJson = getClient() + .currentWeather() + .multiple() + .byCitiesInCycle(Coordinate.forValues(55.5, 37.5)) + .language(Language.GERMAN) + .unitSystem(UnitSystem.IMPERIAL) + .retrieve() + .asJSON(); + + Assert.assertTrue(weatherJson.startsWith("{")); + } + + @Test + public void whenGetMultipleCurrentWeatherByCitiesInCycleRequestAsXML_thenReturnNotNull() { + final String weatherXml = getClient() + .currentWeather() + .multiple() + .byCitiesInCycle(Coordinate.forValues(55.5, 37.5)) + .language(Language.GERMAN) + .unitSystem(UnitSystem.IMPERIAL) + .retrieve() + .asXML(); + + Assert.assertTrue(weatherXml.startsWith("<")); + System.out.println(weatherXml); + } + + @Test + public void whenGetMultipleCurrentWeatherByCitiesInCycleAndCountRequestAsJava_thenReturnNotNull() { + final List weatherList = getClient() + .currentWeather() + .multiple() + .byCitiesInCycle(Coordinate.forValues(55.5, 37.5), 10) + .language(Language.GERMAN) + .unitSystem(UnitSystem.IMPERIAL) + .retrieve() + .asJava(); + + Assert.assertNotNull(weatherList); + for (Weather weather : weatherList) { + System.out.println(weather); + Assert.assertNotNull(weather); + Assert.assertNotNull(weather.getState()); + Assert.assertNotNull(weather.getDescription()); + Assert.assertNotNull(weather.getRequestedOn()); + Assert.assertNotNull(weather.getTemperature()); + Assert.assertNotNull(weather.getLocation()); + Assert.assertNotNull(weather.getAtmosphericPressure()); + Assert.assertNotNull(weather.getHumidity()); + Assert.assertNotNull(weather.getWind()); + } + } + + @Test + public void whenGetMultipleCurrentWeatherByCitiesInCycleAndCountRequestAsJSON_thenReturnNotNull() { + final String weatherJson = getClient() .currentWeather() .multiple() .byCitiesInCycle(Coordinate.forValues(55.5, 37.5), 10) @@ -115,13 +170,12 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest { .retrieve() .asJSON(); - Assert.assertNotNull(weather); - System.out.println(weather); + Assert.assertTrue(weatherJson.startsWith("{")); } @Test - public void whenGetMultipleCurrentWeatherByCitiesInCycleRequestAsXml_thenReturnNotNull() { - final String weather = getClient() + public void whenGetMultipleCurrentWeatherByCitiesInCycleAndCountRequestAsXML_thenReturnNotNull() { + final String weatherXml = getClient() .currentWeather() .multiple() .byCitiesInCycle(Coordinate.forValues(55.5, 37.5), 10) @@ -130,27 +184,11 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest { .retrieve() .asXML(); - Assert.assertNotNull(weather); - System.out.println(weather); + Assert.assertTrue(weatherXml.startsWith("<")); } @Test - public void whenGetMultipleCurrentWeatherByCitiesInCycleRequestAsHtml_thenReturnNotNull() { - final String weather = getClient() - .currentWeather() - .multiple() - .byCitiesInCycle(Coordinate.forValues(55.5, 37.5), 10) - .language(Language.GERMAN) - .unitSystem(UnitSystem.IMPERIAL) - .retrieve() - .asHTML(); - - Assert.assertNotNull(weather); - System.out.println(weather); - } - - @Test - public void whenGetMultipleCurrentWeatherByCoordinateAndServerClusteringAsyncRequestAsJava_thenReturnNotNull() throws ExecutionException, InterruptedException { + public void whenGetMultipleCurrentWeatherByCoordinateAsyncRequestAsJava_thenReturnNotNull() throws ExecutionException, InterruptedException { final CompletableFuture> weatherListFuture = getClient() .currentWeather() .multiple() @@ -167,22 +205,7 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest { } @Test - public void whenGetMultipleCurrentWeatherByCoordinateAndServerClusteringAsyncRequestAsXml_thenReturnNotNull() throws ExecutionException, InterruptedException { - final CompletableFuture weatherFuture = getClient() - .currentWeather() - .multiple() - .byCitiesInCycle(Coordinate.forValues(55.5, 37.5), 10) - .language(Language.GERMAN) - .unitSystem(UnitSystem.IMPERIAL) - .retrieveAsync() - .asXML(); - - Assert.assertNotNull(weatherFuture); - System.out.println(weatherFuture.get()); - } - - @Test - public void whenGetMultipleCurrentWeatherByCoordinateAndServerClusteringAsyncRequestAsJson_thenReturnNotNull() throws ExecutionException, InterruptedException { + public void whenGetMultipleCurrentWeatherByCoordinateAsyncRequestAsJson_thenReturnNotNull() throws ExecutionException, InterruptedException { final CompletableFuture weatherFuture = getClient() .currentWeather() .multiple() @@ -196,21 +219,6 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest { System.out.println(weatherFuture.get()); } - @Test - public void whenGetMultipleCurrentWeatherByCoordinateAndServerClusteringAsyncRequestAsHtml_thenReturnNotNull() throws ExecutionException, InterruptedException { - final CompletableFuture weatherFuture = getClient() - .currentWeather() - .multiple() - .byCitiesInCycle(Coordinate.forValues(55.5, 37.5), 10) - .language(Language.GERMAN) - .unitSystem(UnitSystem.IMPERIAL) - .retrieveAsync() - .asHTML(); - - Assert.assertNotNull(weatherFuture); - System.out.println(weatherFuture.get()); - } - @Test(expected = InvalidAuthTokenException.class) public void whenRequestCurrentWeatherWithInvalidApiKey_thenThrowAnException() { OpenWeatherMapClient client = new OpenWeatherMapClient("invalidKey"); diff --git a/src/test/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherIntegrationTest.java b/src/test/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherIntegrationTest.java index d7e088d..46249c3 100644 --- a/src/test/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherIntegrationTest.java +++ b/src/test/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherIntegrationTest.java @@ -37,21 +37,201 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; public class SingleResultCurrentWeatherIntegrationTest extends ApiTest { - @Test - public void whenGetSingleCurrentWeatherByCoordinateRequestAsJava_thenReturnNotNull() { + public void whenGetSingleCurrentWeatherByCityNameRequestAsJava_thenReturnNotNull() { final Weather weather = getClient() .currentWeather() .single() - .byCoordinate(Coordinate.forValues(5, 5)) + .byCityName("Minsk") + .language(Language.RUSSIAN) .unitSystem(UnitSystem.METRIC) .retrieve() .asJava(); Assert.assertNotNull(weather); + Assert.assertNotNull(weather.getState()); + Assert.assertNotNull(weather.getDescription()); + Assert.assertNotNull(weather.getRequestedOn()); + Assert.assertNotNull(weather.getTemperature()); + Assert.assertNotNull(weather.getLocation()); + Assert.assertNotNull(weather.getAtmosphericPressure()); + Assert.assertNotNull(weather.getHumidity()); + Assert.assertNotNull(weather.getWind()); System.out.println(weather); } + @Test + public void whenGetSingleCurrentWeatherByCityNameRequestAsJSON_thenReturnNotNull() { + final String weatherJson = getClient() + .currentWeather() + .single() + .byCityName("Minsk") + .language(Language.RUSSIAN) + .unitSystem(UnitSystem.IMPERIAL) + .retrieve() + .asJSON(); + + Assert.assertTrue(weatherJson.startsWith("{")); + } + + @Test + public void whenGetSingleCurrentWeatherByCityNameRequestAsXML_thenReturnNotNull() { + final String weatherXml = getClient() + .currentWeather() + .single() + .byCityName("Minsk") + .language(Language.RUSSIAN) + .unitSystem(UnitSystem.STANDARD) + .retrieve() + .asXML(); + + Assert.assertTrue(weatherXml.startsWith("<")); + } + + @Test + public void whenGetSingleCurrentWeatherByCityNameRequestAsHTML_thenReturnNotNull() { + final String weatherHtml = getClient() + .currentWeather() + .single() + .byCityName("Minsk") + .language(Language.RUSSIAN) + .unitSystem(UnitSystem.METRIC) + .retrieve() + .asHTML(); + + Assert.assertTrue(weatherHtml.startsWith("<")); + } + + @Test + public void whenGetSingleCurrentWeatherByCityNameAndCountryCodeRequestAsJava_thenReturnNotNull() { + final Weather weather = getClient() + .currentWeather() + .single() + .byCityName("Minsk", "BY") + .language(Language.RUSSIAN) + .unitSystem(UnitSystem.METRIC) + .retrieve() + .asJava(); + + Assert.assertNotNull(weather); + Assert.assertNotNull(weather.getState()); + Assert.assertNotNull(weather.getDescription()); + Assert.assertNotNull(weather.getRequestedOn()); + Assert.assertNotNull(weather.getTemperature()); + Assert.assertNotNull(weather.getLocation()); + Assert.assertNotNull(weather.getAtmosphericPressure()); + Assert.assertNotNull(weather.getHumidity()); + Assert.assertNotNull(weather.getWind()); + System.out.println(weather); + } + + @Test + public void whenGetSingleCurrentWeatherByCityNameAndCountryCodeRequestAsJSON_thenReturnNotNull() { + final String weatherJson = getClient() + .currentWeather() + .single() + .byCityName("Minsk", "by") + .language(Language.RUSSIAN) + .unitSystem(UnitSystem.METRIC) + .retrieve() + .asJSON(); + + Assert.assertTrue(weatherJson.startsWith("{")); + } + + @Test + public void whenGetSingleCurrentWeatherByCityNameAndCountryCodeRequestAsXML_thenReturnNotNull() { + final String weatherXml = getClient() + .currentWeather() + .single() + .byCityName("Minsk", "by") + .language(Language.RUSSIAN) + .unitSystem(UnitSystem.METRIC) + .retrieve() + .asXML(); + + Assert.assertTrue(weatherXml.startsWith("<")); + } + + @Test + public void whenGetSingleCurrentWeatherByCityNameAndCountryCodeRequestAsHTML_thenReturnNotNull() { + final String weatherHtml = getClient() + .currentWeather() + .single() + .byCityName("Minsk", "by") + .language(Language.RUSSIAN) + .unitSystem(UnitSystem.STANDARD) + .retrieve() + .asHTML(); + + Assert.assertTrue(weatherHtml.startsWith("<")); + } + + @Test + public void whenGetSingleCurrentWeatherByCityNameAndStateCodeAndCountryCodeRequestAsJava_thenReturnNotNull() { + final Weather weather = getClient() + .currentWeather() + .single() + .byCityName("New York", "ny", "us") + .language(Language.SLOVAK) + .unitSystem(UnitSystem.METRIC) + .retrieve() + .asJava(); + + Assert.assertNotNull(weather); + Assert.assertNotNull(weather.getState()); + Assert.assertNotNull(weather.getDescription()); + Assert.assertNotNull(weather.getRequestedOn()); + Assert.assertNotNull(weather.getTemperature()); + Assert.assertNotNull(weather.getLocation()); + Assert.assertNotNull(weather.getAtmosphericPressure()); + Assert.assertNotNull(weather.getHumidity()); + Assert.assertNotNull(weather.getWind()); + System.out.println(weather); + } + + @Test + public void whenGetSingleCurrentWeatherByCityNameAndStateCodeAndCountryCodeRequestAsJSON_thenReturnNotNull() { + final String weatherJson = getClient() + .currentWeather() + .single() + .byCityName("New York", "ny", "us") + .language(Language.HUNGARIAN) + .unitSystem(UnitSystem.IMPERIAL) + .retrieve() + .asJSON(); + + Assert.assertTrue(weatherJson.startsWith("{")); + } + + @Test + public void whenGetSingleCurrentWeatherByCityNameAndStateCodeAndCountryCodeRequestAsXML_thenReturnNotNull() { + final String weatherXml = getClient() + .currentWeather() + .single() + .byCityName("New York", "ny", "us") + .language(Language.ROMANIAN) + .unitSystem(UnitSystem.METRIC) + .retrieve() + .asXML(); + + Assert.assertTrue(weatherXml.startsWith("<")); + } + + @Test + public void whenGetSingleCurrentWeatherByCityNameAndStateCodeAndCountryCodeRequestAsHTML_thenReturnNotNull() { + final String weatherHtml = getClient() + .currentWeather() + .single() + .byCityName("New York", "ny", "us") + .language(Language.ARABIC) + .unitSystem(UnitSystem.METRIC) + .retrieve() + .asHTML(); + + Assert.assertTrue(weatherHtml.startsWith("<")); + } + @Test public void whenGetSingleCurrentWeatherByCityIdRequestAsJava_thenReturnNotNull() { final Weather weather = getClient() @@ -63,37 +243,115 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest { .asJava(); Assert.assertNotNull(weather); + Assert.assertNotNull(weather.getState()); + Assert.assertNotNull(weather.getDescription()); + Assert.assertNotNull(weather.getRequestedOn()); + Assert.assertNotNull(weather.getTemperature()); + Assert.assertNotNull(weather.getLocation()); + Assert.assertNotNull(weather.getAtmosphericPressure()); + Assert.assertNotNull(weather.getHumidity()); + Assert.assertNotNull(weather.getWind()); System.out.println(weather); } @Test - public void whenGetSingleCurrentWeatherByCityNameRequestAsJava_thenReturnNotNull() { + public void whenGetSingleCurrentWeatherByCityIdRequestAsJSON_thenReturnNotNull() { + final String weatherJson = getClient() + .currentWeather() + .single() + .byCityId(350001514) + .language(Language.GERMAN) + .retrieve() + .asJSON(); + + Assert.assertTrue(weatherJson.startsWith("{")); + } + + @Test + public void whenGetSingleCurrentWeatherByCityIdRequestAsXML_thenReturnNotNull() { + final String weatherXml = getClient() + .currentWeather() + .single() + .byCityId(350001514) + .language(Language.GERMAN) + .retrieve() + .asXML(); + + Assert.assertTrue(weatherXml.startsWith("<")); + } + + @Test + public void whenGetSingleCurrentWeatherByCityIdRequestAsHTML_thenReturnNotNull() { + final String weatherHtml = getClient() + .currentWeather() + .single() + .byCityId(350001514) + .language(Language.GERMAN) + .retrieve() + .asXML(); + + Assert.assertTrue(weatherHtml.startsWith("<")); + } + + @Test + public void whenGetSingleCurrentWeatherByCoordinateRequestAsJava_thenReturnNotNull() { final Weather weather = getClient() .currentWeather() .single() - .byCityName("Minsk") - .language(Language.RUSSIAN) + .byCoordinate(Coordinate.forValues(5, 5)) .unitSystem(UnitSystem.METRIC) .retrieve() .asJava(); Assert.assertNotNull(weather); + Assert.assertNotNull(weather.getState()); + Assert.assertNotNull(weather.getDescription()); + Assert.assertNotNull(weather.getRequestedOn()); + Assert.assertNotNull(weather.getTemperature()); + Assert.assertNotNull(weather.getLocation()); + Assert.assertNotNull(weather.getAtmosphericPressure()); + Assert.assertNotNull(weather.getHumidity()); + Assert.assertNotNull(weather.getWind()); System.out.println(weather); } @Test - public void whenGetSingleCurrentWeatherByCityNameAndCountryCodeRequestAsJava_thenReturnNotNull() { - final Weather weather = getClient() + public void whenGetSingleCurrentWeatherByCoordinateRequestAsJSON_thenReturnNotNull() { + final String weatherJson = getClient() .currentWeather() .single() - .byCityName("Moscow", "ru") - .language(Language.RUSSIAN) + .byCoordinate(Coordinate.forValues(5, 5)) .unitSystem(UnitSystem.METRIC) .retrieve() - .asJava(); + .asJSON(); - Assert.assertNotNull(weather); - System.out.println(weather); + Assert.assertTrue(weatherJson.startsWith("{")); + } + + @Test + public void whenGetSingleCurrentWeatherByCoordinateRequestAsXML_thenReturnNotNull() { + final String weatherXml = getClient() + .currentWeather() + .single() + .byCoordinate(Coordinate.forValues(5, 5)) + .unitSystem(UnitSystem.METRIC) + .retrieve() + .asXML(); + + Assert.assertTrue(weatherXml.startsWith("<")); + } + + @Test + public void whenGetSingleCurrentWeatherByCoordinateRequestAsHTML_thenReturnNotNull() { + final String weatherHtml = getClient() + .currentWeather() + .single() + .byCoordinate(Coordinate.forValues(5, 5)) + .unitSystem(UnitSystem.METRIC) + .retrieve() + .asHTML(); + + Assert.assertTrue(weatherHtml.startsWith("<")); } @Test @@ -102,73 +360,128 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest { .currentWeather() .single() .byZipCodeAndCountry("220015", "by") - .language(Language.RUSSIAN) + .language(Language.ENGLISH) .unitSystem(UnitSystem.METRIC) .retrieve() .asJava(); Assert.assertNotNull(weather); + Assert.assertNotNull(weather.getState()); + Assert.assertNotNull(weather.getDescription()); + Assert.assertNotNull(weather.getRequestedOn()); + Assert.assertNotNull(weather.getTemperature()); + Assert.assertNotNull(weather.getLocation()); + Assert.assertNotNull(weather.getAtmosphericPressure()); + Assert.assertNotNull(weather.getHumidity()); + Assert.assertNotNull(weather.getWind()); System.out.println(weather); } @Test - public void whenGetAnySingleCurrentRequestWeatherAsJson_thenReturnNotNull() { + public void whenGetSingleCurrentWeatherByZipCodeAndCountryRequestAsJSON_thenReturnNotNull() { final String weatherJson = getClient() .currentWeather() .single() .byZipCodeAndCountry("220015", "by") - .language(Language.RUSSIAN) + .language(Language.ENGLISH) .unitSystem(UnitSystem.METRIC) .retrieve() .asJSON(); - Assert.assertNotNull(weatherJson); - System.out.println(weatherJson); + Assert.assertTrue(weatherJson.startsWith("{")); } @Test - public void whenGetAnySingleCurrentRequestWeatherAsXml_thenReturnNotNull() { + public void whenGetSingleCurrentWeatherByZipCodeAndCountryRequestAsXML_thenReturnNotNull() { final String weatherXml = getClient() .currentWeather() .single() .byZipCodeAndCountry("220015", "by") - .language(Language.RUSSIAN) + .language(Language.ENGLISH) .unitSystem(UnitSystem.METRIC) .retrieve() .asXML(); - Assert.assertNotNull(weatherXml); - System.out.println(weatherXml); + Assert.assertTrue(weatherXml.startsWith("<")); } @Test - public void whenGetAnySingleCurrentWeatherRequestAsHtml_thenReturnNotNull() { + public void whenGetSingleCurrentWeatherByZipCodeAndCountryRequestAsHTML_thenReturnNotNull() { final String weatherHtml = getClient() .currentWeather() .single() .byZipCodeAndCountry("220015", "by") - .language(Language.RUSSIAN) + .language(Language.ENGLISH) .unitSystem(UnitSystem.METRIC) .retrieve() .asHTML(); - Assert.assertNotNull(weatherHtml); - System.out.println(weatherHtml); + Assert.assertTrue(weatherHtml.startsWith("<")); } @Test - public void whenGetAnySingleCurrentWeatherAsyncRequestAsXml_thenReturnNotNull() throws ExecutionException, InterruptedException { - final CompletableFuture weatherXmlFuture = getClient() + public void whenGetSingleCurrentWeatherByZipCodeInUSARequestAsJava_thenReturnNotNull() { + final Weather weather = getClient() .currentWeather() .single() - .byZipCodeAndCountry("220015", "by") - .language(Language.RUSSIAN) + .byZipCodeInUSA("10006") + .language(Language.ENGLISH) .unitSystem(UnitSystem.METRIC) - .retrieveAsync() + .retrieve() + .asJava(); + + Assert.assertNotNull(weather); + Assert.assertNotNull(weather.getState()); + Assert.assertNotNull(weather.getDescription()); + Assert.assertNotNull(weather.getRequestedOn()); + Assert.assertNotNull(weather.getTemperature()); + Assert.assertNotNull(weather.getLocation()); + Assert.assertNotNull(weather.getAtmosphericPressure()); + Assert.assertNotNull(weather.getHumidity()); + Assert.assertNotNull(weather.getWind()); + System.out.println(weather); + } + + @Test + public void whenGetSingleCurrentWeatherByZipCodeInUSARequestAsJSON_thenReturnNotNull() { + final String weatherJson = getClient() + .currentWeather() + .single() + .byZipCodeInUSA("10006") + .language(Language.ENGLISH) + .unitSystem(UnitSystem.METRIC) + .retrieve() + .asJSON(); + + Assert.assertTrue(weatherJson.startsWith("{")); + } + + @Test + public void whenGetSingleCurrentWeatherByZipCodeInUSARequestAsXML_thenReturnNotNull() { + final String weatherXml = getClient() + .currentWeather() + .single() + .byZipCodeInUSA("10006") + .language(Language.ENGLISH) + .unitSystem(UnitSystem.METRIC) + .retrieve() .asXML(); - Assert.assertNotNull(weatherXmlFuture); - System.out.println(weatherXmlFuture.get()); + Assert.assertTrue(weatherXml.startsWith("<")); + } + + @Test + public void whenGetSingleCurrentWeatherByZipCodeInUSARequestAsHTML_thenReturnNotNull() { + final String weatherHtml = getClient() + .currentWeather() + .single() + .byZipCodeInUSA("10006") + .language(Language.ENGLISH) + .unitSystem(UnitSystem.METRIC) + .retrieve() + .asHTML(); + + Assert.assertTrue(weatherHtml.startsWith("<")); } @Test @@ -201,6 +514,21 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest { System.out.println(weatherFuture.get()); } + @Test + public void whenGetAnySingleCurrentWeatherAsyncRequestAsXml_thenReturnNotNull() throws ExecutionException, InterruptedException { + final CompletableFuture weatherXmlFuture = getClient() + .currentWeather() + .single() + .byZipCodeAndCountry("220015", "by") + .language(Language.RUSSIAN) + .unitSystem(UnitSystem.METRIC) + .retrieveAsync() + .asXML(); + + Assert.assertNotNull(weatherXmlFuture); + System.out.println(weatherXmlFuture.get()); + } + @Test public void whenGetAnySingleCurrentWeatherAsyncRequestAsHtml_thenReturnNotNull() throws ExecutionException, InterruptedException { final CompletableFuture weatherFuture = getClient()