Skip to content

Commit

Permalink
change package name of it test
Browse files Browse the repository at this point in the history
  • Loading branch information
ntqdinh-axonivy committed Dec 27, 2024
1 parent addcc19 commit 2f41401
Show file tree
Hide file tree
Showing 21 changed files with 760 additions and 107 deletions.
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);
}
}
}
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);
}
}
}
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
}
]
}
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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"cod": "400",
"message": "end must be after start"
}
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
}
}
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"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"cod": "404",
"message": "not found"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"cod": "400",
"message": "Nothing to geocode"
}
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"
}
]
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"
}
Loading

0 comments on commit 2f41401

Please sign in to comment.