mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-07-04 03:36:44 +03:00
2.1.0 version implementation.
This commit is contained in:
+102
-104
@@ -31,12 +31,13 @@ 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;
|
||||
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 FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
@Test
|
||||
public void whenGetForecastByCityNameRequestAsJava_thenReturnNotNull() {
|
||||
@@ -49,17 +50,16 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
Assert.assertNotNull(forecast);
|
||||
Assert.assertNotNull(forecast.getLocation());
|
||||
Assert.assertNotNull(forecast.getWeatherForecasts());
|
||||
assertNotNull(forecast);
|
||||
assertNotNull(forecast.getLocation());
|
||||
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());
|
||||
assertNotNull(weatherForecast.getWeatherState());
|
||||
assertNotNull(weatherForecast.getForecastTime());
|
||||
assertNotNull(weatherForecast.getTemperature());
|
||||
assertNotNull(weatherForecast.getAtmosphericPressure());
|
||||
assertNotNull(weatherForecast.getHumidity());
|
||||
assertNotNull(weatherForecast.getWind());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
Assert.assertTrue(forecastJson.startsWith("{"));
|
||||
assertTrue(forecastJson.startsWith("{"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -88,7 +88,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asXML();
|
||||
|
||||
Assert.assertTrue(forecastXml.startsWith("<"));
|
||||
assertTrue(forecastXml.startsWith("<"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -102,17 +102,16 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
Assert.assertNotNull(forecast);
|
||||
Assert.assertNotNull(forecast.getLocation());
|
||||
Assert.assertNotNull(forecast.getWeatherForecasts());
|
||||
assertNotNull(forecast);
|
||||
assertNotNull(forecast.getLocation());
|
||||
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());
|
||||
assertNotNull(weatherForecast.getWeatherState());
|
||||
assertNotNull(weatherForecast.getForecastTime());
|
||||
assertNotNull(weatherForecast.getTemperature());
|
||||
assertNotNull(weatherForecast.getAtmosphericPressure());
|
||||
assertNotNull(weatherForecast.getHumidity());
|
||||
assertNotNull(weatherForecast.getWind());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +126,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
Assert.assertTrue(forecastJson.startsWith("{"));
|
||||
assertTrue(forecastJson.startsWith("{"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -141,7 +140,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asXML();
|
||||
|
||||
Assert.assertTrue(forecastXml.startsWith("<"));
|
||||
assertTrue(forecastXml.startsWith("<"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -155,17 +154,16 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
Assert.assertNotNull(forecast);
|
||||
Assert.assertNotNull(forecast.getLocation());
|
||||
Assert.assertNotNull(forecast.getWeatherForecasts());
|
||||
assertNotNull(forecast);
|
||||
assertNotNull(forecast.getLocation());
|
||||
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());
|
||||
assertNotNull(weatherForecast.getWeatherState());
|
||||
assertNotNull(weatherForecast.getForecastTime());
|
||||
assertNotNull(weatherForecast.getTemperature());
|
||||
assertNotNull(weatherForecast.getAtmosphericPressure());
|
||||
assertNotNull(weatherForecast.getHumidity());
|
||||
assertNotNull(weatherForecast.getWind());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +178,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
Assert.assertTrue(forecastJson.startsWith("{"));
|
||||
assertTrue(forecastJson.startsWith("{"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -193,7 +191,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asXML();
|
||||
|
||||
Assert.assertTrue(forecastXml.startsWith("<"));
|
||||
assertTrue(forecastXml.startsWith("<"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -207,17 +205,16 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
Assert.assertNotNull(forecast);
|
||||
Assert.assertNotNull(forecast.getLocation());
|
||||
Assert.assertNotNull(forecast.getWeatherForecasts());
|
||||
assertNotNull(forecast);
|
||||
assertNotNull(forecast.getLocation());
|
||||
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());
|
||||
assertNotNull(weatherForecast.getWeatherState());
|
||||
assertNotNull(weatherForecast.getForecastTime());
|
||||
assertNotNull(weatherForecast.getTemperature());
|
||||
assertNotNull(weatherForecast.getAtmosphericPressure());
|
||||
assertNotNull(weatherForecast.getHumidity());
|
||||
assertNotNull(weatherForecast.getWind());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,7 +229,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
Assert.assertTrue(forecastJson.startsWith("{"));
|
||||
assertTrue(forecastJson.startsWith("{"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -245,31 +242,30 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asXML();
|
||||
|
||||
Assert.assertTrue(forecastXml.startsWith("<"));
|
||||
assertTrue(forecastXml.startsWith("<"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetForecastByCoordinatesRequestAsJava_thenReturnNotNull() {
|
||||
final Forecast forecast = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byCoordinate(Coordinate.withValues(5, 5))
|
||||
.byCoordinate(Coordinate.of(5, 5))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.count(15)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
Assert.assertNotNull(forecast);
|
||||
Assert.assertNotNull(forecast.getLocation());
|
||||
Assert.assertNotNull(forecast.getWeatherForecasts());
|
||||
assertNotNull(forecast);
|
||||
assertNotNull(forecast.getLocation());
|
||||
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());
|
||||
assertNotNull(weatherForecast.getWeatherState());
|
||||
assertNotNull(weatherForecast.getForecastTime());
|
||||
assertNotNull(weatherForecast.getTemperature());
|
||||
assertNotNull(weatherForecast.getAtmosphericPressure());
|
||||
assertNotNull(weatherForecast.getHumidity());
|
||||
assertNotNull(weatherForecast.getWind());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,27 +273,27 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
public void whenGetForecastByCoordinatesRequestAsJSON_thenReturnNotNull() {
|
||||
final String forecastJson = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byCoordinate(Coordinate.withValues(5, 5))
|
||||
.byCoordinate(Coordinate.of(5, 5))
|
||||
.language(Language.SPANISH)
|
||||
.unitSystem(UnitSystem.IMPERIAL)
|
||||
.count(15)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
Assert.assertTrue(forecastJson.startsWith("{"));
|
||||
assertTrue(forecastJson.startsWith("{"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetForecastByCoordinatesRequestAsXML_thenReturnNotNull() {
|
||||
final String forecastXml = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byCoordinate(Coordinate.withValues(5, 5))
|
||||
.byCoordinate(Coordinate.of(5, 5))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asXML();
|
||||
|
||||
Assert.assertTrue(forecastXml.startsWith("<"));
|
||||
assertTrue(forecastXml.startsWith("<"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -311,17 +307,16 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
Assert.assertNotNull(forecast);
|
||||
Assert.assertNotNull(forecast.getLocation());
|
||||
Assert.assertNotNull(forecast.getWeatherForecasts());
|
||||
assertNotNull(forecast);
|
||||
assertNotNull(forecast.getLocation());
|
||||
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());
|
||||
assertNotNull(weatherForecast.getWeatherState());
|
||||
assertNotNull(weatherForecast.getForecastTime());
|
||||
assertNotNull(weatherForecast.getTemperature());
|
||||
assertNotNull(weatherForecast.getAtmosphericPressure());
|
||||
assertNotNull(weatherForecast.getHumidity());
|
||||
assertNotNull(weatherForecast.getWind());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,7 +331,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
Assert.assertTrue(forecastJson.startsWith("{"));
|
||||
assertTrue(forecastJson.startsWith("{"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -349,7 +344,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asXML();
|
||||
|
||||
Assert.assertTrue(forecastXml.startsWith("<"));
|
||||
assertTrue(forecastXml.startsWith("<"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -363,17 +358,16 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
Assert.assertNotNull(forecast);
|
||||
Assert.assertNotNull(forecast.getLocation());
|
||||
Assert.assertNotNull(forecast.getWeatherForecasts());
|
||||
assertNotNull(forecast);
|
||||
assertNotNull(forecast.getLocation());
|
||||
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());
|
||||
assertNotNull(weatherForecast.getWeatherState());
|
||||
assertNotNull(weatherForecast.getForecastTime());
|
||||
assertNotNull(weatherForecast.getTemperature());
|
||||
assertNotNull(weatherForecast.getAtmosphericPressure());
|
||||
assertNotNull(weatherForecast.getHumidity());
|
||||
assertNotNull(weatherForecast.getWind());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -388,7 +382,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
Assert.assertTrue(forecastJson.startsWith("{"));
|
||||
assertTrue(forecastJson.startsWith("{"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -401,7 +395,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asXML();
|
||||
|
||||
Assert.assertTrue(forecastXml.startsWith("<"));
|
||||
assertTrue(forecastXml.startsWith("<"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -415,7 +409,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
.retrieveAsync()
|
||||
.asJava();
|
||||
|
||||
Assert.assertNotNull(forecastFuture);
|
||||
assertNotNull(forecastFuture);
|
||||
System.out.println(forecastFuture.get());
|
||||
}
|
||||
|
||||
@@ -430,7 +424,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
.retrieveAsync()
|
||||
.asJSON();
|
||||
|
||||
Assert.assertNotNull(forecastFuture);
|
||||
assertNotNull(forecastFuture);
|
||||
System.out.println(forecastFuture.get());
|
||||
}
|
||||
|
||||
@@ -445,26 +439,30 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
.retrieveAsync()
|
||||
.asXML();
|
||||
|
||||
Assert.assertNotNull(forecastFuture);
|
||||
assertNotNull(forecastFuture);
|
||||
System.out.println(forecastFuture.get());
|
||||
}
|
||||
|
||||
@Test(expected = InvalidAuthTokenException.class)
|
||||
@Test
|
||||
public void whenRequestCurrentWeatherWithInvalidApiKey_thenThrowAnException() {
|
||||
OpenWeatherMapClient client = new OpenWeatherMapClient("invalidKey");
|
||||
client
|
||||
.forecast5Day3HourStep()
|
||||
.byCityId(350001514)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
assertThrows(InvalidAuthTokenException.class, () ->
|
||||
client
|
||||
.forecast5Day3HourStep()
|
||||
.byCityId(350001514)
|
||||
.retrieve()
|
||||
.asJSON()
|
||||
);
|
||||
}
|
||||
|
||||
@Test(expected = NoDataFoundException.class)
|
||||
@Test
|
||||
public void whenRequestCurrentWeatherForInvalidLocation_thenThrowAnException() {
|
||||
getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byCityName("invalidCity")
|
||||
.retrieve()
|
||||
.asJava();
|
||||
assertThrows(NoDataFoundException.class, () ->
|
||||
getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byCityName("invalidCity")
|
||||
.retrieve()
|
||||
.asJava()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+170
File diff suppressed because one or more lines are too long
+137
File diff suppressed because one or more lines are too long
+135
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* 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.onecall.current;
|
||||
|
||||
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.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.onecall.current.CurrentWeatherData;
|
||||
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 CurrentWeatherOneCallIntegrationTest extends ApiTest {
|
||||
@Test
|
||||
public void whenRetrieveCurrentOneCallResponseAsJava_thenOk() {
|
||||
final CurrentWeatherData currentWeatherData = getClient()
|
||||
.oneCall()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
assertNotNull(currentWeatherData);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveCurrentOneCallResponseAsJSON_thenOk() {
|
||||
final String responseJson = getClient()
|
||||
.oneCall()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
assertNotNull(responseJson);
|
||||
assertNotEquals("", responseJson);
|
||||
System.out.println(responseJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveCurrentOneCallResponseWithExclusionAsJava_thenOk() {
|
||||
final CurrentWeatherData currentWeatherData = getClient()
|
||||
.oneCall()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.exclude(OneCallResultOptions.CURRENT, OneCallResultOptions.MINUTELY)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
assertNotNull(currentWeatherData);
|
||||
assertNull(currentWeatherData.getCurrent());
|
||||
assertNull(currentWeatherData.getMinutelyList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveCurrentOneCallAsyncResponseAsJava_thenOk() throws ExecutionException, InterruptedException {
|
||||
final CompletableFuture<CurrentWeatherData> currentWeatherDataFuture = getClient()
|
||||
.oneCall()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieveAsync()
|
||||
.asJava();
|
||||
|
||||
assertNotNull(currentWeatherDataFuture);
|
||||
assertNotNull(currentWeatherDataFuture.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveCurrentOneCallAsyncResponseAsJSON_thenOk() throws ExecutionException, InterruptedException {
|
||||
final CompletableFuture<String> responseJsonFuture = getClient()
|
||||
.oneCall()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieveAsync()
|
||||
.asJSON();
|
||||
|
||||
assertNotNull(responseJsonFuture);
|
||||
final String responseJson = responseJsonFuture.get();
|
||||
assertNotNull(responseJson);
|
||||
System.out.println(responseJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRequestOnecallWithInvalidApiKey_thenThrowAnException() {
|
||||
OpenWeatherMapClient client = new OpenWeatherMapClient("invalidKey");
|
||||
assertThrows(InvalidAuthTokenException.class, () ->
|
||||
client
|
||||
.oneCall()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asJSON()
|
||||
);
|
||||
}
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* 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.onecall.historical;
|
||||
|
||||
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.onecall.historical.HistoricalWeatherData;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class HistoricalWeatherOneCallIntegrationTest extends ApiTest {
|
||||
@Test
|
||||
public void whenRetrieveHistoricalOneCallResponseAsJava_thenOk() {
|
||||
final HistoricalWeatherData historicalWeatherData = getClient()
|
||||
.oneCall()
|
||||
.historical()
|
||||
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
assertNotNull(historicalWeatherData);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveHistoricalOneCallResponseAsJSON_thenOk() {
|
||||
final String responseJson = getClient()
|
||||
.oneCall()
|
||||
.historical()
|
||||
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
assertNotNull(responseJson);
|
||||
assertNotEquals("", responseJson);
|
||||
System.out.println(responseJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveHistoricalOneCallAsyncResponseAsJava_thenOk() throws ExecutionException, InterruptedException {
|
||||
final CompletableFuture<HistoricalWeatherData> historicalWeatherDataFuture = getClient()
|
||||
.oneCall()
|
||||
.historical()
|
||||
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieveAsync()
|
||||
.asJava();
|
||||
|
||||
assertNotNull(historicalWeatherDataFuture);
|
||||
assertNotNull(historicalWeatherDataFuture.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveHistoricalOneCallAsyncResponseAsJSON_thenOk() throws ExecutionException, InterruptedException {
|
||||
final CompletableFuture<String> responseJsonFuture = getClient()
|
||||
.oneCall()
|
||||
.historical()
|
||||
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieveAsync()
|
||||
.asJSON();
|
||||
|
||||
assertNotNull(responseJsonFuture);
|
||||
final String responseJson = responseJsonFuture.get();
|
||||
assertNotEquals("", responseJson);
|
||||
System.out.println(responseJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRequestOnecallWithInvalidApiKey_thenThrowAnException() {
|
||||
OpenWeatherMapClient client = new OpenWeatherMapClient("invalidKey");
|
||||
assertThrows(InvalidAuthTokenException.class, () ->
|
||||
client
|
||||
.oneCall()
|
||||
.historical()
|
||||
.byCoordinateAndTimestamp(Coordinate.of(53.54, 27.34), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asJSON()
|
||||
);
|
||||
}
|
||||
}
|
||||
+244
File diff suppressed because one or more lines are too long
+64
-62
@@ -31,13 +31,14 @@ 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.Assert;
|
||||
import org.junit.Test;
|
||||
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() {
|
||||
@@ -58,17 +59,16 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
Assert.assertNotNull(weatherList);
|
||||
assertNotNull(weatherList);
|
||||
for (Weather weather : weatherList) {
|
||||
Assert.assertNotNull(weather);
|
||||
Assert.assertNotNull(weather.getState());
|
||||
Assert.assertNotNull(weather.getDescription());
|
||||
Assert.assertNotNull(weather.getCalculatedOn());
|
||||
Assert.assertNotNull(weather.getTemperature());
|
||||
Assert.assertNotNull(weather.getLocation());
|
||||
Assert.assertNotNull(weather.getAtmosphericPressure());
|
||||
Assert.assertNotNull(weather.getHumidity());
|
||||
Assert.assertNotNull(weather.getWind());
|
||||
assertNotNull(weather);
|
||||
assertNotNull(weather.getWeatherState());
|
||||
assertNotNull(weather.getCalculationTime());
|
||||
assertNotNull(weather.getTemperature());
|
||||
assertNotNull(weather.getLocation());
|
||||
assertNotNull(weather.getAtmosphericPressure());
|
||||
assertNotNull(weather.getHumidity());
|
||||
assertNotNull(weather.getWind());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
Assert.assertTrue(weatherJson.startsWith("{"));
|
||||
assertTrue(weatherJson.startsWith("{"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,24 +91,23 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
final List<Weather> weatherList = getClient()
|
||||
.currentWeather()
|
||||
.multiple()
|
||||
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5))
|
||||
.byCitiesInCycle(Coordinate.of(55.5, 37.5))
|
||||
.language(Language.GERMAN)
|
||||
.unitSystem(UnitSystem.IMPERIAL)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
Assert.assertNotNull(weatherList);
|
||||
assertNotNull(weatherList);
|
||||
for (Weather weather : weatherList) {
|
||||
System.out.println(weather);
|
||||
Assert.assertNotNull(weather);
|
||||
Assert.assertNotNull(weather.getState());
|
||||
Assert.assertNotNull(weather.getDescription());
|
||||
Assert.assertNotNull(weather.getCalculatedOn());
|
||||
Assert.assertNotNull(weather.getTemperature());
|
||||
Assert.assertNotNull(weather.getLocation());
|
||||
Assert.assertNotNull(weather.getAtmosphericPressure());
|
||||
Assert.assertNotNull(weather.getHumidity());
|
||||
Assert.assertNotNull(weather.getWind());
|
||||
assertNotNull(weather);
|
||||
assertNotNull(weather.getWeatherState());
|
||||
assertNotNull(weather.getCalculationTime());
|
||||
assertNotNull(weather.getTemperature());
|
||||
assertNotNull(weather.getLocation());
|
||||
assertNotNull(weather.getAtmosphericPressure());
|
||||
assertNotNull(weather.getHumidity());
|
||||
assertNotNull(weather.getWind());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,13 +116,13 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
final String weatherJson = getClient()
|
||||
.currentWeather()
|
||||
.multiple()
|
||||
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5))
|
||||
.byCitiesInCycle(Coordinate.of(55.5, 37.5))
|
||||
.language(Language.GERMAN)
|
||||
.unitSystem(UnitSystem.IMPERIAL)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
Assert.assertTrue(weatherJson.startsWith("{"));
|
||||
assertTrue(weatherJson.startsWith("{"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -131,13 +130,13 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
final String weatherXml = getClient()
|
||||
.currentWeather()
|
||||
.multiple()
|
||||
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5))
|
||||
.byCitiesInCycle(Coordinate.of(55.5, 37.5))
|
||||
.language(Language.GERMAN)
|
||||
.unitSystem(UnitSystem.IMPERIAL)
|
||||
.retrieve()
|
||||
.asXML();
|
||||
|
||||
Assert.assertTrue(weatherXml.startsWith("<"));
|
||||
assertTrue(weatherXml.startsWith("<"));
|
||||
System.out.println(weatherXml);
|
||||
}
|
||||
|
||||
@@ -146,24 +145,23 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
final List<Weather> weatherList = getClient()
|
||||
.currentWeather()
|
||||
.multiple()
|
||||
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5), 10)
|
||||
.byCitiesInCycle(Coordinate.of(55.5, 37.5), 10)
|
||||
.language(Language.GERMAN)
|
||||
.unitSystem(UnitSystem.IMPERIAL)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
Assert.assertNotNull(weatherList);
|
||||
assertNotNull(weatherList);
|
||||
for (Weather weather : weatherList) {
|
||||
System.out.println(weather);
|
||||
Assert.assertNotNull(weather);
|
||||
Assert.assertNotNull(weather.getState());
|
||||
Assert.assertNotNull(weather.getDescription());
|
||||
Assert.assertNotNull(weather.getCalculatedOn());
|
||||
Assert.assertNotNull(weather.getTemperature());
|
||||
Assert.assertNotNull(weather.getLocation());
|
||||
Assert.assertNotNull(weather.getAtmosphericPressure());
|
||||
Assert.assertNotNull(weather.getHumidity());
|
||||
Assert.assertNotNull(weather.getWind());
|
||||
assertNotNull(weather);
|
||||
assertNotNull(weather.getWeatherState());
|
||||
assertNotNull(weather.getCalculationTime());
|
||||
assertNotNull(weather.getTemperature());
|
||||
assertNotNull(weather.getLocation());
|
||||
assertNotNull(weather.getAtmosphericPressure());
|
||||
assertNotNull(weather.getHumidity());
|
||||
assertNotNull(weather.getWind());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,13 +170,13 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
final String weatherJson = getClient()
|
||||
.currentWeather()
|
||||
.multiple()
|
||||
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5), 10)
|
||||
.byCitiesInCycle(Coordinate.of(55.5, 37.5), 10)
|
||||
.language(Language.GERMAN)
|
||||
.unitSystem(UnitSystem.IMPERIAL)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
Assert.assertTrue(weatherJson.startsWith("{"));
|
||||
assertTrue(weatherJson.startsWith("{"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -186,13 +184,13 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
final String weatherXml = getClient()
|
||||
.currentWeather()
|
||||
.multiple()
|
||||
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5), 10)
|
||||
.byCitiesInCycle(Coordinate.of(55.5, 37.5), 10)
|
||||
.language(Language.GERMAN)
|
||||
.unitSystem(UnitSystem.IMPERIAL)
|
||||
.retrieve()
|
||||
.asXML();
|
||||
|
||||
Assert.assertTrue(weatherXml.startsWith("<"));
|
||||
assertTrue(weatherXml.startsWith("<"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -200,15 +198,15 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
final CompletableFuture<List<Weather>> weatherListFuture = getClient()
|
||||
.currentWeather()
|
||||
.multiple()
|
||||
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5), 10)
|
||||
.byCitiesInCycle(Coordinate.of(55.5, 37.5), 10)
|
||||
.language(Language.GERMAN)
|
||||
.unitSystem(UnitSystem.IMPERIAL)
|
||||
.retrieveAsync()
|
||||
.asJava();
|
||||
|
||||
Assert.assertNotNull(weatherListFuture);
|
||||
assertNotNull(weatherListFuture);
|
||||
List<Weather> weatherList = weatherListFuture.get();
|
||||
Assert.assertTrue(weatherList.size() > 0);
|
||||
assertTrue(weatherList.size() > 0);
|
||||
System.out.println(weatherList);
|
||||
}
|
||||
|
||||
@@ -217,34 +215,38 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
final CompletableFuture<String> weatherFuture = getClient()
|
||||
.currentWeather()
|
||||
.multiple()
|
||||
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5), 10)
|
||||
.byCitiesInCycle(Coordinate.of(55.5, 37.5), 10)
|
||||
.language(Language.GERMAN)
|
||||
.unitSystem(UnitSystem.IMPERIAL)
|
||||
.retrieveAsync()
|
||||
.asJSON();
|
||||
|
||||
Assert.assertNotNull(weatherFuture);
|
||||
assertNotNull(weatherFuture);
|
||||
System.out.println(weatherFuture.get());
|
||||
}
|
||||
|
||||
@Test(expected = InvalidAuthTokenException.class)
|
||||
@Test
|
||||
public void whenRequestCurrentWeatherWithInvalidApiKey_thenThrowAnException() {
|
||||
OpenWeatherMapClient client = new OpenWeatherMapClient("invalidKey");
|
||||
client
|
||||
.currentWeather()
|
||||
.single()
|
||||
.byCityName("London")
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
assertThrows(InvalidAuthTokenException.class, () ->
|
||||
client
|
||||
.currentWeather()
|
||||
.single()
|
||||
.byCityName("London")
|
||||
.retrieve()
|
||||
.asJSON()
|
||||
);
|
||||
}
|
||||
|
||||
@Test(expected = NoDataFoundException.class)
|
||||
@Test
|
||||
public void whenRequestCurrentWeatherForInvalidLocation_thenThrowAnException() {
|
||||
getClient()
|
||||
.currentWeather()
|
||||
.single()
|
||||
.byCityName("InvalidCity")
|
||||
.retrieve()
|
||||
.asJava();
|
||||
assertThrows(NoDataFoundException.class, () ->
|
||||
getClient()
|
||||
.currentWeather()
|
||||
.single()
|
||||
.byCityName("InvalidCity")
|
||||
.retrieve()
|
||||
.asJava()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+106
-108
@@ -30,12 +30,13 @@ import com.github.prominence.openweathermap.api.exception.NoDataFoundException;
|
||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||
import com.github.prominence.openweathermap.api.OpenWeatherMapClient;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
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() {
|
||||
@@ -48,15 +49,14 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
Assert.assertNotNull(weather);
|
||||
Assert.assertNotNull(weather.getState());
|
||||
Assert.assertNotNull(weather.getDescription());
|
||||
Assert.assertNotNull(weather.getCalculatedOn());
|
||||
Assert.assertNotNull(weather.getTemperature());
|
||||
Assert.assertNotNull(weather.getLocation());
|
||||
Assert.assertNotNull(weather.getAtmosphericPressure());
|
||||
Assert.assertNotNull(weather.getHumidity());
|
||||
Assert.assertNotNull(weather.getWind());
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
Assert.assertTrue(weatherJson.startsWith("{"));
|
||||
assertTrue(weatherJson.startsWith("{"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,7 +85,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asXML();
|
||||
|
||||
Assert.assertTrue(weatherXml.startsWith("<"));
|
||||
assertTrue(weatherXml.startsWith("<"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -99,7 +99,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asHTML();
|
||||
|
||||
Assert.assertTrue(weatherHtml.startsWith("<"));
|
||||
assertTrue(weatherHtml.startsWith("<"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -113,15 +113,14 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
Assert.assertNotNull(weather);
|
||||
Assert.assertNotNull(weather.getState());
|
||||
Assert.assertNotNull(weather.getDescription());
|
||||
Assert.assertNotNull(weather.getCalculatedOn());
|
||||
Assert.assertNotNull(weather.getTemperature());
|
||||
Assert.assertNotNull(weather.getLocation());
|
||||
Assert.assertNotNull(weather.getAtmosphericPressure());
|
||||
Assert.assertNotNull(weather.getHumidity());
|
||||
Assert.assertNotNull(weather.getWind());
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -136,7 +135,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
Assert.assertTrue(weatherJson.startsWith("{"));
|
||||
assertTrue(weatherJson.startsWith("{"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -150,7 +149,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asXML();
|
||||
|
||||
Assert.assertTrue(weatherXml.startsWith("<"));
|
||||
assertTrue(weatherXml.startsWith("<"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -164,7 +163,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asHTML();
|
||||
|
||||
Assert.assertTrue(weatherHtml.startsWith("<"));
|
||||
assertTrue(weatherHtml.startsWith("<"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -178,15 +177,14 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
Assert.assertNotNull(weather);
|
||||
Assert.assertNotNull(weather.getState());
|
||||
Assert.assertNotNull(weather.getDescription());
|
||||
Assert.assertNotNull(weather.getCalculatedOn());
|
||||
Assert.assertNotNull(weather.getTemperature());
|
||||
Assert.assertNotNull(weather.getLocation());
|
||||
Assert.assertNotNull(weather.getAtmosphericPressure());
|
||||
Assert.assertNotNull(weather.getHumidity());
|
||||
Assert.assertNotNull(weather.getWind());
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -201,7 +199,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
Assert.assertTrue(weatherJson.startsWith("{"));
|
||||
assertTrue(weatherJson.startsWith("{"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -215,7 +213,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asXML();
|
||||
|
||||
Assert.assertTrue(weatherXml.startsWith("<"));
|
||||
assertTrue(weatherXml.startsWith("<"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -229,7 +227,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asHTML();
|
||||
|
||||
Assert.assertTrue(weatherHtml.startsWith("<"));
|
||||
assertTrue(weatherHtml.startsWith("<"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -242,15 +240,14 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
Assert.assertNotNull(weather);
|
||||
Assert.assertNotNull(weather.getState());
|
||||
Assert.assertNotNull(weather.getDescription());
|
||||
Assert.assertNotNull(weather.getCalculatedOn());
|
||||
Assert.assertNotNull(weather.getTemperature());
|
||||
Assert.assertNotNull(weather.getLocation());
|
||||
Assert.assertNotNull(weather.getAtmosphericPressure());
|
||||
Assert.assertNotNull(weather.getHumidity());
|
||||
Assert.assertNotNull(weather.getWind());
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -264,7 +261,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
Assert.assertTrue(weatherJson.startsWith("{"));
|
||||
assertTrue(weatherJson.startsWith("{"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -277,7 +274,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asXML();
|
||||
|
||||
Assert.assertTrue(weatherXml.startsWith("<"));
|
||||
assertTrue(weatherXml.startsWith("<"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -290,7 +287,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asXML();
|
||||
|
||||
Assert.assertTrue(weatherHtml.startsWith("<"));
|
||||
assertTrue(weatherHtml.startsWith("<"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -298,20 +295,19 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
final Weather weather = getClient()
|
||||
.currentWeather()
|
||||
.single()
|
||||
.byCoordinate(Coordinate.withValues(5, 5))
|
||||
.byCoordinate(Coordinate.of(5, 5))
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
Assert.assertNotNull(weather);
|
||||
Assert.assertNotNull(weather.getState());
|
||||
Assert.assertNotNull(weather.getDescription());
|
||||
Assert.assertNotNull(weather.getCalculatedOn());
|
||||
Assert.assertNotNull(weather.getTemperature());
|
||||
Assert.assertNotNull(weather.getLocation());
|
||||
Assert.assertNotNull(weather.getAtmosphericPressure());
|
||||
Assert.assertNotNull(weather.getHumidity());
|
||||
Assert.assertNotNull(weather.getWind());
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -320,12 +316,12 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
final String weatherJson = getClient()
|
||||
.currentWeather()
|
||||
.single()
|
||||
.byCoordinate(Coordinate.withValues(5, 5))
|
||||
.byCoordinate(Coordinate.of(5, 5))
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
Assert.assertTrue(weatherJson.startsWith("{"));
|
||||
assertTrue(weatherJson.startsWith("{"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -333,12 +329,12 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
final String weatherXml = getClient()
|
||||
.currentWeather()
|
||||
.single()
|
||||
.byCoordinate(Coordinate.withValues(5, 5))
|
||||
.byCoordinate(Coordinate.of(5, 5))
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asXML();
|
||||
|
||||
Assert.assertTrue(weatherXml.startsWith("<"));
|
||||
assertTrue(weatherXml.startsWith("<"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -346,12 +342,12 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
final String weatherHtml = getClient()
|
||||
.currentWeather()
|
||||
.single()
|
||||
.byCoordinate(Coordinate.withValues(5, 5))
|
||||
.byCoordinate(Coordinate.of(5, 5))
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asHTML();
|
||||
|
||||
Assert.assertTrue(weatherHtml.startsWith("<"));
|
||||
assertTrue(weatherHtml.startsWith("<"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -365,15 +361,14 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
Assert.assertNotNull(weather);
|
||||
Assert.assertNotNull(weather.getState());
|
||||
Assert.assertNotNull(weather.getDescription());
|
||||
Assert.assertNotNull(weather.getCalculatedOn());
|
||||
Assert.assertNotNull(weather.getTemperature());
|
||||
Assert.assertNotNull(weather.getLocation());
|
||||
Assert.assertNotNull(weather.getAtmosphericPressure());
|
||||
Assert.assertNotNull(weather.getHumidity());
|
||||
Assert.assertNotNull(weather.getWind());
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -388,7 +383,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
Assert.assertTrue(weatherJson.startsWith("{"));
|
||||
assertTrue(weatherJson.startsWith("{"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -402,7 +397,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asXML();
|
||||
|
||||
Assert.assertTrue(weatherXml.startsWith("<"));
|
||||
assertTrue(weatherXml.startsWith("<"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -416,7 +411,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asHTML();
|
||||
|
||||
Assert.assertTrue(weatherHtml.startsWith("<"));
|
||||
assertTrue(weatherHtml.startsWith("<"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -430,15 +425,14 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
Assert.assertNotNull(weather);
|
||||
Assert.assertNotNull(weather.getState());
|
||||
Assert.assertNotNull(weather.getDescription());
|
||||
Assert.assertNotNull(weather.getCalculatedOn());
|
||||
Assert.assertNotNull(weather.getTemperature());
|
||||
Assert.assertNotNull(weather.getLocation());
|
||||
Assert.assertNotNull(weather.getAtmosphericPressure());
|
||||
Assert.assertNotNull(weather.getHumidity());
|
||||
Assert.assertNotNull(weather.getWind());
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -453,7 +447,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
Assert.assertTrue(weatherJson.startsWith("{"));
|
||||
assertTrue(weatherJson.startsWith("{"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -467,7 +461,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asXML();
|
||||
|
||||
Assert.assertTrue(weatherXml.startsWith("<"));
|
||||
assertTrue(weatherXml.startsWith("<"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -481,7 +475,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
.retrieve()
|
||||
.asHTML();
|
||||
|
||||
Assert.assertTrue(weatherHtml.startsWith("<"));
|
||||
assertTrue(weatherHtml.startsWith("<"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -495,7 +489,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
.retrieveAsync()
|
||||
.asJava();
|
||||
|
||||
Assert.assertNotNull(weatherFuture);
|
||||
assertNotNull(weatherFuture);
|
||||
System.out.println(weatherFuture.get());
|
||||
}
|
||||
|
||||
@@ -510,7 +504,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
.retrieveAsync()
|
||||
.asJSON();
|
||||
|
||||
Assert.assertNotNull(weatherFuture);
|
||||
assertNotNull(weatherFuture);
|
||||
System.out.println(weatherFuture.get());
|
||||
}
|
||||
|
||||
@@ -525,7 +519,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
.retrieveAsync()
|
||||
.asXML();
|
||||
|
||||
Assert.assertNotNull(weatherXmlFuture);
|
||||
assertNotNull(weatherXmlFuture);
|
||||
System.out.println(weatherXmlFuture.get());
|
||||
}
|
||||
|
||||
@@ -540,28 +534,32 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
.retrieveAsync()
|
||||
.asHTML();
|
||||
|
||||
Assert.assertNotNull(weatherFuture);
|
||||
assertNotNull(weatherFuture);
|
||||
System.out.println(weatherFuture.get());
|
||||
}
|
||||
|
||||
@Test(expected = InvalidAuthTokenException.class)
|
||||
@Test
|
||||
public void whenRequestCurrentWeatherWithInvalidApiKey_thenThrowAnException() {
|
||||
OpenWeatherMapClient client = new OpenWeatherMapClient("invalidKey");
|
||||
client
|
||||
.currentWeather()
|
||||
.multiple()
|
||||
.byCitiesInCycle(Coordinate.withValues(34.53, 66.74), 10)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
assertThrows(InvalidAuthTokenException.class, () ->
|
||||
client
|
||||
.currentWeather()
|
||||
.multiple()
|
||||
.byCitiesInCycle(Coordinate.of(34.53, 66.74), 10)
|
||||
.retrieve()
|
||||
.asJSON()
|
||||
);
|
||||
}
|
||||
|
||||
@Test(expected = NoDataFoundException.class)
|
||||
@Test
|
||||
public void whenRequestCurrentWeatherForInvalidLocation_thenThrowAnException() {
|
||||
getClient()
|
||||
.currentWeather()
|
||||
.multiple()
|
||||
.byCitiesInCycle(Coordinate.withValues(90.00, 66.74), 10)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
assertThrows(NoDataFoundException.class, () ->
|
||||
getClient()
|
||||
.currentWeather()
|
||||
.multiple()
|
||||
.byCitiesInCycle(Coordinate.of(90.00, 66.74), 10)
|
||||
.retrieve()
|
||||
.asJava()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user