mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-07-03 03:06:45 +03:00
Releasing 2.2.0 version.
This commit is contained in:
@@ -23,6 +23,8 @@
|
||||
package com.github.prominence.openweathermap.api;
|
||||
|
||||
import com.github.prominence.openweathermap.api.annotation.SubscriptionAvailability;
|
||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequester;
|
||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequesterImpl;
|
||||
import com.github.prominence.openweathermap.api.request.forecast.free.FiveDayThreeHourStepForecastRequester;
|
||||
import com.github.prominence.openweathermap.api.request.forecast.free.FiveDayThreeHourStepForecastRequesterImpl;
|
||||
import com.github.prominence.openweathermap.api.request.onecall.OneCallWeatherRequester;
|
||||
@@ -74,4 +76,14 @@ public class OpenWeatherMapClient {
|
||||
public OneCallWeatherRequester oneCall() {
|
||||
return new OneCallWeatherRequesterImpl(apiKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Air Pollution <a href="https://openweathermap.org/api/air-pollution">API</a>.
|
||||
* Air Pollution API provides current, forecast and historical air pollution data for any coordinates on the globe.
|
||||
* @return requester for air pollution information retrieval.
|
||||
*/
|
||||
@SubscriptionAvailability(plans = ALL)
|
||||
public AirPollutionRequester airPollution() {
|
||||
return new AirPollutionRequesterImpl(apiKey);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
*
|
||||
* * 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.enums;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* The enum Air quality index.
|
||||
*/
|
||||
public enum AirQualityIndex {
|
||||
/**
|
||||
* Good air quality index.
|
||||
*/
|
||||
GOOD(1),
|
||||
/**
|
||||
* Fair air quality index.
|
||||
*/
|
||||
FAIR(2),
|
||||
/**
|
||||
* Moderate air quality index.
|
||||
*/
|
||||
MODERATE(3),
|
||||
/**
|
||||
* Poor air quality index.
|
||||
*/
|
||||
POOR(4),
|
||||
/**
|
||||
* Very poor air quality index.
|
||||
*/
|
||||
VERY_POOR(5);
|
||||
|
||||
private final int value;
|
||||
|
||||
AirQualityIndex(int index) {
|
||||
this.value = index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets by index.
|
||||
*
|
||||
* @param index the index
|
||||
* @return the by index
|
||||
*/
|
||||
public static AirQualityIndex getByIndex(int index) {
|
||||
final Optional<AirQualityIndex> optionalAirQualityIndex = Arrays.stream(values()).filter(airQualityIndex -> airQualityIndex.getValue() == index).findFirst();
|
||||
return optionalAirQualityIndex.orElse(null);
|
||||
}
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
*
|
||||
* * 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.model.air.pollution;
|
||||
|
||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* The type Air pollution.
|
||||
*/
|
||||
public class AirPollutionDetails {
|
||||
private Coordinate coordinate;
|
||||
private List<AirPollutionRecord> airPollutionRecords;
|
||||
|
||||
/**
|
||||
* Gets coordinate.
|
||||
*
|
||||
* @return the coordinate
|
||||
*/
|
||||
public Coordinate getCoordinate() {
|
||||
return coordinate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets coordinate.
|
||||
*
|
||||
* @param coordinate the coordinate
|
||||
*/
|
||||
public void setCoordinate(Coordinate coordinate) {
|
||||
this.coordinate = coordinate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets air pollution details.
|
||||
*
|
||||
* @return the air pollution details
|
||||
*/
|
||||
public List<AirPollutionRecord> getAirPollutionRecords() {
|
||||
return airPollutionRecords;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets air pollution details.
|
||||
*
|
||||
* @param airPollutionRecords the air pollution details
|
||||
*/
|
||||
public void setAirPollutionRecords(List<AirPollutionRecord> airPollutionRecords) {
|
||||
this.airPollutionRecords = airPollutionRecords;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
AirPollutionDetails that = (AirPollutionDetails) o;
|
||||
return Objects.equals(coordinate, that.coordinate) && Objects.equals(airPollutionRecords, that.airPollutionRecords);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(coordinate, airPollutionRecords);
|
||||
}
|
||||
}
|
||||
+376
@@ -0,0 +1,376 @@
|
||||
/*
|
||||
*
|
||||
* * 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.model.air.pollution;
|
||||
|
||||
import com.github.prominence.openweathermap.api.enums.AirQualityIndex;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* The type Air pollution record.
|
||||
*/
|
||||
public class AirPollutionRecord {
|
||||
private LocalDateTime forecastTime;
|
||||
private AirQualityIndex airQualityIndex;
|
||||
|
||||
private Double CO;
|
||||
private Double NO;
|
||||
private Double NO2;
|
||||
private Double O3;
|
||||
private Double SO2;
|
||||
private Double PM2_5;
|
||||
private Double PM10;
|
||||
private Double NH3;
|
||||
|
||||
/**
|
||||
* Gets forecast time.
|
||||
*
|
||||
* @return the forecast time
|
||||
*/
|
||||
public LocalDateTime getForecastTime() {
|
||||
return forecastTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets forecast time.
|
||||
*
|
||||
* @param forecastTime the forecast time
|
||||
*/
|
||||
public void setForecastTime(LocalDateTime forecastTime) {
|
||||
this.forecastTime = forecastTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets air quality index.
|
||||
*
|
||||
* @return the air quality index
|
||||
*/
|
||||
public AirQualityIndex getAirQualityIndex() {
|
||||
return airQualityIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets air quality index.
|
||||
*
|
||||
* @param airQualityIndex the air quality index
|
||||
*/
|
||||
public void setAirQualityIndex(AirQualityIndex airQualityIndex) {
|
||||
this.airQualityIndex = airQualityIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets carbon monoxide concentration value in μg/m^3.
|
||||
*
|
||||
* @return the carbon monoxide value
|
||||
*/
|
||||
public Double getCO() {
|
||||
return CO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets carbon monoxide concentration value in μg/m^3.
|
||||
*
|
||||
* @return the carbon monoxide value
|
||||
*/
|
||||
public Double getCarbonMonoxide() {
|
||||
return getCO();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets carbon monoxide concentration value in μg/m^3.
|
||||
*
|
||||
* @param CO the carbon monoxide value
|
||||
*/
|
||||
public void setCO(Double CO) {
|
||||
this.CO = CO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets nitrogen monoxide concentration value in μg/m^3.
|
||||
*
|
||||
* @return the nitrogen monoxide value
|
||||
*/
|
||||
public Double getNO() {
|
||||
return NO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets nitrogen monoxide concentration value in μg/m^3.
|
||||
*
|
||||
* @return the nitrogen monoxide value
|
||||
*/
|
||||
public Double getNitrogenMonoxide() {
|
||||
return getNO();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets nitrogen monoxide concentration value in μg/m^3.
|
||||
*
|
||||
* @param NO the nitrogen monoxide value
|
||||
*/
|
||||
public void setNO(Double NO) {
|
||||
this.NO = NO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets nitrogen dioxide concentration value in μg/m^3.
|
||||
*
|
||||
* @return the nitrogen dioxide value
|
||||
*/
|
||||
public Double getNO2() {
|
||||
return NO2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets nitrogen dioxide concentration value in μg/m^3.
|
||||
*
|
||||
* @return the nitrogen dioxide value
|
||||
*/
|
||||
public Double getNitrogenDioxide() {
|
||||
return getNO2();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets nitrogen dioxide concentration value in μg/m^3.
|
||||
*
|
||||
* @param NO2 the nitrogen dioxide value
|
||||
*/
|
||||
public void setNO2(Double NO2) {
|
||||
this.NO2 = NO2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets ozone concentration value in μg/m^3.
|
||||
*
|
||||
* @return the ozone value
|
||||
*/
|
||||
public Double getO3() {
|
||||
return O3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets ozone concentration value in μg/m^3.
|
||||
*
|
||||
* @return the ozone value
|
||||
*/
|
||||
public Double getOzone() {
|
||||
return getO3();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets ozone concentration value in μg/m^3.
|
||||
*
|
||||
* @param o3 the ozone value
|
||||
*/
|
||||
public void setO3(Double o3) {
|
||||
O3 = o3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets sulphur dioxide concentration value in μg/m^3.
|
||||
*
|
||||
* @return the sulphur dioxide value
|
||||
*/
|
||||
public Double getSO2() {
|
||||
return SO2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets sulphur dioxide concentration value in μg/m^3.
|
||||
*
|
||||
* @return the sulphur dioxide value
|
||||
*/
|
||||
public Double getSulphurDioxide() {
|
||||
return getSO2();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets sulphur dioxide concentration value in μg/m^3.
|
||||
*
|
||||
* @param SO2 the sulphur dioxide value
|
||||
*/
|
||||
public void setSO2(Double SO2) {
|
||||
this.SO2 = SO2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets fine particles matter concentration value in μg/m^3.
|
||||
*
|
||||
* @return the fine particles matter value
|
||||
*/
|
||||
public Double getPM2_5() {
|
||||
return PM2_5;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets fine particles matter concentration value in μg/m^3.
|
||||
*
|
||||
* @return the fine particles matter value
|
||||
*/
|
||||
public Double getFineParticlesMatter() {
|
||||
return getPM2_5();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets fine particles matter concentration value in μg/m^3.
|
||||
*
|
||||
* @param PM2_5 the fine particles matter value
|
||||
*/
|
||||
public void setPM2_5(Double PM2_5) {
|
||||
this.PM2_5 = PM2_5;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets coarse particulate matter concentration value in μg/m^3.
|
||||
*
|
||||
* @return the coarse particulate matter value
|
||||
*/
|
||||
public Double getPM10() {
|
||||
return PM10;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets coarse particulate matter concentration value in μg/m^3.
|
||||
*
|
||||
* @return the coarse particulate matter value
|
||||
*/
|
||||
public Double getCoarseParticulateMatter() {
|
||||
return getPM10();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets coarse particulate matter concentration value in μg/m^3.
|
||||
*
|
||||
* @param PM10 the coarse particulate matter value
|
||||
*/
|
||||
public void setPM10(Double PM10) {
|
||||
this.PM10 = PM10;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets ammonia concentration value in μg/m^3.
|
||||
*
|
||||
* @return the ammonia value
|
||||
*/
|
||||
public Double getNH3() {
|
||||
return NH3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets ammonia concentration value in μg/m^3.
|
||||
*
|
||||
* @return the ammonia value
|
||||
*/
|
||||
public Double getAmmonia() {
|
||||
return getNH3();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets ammonia concentration value in μg/m^3.
|
||||
*
|
||||
* @param NH3 the ammonia value
|
||||
*/
|
||||
public void setNH3(Double NH3) {
|
||||
this.NH3 = NH3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
AirPollutionRecord that = (AirPollutionRecord) o;
|
||||
return Objects.equals(forecastTime, that.forecastTime) && airQualityIndex == that.airQualityIndex && Objects.equals(CO, that.CO) && Objects.equals(NO, that.NO) && Objects.equals(NO2, that.NO2) && Objects.equals(O3, that.O3) && Objects.equals(SO2, that.SO2) && Objects.equals(PM2_5, that.PM2_5) && Objects.equals(PM10, that.PM10) && Objects.equals(NH3, that.NH3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(forecastTime, airQualityIndex, CO, NO, NO2, O3, SO2, PM2_5, PM10, NH3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder stringBuilder = new StringBuilder()
|
||||
.append("Air Pollution Record for ")
|
||||
.append(forecastTime)
|
||||
.append(", AQI=")
|
||||
.append(airQualityIndex.name())
|
||||
.append(".");
|
||||
final boolean anyConcentrationAvailable = Stream.of(CO, NO, NO2, O3, SO2, PM2_5, PM10, NH3).anyMatch(Objects::nonNull);
|
||||
if (anyConcentrationAvailable) {
|
||||
stringBuilder.append(" Concentrations:");
|
||||
if (CO != null) {
|
||||
stringBuilder
|
||||
.append(" CO(Carbon monoxide) = ")
|
||||
.append(CO)
|
||||
.append(" μg/m^3;");
|
||||
}
|
||||
if (NO != null) {
|
||||
stringBuilder
|
||||
.append(" NO(Nitrogen monoxide) = ")
|
||||
.append(NO)
|
||||
.append(" μg/m^3;");
|
||||
}
|
||||
if (NO2 != null) {
|
||||
stringBuilder
|
||||
.append(" NO2(Nitrogen dioxide) = ")
|
||||
.append(NO2)
|
||||
.append(" μg/m^3;");
|
||||
}
|
||||
if (O3 != null) {
|
||||
stringBuilder
|
||||
.append(" O3(Ozone) = ")
|
||||
.append(O3)
|
||||
.append(" μg/m^3;");
|
||||
}
|
||||
if (SO2 != null) {
|
||||
stringBuilder
|
||||
.append(" SO2(Sulphur dioxide) = ")
|
||||
.append(SO2)
|
||||
.append(" μg/m^3;");
|
||||
}
|
||||
if (PM2_5 != null) {
|
||||
stringBuilder
|
||||
.append(" PM2.5(Fine particles matter) = ")
|
||||
.append(PM2_5)
|
||||
.append(" μg/m^3;");
|
||||
}
|
||||
if (PM10 != null) {
|
||||
stringBuilder
|
||||
.append(" PM10(Coarse particulate matter) = ")
|
||||
.append(PM10)
|
||||
.append(" μg/m^3;");
|
||||
}
|
||||
if (NH3 != null) {
|
||||
stringBuilder
|
||||
.append(" NH3(Ammonia) = ")
|
||||
.append(NH3)
|
||||
.append(" μg/m^3;");
|
||||
}
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright (c) 2021 Alexey Zinchenko
|
||||
* *
|
||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* * of this software and associated documentation files (the "Software"), to deal
|
||||
* * in the Software without restriction, including without limitation the rights
|
||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* * copies of the Software, and to permit persons to whom the Software is
|
||||
* * furnished to do so, subject to the following conditions:
|
||||
* *
|
||||
* * The above copyright notice and this permission notice shall be included in all
|
||||
* * copies or substantial portions of the Software.
|
||||
* *
|
||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* * SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
||||
|
||||
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails;
|
||||
import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator;
|
||||
|
||||
/**
|
||||
* The interface Current air pollution async request terminator.
|
||||
*/
|
||||
public interface AirPollutionAsyncRequestTerminator extends AsyncRequestTerminator<AirPollutionDetails, String> {
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright (c) 2021 Alexey Zinchenko
|
||||
* *
|
||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* * of this software and associated documentation files (the "Software"), to deal
|
||||
* * in the Software without restriction, including without limitation the rights
|
||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* * copies of the Software, and to permit persons to whom the Software is
|
||||
* * furnished to do so, subject to the following conditions:
|
||||
* *
|
||||
* * The above copyright notice and this permission notice shall be included in all
|
||||
* * copies or substantial portions of the Software.
|
||||
* *
|
||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* * SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
||||
|
||||
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails;
|
||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* The type Air pollution async request terminator.
|
||||
*/
|
||||
public class AirPollutionAsyncRequestTerminatorImpl implements AirPollutionAsyncRequestTerminator {
|
||||
private final RequestUrlBuilder urlBuilder;
|
||||
|
||||
/**
|
||||
* Instantiates a new Air pollution async request terminator.
|
||||
*
|
||||
* @param urlBuilder the url builder
|
||||
*/
|
||||
public AirPollutionAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder) {
|
||||
this.urlBuilder = urlBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<AirPollutionDetails> asJava() {
|
||||
return CompletableFuture.supplyAsync(() -> new AirPollutionResponseMapper().mapToAirPollution(getRawResponse()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<String> asJSON() {
|
||||
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||
}
|
||||
|
||||
private String getRawResponse() {
|
||||
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright (c) 2021 Alexey Zinchenko
|
||||
* *
|
||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* * of this software and associated documentation files (the "Software"), to deal
|
||||
* * in the Software without restriction, including without limitation the rights
|
||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* * copies of the Software, and to permit persons to whom the Software is
|
||||
* * furnished to do so, subject to the following conditions:
|
||||
* *
|
||||
* * The above copyright notice and this permission notice shall be included in all
|
||||
* * copies or substantial portions of the Software.
|
||||
* *
|
||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* * SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
||||
|
||||
/**
|
||||
* The interface Current air pollution request customizer.
|
||||
*/
|
||||
public interface AirPollutionRequestCustomizer {
|
||||
/**
|
||||
* Retrieve current air pollution request terminator.
|
||||
*
|
||||
* @return the current air pollution request terminator
|
||||
*/
|
||||
AirPollutionRequestTerminator retrieve();
|
||||
|
||||
/**
|
||||
* Retrieve async current air pollution async request terminator.
|
||||
*
|
||||
* @return the current air pollution async request terminator
|
||||
*/
|
||||
AirPollutionAsyncRequestTerminator retrieveAsync();
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright (c) 2021 Alexey Zinchenko
|
||||
* *
|
||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* * of this software and associated documentation files (the "Software"), to deal
|
||||
* * in the Software without restriction, including without limitation the rights
|
||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* * copies of the Software, and to permit persons to whom the Software is
|
||||
* * furnished to do so, subject to the following conditions:
|
||||
* *
|
||||
* * The above copyright notice and this permission notice shall be included in all
|
||||
* * copies or substantial portions of the Software.
|
||||
* *
|
||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* * SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
||||
|
||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||
|
||||
public class AirPollutionRequestCustomizerImpl implements AirPollutionRequestCustomizer {
|
||||
private final RequestUrlBuilder urlBuilder;
|
||||
|
||||
public AirPollutionRequestCustomizerImpl(RequestUrlBuilder urlBuilder) {
|
||||
this.urlBuilder = urlBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AirPollutionRequestTerminator retrieve() {
|
||||
return new AirPollutionRequestTerminatorImpl(urlBuilder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AirPollutionAsyncRequestTerminator retrieveAsync() {
|
||||
return new AirPollutionAsyncRequestTerminatorImpl(urlBuilder);
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright (c) 2021 Alexey Zinchenko
|
||||
* *
|
||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* * of this software and associated documentation files (the "Software"), to deal
|
||||
* * in the Software without restriction, including without limitation the rights
|
||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* * copies of the Software, and to permit persons to whom the Software is
|
||||
* * furnished to do so, subject to the following conditions:
|
||||
* *
|
||||
* * The above copyright notice and this permission notice shall be included in all
|
||||
* * copies or substantial portions of the Software.
|
||||
* *
|
||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* * SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
||||
|
||||
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails;
|
||||
import com.github.prominence.openweathermap.api.request.RequestTerminator;
|
||||
|
||||
/**
|
||||
* The interface Current air pollution request terminator.
|
||||
*/
|
||||
public interface AirPollutionRequestTerminator extends RequestTerminator<AirPollutionDetails, String> {
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright (c) 2021 Alexey Zinchenko
|
||||
* *
|
||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* * of this software and associated documentation files (the "Software"), to deal
|
||||
* * in the Software without restriction, including without limitation the rights
|
||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* * copies of the Software, and to permit persons to whom the Software is
|
||||
* * furnished to do so, subject to the following conditions:
|
||||
* *
|
||||
* * The above copyright notice and this permission notice shall be included in all
|
||||
* * copies or substantial portions of the Software.
|
||||
* *
|
||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* * SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
||||
|
||||
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails;
|
||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||
|
||||
/**
|
||||
* The type Air pollution request terminator.
|
||||
*/
|
||||
public class AirPollutionRequestTerminatorImpl implements AirPollutionRequestTerminator {
|
||||
private final RequestUrlBuilder urlBuilder;
|
||||
|
||||
/**
|
||||
* Instantiates a new Air pollution request terminator.
|
||||
*
|
||||
* @param urlBuilder the url builder
|
||||
*/
|
||||
public AirPollutionRequestTerminatorImpl(RequestUrlBuilder urlBuilder) {
|
||||
this.urlBuilder = urlBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AirPollutionDetails asJava() {
|
||||
return new AirPollutionResponseMapper().mapToAirPollution(getRawResponse());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asJSON() {
|
||||
return getRawResponse();
|
||||
}
|
||||
|
||||
private String getRawResponse() {
|
||||
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Alexey Zinchenko
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
||||
|
||||
import com.github.prominence.openweathermap.api.request.air.pollution.current.CurrentAirPollutionRequester;
|
||||
import com.github.prominence.openweathermap.api.request.air.pollution.forecast.ForecastAirPollutionRequester;
|
||||
import com.github.prominence.openweathermap.api.request.air.pollution.historical.HistoricalAirPollutionRequester;
|
||||
|
||||
/**
|
||||
* The interface Air pollution requester.
|
||||
*/
|
||||
public interface AirPollutionRequester {
|
||||
/**
|
||||
* Current current air pollution requester.
|
||||
*
|
||||
* @return the current air pollution requester
|
||||
*/
|
||||
CurrentAirPollutionRequester current();
|
||||
|
||||
/**
|
||||
* Forecast forecast air pollution requester.
|
||||
*
|
||||
* @return the forecast air pollution requester
|
||||
*/
|
||||
ForecastAirPollutionRequester forecast();
|
||||
|
||||
/**
|
||||
* Historical historical air pollution requester.
|
||||
*
|
||||
* @return the historical air pollution requester
|
||||
*/
|
||||
HistoricalAirPollutionRequester historical();
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright (c) 2021 Alexey Zinchenko
|
||||
* *
|
||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* * of this software and associated documentation files (the "Software"), to deal
|
||||
* * in the Software without restriction, including without limitation the rights
|
||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* * copies of the Software, and to permit persons to whom the Software is
|
||||
* * furnished to do so, subject to the following conditions:
|
||||
* *
|
||||
* * The above copyright notice and this permission notice shall be included in all
|
||||
* * copies or substantial portions of the Software.
|
||||
* *
|
||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* * SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
||||
|
||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||
import com.github.prominence.openweathermap.api.request.air.pollution.current.CurrentAirPollutionRequester;
|
||||
import com.github.prominence.openweathermap.api.request.air.pollution.current.CurrentAirPollutionRequesterImpl;
|
||||
import com.github.prominence.openweathermap.api.request.air.pollution.forecast.ForecastAirPollutionRequester;
|
||||
import com.github.prominence.openweathermap.api.request.air.pollution.forecast.ForecastAirPollutionRequesterImpl;
|
||||
import com.github.prominence.openweathermap.api.request.air.pollution.historical.HistoricalAirPollutionRequester;
|
||||
import com.github.prominence.openweathermap.api.request.air.pollution.historical.HistoricalAirPollutionRequesterImpl;
|
||||
|
||||
/**
|
||||
* The type Air pollution requester.
|
||||
*/
|
||||
public class AirPollutionRequesterImpl implements AirPollutionRequester {
|
||||
private final RequestUrlBuilder urlBuilder;
|
||||
|
||||
/**
|
||||
* Instantiates a new Air pollution requester.
|
||||
*
|
||||
* @param apiKey the api key
|
||||
*/
|
||||
public AirPollutionRequesterImpl(String apiKey) {
|
||||
urlBuilder = new RequestUrlBuilder(apiKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CurrentAirPollutionRequester current() {
|
||||
urlBuilder.append("air_pollution");
|
||||
return new CurrentAirPollutionRequesterImpl(urlBuilder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForecastAirPollutionRequester forecast() {
|
||||
urlBuilder.append("air_pollution/forecast");
|
||||
return new ForecastAirPollutionRequesterImpl(urlBuilder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HistoricalAirPollutionRequester historical() {
|
||||
urlBuilder.append("air_pollution/history");
|
||||
return new HistoricalAirPollutionRequesterImpl(urlBuilder);
|
||||
}
|
||||
}
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright (c) 2021 Alexey Zinchenko
|
||||
* *
|
||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* * of this software and associated documentation files (the "Software"), to deal
|
||||
* * in the Software without restriction, including without limitation the rights
|
||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* * copies of the Software, and to permit persons to whom the Software is
|
||||
* * furnished to do so, subject to the following conditions:
|
||||
* *
|
||||
* * The above copyright notice and this permission notice shall be included in all
|
||||
* * copies or substantial portions of the Software.
|
||||
* *
|
||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* * SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.github.prominence.openweathermap.api.enums.AirQualityIndex;
|
||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails;
|
||||
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionRecord;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* The type Air pollution response mapper.
|
||||
*/
|
||||
public class AirPollutionResponseMapper {
|
||||
/**
|
||||
* Map to air pollution air pollution.
|
||||
*
|
||||
* @param json the json
|
||||
* @return the air pollution
|
||||
*/
|
||||
public AirPollutionDetails mapToAirPollution(String json) {
|
||||
final ObjectMapper objectMapper = new ObjectMapper();
|
||||
AirPollutionDetails airPollutionDetails;
|
||||
try {
|
||||
final JsonNode root = objectMapper.readTree(json);
|
||||
airPollutionDetails = mapToAirPollution(root);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException("Cannot parse Air Pollution response");
|
||||
}
|
||||
|
||||
return airPollutionDetails;
|
||||
}
|
||||
|
||||
private AirPollutionDetails mapToAirPollution(JsonNode rootNode) {
|
||||
final AirPollutionDetails airPollutionDetails = new AirPollutionDetails();
|
||||
airPollutionDetails.setCoordinate(parseCoordinate(rootNode.get("coord")));
|
||||
|
||||
final List<AirPollutionRecord> sampleList = new ArrayList<>();
|
||||
final JsonNode sampleListNode = rootNode.get("list");
|
||||
sampleListNode.forEach(sampleNode -> {
|
||||
sampleList.add(parseAirPollutionSample(sampleNode));
|
||||
});
|
||||
airPollutionDetails.setAirPollutionRecords(sampleList);
|
||||
|
||||
return airPollutionDetails;
|
||||
}
|
||||
|
||||
private AirPollutionRecord parseAirPollutionSample(JsonNode sampleNode) {
|
||||
AirPollutionRecord airPollutionRecord = new AirPollutionRecord();
|
||||
airPollutionRecord.setForecastTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(sampleNode.get("dt").asInt()), TimeZone.getDefault().toZoneId()));
|
||||
airPollutionRecord.setAirQualityIndex(AirQualityIndex.getByIndex(sampleNode.get("main").get("aqi").asInt()));
|
||||
|
||||
final JsonNode componentsNode = sampleNode.get("components");
|
||||
airPollutionRecord.setCO(componentsNode.get("co").asDouble());
|
||||
airPollutionRecord.setNO(componentsNode.get("no").asDouble());
|
||||
airPollutionRecord.setNO2(componentsNode.get("no2").asDouble());
|
||||
airPollutionRecord.setO3(componentsNode.get("o3").asDouble());
|
||||
airPollutionRecord.setSO2(componentsNode.get("so2").asDouble());
|
||||
airPollutionRecord.setPM2_5(componentsNode.get("pm2_5").asDouble());
|
||||
airPollutionRecord.setPM10(componentsNode.get("pm10").asDouble());
|
||||
airPollutionRecord.setNH3(componentsNode.get("nh3").asDouble());
|
||||
|
||||
return airPollutionRecord;
|
||||
}
|
||||
|
||||
private Coordinate parseCoordinate(JsonNode rootNode) {
|
||||
final JsonNode latitudeNode = rootNode.get("lat");
|
||||
final JsonNode longitudeNode = rootNode.get("lon");
|
||||
if (latitudeNode != null && longitudeNode != null) {
|
||||
return Coordinate.of(latitudeNode.asDouble(), longitudeNode.asDouble());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Alexey Zinchenko
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.request.air.pollution.current;
|
||||
|
||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequestCustomizer;
|
||||
|
||||
/**
|
||||
* The interface Current air pollution requester.
|
||||
*/
|
||||
public interface CurrentAirPollutionRequester {
|
||||
/**
|
||||
* By coordinate current air pollution request customizer.
|
||||
*
|
||||
* @param coordinate the coordinate
|
||||
* @return the current air pollution request customizer
|
||||
*/
|
||||
AirPollutionRequestCustomizer byCoordinate(Coordinate coordinate);
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright (c) 2021 Alexey Zinchenko
|
||||
* *
|
||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* * of this software and associated documentation files (the "Software"), to deal
|
||||
* * in the Software without restriction, including without limitation the rights
|
||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* * copies of the Software, and to permit persons to whom the Software is
|
||||
* * furnished to do so, subject to the following conditions:
|
||||
* *
|
||||
* * The above copyright notice and this permission notice shall be included in all
|
||||
* * copies or substantial portions of the Software.
|
||||
* *
|
||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* * SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.request.air.pollution.current;
|
||||
|
||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequestCustomizer;
|
||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequestCustomizerImpl;
|
||||
|
||||
/**
|
||||
* The type Current air pollution requester.
|
||||
*/
|
||||
public class CurrentAirPollutionRequesterImpl implements CurrentAirPollutionRequester {
|
||||
private final RequestUrlBuilder urlBuilder;
|
||||
|
||||
/**
|
||||
* Instantiates a new Current air pollution requester.
|
||||
*
|
||||
* @param urlBuilder the url builder
|
||||
*/
|
||||
public CurrentAirPollutionRequesterImpl(RequestUrlBuilder urlBuilder) {
|
||||
this.urlBuilder = urlBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AirPollutionRequestCustomizer byCoordinate(Coordinate coordinate) {
|
||||
urlBuilder.addRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
||||
urlBuilder.addRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
||||
return new AirPollutionRequestCustomizerImpl(urlBuilder);
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright (c) 2021 Alexey Zinchenko
|
||||
* *
|
||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* * of this software and associated documentation files (the "Software"), to deal
|
||||
* * in the Software without restriction, including without limitation the rights
|
||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* * copies of the Software, and to permit persons to whom the Software is
|
||||
* * furnished to do so, subject to the following conditions:
|
||||
* *
|
||||
* * The above copyright notice and this permission notice shall be included in all
|
||||
* * copies or substantial portions of the Software.
|
||||
* *
|
||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* * SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.request.air.pollution.forecast;
|
||||
|
||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequestCustomizer;
|
||||
|
||||
/**
|
||||
* The interface Forecast air pollution requester.
|
||||
*/
|
||||
public interface ForecastAirPollutionRequester {
|
||||
/**
|
||||
* By coordinate forecast air pollution request customizer.
|
||||
*
|
||||
* @param coordinate the coordinate
|
||||
* @return the forecast air pollution request customizer
|
||||
*/
|
||||
AirPollutionRequestCustomizer byCoordinate(Coordinate coordinate);
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright (c) 2021 Alexey Zinchenko
|
||||
* *
|
||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* * of this software and associated documentation files (the "Software"), to deal
|
||||
* * in the Software without restriction, including without limitation the rights
|
||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* * copies of the Software, and to permit persons to whom the Software is
|
||||
* * furnished to do so, subject to the following conditions:
|
||||
* *
|
||||
* * The above copyright notice and this permission notice shall be included in all
|
||||
* * copies or substantial portions of the Software.
|
||||
* *
|
||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* * SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.request.air.pollution.forecast;
|
||||
|
||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequestCustomizer;
|
||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequestCustomizerImpl;
|
||||
|
||||
/**
|
||||
* The type Forecast air pollution requester.
|
||||
*/
|
||||
public class ForecastAirPollutionRequesterImpl implements ForecastAirPollutionRequester {
|
||||
private final RequestUrlBuilder urlBuilder;
|
||||
|
||||
/**
|
||||
* Instantiates a new Forecast air pollution requester.
|
||||
*
|
||||
* @param urlBuilder the url builder
|
||||
*/
|
||||
public ForecastAirPollutionRequesterImpl(RequestUrlBuilder urlBuilder) {
|
||||
this.urlBuilder = urlBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AirPollutionRequestCustomizer byCoordinate(Coordinate coordinate) {
|
||||
urlBuilder.addRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
||||
urlBuilder.addRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
||||
return new AirPollutionRequestCustomizerImpl(urlBuilder);
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright (c) 2021 Alexey Zinchenko
|
||||
* *
|
||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* * of this software and associated documentation files (the "Software"), to deal
|
||||
* * in the Software without restriction, including without limitation the rights
|
||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* * copies of the Software, and to permit persons to whom the Software is
|
||||
* * furnished to do so, subject to the following conditions:
|
||||
* *
|
||||
* * The above copyright notice and this permission notice shall be included in all
|
||||
* * copies or substantial portions of the Software.
|
||||
* *
|
||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* * SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.request.air.pollution.historical;
|
||||
|
||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequestCustomizer;
|
||||
|
||||
/**
|
||||
* The interface Historical air pollution requester.
|
||||
*/
|
||||
public interface HistoricalAirPollutionRequester {
|
||||
/**
|
||||
* By coordinate historical air pollution request customizer.
|
||||
*
|
||||
* @param coordinate the coordinate
|
||||
* @param startUnixTime the start unix time
|
||||
* @param endUnixTime the end unix time
|
||||
* @return the historical air pollution request customizer
|
||||
*/
|
||||
AirPollutionRequestCustomizer byCoordinateAndPeriod(Coordinate coordinate, long startUnixTime, long endUnixTime);
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright (c) 2021 Alexey Zinchenko
|
||||
* *
|
||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* * of this software and associated documentation files (the "Software"), to deal
|
||||
* * in the Software without restriction, including without limitation the rights
|
||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* * copies of the Software, and to permit persons to whom the Software is
|
||||
* * furnished to do so, subject to the following conditions:
|
||||
* *
|
||||
* * The above copyright notice and this permission notice shall be included in all
|
||||
* * copies or substantial portions of the Software.
|
||||
* *
|
||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* * SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.request.air.pollution.historical;
|
||||
|
||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequestCustomizer;
|
||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequestCustomizerImpl;
|
||||
|
||||
/**
|
||||
* The type Historical air pollution requester.
|
||||
*/
|
||||
public class HistoricalAirPollutionRequesterImpl implements HistoricalAirPollutionRequester {
|
||||
private final RequestUrlBuilder urlBuilder;
|
||||
|
||||
/**
|
||||
* Instantiates a new Historical air pollution requester.
|
||||
*
|
||||
* @param urlBuilder the url builder
|
||||
*/
|
||||
public HistoricalAirPollutionRequesterImpl(RequestUrlBuilder urlBuilder) {
|
||||
this.urlBuilder = urlBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AirPollutionRequestCustomizer byCoordinateAndPeriod(Coordinate coordinate, long startUnixTime, long endUnixTime) {
|
||||
urlBuilder.addRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
||||
urlBuilder.addRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
||||
urlBuilder.addRequestParameter("start", String.valueOf(startUnixTime));
|
||||
urlBuilder.addRequestParameter("end", String.valueOf(endUnixTime));
|
||||
return new AirPollutionRequestCustomizerImpl(urlBuilder);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -72,7 +72,7 @@ public class OneCallWeatherResponseMapper {
|
||||
final JsonNode root = objectMapper.readTree(json);
|
||||
currentData = mapToCurrent(root);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException("Cannot parse Forecast response");
|
||||
throw new RuntimeException("Cannot parse OneCall response");
|
||||
}
|
||||
|
||||
return currentData;
|
||||
@@ -91,7 +91,7 @@ public class OneCallWeatherResponseMapper {
|
||||
final JsonNode root = objectMapper.readTree(json);
|
||||
historicalData = mapToHistorical(root);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException("Cannot parse Forecast response");
|
||||
throw new RuntimeException("Cannot parse OneCall response");
|
||||
}
|
||||
|
||||
return historicalData;
|
||||
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
*
|
||||
* * 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.model.air.pollution;
|
||||
|
||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class AirPollutionDetailsUnitTest {
|
||||
@Test
|
||||
public void getCoordinate() {
|
||||
final AirPollutionDetails airPollutionDetails = new AirPollutionDetails();
|
||||
final Coordinate coordinate = Coordinate.of(22.3, 44.2);
|
||||
airPollutionDetails.setCoordinate(coordinate);
|
||||
|
||||
assertEquals(coordinate, airPollutionDetails.getCoordinate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAirPollutionSamples() {
|
||||
final AirPollutionDetails airPollutionDetails = new AirPollutionDetails();
|
||||
final List<AirPollutionRecord> airPollutionRecords = new ArrayList<>();
|
||||
airPollutionDetails.setAirPollutionRecords(airPollutionRecords);
|
||||
|
||||
assertEquals(airPollutionRecords, airPollutionDetails.getAirPollutionRecords());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
final AirPollutionDetails first = new AirPollutionDetails();
|
||||
final AirPollutionDetails second = new AirPollutionDetails();
|
||||
final Coordinate coordinate = Coordinate.of(22.3, 44.2);
|
||||
final List<AirPollutionRecord> airPollutionRecords = new ArrayList<>();
|
||||
|
||||
assertEquals(first, first);
|
||||
assertNotEquals(first, null);
|
||||
assertEquals(first, second);
|
||||
assertNotEquals(first, new Object());
|
||||
|
||||
assertEquals(first, second);
|
||||
|
||||
first.setCoordinate(coordinate);
|
||||
|
||||
assertNotEquals(first, second);
|
||||
|
||||
second.setCoordinate(coordinate);
|
||||
|
||||
assertEquals(first, second);
|
||||
|
||||
first.setAirPollutionRecords(airPollutionRecords);
|
||||
|
||||
assertNotEquals(first, second);
|
||||
|
||||
second.setAirPollutionRecords(airPollutionRecords);
|
||||
|
||||
assertEquals(first, second);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
final AirPollutionDetails first = new AirPollutionDetails();
|
||||
final AirPollutionDetails second = new AirPollutionDetails();
|
||||
final Coordinate coordinate = Coordinate.of(22.3, 44.2);
|
||||
|
||||
assertEquals(first.hashCode(), second.hashCode());
|
||||
|
||||
first.setCoordinate(coordinate);
|
||||
|
||||
assertNotEquals(first.hashCode(), second.hashCode());
|
||||
}
|
||||
}
|
||||
+280
@@ -0,0 +1,280 @@
|
||||
/*
|
||||
*
|
||||
* * 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.model.air.pollution;
|
||||
|
||||
import com.github.prominence.openweathermap.api.enums.AirQualityIndex;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class AirPollutionRecordUnitTest {
|
||||
@Test
|
||||
public void getForecastTime() {
|
||||
final AirPollutionRecord airPollutionRecord = new AirPollutionRecord();
|
||||
final LocalDateTime now = LocalDateTime.now();
|
||||
airPollutionRecord.setForecastTime(now);
|
||||
|
||||
assertEquals(now, airPollutionRecord.getForecastTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAirQualityIndex() {
|
||||
final AirPollutionRecord airPollutionRecord = new AirPollutionRecord();
|
||||
airPollutionRecord.setAirQualityIndex(AirQualityIndex.FAIR);
|
||||
|
||||
assertEquals(AirQualityIndex.FAIR, airPollutionRecord.getAirQualityIndex());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCarbonMonoxide() {
|
||||
final AirPollutionRecord airPollutionRecord = new AirPollutionRecord();
|
||||
final double value = 0.55;
|
||||
airPollutionRecord.setCO(value);
|
||||
|
||||
assertEquals(value, airPollutionRecord.getCarbonMonoxide(), 0.00001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNitrogenMonoxide() {
|
||||
final AirPollutionRecord airPollutionRecord = new AirPollutionRecord();
|
||||
final double value = 0.55;
|
||||
airPollutionRecord.setNO(value);
|
||||
|
||||
assertEquals(value, airPollutionRecord.getNitrogenMonoxide(), 0.00001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNitrogenDioxide() {
|
||||
final AirPollutionRecord airPollutionRecord = new AirPollutionRecord();
|
||||
final double value = 0.55;
|
||||
airPollutionRecord.setNO2(value);
|
||||
|
||||
assertEquals(value, airPollutionRecord.getNitrogenDioxide(), 0.00001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getOzone() {
|
||||
final AirPollutionRecord airPollutionRecord = new AirPollutionRecord();
|
||||
final double value = 0.55;
|
||||
airPollutionRecord.setO3(value);
|
||||
|
||||
assertEquals(value, airPollutionRecord.getOzone(), 0.00001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSulphurDioxide() {
|
||||
final AirPollutionRecord airPollutionRecord = new AirPollutionRecord();
|
||||
final double value = 0.55;
|
||||
airPollutionRecord.setSO2(value);
|
||||
|
||||
assertEquals(value, airPollutionRecord.getSulphurDioxide(), 0.00001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFineParticlesMatter() {
|
||||
final AirPollutionRecord airPollutionRecord = new AirPollutionRecord();
|
||||
final double value = 0.55;
|
||||
airPollutionRecord.setPM2_5(value);
|
||||
|
||||
assertEquals(value, airPollutionRecord.getFineParticlesMatter(), 0.00001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCoarseParticulateMatter() {
|
||||
final AirPollutionRecord airPollutionRecord = new AirPollutionRecord();
|
||||
final double value = 0.55;
|
||||
airPollutionRecord.setPM10(value);
|
||||
|
||||
assertEquals(value, airPollutionRecord.getCoarseParticulateMatter(), 0.00001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAmmonia() {
|
||||
final AirPollutionRecord airPollutionRecord = new AirPollutionRecord();
|
||||
final double value = 0.55;
|
||||
airPollutionRecord.setNH3(value);
|
||||
|
||||
assertEquals(value, airPollutionRecord.getAmmonia());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
final AirPollutionRecord first = new AirPollutionRecord();
|
||||
final AirPollutionRecord second = new AirPollutionRecord();
|
||||
final LocalDateTime now = LocalDateTime.now();
|
||||
final AirQualityIndex aqi = AirQualityIndex.GOOD;
|
||||
final double value = 0.55;
|
||||
|
||||
assertEquals(first, first);
|
||||
assertNotEquals(first, null);
|
||||
assertEquals(first, second);
|
||||
assertNotEquals(first, new Object());
|
||||
|
||||
assertEquals(first, second);
|
||||
|
||||
first.setForecastTime(now);
|
||||
|
||||
assertNotEquals(first, second);
|
||||
|
||||
second.setForecastTime(now);
|
||||
|
||||
assertEquals(first, second);
|
||||
|
||||
first.setAirQualityIndex(aqi);
|
||||
|
||||
assertNotEquals(first, second);
|
||||
|
||||
second.setAirQualityIndex(aqi);
|
||||
|
||||
assertEquals(first, second);
|
||||
|
||||
first.setCO(value);
|
||||
|
||||
assertNotEquals(first, second);
|
||||
|
||||
second.setCO(value);
|
||||
|
||||
assertEquals(first, second);
|
||||
|
||||
first.setNO(value);
|
||||
|
||||
assertNotEquals(first, second);
|
||||
|
||||
second.setNO(value);
|
||||
|
||||
assertEquals(first, second);
|
||||
|
||||
first.setNO2(value);
|
||||
|
||||
assertNotEquals(first, second);
|
||||
|
||||
second.setNO2(value);
|
||||
|
||||
assertEquals(first, second);
|
||||
|
||||
first.setO3(value);
|
||||
|
||||
assertNotEquals(first, second);
|
||||
|
||||
second.setO3(value);
|
||||
|
||||
assertEquals(first, second);
|
||||
|
||||
first.setSO2(value);
|
||||
|
||||
assertNotEquals(first, second);
|
||||
|
||||
second.setSO2(value);
|
||||
|
||||
assertEquals(first, second);
|
||||
|
||||
first.setPM2_5(value);
|
||||
|
||||
assertNotEquals(first, second);
|
||||
|
||||
second.setPM2_5(value);
|
||||
|
||||
assertEquals(first, second);
|
||||
|
||||
first.setPM10(value);
|
||||
|
||||
assertNotEquals(first, second);
|
||||
|
||||
second.setPM10(value);
|
||||
|
||||
assertEquals(first, second);
|
||||
|
||||
first.setNH3(value);
|
||||
|
||||
assertNotEquals(first, second);
|
||||
|
||||
second.setNH3(value);
|
||||
|
||||
assertEquals(first, second);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
final AirPollutionRecord first = new AirPollutionRecord();
|
||||
final AirPollutionRecord second = new AirPollutionRecord();
|
||||
|
||||
assertEquals(first.hashCode(), second.hashCode());
|
||||
|
||||
first.setSO2(33.2);
|
||||
|
||||
assertNotEquals(first.hashCode(), second.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
final AirPollutionRecord airPollutionRecord = new AirPollutionRecord();
|
||||
final LocalDateTime now = LocalDateTime.now();
|
||||
final AirQualityIndex aqi = AirQualityIndex.GOOD;
|
||||
final double value = 0.55;
|
||||
|
||||
airPollutionRecord.setForecastTime(now);
|
||||
airPollutionRecord.setAirQualityIndex(aqi);
|
||||
|
||||
assertNotNull(airPollutionRecord.toString());
|
||||
|
||||
airPollutionRecord.setCO(value);
|
||||
|
||||
assertNotNull(airPollutionRecord.toString());
|
||||
|
||||
airPollutionRecord.setNO(value);
|
||||
|
||||
assertNotNull(airPollutionRecord.toString());
|
||||
|
||||
airPollutionRecord.setNO2(value);
|
||||
|
||||
assertNotNull(airPollutionRecord.toString());
|
||||
|
||||
airPollutionRecord.setO3(value);
|
||||
|
||||
assertNotNull(airPollutionRecord.toString());
|
||||
|
||||
airPollutionRecord.setSO2(value);
|
||||
|
||||
assertNotNull(airPollutionRecord.toString());
|
||||
|
||||
airPollutionRecord.setPM2_5(value);
|
||||
|
||||
assertNotNull(airPollutionRecord.toString());
|
||||
|
||||
airPollutionRecord.setPM10(value);
|
||||
|
||||
assertNotNull(airPollutionRecord.toString());
|
||||
|
||||
airPollutionRecord.setNH3(value);
|
||||
|
||||
assertNotNull(airPollutionRecord.toString());
|
||||
|
||||
airPollutionRecord.setCO(null);
|
||||
|
||||
assertNotNull(airPollutionRecord.toString());
|
||||
}
|
||||
}
|
||||
+208
@@ -0,0 +1,208 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright (c) 2021 Alexey Zinchenko
|
||||
* *
|
||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* * of this software and associated documentation files (the "Software"), to deal
|
||||
* * in the Software without restriction, including without limitation the rights
|
||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* * copies of the Software, and to permit persons to whom the Software is
|
||||
* * furnished to do so, subject to the following conditions:
|
||||
* *
|
||||
* * The above copyright notice and this permission notice shall be included in all
|
||||
* * copies or substantial portions of the Software.
|
||||
* *
|
||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* * SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
||||
|
||||
import com.github.prominence.openweathermap.api.ApiTest;
|
||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
public class AirPollutionIntegrationTest extends ApiTest {
|
||||
@Test
|
||||
public void whenRetrieveCurrentAirPollutionResponseAsJava_thenOk() {
|
||||
final AirPollutionDetails airPollutionDetails = getClient()
|
||||
.airPollution()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
assertNotNull(airPollutionDetails);
|
||||
airPollutionDetails.getAirPollutionRecords().forEach(airPollutionRecord -> {
|
||||
assertNotNull(airPollutionRecord);
|
||||
System.out.println(airPollutionRecord);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveCurrentAirPollutionResponseAsJSON_thenOk() {
|
||||
final String jsonString = getClient()
|
||||
.airPollution()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
assertNotNull(jsonString);
|
||||
System.out.println(jsonString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveCurrentAirPollutionAsyncResponseAsJava_thenOk() throws ExecutionException, InterruptedException {
|
||||
final CompletableFuture<AirPollutionDetails> pollutionDetailsFuture = getClient()
|
||||
.airPollution()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.retrieveAsync()
|
||||
.asJava();
|
||||
|
||||
assertNotNull(pollutionDetailsFuture);
|
||||
assertNotNull(pollutionDetailsFuture.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveCurrentAirPollutionAsyncResponseAsJSON_thenOk() throws ExecutionException, InterruptedException {
|
||||
final CompletableFuture<String> jsonStringFuture = getClient()
|
||||
.airPollution()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.retrieveAsync()
|
||||
.asJSON();
|
||||
|
||||
assertNotNull(jsonStringFuture);
|
||||
final String jsonString = jsonStringFuture.get();
|
||||
assertNotNull(jsonString);
|
||||
System.out.println(jsonString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveForecastAirPollutionResponseAsJava_thenOk() {
|
||||
final AirPollutionDetails airPollutionDetails = getClient()
|
||||
.airPollution()
|
||||
.forecast()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
assertNotNull(airPollutionDetails);
|
||||
airPollutionDetails.getAirPollutionRecords().forEach(airPollutionRecord -> {
|
||||
assertNotNull(airPollutionRecord);
|
||||
System.out.println(airPollutionRecord);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveForecastAirPollutionResponseAsJSON_thenOk() {
|
||||
final String jsonString = getClient()
|
||||
.airPollution()
|
||||
.forecast()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
assertNotNull(jsonString);
|
||||
System.out.println(jsonString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveForecastAirPollutionAsyncResponseAsJava_thenOk() throws ExecutionException, InterruptedException {
|
||||
final CompletableFuture<AirPollutionDetails> pollutionDetailsFuture = getClient()
|
||||
.airPollution()
|
||||
.forecast()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.retrieveAsync()
|
||||
.asJava();
|
||||
|
||||
assertNotNull(pollutionDetailsFuture);
|
||||
assertNotNull(pollutionDetailsFuture.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveForecastAirPollutionAsyncResponseAsJSON_thenOk() throws ExecutionException, InterruptedException {
|
||||
final CompletableFuture<String> jsonStringFuture = getClient()
|
||||
.airPollution()
|
||||
.forecast()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.retrieveAsync()
|
||||
.asJSON();
|
||||
|
||||
assertNotNull(jsonStringFuture);
|
||||
final String jsonString = jsonStringFuture.get();
|
||||
assertNotNull(jsonString);
|
||||
System.out.println(jsonString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveHistoricalAirPollutionResponseAsJava_thenOk() {
|
||||
final AirPollutionDetails airPollutionDetails = getClient()
|
||||
.airPollution()
|
||||
.historical()
|
||||
.byCoordinateAndPeriod(Coordinate.of(53.54, 27.34), 1606223802, 1606482999)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
assertNotNull(airPollutionDetails);
|
||||
airPollutionDetails.getAirPollutionRecords().forEach(airPollutionRecord -> {
|
||||
assertNotNull(airPollutionRecord);
|
||||
System.out.println(airPollutionRecord);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveHistoricalAirPollutionResponseAsJSON_thenOk() {
|
||||
final String jsonString = getClient()
|
||||
.airPollution()
|
||||
.historical()
|
||||
.byCoordinateAndPeriod(Coordinate.of(53.54, 27.34), 1606223802, 1606482999)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
assertNotNull(jsonString);
|
||||
System.out.println(jsonString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveHistoricalAirPollutionAsyncResponseAsJava_thenOk() throws ExecutionException, InterruptedException {
|
||||
final CompletableFuture<AirPollutionDetails> pollutionDetailsFuture = getClient()
|
||||
.airPollution()
|
||||
.historical()
|
||||
.byCoordinateAndPeriod(Coordinate.of(53.54, 27.34), 1606223802, 1606482999)
|
||||
.retrieveAsync()
|
||||
.asJava();
|
||||
|
||||
assertNotNull(pollutionDetailsFuture);
|
||||
assertNotNull(pollutionDetailsFuture.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveHistoricalAirPollutionAsyncResponseAsJSON_thenOk() throws ExecutionException, InterruptedException {
|
||||
final CompletableFuture<String> jsonStringFuture = getClient()
|
||||
.airPollution()
|
||||
.historical()
|
||||
.byCoordinateAndPeriod(Coordinate.of(53.54, 27.34), 1606223802, 1606482999)
|
||||
.retrieveAsync()
|
||||
.asJSON();
|
||||
|
||||
assertNotNull(jsonStringFuture);
|
||||
final String jsonString = jsonStringFuture.get();
|
||||
assertNotNull(jsonString);
|
||||
System.out.println(jsonString);
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright (c) 2021 Alexey Zinchenko
|
||||
* *
|
||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* * of this software and associated documentation files (the "Software"), to deal
|
||||
* * in the Software without restriction, including without limitation the rights
|
||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* * copies of the Software, and to permit persons to whom the Software is
|
||||
* * furnished to do so, subject to the following conditions:
|
||||
* *
|
||||
* * The above copyright notice and this permission notice shall be included in all
|
||||
* * copies or substantial portions of the Software.
|
||||
* *
|
||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* * SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
||||
|
||||
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
public class AirPollutionResponseMapperUnitTest {
|
||||
@Test
|
||||
public void mapToAirPollution_withInvalidJSON() {
|
||||
final String jsonString = "{\"coord\":{lon\":27.34,\"lat\":53.54},\"list\":[{\"main\":{\"aqi\":1},\"components\":{\"co\":243.66,\"no\":0,\"no2\":4.07,\"o3\":62.23,\"so2\":1.77,\"pm2_5\":3.87,\"pm10\":4.58,\"nh3\":2.41},\"dt\":1618610400}]}";
|
||||
assertThrows(RuntimeException.class, () -> new AirPollutionResponseMapper().mapToAirPollution(jsonString));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapToAirPollution_withCoordinatesVariation() {
|
||||
String jsonResponse = "{\"coord\":{},\"list\":[{\"main\":{\"aqi\":1},\"components\":{\"co\":243.66,\"no\":0,\"no2\":4.07,\"o3\":62.23,\"so2\":1.77,\"pm2_5\":3.87,\"pm10\":4.58,\"nh3\":2.41},\"dt\":1618610400}]}";
|
||||
AirPollutionDetails airPollutionDetails = new AirPollutionResponseMapper().mapToAirPollution(jsonResponse);
|
||||
|
||||
assertNotNull(airPollutionDetails);
|
||||
|
||||
jsonResponse = "{\"coord\":{\"lon\":27.34},\"list\":[{\"main\":{\"aqi\":1},\"components\":{\"co\":243.66,\"no\":0,\"no2\":4.07,\"o3\":62.23,\"so2\":1.77,\"pm2_5\":3.87,\"pm10\":4.58,\"nh3\":2.41},\"dt\":1618610400}]}";
|
||||
airPollutionDetails = new AirPollutionResponseMapper().mapToAirPollution(jsonResponse);
|
||||
|
||||
assertNotNull(airPollutionDetails);
|
||||
|
||||
jsonResponse = "{\"coord\":{\"lat\":53.54},\"list\":[{\"main\":{\"aqi\":1},\"components\":{\"co\":243.66,\"no\":0,\"no2\":4.07,\"o3\":62.23,\"so2\":1.77,\"pm2_5\":3.87,\"pm10\":4.58,\"nh3\":2.41},\"dt\":1618610400}]}";
|
||||
airPollutionDetails = new AirPollutionResponseMapper().mapToAirPollution(jsonResponse);
|
||||
|
||||
assertNotNull(airPollutionDetails);
|
||||
}
|
||||
}
|
||||
-11
File diff suppressed because one or more lines are too long
+43
@@ -86,6 +86,34 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
assertTrue(weatherJson.startsWith("{"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetMultipleCurrentWeatherByCoordinateRectangleAsyncRequestAsJava_thenReturnNotNull() throws ExecutionException, InterruptedException {
|
||||
final CompletableFuture<List<Weather>> weatherListFuture = getClient()
|
||||
.currentWeather()
|
||||
.multiple()
|
||||
.byRectangle(CoordinateRectangle.withValues(12, 32, 15, 37), 10)
|
||||
.language(Language.ROMANIAN)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieveAsync()
|
||||
.asJava();
|
||||
|
||||
assertNotNull(weatherListFuture.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetMultipleCurrentWeatherByCoordinateRectangleAsyncRequestAsJSON_thenReturnNotNull() throws ExecutionException, InterruptedException {
|
||||
final CompletableFuture<String> weatherJsonFuture = getClient()
|
||||
.currentWeather()
|
||||
.multiple()
|
||||
.byRectangle(CoordinateRectangle.withValues(12, 32, 15, 37), 10)
|
||||
.language(Language.ROMANIAN)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieveAsync()
|
||||
.asJSON();
|
||||
|
||||
assertTrue(weatherJsonFuture.get().startsWith("{"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetMultipleCurrentWeatherByCitiesInCycleRequestAsJava_thenReturnNotNull() {
|
||||
final List<Weather> weatherList = getClient()
|
||||
@@ -225,6 +253,21 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
|
||||
System.out.println(weatherFuture.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetMultipleCurrentWeatherByCoordinateAsyncRequestAsXML_thenReturnNotNull() throws ExecutionException, InterruptedException {
|
||||
final CompletableFuture<String> weatherXMLFuture = getClient()
|
||||
.currentWeather()
|
||||
.multiple()
|
||||
.byCitiesInCycle(Coordinate.of(55.5, 37.5), 10)
|
||||
.language(Language.GERMAN)
|
||||
.unitSystem(UnitSystem.IMPERIAL)
|
||||
.retrieveAsync()
|
||||
.asXML();
|
||||
|
||||
assertNotNull(weatherXMLFuture);
|
||||
System.out.println(weatherXMLFuture.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRequestCurrentWeatherWithInvalidApiKey_thenThrowAnException() {
|
||||
OpenWeatherMapClient client = new OpenWeatherMapClient("invalidKey");
|
||||
|
||||
Reference in New Issue
Block a user