generated from axonivy-market/market-product
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
addcc19
commit 2f41401
Showing
21 changed files
with
760 additions
and
107 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
...eather-connector-test/src/com/axonivy/connector/openweather/test/OpenWeatherDataMock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.axonivy.connector.openweather.test; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import javax.annotation.security.PermitAll; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.QueryParam; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.apache.commons.lang3.ObjectUtils; | ||
|
||
import io.swagger.v3.oas.annotations.Hidden; | ||
|
||
@Path("weatherDataMock") | ||
@PermitAll | ||
@Hidden | ||
public class OpenWeatherDataMock { | ||
@GET | ||
@Path("air_pollution") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Response getAirPollution(@QueryParam("lat") double lat, @QueryParam("lon") double lon) { | ||
if (ObjectUtils.anyNull(lat, lon)) { | ||
return Response.status(400).entity(load("json/geo-nothing.json")).build(); | ||
} | ||
return Response.status(200).entity(load("json/air-pollution-result.json")).build(); | ||
} | ||
|
||
@GET | ||
@Path("air_pollution/forecast") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Response getForeacastAirPollution(@QueryParam("lat") double lat, @QueryParam("lon") double lon) { | ||
if (ObjectUtils.anyNull(lat, lon)) { | ||
return Response.status(400).entity(load("json/geo-nothing.json")).build(); | ||
} | ||
return Response.status(200).entity(load("json/air-pollution-result.json")).build(); | ||
} | ||
|
||
@GET | ||
@Path("air_pollution/history") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Response getHistoryAirPollution(@QueryParam("lat") double lat, @QueryParam("lon") double lon, | ||
@QueryParam("start") long start, @QueryParam("end") long end) { | ||
if (ObjectUtils.anyNull(lat, lon)) { | ||
return Response.status(400).entity(load("json/geo-nothing.json")).build(); | ||
} | ||
if (start > end) { | ||
return Response.status(400).entity(load("json/end-must-be-after-start.json")).build(); | ||
} | ||
return Response.status(200).entity(load("json/air-pollution-result.json")).build(); | ||
} | ||
|
||
@GET | ||
@Path("weather") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Response getWeather(@QueryParam("lat") Double lat, @QueryParam("lon") Double lon, | ||
@QueryParam("lang") String lang, @QueryParam("units") String units) { | ||
if (ObjectUtils.anyNull(lat, lon)) { | ||
return Response.status(400).entity(load("json/geo-nothing.json")).build(); | ||
} | ||
return Response.status(200).entity(load("json/current-weather-result.json")).build(); | ||
} | ||
|
||
@GET | ||
@Path("forecast") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Response getForecast(@QueryParam("lat") double lat, @QueryParam("lon") double lon, | ||
@QueryParam("lang") String lang, @QueryParam("units") String units, @QueryParam("cnt") int cnt) { | ||
if (ObjectUtils.anyNull(lat, lon)) { | ||
return Response.status(400).entity(load("json/geo-nothing.json")).build(); | ||
} | ||
return Response.status(200).entity(load("json/forecast-result.json")).build(); | ||
} | ||
|
||
private static String load(String path) { | ||
try (InputStream is = OpenWeatherDataMock.class.getResourceAsStream(path)) { | ||
return IOUtils.toString(is, StandardCharsets.UTF_8); | ||
} catch (IOException ex) { | ||
throw new RuntimeException("Failed to read resource: " + path); | ||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...weather-connector-test/src/com/axonivy/connector/openweather/test/OpenWeatherGeoMock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.axonivy.connector.openweather.test; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import javax.annotation.security.PermitAll; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.QueryParam; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.apache.commons.lang3.ObjectUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import io.swagger.v3.oas.annotations.Hidden; | ||
|
||
@Path("weatherGeoMock") | ||
@PermitAll | ||
@Hidden | ||
public class OpenWeatherGeoMock { | ||
@GET | ||
@Path("direct") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Response getGeoByCoordinates(@QueryParam("q") String q, @QueryParam("limit") int limit) { | ||
if (StringUtils.isBlank(q)) { | ||
return Response.status(400).entity(load("json/geo-nothing.json")).build(); | ||
} | ||
return Response.status(200).entity(load("json/geo-direct-result.json")).build(); | ||
} | ||
|
||
@GET | ||
@Path("zip") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Response getGeoByZip(@QueryParam("zip") String zip) { | ||
if (StringUtils.isBlank(zip)) { | ||
return Response.status(400).entity(load("json/geo-nothing.json")).build(); | ||
} | ||
return Response.status(200).entity(load("json/geo-zip-result.json")).build(); | ||
} | ||
|
||
@GET | ||
@Path("reverse") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Response getLocationInformation(@QueryParam("lat") double lat, @QueryParam("lon") double lon, | ||
@QueryParam("limit") int limit) { | ||
if (ObjectUtils.anyNull(lat, lon)) { | ||
return Response.status(400).entity(load("json/geo-nothing.json")).build(); | ||
} | ||
return Response.status(200).entity(load("json/geo-reverse-result.json")).build(); | ||
} | ||
|
||
private static String load(String path) { | ||
try (InputStream is = OpenWeatherGeoMock.class.getResourceAsStream(path)) { | ||
return IOUtils.toString(is, StandardCharsets.UTF_8); | ||
} catch (IOException ex) { | ||
throw new RuntimeException("Failed to read resource: " + path); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...-connector-test/src/com/axonivy/connector/openweather/test/json/air-pollution-result.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"coord": { | ||
"lon": -73.9967, | ||
"lat": 40.7484 | ||
}, | ||
"list": [ | ||
{ | ||
"main": { | ||
"aqi": 3 | ||
}, | ||
"components": { | ||
"co": 907.9, | ||
"no": 82.25, | ||
"no2": 45.24, | ||
"o3": 4.11, | ||
"so2": 9.18, | ||
"pm2_5": 32.24, | ||
"pm10": 44.75, | ||
"nh3": 4.12 | ||
}, | ||
"dt": 1709560558 | ||
} | ||
] | ||
} |
44 changes: 44 additions & 0 deletions
44
...onnector-test/src/com/axonivy/connector/openweather/test/json/current-weather-result.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"coord": { | ||
"lon": -73.9967, | ||
"lat": 40.7484 | ||
}, | ||
"weather": [ | ||
{ | ||
"id": 804, | ||
"main": "Clouds", | ||
"description": "overcast clouds", | ||
"icon": "04d" | ||
} | ||
], | ||
"base": "stations", | ||
"main": { | ||
"temp": 283.38, | ||
"feels_like": 282.5, | ||
"temp_min": 281.16, | ||
"temp_max": 285.07, | ||
"pressure": 1030, | ||
"humidity": 78 | ||
}, | ||
"visibility": 10000, | ||
"wind": { | ||
"speed": 5.36, | ||
"deg": 53, | ||
"gust": 5.81 | ||
}, | ||
"clouds": { | ||
"all": 100 | ||
}, | ||
"dt": 1709560480, | ||
"sys": { | ||
"type": 2, | ||
"id": 2008101, | ||
"country": "US", | ||
"sunrise": 1709551486, | ||
"sunset": 1709592643 | ||
}, | ||
"timezone": -18000, | ||
"id": 5099133, | ||
"name": "Hoboken", | ||
"cod": 200 | ||
} |
4 changes: 4 additions & 0 deletions
4
...nnector-test/src/com/axonivy/connector/openweather/test/json/end-must-be-after-start.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"cod": "400", | ||
"message": "end must be after start" | ||
} |
56 changes: 56 additions & 0 deletions
56
...ather-connector-test/src/com/axonivy/connector/openweather/test/json/forecast-result.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"cod": "200", | ||
"message": 0, | ||
"cnt": 1, | ||
"list": [ | ||
{ | ||
"dt": 1709564400, | ||
"main": { | ||
"temp": 283.35, | ||
"feels_like": 282.49, | ||
"temp_min": 283.35, | ||
"temp_max": 285.34, | ||
"pressure": 1030, | ||
"sea_level": 1030, | ||
"grnd_level": 1027, | ||
"humidity": 79, | ||
"temp_kf": -1.99 | ||
}, | ||
"weather": [ | ||
{ | ||
"id": 804, | ||
"main": "Clouds", | ||
"description": "overcast clouds", | ||
"icon": "04d" | ||
} | ||
], | ||
"clouds": { | ||
"all": 100 | ||
}, | ||
"wind": { | ||
"speed": 2.78, | ||
"deg": 87, | ||
"gust": 3.92 | ||
}, | ||
"visibility": 10000, | ||
"pop": 0, | ||
"sys": { | ||
"pod": "d" | ||
}, | ||
"dt_txt": "2024-03-04 15:00:00" | ||
} | ||
], | ||
"city": { | ||
"id": 5099133, | ||
"name": "Hoboken", | ||
"coord": { | ||
"lat": 40.7484, | ||
"lon": -73.9967 | ||
}, | ||
"country": "US", | ||
"population": 50005, | ||
"timezone": -18000, | ||
"sunrise": 1709551486, | ||
"sunset": 1709592643 | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...her-connector-test/src/com/axonivy/connector/openweather/test/json/geo-direct-result.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
[ | ||
{ | ||
"name": "New York County", | ||
"local_names": { | ||
"uk": "Нью-Йорк", | ||
"es": "Nueva York", | ||
"pl": "Nowy Jork", | ||
"ko": "뉴욕", | ||
"cy": "Efrog Newydd", | ||
"pt": "Nova Iorque", | ||
"cs": "New York", | ||
"is": "Nýja Jórvík", | ||
"el": "Νέα Υόρκη", | ||
"kn": "ನ್ಯೂಯೊರ್ಕ್", | ||
"te": "న్యూయొర్క్", | ||
"vi": "New York", | ||
"hi": "न्यूयॊर्क्", | ||
"gl": "Nova York", | ||
"he": "ניו יורק", | ||
"eo": "Novjorko", | ||
"ja": "ニューヨーク", | ||
"ar": "نيويورك", | ||
"it": "New York", | ||
"ru": "Нью-Йорк", | ||
"de": "New York", | ||
"fr": "New York", | ||
"oc": "Nòva York", | ||
"zh": "纽约/紐約", | ||
"en": "New York", | ||
"be": "Нью-Ёрк", | ||
"fa": "نیویورک", | ||
"ca": "Nova York" | ||
}, | ||
"lat": 40.7127281, | ||
"lon": -74.0060152, | ||
"country": "US", | ||
"state": "New York" | ||
} | ||
] |
4 changes: 4 additions & 0 deletions
4
...weather-connector-test/src/com/axonivy/connector/openweather/test/json/geo-not-found.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"cod": "404", | ||
"message": "not found" | ||
} |
4 changes: 4 additions & 0 deletions
4
open-weather-connector-test/src/com/axonivy/connector/openweather/test/json/geo-nothing.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"cod": "400", | ||
"message": "Nothing to geocode" | ||
} |
39 changes: 39 additions & 0 deletions
39
...er-connector-test/src/com/axonivy/connector/openweather/test/json/geo-reverse-result.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
[ | ||
{ | ||
"name": "New York County", | ||
"local_names": { | ||
"ca": "Nova York", | ||
"is": "Nýja Jórvík", | ||
"en": "New York", | ||
"ko": "뉴욕", | ||
"he": "ניו יורק", | ||
"es": "Nueva York", | ||
"cy": "Efrog Newydd", | ||
"kn": "ನ್ಯೂಯೊರ್ಕ್", | ||
"cs": "New York", | ||
"fr": "New York", | ||
"pt": "Nova Iorque", | ||
"vi": "New York", | ||
"zh": "纽约/紐約", | ||
"it": "New York", | ||
"uk": "Нью-Йорк", | ||
"fa": "نیویورک", | ||
"be": "Нью-Ёрк", | ||
"ru": "Нью-Йорк", | ||
"hi": "न्यूयॊर्क्", | ||
"te": "న్యూయొర్క్", | ||
"ar": "نيويورك", | ||
"ja": "ニューヨーク", | ||
"gl": "Nova York", | ||
"pl": "Nowy Jork", | ||
"oc": "Nòva York", | ||
"eo": "Novjorko", | ||
"el": "Νέα Υόρκη", | ||
"de": "New York" | ||
}, | ||
"lat": 40.7127281, | ||
"lon": -74.0060152, | ||
"country": "US", | ||
"state": "New York" | ||
} | ||
] |
7 changes: 7 additions & 0 deletions
7
...eather-connector-test/src/com/axonivy/connector/openweather/test/json/geo-zip-result.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"zip": "10001", | ||
"name": "New York", | ||
"lat": 40.7484, | ||
"lon": -73.9967, | ||
"country": "US" | ||
} |
Oops, something went wrong.