A bunch of global refactoring and improvements.

Improved coverage reports generation.
Updated docs.
Moved logic out of large mappers into small deserializers.
Implemented Geocoding API functionality.
Implemented Hourly forecast functionality.
Implemented Daily forecast functionality.
Renamed Coordinate class.
Reimplemented Current Weather API: removed multiple locations requests. Marked officially deprecated methods as @Deprecated.
Updated tests.
This commit is contained in:
2022-04-30 01:35:45 +03:00
parent 8ca55b15f7
commit 4fdb48986e
154 changed files with 7881 additions and 2429 deletions
@@ -25,7 +25,7 @@
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.Coordinates;
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails;
import org.junit.jupiter.api.Test;
@@ -40,7 +40,7 @@ public class AirPollutionIntegrationTest extends ApiTest {
final AirPollutionDetails airPollutionDetails = getClient()
.airPollution()
.current()
.byCoordinate(Coordinate.of(53.54, 27.34))
.byCoordinates(Coordinates.of(53.54, 27.34))
.retrieve()
.asJava();
@@ -56,7 +56,7 @@ public class AirPollutionIntegrationTest extends ApiTest {
final String jsonString = getClient()
.airPollution()
.current()
.byCoordinate(Coordinate.of(53.54, 27.34))
.byCoordinates(Coordinates.of(53.54, 27.34))
.retrieve()
.asJSON();
@@ -69,7 +69,7 @@ public class AirPollutionIntegrationTest extends ApiTest {
final CompletableFuture<AirPollutionDetails> pollutionDetailsFuture = getClient()
.airPollution()
.current()
.byCoordinate(Coordinate.of(53.54, 27.34))
.byCoordinates(Coordinates.of(53.54, 27.34))
.retrieveAsync()
.asJava();
@@ -82,7 +82,7 @@ public class AirPollutionIntegrationTest extends ApiTest {
final CompletableFuture<String> jsonStringFuture = getClient()
.airPollution()
.current()
.byCoordinate(Coordinate.of(53.54, 27.34))
.byCoordinates(Coordinates.of(53.54, 27.34))
.retrieveAsync()
.asJSON();
@@ -97,7 +97,7 @@ public class AirPollutionIntegrationTest extends ApiTest {
final AirPollutionDetails airPollutionDetails = getClient()
.airPollution()
.forecast()
.byCoordinate(Coordinate.of(53.54, 27.34))
.byCoordinates(Coordinates.of(53.54, 27.34))
.retrieve()
.asJava();
@@ -113,7 +113,7 @@ public class AirPollutionIntegrationTest extends ApiTest {
final String jsonString = getClient()
.airPollution()
.forecast()
.byCoordinate(Coordinate.of(53.54, 27.34))
.byCoordinates(Coordinates.of(53.54, 27.34))
.retrieve()
.asJSON();
@@ -126,7 +126,7 @@ public class AirPollutionIntegrationTest extends ApiTest {
final CompletableFuture<AirPollutionDetails> pollutionDetailsFuture = getClient()
.airPollution()
.forecast()
.byCoordinate(Coordinate.of(53.54, 27.34))
.byCoordinates(Coordinates.of(53.54, 27.34))
.retrieveAsync()
.asJava();
@@ -139,7 +139,7 @@ public class AirPollutionIntegrationTest extends ApiTest {
final CompletableFuture<String> jsonStringFuture = getClient()
.airPollution()
.forecast()
.byCoordinate(Coordinate.of(53.54, 27.34))
.byCoordinates(Coordinates.of(53.54, 27.34))
.retrieveAsync()
.asJSON();
@@ -154,7 +154,7 @@ public class AirPollutionIntegrationTest extends ApiTest {
final AirPollutionDetails airPollutionDetails = getClient()
.airPollution()
.historical()
.byCoordinateAndPeriod(Coordinate.of(53.54, 27.34), 1606223802, 1606482999)
.byCoordinateAndPeriod(Coordinates.of(53.54, 27.34), 1606223802, 1606482999)
.retrieve()
.asJava();
@@ -170,7 +170,7 @@ public class AirPollutionIntegrationTest extends ApiTest {
final String jsonString = getClient()
.airPollution()
.historical()
.byCoordinateAndPeriod(Coordinate.of(53.54, 27.34), 1606223802, 1606482999)
.byCoordinateAndPeriod(Coordinates.of(53.54, 27.34), 1606223802, 1606482999)
.retrieve()
.asJSON();
@@ -183,7 +183,7 @@ public class AirPollutionIntegrationTest extends ApiTest {
final CompletableFuture<AirPollutionDetails> pollutionDetailsFuture = getClient()
.airPollution()
.historical()
.byCoordinateAndPeriod(Coordinate.of(53.54, 27.34), 1606223802, 1606482999)
.byCoordinateAndPeriod(Coordinates.of(53.54, 27.34), 1606223802, 1606482999)
.retrieveAsync()
.asJava();
@@ -196,7 +196,7 @@ public class AirPollutionIntegrationTest extends ApiTest {
final CompletableFuture<String> jsonStringFuture = getClient()
.airPollution()
.historical()
.byCoordinateAndPeriod(Coordinate.of(53.54, 27.34), 1606223802, 1606482999)
.byCoordinateAndPeriod(Coordinates.of(53.54, 27.34), 1606223802, 1606482999)
.retrieveAsync()
.asJSON();
@@ -28,9 +28,9 @@ import com.github.prominence.openweathermap.api.enums.Language;
import com.github.prominence.openweathermap.api.enums.UnitSystem;
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
import com.github.prominence.openweathermap.api.exception.NoDataFoundException;
import com.github.prominence.openweathermap.api.model.Coordinate;
import com.github.prominence.openweathermap.api.model.forecast.Forecast;
import com.github.prominence.openweathermap.api.model.forecast.WeatherForecast;
import com.github.prominence.openweathermap.api.model.Coordinates;
import com.github.prominence.openweathermap.api.model.forecast.free.Forecast;
import com.github.prominence.openweathermap.api.model.forecast.free.WeatherForecast;
import org.junit.jupiter.api.Test;
import java.util.concurrent.CompletableFuture;
@@ -249,7 +249,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
public void whenGetForecastByCoordinatesRequestAsJava_thenReturnNotNull() {
final Forecast forecast = getClient()
.forecast5Day3HourStep()
.byCoordinate(Coordinate.of(5, 5))
.byCoordinates(Coordinates.of(5, 5))
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
.count(15)
@@ -273,7 +273,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
public void whenGetForecastByCoordinatesRequestAsJSON_thenReturnNotNull() {
final String forecastJson = getClient()
.forecast5Day3HourStep()
.byCoordinate(Coordinate.of(5, 5))
.byCoordinates(Coordinates.of(5, 5))
.language(Language.SPANISH)
.unitSystem(UnitSystem.IMPERIAL)
.count(15)
@@ -287,7 +287,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
public void whenGetForecastByCoordinatesRequestAsXML_thenReturnNotNull() {
final String forecastXml = getClient()
.forecast5Day3HourStep()
.byCoordinate(Coordinate.of(5, 5))
.byCoordinates(Coordinates.of(5, 5))
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
.retrieve()
@@ -24,7 +24,7 @@ package com.github.prominence.openweathermap.api.request.forecast.free;
import com.github.prominence.openweathermap.api.enums.UnitSystem;
import com.github.prominence.openweathermap.api.mapper.FiveDayThreeHourStepForecastResponseMapper;
import com.github.prominence.openweathermap.api.model.forecast.Forecast;
import com.github.prominence.openweathermap.api.model.forecast.free.Forecast;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
File diff suppressed because one or more lines are too long
@@ -28,8 +28,7 @@ import com.github.prominence.openweathermap.api.enums.Language;
import com.github.prominence.openweathermap.api.enums.OneCallResultOptions;
import com.github.prominence.openweathermap.api.enums.UnitSystem;
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
import com.github.prominence.openweathermap.api.exception.NoDataFoundException;
import com.github.prominence.openweathermap.api.model.Coordinate;
import com.github.prominence.openweathermap.api.model.Coordinates;
import com.github.prominence.openweathermap.api.model.onecall.current.CurrentWeatherData;
import org.junit.jupiter.api.Test;
@@ -44,7 +43,7 @@ public class CurrentWeatherOneCallIntegrationTest extends ApiTest {
final CurrentWeatherData currentWeatherData = getClient()
.oneCall()
.current()
.byCoordinate(Coordinate.of(53.54, 27.34))
.byCoordinates(Coordinates.of(53.54, 27.34))
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
.retrieve()
@@ -58,7 +57,7 @@ public class CurrentWeatherOneCallIntegrationTest extends ApiTest {
final String responseJson = getClient()
.oneCall()
.current()
.byCoordinate(Coordinate.of(53.54, 27.34))
.byCoordinates(Coordinates.of(53.54, 27.34))
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
.retrieve()
@@ -74,7 +73,7 @@ public class CurrentWeatherOneCallIntegrationTest extends ApiTest {
final CurrentWeatherData currentWeatherData = getClient()
.oneCall()
.current()
.byCoordinate(Coordinate.of(53.54, 27.34))
.byCoordinates(Coordinates.of(53.54, 27.34))
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
.exclude(OneCallResultOptions.CURRENT, OneCallResultOptions.MINUTELY)
@@ -91,7 +90,7 @@ public class CurrentWeatherOneCallIntegrationTest extends ApiTest {
final CompletableFuture<CurrentWeatherData> currentWeatherDataFuture = getClient()
.oneCall()
.current()
.byCoordinate(Coordinate.of(53.54, 27.34))
.byCoordinates(Coordinates.of(53.54, 27.34))
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
.retrieveAsync()
@@ -106,7 +105,7 @@ public class CurrentWeatherOneCallIntegrationTest extends ApiTest {
final CompletableFuture<String> responseJsonFuture = getClient()
.oneCall()
.current()
.byCoordinate(Coordinate.of(53.54, 27.34))
.byCoordinates(Coordinates.of(53.54, 27.34))
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
.retrieveAsync()
@@ -125,7 +124,7 @@ public class CurrentWeatherOneCallIntegrationTest extends ApiTest {
client
.oneCall()
.current()
.byCoordinate(Coordinate.of(53.54, 27.34))
.byCoordinates(Coordinates.of(53.54, 27.34))
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
.retrieve()
@@ -27,8 +27,7 @@ import com.github.prominence.openweathermap.api.OpenWeatherMapClient;
import com.github.prominence.openweathermap.api.enums.Language;
import com.github.prominence.openweathermap.api.enums.UnitSystem;
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
import com.github.prominence.openweathermap.api.exception.NoDataFoundException;
import com.github.prominence.openweathermap.api.model.Coordinate;
import com.github.prominence.openweathermap.api.model.Coordinates;
import com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeatherData;
import org.junit.jupiter.api.Test;
@@ -45,7 +44,7 @@ public class HistoricalWeatherOneCallIntegrationTest extends ApiTest {
final HistoricalWeatherData historicalWeatherData = getClient()
.oneCall()
.historical()
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
.byCoordinateAndTimestamp(Coordinates.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
.retrieve()
@@ -59,7 +58,7 @@ public class HistoricalWeatherOneCallIntegrationTest extends ApiTest {
final String responseJson = getClient()
.oneCall()
.historical()
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
.byCoordinateAndTimestamp(Coordinates.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
.retrieve()
@@ -75,7 +74,7 @@ public class HistoricalWeatherOneCallIntegrationTest extends ApiTest {
final CompletableFuture<HistoricalWeatherData> historicalWeatherDataFuture = getClient()
.oneCall()
.historical()
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
.byCoordinateAndTimestamp(Coordinates.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
.retrieveAsync()
@@ -90,7 +89,7 @@ public class HistoricalWeatherOneCallIntegrationTest extends ApiTest {
final CompletableFuture<String> responseJsonFuture = getClient()
.oneCall()
.historical()
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
.byCoordinateAndTimestamp(Coordinates.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
.retrieveAsync()
@@ -109,7 +108,7 @@ public class HistoricalWeatherOneCallIntegrationTest extends ApiTest {
client
.oneCall()
.historical()
.byCoordinateAndTimestamp(Coordinate.of(53.54, 27.34), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
.byCoordinateAndTimestamp(Coordinates.of(53.54, 27.34), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
.retrieve()
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Alexey Zinchenko
* Copyright (c) 2022 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
@@ -20,288 +20,34 @@
* SOFTWARE.
*/
package com.github.prominence.openweathermap.api.request.weather.single;
package com.github.prominence.openweathermap.api.request.weather;
import com.github.prominence.openweathermap.api.ApiTest;
import com.github.prominence.openweathermap.api.enums.Language;
import com.github.prominence.openweathermap.api.enums.UnitSystem;
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
import com.github.prominence.openweathermap.api.exception.NoDataFoundException;
import com.github.prominence.openweathermap.api.model.Coordinate;
import com.github.prominence.openweathermap.api.model.Coordinates;
import com.github.prominence.openweathermap.api.model.weather.Weather;
import com.github.prominence.openweathermap.api.OpenWeatherMapClient;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import static org.junit.jupiter.api.Assertions.*;
public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
@Test
public void whenGetSingleCurrentWeatherByCityNameRequestAsJava_thenReturnNotNull() {
final Weather weather = getClient()
.currentWeather()
.single()
.byCityName("Minsk")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJava();
assertNotNull(weather);
assertNotNull(weather.getWeatherState());
assertNotNull(weather.getCalculationTime());
assertNotNull(weather.getTemperature());
assertNotNull(weather.getLocation());
assertNotNull(weather.getAtmosphericPressure());
assertNotNull(weather.getHumidity());
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();
assertTrue(weatherJson.startsWith("{"));
}
@Test
public void whenGetSingleCurrentWeatherByCityNameRequestAsXML_thenReturnNotNull() {
final String weatherXml = getClient()
.currentWeather()
.single()
.byCityName("Minsk")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.STANDARD)
.retrieve()
.asXML();
assertTrue(weatherXml.startsWith("<"));
}
@Test
public void whenGetSingleCurrentWeatherByCityNameRequestAsHTML_thenReturnNotNull() {
final String weatherHtml = getClient()
.currentWeather()
.single()
.byCityName("Minsk")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asHTML();
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();
assertNotNull(weather);
assertNotNull(weather.getWeatherState());
assertNotNull(weather.getCalculationTime());
assertNotNull(weather.getTemperature());
assertNotNull(weather.getLocation());
assertNotNull(weather.getAtmosphericPressure());
assertNotNull(weather.getHumidity());
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();
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();
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();
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();
assertNotNull(weather);
assertNotNull(weather.getWeatherState());
assertNotNull(weather.getCalculationTime());
assertNotNull(weather.getTemperature());
assertNotNull(weather.getLocation());
assertNotNull(weather.getAtmosphericPressure());
assertNotNull(weather.getHumidity());
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();
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();
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();
assertTrue(weatherHtml.startsWith("<"));
}
@Test
public void whenGetSingleCurrentWeatherByCityIdRequestAsJava_thenReturnNotNull() {
final Weather weather = getClient()
.currentWeather()
.single()
.byCityId(350001514)
.language(Language.GERMAN)
.retrieve()
.asJava();
assertNotNull(weather);
assertNotNull(weather.getWeatherState());
assertNotNull(weather.getCalculationTime());
assertNotNull(weather.getTemperature());
assertNotNull(weather.getLocation());
assertNotNull(weather.getAtmosphericPressure());
assertNotNull(weather.getHumidity());
assertNotNull(weather.getWind());
System.out.println(weather);
}
@Test
public void whenGetSingleCurrentWeatherByCityIdRequestAsJSON_thenReturnNotNull() {
final String weatherJson = getClient()
.currentWeather()
.single()
.byCityId(350001514)
.language(Language.GERMAN)
.retrieve()
.asJSON();
assertTrue(weatherJson.startsWith("{"));
}
@Test
public void whenGetSingleCurrentWeatherByCityIdRequestAsXML_thenReturnNotNull() {
final String weatherXml = getClient()
.currentWeather()
.single()
.byCityId(350001514)
.language(Language.GERMAN)
.retrieve()
.asXML();
assertTrue(weatherXml.startsWith("<"));
}
@Test
public void whenGetSingleCurrentWeatherByCityIdRequestAsHTML_thenReturnNotNull() {
final String weatherHtml = getClient()
.currentWeather()
.single()
.byCityId(350001514)
.language(Language.GERMAN)
.retrieve()
.asXML();
assertTrue(weatherHtml.startsWith("<"));
}
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class CurrentWeatherIntegrationTest extends ApiTest {
@Test
public void whenGetSingleCurrentWeatherByCoordinateRequestAsJava_thenReturnNotNull() {
final Weather weather = getClient()
.currentWeather()
.single()
.byCoordinate(Coordinate.of(5, 5))
.byCoordinates(Coordinates.of(5, 5))
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJava();
assertNotNull(weather);
assertNotNull(weather.getWeatherState());
assertNotNull(weather.getWeatherStates());
assertNotNull(weather.getCalculationTime());
assertNotNull(weather.getTemperature());
assertNotNull(weather.getLocation());
@@ -315,8 +61,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
public void whenGetSingleCurrentWeatherByCoordinateRequestAsJSON_thenReturnNotNull() {
final String weatherJson = getClient()
.currentWeather()
.single()
.byCoordinate(Coordinate.of(5, 5))
.byCoordinates(Coordinates.of(5, 5))
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJSON();
@@ -328,8 +73,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
public void whenGetSingleCurrentWeatherByCoordinateRequestAsXML_thenReturnNotNull() {
final String weatherXml = getClient()
.currentWeather()
.single()
.byCoordinate(Coordinate.of(5, 5))
.byCoordinates(Coordinates.of(5, 5))
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asXML();
@@ -341,8 +85,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
public void whenGetSingleCurrentWeatherByCoordinateRequestAsHTML_thenReturnNotNull() {
final String weatherHtml = getClient()
.currentWeather()
.single()
.byCoordinate(Coordinate.of(5, 5))
.byCoordinates(Coordinates.of(5, 5))
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asHTML();
@@ -351,10 +94,262 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
}
@Test
@Disabled
public void whenGetSingleCurrentWeatherByCityNameRequestAsJava_thenReturnNotNull() {
final Weather weather = getClient()
.currentWeather()
.byCityName("Minsk")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJava();
assertNotNull(weather);
assertNotNull(weather.getWeatherStates());
assertNotNull(weather.getCalculationTime());
assertNotNull(weather.getTemperature());
assertNotNull(weather.getLocation());
assertNotNull(weather.getAtmosphericPressure());
assertNotNull(weather.getHumidity());
assertNotNull(weather.getWind());
System.out.println(weather);
}
@Test
@Disabled
public void whenGetSingleCurrentWeatherByCityNameRequestAsJSON_thenReturnNotNull() {
final String weatherJson = getClient()
.currentWeather()
.byCityName("Minsk")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
.asJSON();
assertTrue(weatherJson.startsWith("{"));
}
@Test
@Disabled
public void whenGetSingleCurrentWeatherByCityNameRequestAsXML_thenReturnNotNull() {
final String weatherXml = getClient()
.currentWeather()
.byCityName("Minsk")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.STANDARD)
.retrieve()
.asXML();
assertTrue(weatherXml.startsWith("<"));
}
@Test
@Disabled
public void whenGetSingleCurrentWeatherByCityNameRequestAsHTML_thenReturnNotNull() {
final String weatherHtml = getClient()
.currentWeather()
.byCityName("Minsk")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asHTML();
assertTrue(weatherHtml.startsWith("<"));
}
@Test
@Disabled
public void whenGetSingleCurrentWeatherByCityNameAndCountryCodeRequestAsJava_thenReturnNotNull() {
final Weather weather = getClient()
.currentWeather()
.byCityName("Minsk", "BY")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJava();
assertNotNull(weather);
assertNotNull(weather.getWeatherStates());
assertNotNull(weather.getCalculationTime());
assertNotNull(weather.getTemperature());
assertNotNull(weather.getLocation());
assertNotNull(weather.getAtmosphericPressure());
assertNotNull(weather.getHumidity());
assertNotNull(weather.getWind());
System.out.println(weather);
}
@Test
@Disabled
public void whenGetSingleCurrentWeatherByCityNameAndCountryCodeRequestAsJSON_thenReturnNotNull() {
final String weatherJson = getClient()
.currentWeather()
.byCityName("Minsk", "by")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJSON();
assertTrue(weatherJson.startsWith("{"));
}
@Test
@Disabled
public void whenGetSingleCurrentWeatherByCityNameAndCountryCodeRequestAsXML_thenReturnNotNull() {
final String weatherXml = getClient()
.currentWeather()
.byCityName("Minsk", "by")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asXML();
assertTrue(weatherXml.startsWith("<"));
}
@Test
@Disabled
public void whenGetSingleCurrentWeatherByCityNameAndCountryCodeRequestAsHTML_thenReturnNotNull() {
final String weatherHtml = getClient()
.currentWeather()
.byCityName("Minsk", "by")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.STANDARD)
.retrieve()
.asHTML();
assertTrue(weatherHtml.startsWith("<"));
}
@Test
@Disabled
public void whenGetSingleCurrentWeatherByCityNameAndStateCodeAndCountryCodeRequestAsJava_thenReturnNotNull() {
final Weather weather = getClient()
.currentWeather()
.byCityName("New York", "ny", "us")
.language(Language.SLOVAK)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJava();
assertNotNull(weather);
assertNotNull(weather.getWeatherStates());
assertNotNull(weather.getCalculationTime());
assertNotNull(weather.getTemperature());
assertNotNull(weather.getLocation());
assertNotNull(weather.getAtmosphericPressure());
assertNotNull(weather.getHumidity());
assertNotNull(weather.getWind());
System.out.println(weather);
}
@Test
@Disabled
public void whenGetSingleCurrentWeatherByCityNameAndStateCodeAndCountryCodeRequestAsJSON_thenReturnNotNull() {
final String weatherJson = getClient()
.currentWeather()
.byCityName("New York", "ny", "us")
.language(Language.HUNGARIAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
.asJSON();
assertTrue(weatherJson.startsWith("{"));
}
@Test
@Disabled
public void whenGetSingleCurrentWeatherByCityNameAndStateCodeAndCountryCodeRequestAsXML_thenReturnNotNull() {
final String weatherXml = getClient()
.currentWeather()
.byCityName("New York", "ny", "us")
.language(Language.ROMANIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asXML();
assertTrue(weatherXml.startsWith("<"));
}
@Test
@Disabled
public void whenGetSingleCurrentWeatherByCityNameAndStateCodeAndCountryCodeRequestAsHTML_thenReturnNotNull() {
final String weatherHtml = getClient()
.currentWeather()
.byCityName("New York", "ny", "us")
.language(Language.ARABIC)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asHTML();
assertTrue(weatherHtml.startsWith("<"));
}
@Test
@Disabled
public void whenGetSingleCurrentWeatherByCityIdRequestAsJava_thenReturnNotNull() {
final Weather weather = getClient()
.currentWeather()
.byCityId(350001514)
.language(Language.GERMAN)
.retrieve()
.asJava();
assertNotNull(weather);
assertNotNull(weather.getWeatherStates());
assertNotNull(weather.getCalculationTime());
assertNotNull(weather.getTemperature());
assertNotNull(weather.getLocation());
assertNotNull(weather.getAtmosphericPressure());
assertNotNull(weather.getHumidity());
assertNotNull(weather.getWind());
System.out.println(weather);
}
@Test
@Disabled
public void whenGetSingleCurrentWeatherByCityIdRequestAsJSON_thenReturnNotNull() {
final String weatherJson = getClient()
.currentWeather()
.byCityId(350001514)
.language(Language.GERMAN)
.retrieve()
.asJSON();
assertTrue(weatherJson.startsWith("{"));
}
@Test
@Disabled
public void whenGetSingleCurrentWeatherByCityIdRequestAsXML_thenReturnNotNull() {
final String weatherXml = getClient()
.currentWeather()
.byCityId(350001514)
.language(Language.GERMAN)
.retrieve()
.asXML();
assertTrue(weatherXml.startsWith("<"));
}
@Test
@Disabled
public void whenGetSingleCurrentWeatherByCityIdRequestAsHTML_thenReturnNotNull() {
final String weatherHtml = getClient()
.currentWeather()
.byCityId(350001514)
.language(Language.GERMAN)
.retrieve()
.asXML();
assertTrue(weatherHtml.startsWith("<"));
}
@Test
@Disabled
public void whenGetSingleCurrentWeatherByZipCodeAndCountryRequestAsJava_thenReturnNotNull() {
final Weather weather = getClient()
.currentWeather()
.single()
.byZipCodeAndCountry("220015", "by")
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
@@ -362,7 +357,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
.asJava();
assertNotNull(weather);
assertNotNull(weather.getWeatherState());
assertNotNull(weather.getWeatherStates());
assertNotNull(weather.getCalculationTime());
assertNotNull(weather.getTemperature());
assertNotNull(weather.getLocation());
@@ -373,10 +368,10 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
}
@Test
@Disabled
public void whenGetSingleCurrentWeatherByZipCodeAndCountryRequestAsJSON_thenReturnNotNull() {
final String weatherJson = getClient()
.currentWeather()
.single()
.byZipCodeAndCountry("220015", "by")
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
@@ -387,10 +382,10 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
}
@Test
@Disabled
public void whenGetSingleCurrentWeatherByZipCodeAndCountryRequestAsXML_thenReturnNotNull() {
final String weatherXml = getClient()
.currentWeather()
.single()
.byZipCodeAndCountry("220015", "by")
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
@@ -401,10 +396,10 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
}
@Test
@Disabled
public void whenGetSingleCurrentWeatherByZipCodeAndCountryRequestAsHTML_thenReturnNotNull() {
final String weatherHtml = getClient()
.currentWeather()
.single()
.byZipCodeAndCountry("220015", "by")
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
@@ -415,10 +410,10 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
}
@Test
@Disabled
public void whenGetSingleCurrentWeatherByZipCodeInUSARequestAsJava_thenReturnNotNull() {
final Weather weather = getClient()
.currentWeather()
.single()
.byZipCodeInUSA("10006")
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
@@ -426,7 +421,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
.asJava();
assertNotNull(weather);
assertNotNull(weather.getWeatherState());
assertNotNull(weather.getWeatherStates());
assertNotNull(weather.getCalculationTime());
assertNotNull(weather.getTemperature());
assertNotNull(weather.getLocation());
@@ -437,10 +432,10 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
}
@Test
@Disabled
public void whenGetSingleCurrentWeatherByZipCodeInUSARequestAsJSON_thenReturnNotNull() {
final String weatherJson = getClient()
.currentWeather()
.single()
.byZipCodeInUSA("10006")
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
@@ -451,10 +446,10 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
}
@Test
@Disabled
public void whenGetSingleCurrentWeatherByZipCodeInUSARequestAsXML_thenReturnNotNull() {
final String weatherXml = getClient()
.currentWeather()
.single()
.byZipCodeInUSA("10006")
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
@@ -465,10 +460,10 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
}
@Test
@Disabled
public void whenGetSingleCurrentWeatherByZipCodeInUSARequestAsHTML_thenReturnNotNull() {
final String weatherHtml = getClient()
.currentWeather()
.single()
.byZipCodeInUSA("10006")
.language(Language.ENGLISH)
.unitSystem(UnitSystem.METRIC)
@@ -479,10 +474,10 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
}
@Test
@Disabled
public void whenGetAnySingleCurrentWeatherAsyncRequestAsJava_thenReturnNotNull() throws ExecutionException, InterruptedException {
final CompletableFuture<Weather> weatherFuture = getClient()
.currentWeather()
.single()
.byZipCodeAndCountry("220015", "by")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
@@ -494,10 +489,10 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
}
@Test
@Disabled
public void whenGetAnySingleCurrentWeatherAsyncRequestAsJson_thenReturnNotNull() throws ExecutionException, InterruptedException {
final CompletableFuture<String> weatherFuture = getClient()
.currentWeather()
.single()
.byZipCodeAndCountry("220015", "by")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
@@ -509,10 +504,10 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
}
@Test
@Disabled
public void whenGetAnySingleCurrentWeatherAsyncRequestAsXml_thenReturnNotNull() throws ExecutionException, InterruptedException {
final CompletableFuture<String> weatherXmlFuture = getClient()
.currentWeather()
.single()
.byZipCodeAndCountry("220015", "by")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
@@ -524,10 +519,10 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
}
@Test
@Disabled
public void whenGetAnySingleCurrentWeatherAsyncRequestAsHtml_thenReturnNotNull() throws ExecutionException, InterruptedException {
final CompletableFuture<String> weatherFuture = getClient()
.currentWeather()
.single()
.byZipCodeAndCountry("220015", "by")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
@@ -537,29 +532,4 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
assertNotNull(weatherFuture);
System.out.println(weatherFuture.get());
}
@Test
public void whenRequestCurrentWeatherWithInvalidApiKey_thenThrowAnException() {
OpenWeatherMapClient client = new OpenWeatherMapClient("invalidKey");
assertThrows(InvalidAuthTokenException.class, () ->
client
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.of(34.53, 66.74), 10)
.retrieve()
.asJSON()
);
}
@Test
public void whenRequestCurrentWeatherForInvalidLocation_thenThrowAnException() {
assertThrows(NoDataFoundException.class, () ->
getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.of(90.00, 66.74), 10)
.retrieve()
.asJava()
);
}
}
@@ -1,295 +0,0 @@
/*
* 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.ApiTest;
import com.github.prominence.openweathermap.api.enums.Language;
import com.github.prominence.openweathermap.api.enums.UnitSystem;
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
import com.github.prominence.openweathermap.api.exception.NoDataFoundException;
import com.github.prominence.openweathermap.api.model.Coordinate;
import com.github.prominence.openweathermap.api.model.CoordinateRectangle;
import com.github.prominence.openweathermap.api.model.weather.Weather;
import com.github.prominence.openweathermap.api.OpenWeatherMapClient;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import static org.junit.jupiter.api.Assertions.*;
public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
@Test
public void whenGetMultipleCurrentWeatherByCoordinateRectangleRequestAsJava_thenReturnNotNull() {
final List<Weather> weatherList = getClient()
.currentWeather()
.multiple()
.byRectangle(
new CoordinateRectangle.Builder()
.setLongitudeLeft(12)
.setLatitudeBottom(32)
.setLongitudeRight(15)
.setLatitudeTop(37)
.build(),
10
)
.language(Language.ROMANIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJava();
assertNotNull(weatherList);
for (Weather weather : weatherList) {
assertNotNull(weather);
assertNotNull(weather.getWeatherState());
assertNotNull(weather.getCalculationTime());
assertNotNull(weather.getTemperature());
assertNotNull(weather.getLocation());
assertNotNull(weather.getAtmosphericPressure());
assertNotNull(weather.getHumidity());
assertNotNull(weather.getWind());
}
}
@Test
public void whenGetMultipleCurrentWeatherByCoordinateRectangleRequestAsJSON_thenReturnNotNull() {
final String weatherJson = getClient()
.currentWeather()
.multiple()
.byRectangle(CoordinateRectangle.withValues(12, 32, 15, 37), 10)
.language(Language.ROMANIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJSON();
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()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.of(55.5, 37.5))
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
.asJava();
assertNotNull(weatherList);
for (Weather weather : weatherList) {
System.out.println(weather);
assertNotNull(weather);
assertNotNull(weather.getWeatherState());
assertNotNull(weather.getCalculationTime());
assertNotNull(weather.getTemperature());
assertNotNull(weather.getLocation());
assertNotNull(weather.getAtmosphericPressure());
assertNotNull(weather.getHumidity());
assertNotNull(weather.getWind());
}
}
@Test
public void whenGetMultipleCurrentWeatherByCitiesInCycleRequestAsJSON_thenReturnNotNull() {
final String weatherJson = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.of(55.5, 37.5))
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
.asJSON();
assertTrue(weatherJson.startsWith("{"));
}
@Test
public void whenGetMultipleCurrentWeatherByCitiesInCycleRequestAsXML_thenReturnNotNull() {
final String weatherXml = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.of(55.5, 37.5))
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
.asXML();
assertTrue(weatherXml.startsWith("<"));
System.out.println(weatherXml);
}
@Test
public void whenGetMultipleCurrentWeatherByCitiesInCycleAndCountRequestAsJava_thenReturnNotNull() {
final List<Weather> weatherList = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.of(55.5, 37.5), 10)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
.asJava();
assertNotNull(weatherList);
for (Weather weather : weatherList) {
System.out.println(weather);
assertNotNull(weather);
assertNotNull(weather.getWeatherState());
assertNotNull(weather.getCalculationTime());
assertNotNull(weather.getTemperature());
assertNotNull(weather.getLocation());
assertNotNull(weather.getAtmosphericPressure());
assertNotNull(weather.getHumidity());
assertNotNull(weather.getWind());
}
}
@Test
public void whenGetMultipleCurrentWeatherByCitiesInCycleAndCountRequestAsJSON_thenReturnNotNull() {
final String weatherJson = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.of(55.5, 37.5), 10)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
.asJSON();
assertTrue(weatherJson.startsWith("{"));
}
@Test
public void whenGetMultipleCurrentWeatherByCitiesInCycleAndCountRequestAsXML_thenReturnNotNull() {
final String weatherXml = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.of(55.5, 37.5), 10)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
.asXML();
assertTrue(weatherXml.startsWith("<"));
}
@Test
public void whenGetMultipleCurrentWeatherByCoordinateAsyncRequestAsJava_thenReturnNotNull() throws ExecutionException, InterruptedException {
final CompletableFuture<List<Weather>> weatherListFuture = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.of(55.5, 37.5), 10)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieveAsync()
.asJava();
assertNotNull(weatherListFuture);
List<Weather> weatherList = weatherListFuture.get();
assertTrue(weatherList.size() > 0);
System.out.println(weatherList);
}
@Test
public void whenGetMultipleCurrentWeatherByCoordinateAsyncRequestAsJson_thenReturnNotNull() throws ExecutionException, InterruptedException {
final CompletableFuture<String> weatherFuture = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(Coordinate.of(55.5, 37.5), 10)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieveAsync()
.asJSON();
assertNotNull(weatherFuture);
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");
assertThrows(InvalidAuthTokenException.class, () ->
client
.currentWeather()
.single()
.byCityName("London")
.retrieve()
.asJSON()
);
}
@Test
public void whenRequestCurrentWeatherForInvalidLocation_thenThrowAnException() {
assertThrows(NoDataFoundException.class, () ->
getClient()
.currentWeather()
.single()
.byCityName("InvalidCity")
.retrieve()
.asJava()
);
}
}