mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-07-04 03:36:44 +03:00
Releasing 2.2.0 version.
This commit is contained in:
+208
@@ -0,0 +1,208 @@
|
||||
/*
|
||||
*
|
||||
* * 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.air.pollution;
|
||||
|
||||
import com.github.prominence.openweathermap.api.ApiTest;
|
||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
public class AirPollutionIntegrationTest extends ApiTest {
|
||||
@Test
|
||||
public void whenRetrieveCurrentAirPollutionResponseAsJava_thenOk() {
|
||||
final AirPollutionDetails airPollutionDetails = getClient()
|
||||
.airPollution()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
assertNotNull(airPollutionDetails);
|
||||
airPollutionDetails.getAirPollutionRecords().forEach(airPollutionRecord -> {
|
||||
assertNotNull(airPollutionRecord);
|
||||
System.out.println(airPollutionRecord);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveCurrentAirPollutionResponseAsJSON_thenOk() {
|
||||
final String jsonString = getClient()
|
||||
.airPollution()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
assertNotNull(jsonString);
|
||||
System.out.println(jsonString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveCurrentAirPollutionAsyncResponseAsJava_thenOk() throws ExecutionException, InterruptedException {
|
||||
final CompletableFuture<AirPollutionDetails> pollutionDetailsFuture = getClient()
|
||||
.airPollution()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.retrieveAsync()
|
||||
.asJava();
|
||||
|
||||
assertNotNull(pollutionDetailsFuture);
|
||||
assertNotNull(pollutionDetailsFuture.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveCurrentAirPollutionAsyncResponseAsJSON_thenOk() throws ExecutionException, InterruptedException {
|
||||
final CompletableFuture<String> jsonStringFuture = getClient()
|
||||
.airPollution()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.retrieveAsync()
|
||||
.asJSON();
|
||||
|
||||
assertNotNull(jsonStringFuture);
|
||||
final String jsonString = jsonStringFuture.get();
|
||||
assertNotNull(jsonString);
|
||||
System.out.println(jsonString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveForecastAirPollutionResponseAsJava_thenOk() {
|
||||
final AirPollutionDetails airPollutionDetails = getClient()
|
||||
.airPollution()
|
||||
.forecast()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
assertNotNull(airPollutionDetails);
|
||||
airPollutionDetails.getAirPollutionRecords().forEach(airPollutionRecord -> {
|
||||
assertNotNull(airPollutionRecord);
|
||||
System.out.println(airPollutionRecord);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveForecastAirPollutionResponseAsJSON_thenOk() {
|
||||
final String jsonString = getClient()
|
||||
.airPollution()
|
||||
.forecast()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
assertNotNull(jsonString);
|
||||
System.out.println(jsonString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveForecastAirPollutionAsyncResponseAsJava_thenOk() throws ExecutionException, InterruptedException {
|
||||
final CompletableFuture<AirPollutionDetails> pollutionDetailsFuture = getClient()
|
||||
.airPollution()
|
||||
.forecast()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.retrieveAsync()
|
||||
.asJava();
|
||||
|
||||
assertNotNull(pollutionDetailsFuture);
|
||||
assertNotNull(pollutionDetailsFuture.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveForecastAirPollutionAsyncResponseAsJSON_thenOk() throws ExecutionException, InterruptedException {
|
||||
final CompletableFuture<String> jsonStringFuture = getClient()
|
||||
.airPollution()
|
||||
.forecast()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.retrieveAsync()
|
||||
.asJSON();
|
||||
|
||||
assertNotNull(jsonStringFuture);
|
||||
final String jsonString = jsonStringFuture.get();
|
||||
assertNotNull(jsonString);
|
||||
System.out.println(jsonString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveHistoricalAirPollutionResponseAsJava_thenOk() {
|
||||
final AirPollutionDetails airPollutionDetails = getClient()
|
||||
.airPollution()
|
||||
.historical()
|
||||
.byCoordinateAndPeriod(Coordinate.of(53.54, 27.34), 1606223802, 1606482999)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
assertNotNull(airPollutionDetails);
|
||||
airPollutionDetails.getAirPollutionRecords().forEach(airPollutionRecord -> {
|
||||
assertNotNull(airPollutionRecord);
|
||||
System.out.println(airPollutionRecord);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveHistoricalAirPollutionResponseAsJSON_thenOk() {
|
||||
final String jsonString = getClient()
|
||||
.airPollution()
|
||||
.historical()
|
||||
.byCoordinateAndPeriod(Coordinate.of(53.54, 27.34), 1606223802, 1606482999)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
assertNotNull(jsonString);
|
||||
System.out.println(jsonString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveHistoricalAirPollutionAsyncResponseAsJava_thenOk() throws ExecutionException, InterruptedException {
|
||||
final CompletableFuture<AirPollutionDetails> pollutionDetailsFuture = getClient()
|
||||
.airPollution()
|
||||
.historical()
|
||||
.byCoordinateAndPeriod(Coordinate.of(53.54, 27.34), 1606223802, 1606482999)
|
||||
.retrieveAsync()
|
||||
.asJava();
|
||||
|
||||
assertNotNull(pollutionDetailsFuture);
|
||||
assertNotNull(pollutionDetailsFuture.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveHistoricalAirPollutionAsyncResponseAsJSON_thenOk() throws ExecutionException, InterruptedException {
|
||||
final CompletableFuture<String> jsonStringFuture = getClient()
|
||||
.airPollution()
|
||||
.historical()
|
||||
.byCoordinateAndPeriod(Coordinate.of(53.54, 27.34), 1606223802, 1606482999)
|
||||
.retrieveAsync()
|
||||
.asJSON();
|
||||
|
||||
assertNotNull(jsonStringFuture);
|
||||
final String jsonString = jsonStringFuture.get();
|
||||
assertNotNull(jsonString);
|
||||
System.out.println(jsonString);
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
*
|
||||
* * 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.air.pollution;
|
||||
|
||||
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
public class AirPollutionResponseMapperUnitTest {
|
||||
@Test
|
||||
public void mapToAirPollution_withInvalidJSON() {
|
||||
final String jsonString = "{\"coord\":{lon\":27.34,\"lat\":53.54},\"list\":[{\"main\":{\"aqi\":1},\"components\":{\"co\":243.66,\"no\":0,\"no2\":4.07,\"o3\":62.23,\"so2\":1.77,\"pm2_5\":3.87,\"pm10\":4.58,\"nh3\":2.41},\"dt\":1618610400}]}";
|
||||
assertThrows(RuntimeException.class, () -> new AirPollutionResponseMapper().mapToAirPollution(jsonString));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapToAirPollution_withCoordinatesVariation() {
|
||||
String jsonResponse = "{\"coord\":{},\"list\":[{\"main\":{\"aqi\":1},\"components\":{\"co\":243.66,\"no\":0,\"no2\":4.07,\"o3\":62.23,\"so2\":1.77,\"pm2_5\":3.87,\"pm10\":4.58,\"nh3\":2.41},\"dt\":1618610400}]}";
|
||||
AirPollutionDetails airPollutionDetails = new AirPollutionResponseMapper().mapToAirPollution(jsonResponse);
|
||||
|
||||
assertNotNull(airPollutionDetails);
|
||||
|
||||
jsonResponse = "{\"coord\":{\"lon\":27.34},\"list\":[{\"main\":{\"aqi\":1},\"components\":{\"co\":243.66,\"no\":0,\"no2\":4.07,\"o3\":62.23,\"so2\":1.77,\"pm2_5\":3.87,\"pm10\":4.58,\"nh3\":2.41},\"dt\":1618610400}]}";
|
||||
airPollutionDetails = new AirPollutionResponseMapper().mapToAirPollution(jsonResponse);
|
||||
|
||||
assertNotNull(airPollutionDetails);
|
||||
|
||||
jsonResponse = "{\"coord\":{\"lat\":53.54},\"list\":[{\"main\":{\"aqi\":1},\"components\":{\"co\":243.66,\"no\":0,\"no2\":4.07,\"o3\":62.23,\"so2\":1.77,\"pm2_5\":3.87,\"pm10\":4.58,\"nh3\":2.41},\"dt\":1618610400}]}";
|
||||
airPollutionDetails = new AirPollutionResponseMapper().mapToAirPollution(jsonResponse);
|
||||
|
||||
assertNotNull(airPollutionDetails);
|
||||
}
|
||||
}
|
||||
-11
File diff suppressed because one or more lines are too long
+43
@@ -86,6 +86,34 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
assertTrue(weatherJson.startsWith("{"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetMultipleCurrentWeatherByCoordinateRectangleAsyncRequestAsJava_thenReturnNotNull() throws ExecutionException, InterruptedException {
|
||||
final CompletableFuture<List<Weather>> weatherListFuture = getClient()
|
||||
.currentWeather()
|
||||
.multiple()
|
||||
.byRectangle(CoordinateRectangle.withValues(12, 32, 15, 37), 10)
|
||||
.language(Language.ROMANIAN)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieveAsync()
|
||||
.asJava();
|
||||
|
||||
assertNotNull(weatherListFuture.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetMultipleCurrentWeatherByCoordinateRectangleAsyncRequestAsJSON_thenReturnNotNull() throws ExecutionException, InterruptedException {
|
||||
final CompletableFuture<String> weatherJsonFuture = getClient()
|
||||
.currentWeather()
|
||||
.multiple()
|
||||
.byRectangle(CoordinateRectangle.withValues(12, 32, 15, 37), 10)
|
||||
.language(Language.ROMANIAN)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieveAsync()
|
||||
.asJSON();
|
||||
|
||||
assertTrue(weatherJsonFuture.get().startsWith("{"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetMultipleCurrentWeatherByCitiesInCycleRequestAsJava_thenReturnNotNull() {
|
||||
final List<Weather> weatherList = getClient()
|
||||
@@ -225,6 +253,21 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
System.out.println(weatherFuture.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetMultipleCurrentWeatherByCoordinateAsyncRequestAsXML_thenReturnNotNull() throws ExecutionException, InterruptedException {
|
||||
final CompletableFuture<String> weatherXMLFuture = getClient()
|
||||
.currentWeather()
|
||||
.multiple()
|
||||
.byCitiesInCycle(Coordinate.of(55.5, 37.5), 10)
|
||||
.language(Language.GERMAN)
|
||||
.unitSystem(UnitSystem.IMPERIAL)
|
||||
.retrieveAsync()
|
||||
.asXML();
|
||||
|
||||
assertNotNull(weatherXMLFuture);
|
||||
System.out.println(weatherXMLFuture.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRequestCurrentWeatherWithInvalidApiKey_thenThrowAnException() {
|
||||
OpenWeatherMapClient client = new OpenWeatherMapClient("invalidKey");
|
||||
|
||||
Reference in New Issue
Block a user