Initial implementation of free-plan forecast retriever. Small refactoring.

This commit is contained in:
2021-03-21 02:32:39 +03:00
parent d63de824b3
commit ea39441e83
60 changed files with 697 additions and 526 deletions
@@ -0,0 +1,46 @@
/*
* 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.forecast.free;
import com.github.prominence.openweathermap.api.ApiTest;
import com.github.prominence.openweathermap.api.enums.Language;
import com.github.prominence.openweathermap.api.enums.UnitSystem;
import org.junit.Test;
public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
@Test
public void whenGetTest_thenReturnNotNull() {
final String weatherJSON = getClient()
.forecast5Day3HourStep()
.byCityName("Minsk")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
.count(15)
.retrieve()
.asJSON();
assert weatherJSON != null;
System.out.println(weatherJSON);
}
}
@@ -1,415 +0,0 @@
/*
* Copyright (c) 2019 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;
import com.github.prominence.openweathermap.api.ApiTest;
import com.github.prominence.openweathermap.api.enums.Accuracy;
import com.github.prominence.openweathermap.api.enums.Language;
import com.github.prominence.openweathermap.api.enums.UnitSystem;
import com.github.prominence.openweathermap.api.exception.NoDataFoundException;
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
import com.github.prominence.openweathermap.api.OpenWeatherMapClient;
import com.github.prominence.openweathermap.api.model.Coordinate;
import com.github.prominence.openweathermap.api.model.CoordinateRectangle;
import com.github.prominence.openweathermap.api.model.Weather;
import org.junit.Test;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
public class CurrentWeatherIntegrationTest extends ApiTest {
@Test
public void whenGetSingleCurrentWeatherByCoordinateRequestAsJava_thenReturnNotNull() {
final Weather weather = getClient()
.currentWeather()
.single()
.byCoordinate(new Coordinate(5, 5))
.accuracy(Accuracy.ACCURATE)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJava();
assert weather != null;
System.out.println(weather);
}
@Test
public void whenGetSingleCurrentWeatherByCityIdRequestAsJava_thenReturnNotNull() {
final Weather weather = getClient()
.currentWeather()
.single()
.byCityId(350001514)
.language(Language.GERMAN)
.retrieve()
.asJava();
assert weather != null;
System.out.println(weather);
}
@Test
public void whenGetSingleCurrentWeatherByCityNameRequestAsJava_thenReturnNotNull() {
final Weather weather = getClient()
.currentWeather()
.single()
.byCityName("Minsk")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJava();
assert weather != null;
System.out.println(weather);
}
@Test
public void whenGetSingleCurrentWeatherByCityNameAndCountryCodeRequestAsJava_thenReturnNotNull() {
final Weather weather = getClient()
.currentWeather()
.single()
.byCityName("Moscow", "ru")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJava();
assert weather != null;
System.out.println(weather);
}
@Test
public void whenGetSingleCurrentWeatherByZipCodeAndCountryRequestAsJava_thenReturnNotNull() {
final Weather weather = getClient()
.currentWeather()
.single()
.byZipCodeAndCountry("220015", "by")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJava();
assert weather != null;
System.out.println(weather);
}
@Test
public void whenGetAnySingleCurrentRequestWeatherAsJson_thenReturnNotNull() {
final String weatherJson = getClient()
.currentWeather()
.single()
.byZipCodeAndCountry("220015", "by")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJSON();
assert weatherJson != null;
System.out.println(weatherJson);
}
@Test
public void whenGetAnySingleCurrentRequestWeatherAsXml_thenReturnNotNull() {
final String weatherXml = getClient()
.currentWeather()
.single()
.byZipCodeAndCountry("220015", "by")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asXML();
assert weatherXml != null;
System.out.println(weatherXml);
}
@Test
public void whenGetAnySingleCurrentWeatherRequestAsHtml_thenReturnNotNull() {
final String weatherHtml = getClient()
.currentWeather()
.single()
.byZipCodeAndCountry("220015", "by")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asHTML();
assert weatherHtml != null;
System.out.println(weatherHtml);
}
@Test
public void whenGetAnySingleCurrentWeatherAsyncRequestAsXml_thenReturnNotNull() throws ExecutionException, InterruptedException {
final CompletableFuture<String> weatherXmlFuture = getClient()
.currentWeather()
.single()
.byZipCodeAndCountry("220015", "by")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
.retrieveAsync()
.asXML();
assert weatherXmlFuture != null;
System.out.println(weatherXmlFuture.get());
}
@Test
public void whenGetAnySingleCurrentWeatherAsyncRequestAsJava_thenReturnNotNull() throws ExecutionException, InterruptedException {
final CompletableFuture<Weather> weatherFuture = getClient()
.currentWeather()
.single()
.byZipCodeAndCountry("220015", "by")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
.retrieveAsync()
.asJava();
assert weatherFuture != null;
System.out.println(weatherFuture.get());
}
@Test
public void whenGetAnySingleCurrentWeatherAsyncRequestAsJson_thenReturnNotNull() throws ExecutionException, InterruptedException {
final CompletableFuture<String> weatherFuture = getClient()
.currentWeather()
.single()
.byZipCodeAndCountry("220015", "by")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
.retrieveAsync()
.asJSON();
assert weatherFuture != null;
System.out.println(weatherFuture.get());
}
@Test
public void whenGetAnySingleCurrentWeatherAsyncRequestAsHtml_thenReturnNotNull() throws ExecutionException, InterruptedException {
final CompletableFuture<String> weatherFuture = getClient()
.currentWeather()
.single()
.byZipCodeAndCountry("220015", "by")
.language(Language.RUSSIAN)
.unitSystem(UnitSystem.METRIC)
.retrieveAsync()
.asHTML();
assert weatherFuture != null;
System.out.println(weatherFuture.get());
}
@Test
public void whenGetMultipleCurrentWeatherByCoordinateRequestAsJava_thenReturnNotNull() {
final List<Weather> weatherList = getClient()
.currentWeather()
.multiple()
.byRectangle(new CoordinateRectangle(12, 32, 15, 37), 10)
.accuracy(Accuracy.ACCURATE)
.language(Language.ROMANIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJava();
assert weatherList != null;
assert weatherList.size() > 0;
System.out.println(weatherList);
}
@Test
public void whenGetMultipleCurrentWeatherByCoordinateAndServerClusteringRequestAsJava_thenReturnNotNull() {
final List<Weather> weatherList = getClient()
.currentWeather()
.multiple()
.byRectangle(new CoordinateRectangle(12, 32, 15, 37), 10, true)
.accuracy(Accuracy.ACCURATE)
.language(Language.ROMANIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJava();
assert weatherList != null;
assert weatherList.size() > 0;
System.out.println(weatherList);
}
@Test
public void whenGetMultipleCurrentWeatherByCitiesInCycleRequestAsJava_thenReturnNotNull() {
final List<Weather> weatherList = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
.asJava();
assert weatherList != null;
assert weatherList.size() > 0;
System.out.println(weatherList);
}
@Test
public void whenGetMultipleCurrentWeatherByCitiesInCycleAndServerClusteringRequestAsJava_thenReturnNotNull() {
final List<Weather> weatherList = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10, true)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
.asJava();
assert weatherList != null;
assert weatherList.size() > 0;
System.out.println(weatherList);
}
@Test
public void whenGetMultipleCurrentWeatherByCitiesInCycleRequestAsJson_thenReturnNotNull() {
final String weather = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
.asJSON();
assert weather != null;
System.out.println(weather);
}
@Test
public void whenGetMultipleCurrentWeatherByCitiesInCycleRequestAsXml_thenReturnNotNull() {
final String weather = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
.asXML();
assert weather != null;
System.out.println(weather);
}
@Test
public void whenGetMultipleCurrentWeatherByCitiesInCycleRequestAsHtml_thenReturnNotNull() {
final String weather = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieve()
.asHTML();
assert weather != null;
System.out.println(weather);
}
@Test
public void whenGetMultipleCurrentWeatherByCoordinateAndServerClusteringAsyncRequestAsJava_thenReturnNotNull() throws ExecutionException, InterruptedException {
final CompletableFuture<List<Weather>> weatherListFuture = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10, true)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieveAsync()
.asJava();
assert weatherListFuture != null;
List<Weather> weatherList = weatherListFuture.get();
assert weatherList.size() > 0;
System.out.println(weatherList);
}
@Test
public void whenGetMultipleCurrentWeatherByCoordinateAndServerClusteringAsyncRequestAsXml_thenReturnNotNull() throws ExecutionException, InterruptedException {
final CompletableFuture<String> weatherFuture = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10, true)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieveAsync()
.asXML();
assert weatherFuture != null;
System.out.println(weatherFuture.get());
}
@Test
public void whenGetMultipleCurrentWeatherByCoordinateAndServerClusteringAsyncRequestAsJson_thenReturnNotNull() throws ExecutionException, InterruptedException {
final CompletableFuture<String> weatherFuture = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10, true)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieveAsync()
.asJSON();
assert weatherFuture != null;
System.out.println(weatherFuture.get());
}
@Test
public void whenGetMultipleCurrentWeatherByCoordinateAndServerClusteringAsyncRequestAsHtml_thenReturnNotNull() throws ExecutionException, InterruptedException {
final CompletableFuture<String> weatherFuture = getClient()
.currentWeather()
.multiple()
.byCitiesInCycle(new Coordinate(55.5, 37.5), 10, true)
.language(Language.GERMAN)
.unitSystem(UnitSystem.IMPERIAL)
.retrieveAsync()
.asHTML();
assert weatherFuture != null;
System.out.println(weatherFuture.get());
}
@Test(expected = InvalidAuthTokenException.class)
public void whenRequestCurrentWeatherWithInvalidApiKey_thenThrowAnException() {
OpenWeatherMapClient client = new OpenWeatherMapClient("invalidKey");
client
.currentWeather()
.single()
.byCityName("London")
.retrieve()
.asJSON();
}
@Test(expected = NoDataFoundException.class)
public void whenRequestCurrentWeatherForInvalidLocation_thenThrowAnException() {
getClient()
.currentWeather()
.single()
.byCityName("InvalidCity")
.retrieve()
.asJava();
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019 Alexey Zinchenko
* 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
@@ -23,7 +23,6 @@
package com.github.prominence.openweathermap.api.request.weather.multiple;
import com.github.prominence.openweathermap.api.ApiTest;
import com.github.prominence.openweathermap.api.enums.Accuracy;
import com.github.prominence.openweathermap.api.enums.Language;
import com.github.prominence.openweathermap.api.enums.UnitSystem;
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
@@ -38,7 +37,7 @@ import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
public class CurrentWeatherIntegrationTest extends ApiTest {
public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
@Test
public void whenGetMultipleCurrentWeatherByCoordinateRequestAsJava_thenReturnNotNull() {
@@ -46,7 +45,6 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
.currentWeather()
.multiple()
.byRectangle(new CoordinateRectangle(12, 32, 15, 37), 10)
.accuracy(Accuracy.ACCURATE)
.language(Language.ROMANIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
@@ -63,7 +61,6 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
.currentWeather()
.multiple()
.byRectangle(new CoordinateRectangle(12, 32, 15, 37), 10, true)
.accuracy(Accuracy.ACCURATE)
.language(Language.ROMANIAN)
.unitSystem(UnitSystem.METRIC)
.retrieve()
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019 Alexey Zinchenko
* 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
@@ -23,7 +23,6 @@
package com.github.prominence.openweathermap.api.request.weather.single;
import com.github.prominence.openweathermap.api.ApiTest;
import com.github.prominence.openweathermap.api.enums.Accuracy;
import com.github.prominence.openweathermap.api.enums.Language;
import com.github.prominence.openweathermap.api.enums.UnitSystem;
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
@@ -36,7 +35,7 @@ import org.junit.Test;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
public class CurrentWeatherIntegrationTest extends ApiTest {
public class SingleResultCurrentWeatherIntegrationTest extends ApiTest {
@Test
public void whenGetSingleCurrentWeatherByCoordinateRequestAsJava_thenReturnNotNull() {
@@ -44,7 +43,6 @@ public class CurrentWeatherIntegrationTest extends ApiTest {
.currentWeather()
.single()
.byCoordinate(new Coordinate(5, 5))
.accuracy(Accuracy.ACCURATE)
.unitSystem(UnitSystem.METRIC)
.retrieve()
.asJava();