mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-07-04 03:36:44 +03:00
Added tests for forecast functionality.
This commit is contained in:
+415
-6
@@ -23,16 +23,23 @@
|
||||
package com.github.prominence.openweathermap.api.request.forecast.free;
|
||||
|
||||
import com.github.prominence.openweathermap.api.ApiTest;
|
||||
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.forecast.Forecast;
|
||||
import com.github.prominence.openweathermap.api.model.forecast.WeatherForecast;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
@Test
|
||||
public void whenGetJavaObject_thenReturnNotNull() {
|
||||
public void whenGetForecastByCityNameRequestAsJava_thenReturnNotNull() {
|
||||
final Forecast forecast = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byCityName("Minsk")
|
||||
@@ -43,19 +50,421 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
.asJava();
|
||||
|
||||
Assert.assertNotNull(forecast);
|
||||
System.out.println(forecast);
|
||||
Assert.assertNotNull(forecast.getLocation());
|
||||
Assert.assertNotNull(forecast.getWeatherForecasts());
|
||||
for (WeatherForecast weatherForecast : forecast.getWeatherForecasts()) {
|
||||
Assert.assertNotNull(weatherForecast.getState());
|
||||
Assert.assertNotNull(weatherForecast.getDescription());
|
||||
Assert.assertNotNull(weatherForecast.getForecastTime());
|
||||
Assert.assertNotNull(weatherForecast.getTemperature());
|
||||
Assert.assertNotNull(weatherForecast.getAtmosphericPressure());
|
||||
Assert.assertNotNull(weatherForecast.getHumidity());
|
||||
Assert.assertNotNull(weatherForecast.getWind());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetJavaObject_thenFieldsAreFilled() {
|
||||
public void whenGetForecastByCityNameRequestAsJSON_thenReturnNotNull() {
|
||||
final String forecastJson = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byCityName("Minsk")
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.count(15)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
Assert.assertTrue(forecastJson.startsWith("{"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetForecastByCityNameRequestAsXML_thenReturnNotNull() {
|
||||
final String forecastXml = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byCityName("Minsk")
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.count(15)
|
||||
.retrieve()
|
||||
.asXML();
|
||||
|
||||
Assert.assertTrue(forecastXml.startsWith("<"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetForecastByCityNameAndCountryCodeRequestAsJava_thenReturnNotNull() {
|
||||
final Forecast forecast = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byCityName("London")
|
||||
.byCityName("Minsk", "BY")
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.count(15)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
Assert.assertNotNull(forecast);
|
||||
System.out.println(forecast);
|
||||
Assert.assertNotNull(forecast.getLocation());
|
||||
Assert.assertNotNull(forecast.getWeatherForecasts());
|
||||
for (WeatherForecast weatherForecast : forecast.getWeatherForecasts()) {
|
||||
Assert.assertNotNull(weatherForecast.getState());
|
||||
Assert.assertNotNull(weatherForecast.getDescription());
|
||||
Assert.assertNotNull(weatherForecast.getForecastTime());
|
||||
Assert.assertNotNull(weatherForecast.getTemperature());
|
||||
Assert.assertNotNull(weatherForecast.getAtmosphericPressure());
|
||||
Assert.assertNotNull(weatherForecast.getHumidity());
|
||||
Assert.assertNotNull(weatherForecast.getWind());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetForecastByCityNameAndCountryCodeRequestAsJSON_thenReturnNotNull() {
|
||||
final String forecastJson = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byCityName("Minsk", "by")
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.count(15)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
Assert.assertTrue(forecastJson.startsWith("{"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetForecastByCityNameAndCountryCodeRequestAsXML_thenReturnNotNull() {
|
||||
final String forecastXml = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byCityName("Minsk", "by")
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.count(15)
|
||||
.retrieve()
|
||||
.asXML();
|
||||
|
||||
Assert.assertTrue(forecastXml.startsWith("<"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetForecastByCityNameAndStateCodeAndCountryCodeRequestAsJava_thenReturnNotNull() {
|
||||
final Forecast forecast = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byCityName("New York", "NY", "US")
|
||||
.language(Language.CHINESE_TRADITIONAL)
|
||||
.unitSystem(UnitSystem.STANDARD)
|
||||
.count(15)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
Assert.assertNotNull(forecast);
|
||||
Assert.assertNotNull(forecast.getLocation());
|
||||
Assert.assertNotNull(forecast.getWeatherForecasts());
|
||||
for (WeatherForecast weatherForecast : forecast.getWeatherForecasts()) {
|
||||
Assert.assertNotNull(weatherForecast.getState());
|
||||
Assert.assertNotNull(weatherForecast.getDescription());
|
||||
Assert.assertNotNull(weatherForecast.getForecastTime());
|
||||
Assert.assertNotNull(weatherForecast.getTemperature());
|
||||
Assert.assertNotNull(weatherForecast.getAtmosphericPressure());
|
||||
Assert.assertNotNull(weatherForecast.getHumidity());
|
||||
Assert.assertNotNull(weatherForecast.getWind());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetForecastByCityNameAndStateCodeAndCountryCodeRequestAsJSON_thenReturnNotNull() {
|
||||
final String forecastJson = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byCityName("New York", "NY", "US")
|
||||
.language(Language.SPANISH)
|
||||
.unitSystem(UnitSystem.IMPERIAL)
|
||||
.count(15)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
Assert.assertTrue(forecastJson.startsWith("{"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetForecastByCityNameAndStateCodeAndCountryCodeRequestAsXML_thenReturnNotNull() {
|
||||
final String forecastXml = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byCityName("New York", "NY", "US")
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asXML();
|
||||
|
||||
Assert.assertTrue(forecastXml.startsWith("<"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetForecastByCityIdRequestAsJava_thenReturnNotNull() {
|
||||
final Forecast forecast = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byCityId(350001514)
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.count(15)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
Assert.assertNotNull(forecast);
|
||||
Assert.assertNotNull(forecast.getLocation());
|
||||
Assert.assertNotNull(forecast.getWeatherForecasts());
|
||||
for (WeatherForecast weatherForecast : forecast.getWeatherForecasts()) {
|
||||
Assert.assertNotNull(weatherForecast.getState());
|
||||
Assert.assertNotNull(weatherForecast.getDescription());
|
||||
Assert.assertNotNull(weatherForecast.getForecastTime());
|
||||
Assert.assertNotNull(weatherForecast.getTemperature());
|
||||
Assert.assertNotNull(weatherForecast.getAtmosphericPressure());
|
||||
Assert.assertNotNull(weatherForecast.getHumidity());
|
||||
Assert.assertNotNull(weatherForecast.getWind());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetForecastByCityIdRequestAsJSON_thenReturnNotNull() {
|
||||
final String forecastJson = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byCityId(350001514)
|
||||
.language(Language.SPANISH)
|
||||
.unitSystem(UnitSystem.IMPERIAL)
|
||||
.count(15)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
Assert.assertTrue(forecastJson.startsWith("{"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetForecastByCityIdRequestAsXML_thenReturnNotNull() {
|
||||
final String forecastXml = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byCityId(350001514)
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asXML();
|
||||
|
||||
Assert.assertTrue(forecastXml.startsWith("<"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetForecastByCoordinatesRequestAsJava_thenReturnNotNull() {
|
||||
final Forecast forecast = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byCoordinate(Coordinate.forValues(5, 5))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.count(15)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
Assert.assertNotNull(forecast);
|
||||
Assert.assertNotNull(forecast.getLocation());
|
||||
Assert.assertNotNull(forecast.getWeatherForecasts());
|
||||
for (WeatherForecast weatherForecast : forecast.getWeatherForecasts()) {
|
||||
Assert.assertNotNull(weatherForecast.getState());
|
||||
Assert.assertNotNull(weatherForecast.getDescription());
|
||||
Assert.assertNotNull(weatherForecast.getForecastTime());
|
||||
Assert.assertNotNull(weatherForecast.getTemperature());
|
||||
Assert.assertNotNull(weatherForecast.getAtmosphericPressure());
|
||||
Assert.assertNotNull(weatherForecast.getHumidity());
|
||||
Assert.assertNotNull(weatherForecast.getWind());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetForecastByCoordinatesRequestAsJSON_thenReturnNotNull() {
|
||||
final String forecastJson = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byCoordinate(Coordinate.forValues(5, 5))
|
||||
.language(Language.SPANISH)
|
||||
.unitSystem(UnitSystem.IMPERIAL)
|
||||
.count(15)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
Assert.assertTrue(forecastJson.startsWith("{"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetForecastByCoordinatesRequestAsXML_thenReturnNotNull() {
|
||||
final String forecastXml = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byCoordinate(Coordinate.forValues(5, 5))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asXML();
|
||||
|
||||
Assert.assertTrue(forecastXml.startsWith("<"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetForecastByZipCodeInUSARequestAsJava_thenReturnNotNull() {
|
||||
final Forecast forecast = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byZipCodeInUSA("10005")
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.count(15)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
Assert.assertNotNull(forecast);
|
||||
Assert.assertNotNull(forecast.getLocation());
|
||||
Assert.assertNotNull(forecast.getWeatherForecasts());
|
||||
for (WeatherForecast weatherForecast : forecast.getWeatherForecasts()) {
|
||||
Assert.assertNotNull(weatherForecast.getState());
|
||||
Assert.assertNotNull(weatherForecast.getDescription());
|
||||
Assert.assertNotNull(weatherForecast.getForecastTime());
|
||||
Assert.assertNotNull(weatherForecast.getTemperature());
|
||||
Assert.assertNotNull(weatherForecast.getAtmosphericPressure());
|
||||
Assert.assertNotNull(weatherForecast.getHumidity());
|
||||
Assert.assertNotNull(weatherForecast.getWind());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetForecastByZipCodeInUSARequestAsJSON_thenReturnNotNull() {
|
||||
final String forecastJson = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byZipCodeInUSA("10005")
|
||||
.language(Language.SPANISH)
|
||||
.unitSystem(UnitSystem.IMPERIAL)
|
||||
.count(15)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
Assert.assertTrue(forecastJson.startsWith("{"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetForecastByZipCodeInUSARequestAsXML_thenReturnNotNull() {
|
||||
final String forecastXml = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byZipCodeInUSA("10005")
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asXML();
|
||||
|
||||
Assert.assertTrue(forecastXml.startsWith("<"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetForecastByZipCodeAndCountryCodeRequestAsJava_thenReturnNotNull() {
|
||||
final Forecast forecast = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byZipCodeAndCountry("220015", "by")
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.count(15)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
Assert.assertNotNull(forecast);
|
||||
Assert.assertNotNull(forecast.getLocation());
|
||||
Assert.assertNotNull(forecast.getWeatherForecasts());
|
||||
for (WeatherForecast weatherForecast : forecast.getWeatherForecasts()) {
|
||||
Assert.assertNotNull(weatherForecast.getState());
|
||||
Assert.assertNotNull(weatherForecast.getDescription());
|
||||
Assert.assertNotNull(weatherForecast.getForecastTime());
|
||||
Assert.assertNotNull(weatherForecast.getTemperature());
|
||||
Assert.assertNotNull(weatherForecast.getAtmosphericPressure());
|
||||
Assert.assertNotNull(weatherForecast.getHumidity());
|
||||
Assert.assertNotNull(weatherForecast.getWind());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetForecastByZipCodeAndCountryCodeRequestAsJSON_thenReturnNotNull() {
|
||||
final String forecastJson = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byZipCodeAndCountry("220015", "by")
|
||||
.language(Language.SPANISH)
|
||||
.unitSystem(UnitSystem.IMPERIAL)
|
||||
.count(15)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
Assert.assertTrue(forecastJson.startsWith("{"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetForecastByZipCodeAndCountryCodeRequestAsXML_thenReturnNotNull() {
|
||||
final String forecastXml = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byZipCodeAndCountry("220015", "by")
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asXML();
|
||||
|
||||
Assert.assertTrue(forecastXml.startsWith("<"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetForecastByCityNameAsyncRequestAsJava_thenReturnNotNull() throws ExecutionException, InterruptedException {
|
||||
final CompletableFuture<Forecast> forecastFuture = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byCityName("Minsk")
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.count(15)
|
||||
.retrieveAsync()
|
||||
.asJava();
|
||||
|
||||
Assert.assertNotNull(forecastFuture);
|
||||
System.out.println(forecastFuture.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetForecastByCityNameAsyncRequestAsJSON_thenReturnNotNull() throws ExecutionException, InterruptedException {
|
||||
final CompletableFuture<String> forecastFuture = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byCityId(350001514)
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.count(15)
|
||||
.retrieveAsync()
|
||||
.asJSON();
|
||||
|
||||
Assert.assertNotNull(forecastFuture);
|
||||
System.out.println(forecastFuture.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetForecastByCityNameAsyncRequestAsXML_thenReturnNotNull() throws ExecutionException, InterruptedException {
|
||||
final CompletableFuture<String> forecastFuture = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byCityId(350001514)
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.count(15)
|
||||
.retrieveAsync()
|
||||
.asXML();
|
||||
|
||||
Assert.assertNotNull(forecastFuture);
|
||||
System.out.println(forecastFuture.get());
|
||||
}
|
||||
|
||||
@Test(expected = InvalidAuthTokenException.class)
|
||||
public void whenRequestCurrentWeatherWithInvalidApiKey_thenThrowAnException() {
|
||||
OpenWeatherMapClient client = new OpenWeatherMapClient("invalidKey");
|
||||
client
|
||||
.forecast5Day3HourStep()
|
||||
.byCityId(350001514)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
}
|
||||
|
||||
@Test(expected = NoDataFoundException.class)
|
||||
public void whenRequestCurrentWeatherForInvalidLocation_thenThrowAnException() {
|
||||
getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byCityName("invalidCity")
|
||||
.retrieve()
|
||||
.asJava();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user