Rechecked all tests. Fixed API customization possibilities.

This commit is contained in:
Alexey Zinchenko 2021-03-24 01:32:49 +03:00
parent ef138d3bfe
commit a0e289cc2c
18 changed files with 746 additions and 160 deletions

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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<List<Weather>, String> {
CompletableFuture<String> asXML();
}

View File

@ -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<List<Weather>> asJava() {
return CompletableFuture.supplyAsync(() -> new CurrentWeatherResponseMapper(unitSystem).getList(getRawResponse()));
}
@Override
public CompletableFuture<String> asJSON() {
return CompletableFuture.supplyAsync(this::getRawResponse);
}
@Override
public CompletableFuture<String> asXML() {
urlBuilder.addRequestParameter("mode", "xml");
return CompletableFuture.supplyAsync(this::getRawResponse);
}
private String getRawResponse() {
return RequestUtils.getResponse(urlBuilder.buildUrl());
}
}

View File

@ -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<MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer> {
MultipleResultCitiesInCircleCurrentWeatherRequestTerminator retrieve();
MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator retrieveAsync();
}

View File

@ -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;
}
}

View File

@ -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<T, S> extends RequestTerminator<T, S> {
import java.util.List;
S asXML();
S asHTML();
public interface MultipleResultCitiesInCircleCurrentWeatherRequestTerminator extends RequestTerminator<List<Weather>, String> {
String asXML();
}

View File

@ -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<Weather> 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());
}
}

View File

@ -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<List<Weather>>, CompletableFuture<String>> {
public interface MultipleResultCurrentWeatherAsyncRequestTerminator extends AsyncRequestTerminator<List<Weather>, String> {
}

View File

@ -51,18 +51,6 @@ public class MultipleResultCurrentWeatherAsyncRequestTerminatorImpl implements M
return CompletableFuture.supplyAsync(this::getRawResponse);
}
@Override
public CompletableFuture<String> asXML() {
urlBuilder.addRequestParameter("mode", "xml");
return CompletableFuture.supplyAsync(this::getRawResponse);
}
@Override
public CompletableFuture<String> asHTML() {
urlBuilder.addRequestParameter("mode", "html");
return CompletableFuture.supplyAsync(this::getRawResponse);
}
private String getRawResponse() {
return RequestUtils.getResponse(urlBuilder.buildUrl());
}

View File

@ -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<List<Weather>, String> {
public interface MultipleResultCurrentWeatherRequestTerminator extends RequestTerminator<List<Weather>, String> {
}

View File

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

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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<Weather>, CompletableFuture<String>> {
public interface SingleResultCurrentWeatherAsyncRequestTerminator extends AsyncRequestTerminator<Weather, String> {
CompletableFuture<String> asXML();
CompletableFuture<String> asHTML();
}

View File

@ -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<Weather, String> {
public interface SingleResultCurrentWeatherRequestTerminator extends RequestTerminator<Weather, String> {
String asXML();
String asHTML();
}

View File

@ -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<Weather> 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<Weather> 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<Weather> 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<Weather> 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<List<Weather>> weatherListFuture = getClient()
.currentWeather()
.multiple()
@ -167,22 +205,7 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
}
@Test
public void whenGetMultipleCurrentWeatherByCoordinateAndServerClusteringAsyncRequestAsXml_thenReturnNotNull() throws ExecutionException, InterruptedException {
final CompletableFuture<String> 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<String> 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<String> 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");

View File

@ -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<String> 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<String> 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<String> weatherFuture = getClient()