diff --git a/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/it/AirPollutionProcessTest.java b/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/it/AirPollutionProcessTest.java index 1d45f00..8d03a45 100644 --- a/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/it/AirPollutionProcessTest.java +++ b/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/it/AirPollutionProcessTest.java @@ -5,6 +5,7 @@ import java.time.Duration; import java.time.OffsetDateTime; +import org.apache.http.HttpStatus; import org.junit.jupiter.api.Test; import org.openweathermap.api.data2_5.client.AirPollution; @@ -21,8 +22,8 @@ public class AirPollutionProcessTest extends BaseProcessTest { @Test public void testGetAirPollutionByGeoCode_ReturnsAirPollution(BpmClient bpmClient) throws NoSuchFieldException { ExecutionResult result = getSubProcessWithNameAndPath(bpmClient, GET_AIR_POLLUTION_PROCESS_PATH, - GET_AIR_POLLUTION_BY_GEOCODE_SIGNATURE).execute(40.7127281, -74.0060152); - var object = result.data().last().get("result"); + GET_AIR_POLLUTION_BY_GEOCODE_SIGNATURE).execute(TEST_LON_VALUE, TEST_LAT_VALUE); + var object = result.data().last().get(RESULT_KEY); assertThat(object).isInstanceOf(AirPollution.class); } @@ -32,7 +33,7 @@ public void testGetAirPollutionByGeoCode_ThrowsBpmException(BpmClient bpmClient) getSubProcessWithNameAndPath(bpmClient, GET_AIR_POLLUTION_PROCESS_PATH, GET_AIR_POLLUTION_BY_GEOCODE_SIGNATURE).execute(null, null); } catch (BpmError e) { - assertThat(e.getHttpStatusCode()).isEqualTo(400); + assertThat(e.getHttpStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST); } } @@ -40,8 +41,8 @@ public void testGetAirPollutionByGeoCode_ThrowsBpmException(BpmClient bpmClient) public void testGetForecastAirPollutionByGeoCode_ReturnsAirPollution(BpmClient bpmClient) throws NoSuchFieldException { ExecutionResult result = getSubProcessWithNameAndPath(bpmClient, GET_AIR_POLLUTION_PROCESS_PATH, - GET_FORECAST_AIR_POLLUTION_BY_GEOCODE_SIGNATURE).execute(40.7127281, -74.0060152); - var object = result.data().last().get("result"); + GET_FORECAST_AIR_POLLUTION_BY_GEOCODE_SIGNATURE).execute(TEST_LON_VALUE, TEST_LAT_VALUE); + var object = result.data().last().get(RESULT_KEY); assertThat(object).isInstanceOf(AirPollution.class); } @@ -52,7 +53,7 @@ public void testGetForecastAirPollutionByGeoCode_ThrowsBpmException(BpmClient bp getSubProcessWithNameAndPath(bpmClient, GET_AIR_POLLUTION_PROCESS_PATH, GET_FORECAST_AIR_POLLUTION_BY_GEOCODE_SIGNATURE).execute(null, null); } catch (BpmError e) { - assertThat(e.getHttpStatusCode()).isEqualTo(400); + assertThat(e.getHttpStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST); } } @@ -62,8 +63,9 @@ public void testGetHistoricalAirPollutionByGeoCode_ReturnsAirPollution(BpmClient OffsetDateTime now = OffsetDateTime.now(); OffsetDateTime twoDaysLater = now.plus(Duration.ofDays(2)); ExecutionResult result = getSubProcessWithNameAndPath(bpmClient, GET_AIR_POLLUTION_PROCESS_PATH, - GET_HISTORICAL_AIR_POLLUTION_BY_GEOCODE_SIGNATURE).execute(40.7127281, -74.0060152, now, twoDaysLater); - var object = result.data().last().get("result"); + GET_HISTORICAL_AIR_POLLUTION_BY_GEOCODE_SIGNATURE) + .execute(TEST_LON_VALUE, TEST_LAT_VALUE, now, twoDaysLater); + var object = result.data().last().get(RESULT_KEY); assertThat(object).isInstanceOf(AirPollution.class); } @@ -76,7 +78,7 @@ public void testGetHistoricalAirPollutionByGeoCode_ThrowsBpmExceptionCanNotGeo(B getSubProcessWithNameAndPath(bpmClient, GET_AIR_POLLUTION_PROCESS_PATH, GET_HISTORICAL_AIR_POLLUTION_BY_GEOCODE_SIGNATURE).execute(null, null, now, twoDaysLater); } catch (BpmError e) { - assertThat(e.getHttpStatusCode()).isEqualTo(400); + assertThat(e.getHttpStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST); } } @@ -88,9 +90,9 @@ public void testGetHistoricalAirPollutionByGeoCode_ThrowsBpmExceptionStartMoreTh try { getSubProcessWithNameAndPath(bpmClient, GET_AIR_POLLUTION_PROCESS_PATH, GET_HISTORICAL_AIR_POLLUTION_BY_GEOCODE_SIGNATURE) - .execute(40.7127281, -74.0060152, twoDaysLater, now); + .execute(TEST_LON_VALUE, TEST_LAT_VALUE, twoDaysLater, now); } catch (BpmError e) { - assertThat(e.getHttpStatusCode()).isEqualTo(400); + assertThat(e.getHttpStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST); } } } diff --git a/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/it/BaseProcessTest.java b/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/it/BaseProcessTest.java index 9877cf3..3de064d 100644 --- a/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/it/BaseProcessTest.java +++ b/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/it/BaseProcessTest.java @@ -24,6 +24,11 @@ public class BaseProcessTest { private static final String LOCAL_CREDENTIALS_FILE_PATH = "credentials.properties"; private static final String WEATHER_DATA_REST_CLIENT_NAME = "WeatherData (Openweathermap weather API)"; private static final String GEO_DATA_REST_CLIENT_NAME = "GeocodingCoordinates (Openweathermap geocoding API)"; + protected static final String RESULT_KEY = "result"; + protected static final String RESULTS_KEY = "results"; + protected static final Double TEST_LON_VALUE = 40.7484; + protected static final Double TEST_LAT_VALUE = -73.9967; + protected static final String TEST_ZIPCODE_VALUE = "10001"; private static String appId; private static String weatherDataUrl; private static String weatherGeoUrl; diff --git a/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/it/CurrentWeatherProcessTest.java b/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/it/CurrentWeatherProcessTest.java index e516450..a7939e3 100644 --- a/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/it/CurrentWeatherProcessTest.java +++ b/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/it/CurrentWeatherProcessTest.java @@ -3,6 +3,7 @@ import static org.assertj.core.api.Assertions.assertThat; import org.apache.commons.lang3.StringUtils; +import org.apache.http.HttpStatus; import org.junit.jupiter.api.Test; import org.openweathermap.api.data2_5.client.Current; @@ -18,8 +19,8 @@ public class CurrentWeatherProcessTest extends BaseProcessTest { public void testGetCurrentWeatherByGeoCode_ReturnsCurrentWeather(BpmClient bpmClient) throws NoSuchFieldException { ExecutionResult result = getSubProcessWithNameAndPath(bpmClient, GET_CURRENT_WEATHER_PROCESS_PATH, GET_CURRENT_WEATHER_BY_GEOCODE_SIGNATURE) - .execute(40.7127281, -74.0060152, StringUtils.EMPTY, StringUtils.EMPTY); - var object = result.data().last().get("result"); + .execute(TEST_LON_VALUE, TEST_LAT_VALUE, StringUtils.EMPTY, StringUtils.EMPTY); + var object = result.data().last().get(RESULT_KEY); assertThat(object).isInstanceOf(Current.class); } @@ -29,7 +30,7 @@ public void testGetCurrentWeatherByGeoCode_ThrowsBpmException(BpmClient bpmClien getSubProcessWithNameAndPath(bpmClient, GET_CURRENT_WEATHER_PROCESS_PATH, GET_CURRENT_WEATHER_BY_GEOCODE_SIGNATURE).execute(null, null, StringUtils.EMPTY, StringUtils.EMPTY); } catch (BpmError e) { - assertThat(e.getHttpStatusCode()).isEqualTo(400); + assertThat(e.getHttpStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST); } } } diff --git a/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/it/ForecastWeatherProcessTest.java b/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/it/ForecastWeatherProcessTest.java index 505c8d1..1a6fa3a 100644 --- a/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/it/ForecastWeatherProcessTest.java +++ b/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/it/ForecastWeatherProcessTest.java @@ -3,6 +3,7 @@ import static org.assertj.core.api.Assertions.assertThat; import org.apache.commons.lang3.StringUtils; +import org.apache.http.HttpStatus; import org.junit.jupiter.api.Test; import org.openweathermap.api.data2_5.client.Forecast; @@ -19,8 +20,8 @@ public class ForecastWeatherProcessTest extends BaseProcessTest { public void testGetForecastWeatherByGeoCode_ReturnsForecast(BpmClient bpmClient) throws NoSuchFieldException { ExecutionResult result = getSubProcessWithNameAndPath(bpmClient, GET_FORECAST_PROCESS_PATH, GET_FORECAST_BY_GEOCODE_SIGNATURE) - .execute(40.7127281, -74.0060152, 1, StringUtils.EMPTY, StringUtils.EMPTY); - var object = result.data().last().get("result"); + .execute(TEST_LON_VALUE, TEST_LAT_VALUE, 1, StringUtils.EMPTY, StringUtils.EMPTY); + var object = result.data().last().get(RESULT_KEY); assertThat(object).isInstanceOf(Forecast.class); } @@ -30,7 +31,7 @@ public void testGetForecastByGeoCode_ThrowsBpmException(BpmClient bpmClient) thr getSubProcessWithNameAndPath(bpmClient, GET_FORECAST_PROCESS_PATH, GET_FORECAST_BY_GEOCODE_SIGNATURE) .execute(null, null, 1, StringUtils.EMPTY, StringUtils.EMPTY); } catch (BpmError e) { - assertThat(e.getHttpStatusCode()).isEqualTo(400); + assertThat(e.getHttpStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST); } } } diff --git a/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/it/GeocodingLocationProcessTest.java b/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/it/GeocodingLocationProcessTest.java index 0b5bc21..4e1a1bf 100644 --- a/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/it/GeocodingLocationProcessTest.java +++ b/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/it/GeocodingLocationProcessTest.java @@ -6,6 +6,7 @@ import java.util.List; import org.apache.commons.lang3.StringUtils; +import org.apache.http.HttpStatus; import org.junit.jupiter.api.Test; import org.openweathermap.api.geo1_0.client.GeoLocation; @@ -24,7 +25,7 @@ public class GeocodingLocationProcessTest extends BaseProcessTest { public void testGeocodingByName_ReturnsListOfGeoLocations(BpmClient bpmClient) throws NoSuchFieldException { ExecutionResult result = getSubProcessWithNameAndPath(bpmClient, GEOCODING_LOCATION_PROCESS_PATH, GEOCODING_LOCATION_BY_NAME_SIGNATURE).execute("London", StringUtils.EMPTY, StringUtils.EMPTY, 1); - var object = result.data().last().get("results"); + var object = result.data().last().get(RESULTS_KEY); assertThat(object).isInstanceOf(List.class); var objects = (ArrayList) object; assertThat(objects).isNotEmpty(); @@ -38,15 +39,15 @@ public void testGeocodingByName_ThrowsBpmException(BpmClient bpmClient) throws N GEOCODING_LOCATION_BY_NAME_SIGNATURE) .execute(StringUtils.EMPTY, StringUtils.EMPTY, StringUtils.EMPTY, 1); } catch (BpmError e) { - assertThat(e.getHttpStatusCode()).isEqualTo(400); + assertThat(e.getHttpStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST); } } @Test public void testGeocodingByZip_ReturnsGeoLocation(BpmClient bpmClient) throws NoSuchFieldException { ExecutionResult result = getSubProcessWithNameAndPath(bpmClient, GEOCODING_LOCATION_PROCESS_PATH, - GEOCODING_LOCATION_BY_ZIP_CODE_SIGNATURE).execute("10001", StringUtils.EMPTY); - var object = result.data().last().get("result"); + GEOCODING_LOCATION_BY_ZIP_CODE_SIGNATURE).execute(TEST_ZIPCODE_VALUE, StringUtils.EMPTY); + var object = result.data().last().get(RESULT_KEY); assertThat(object).isInstanceOf(GeoLocation.class); } @@ -56,15 +57,15 @@ public void testGeocodingByZip_ThrowsBpmException(BpmClient bpmClient) throws No getSubProcessWithNameAndPath(bpmClient, GEOCODING_LOCATION_PROCESS_PATH, GEOCODING_LOCATION_BY_ZIP_CODE_SIGNATURE).execute(StringUtils.EMPTY, StringUtils.EMPTY); } catch (BpmError e) { - assertThat(e.getHttpStatusCode()).isEqualTo(400); + assertThat(e.getHttpStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST); } } @Test public void testReverse_ReturnsListOfGeoLocations(BpmClient bpmClient) throws NoSuchFieldException { ExecutionResult result = getSubProcessWithNameAndPath(bpmClient, GEOCODING_LOCATION_PROCESS_PATH, - GEOCODING_LOCATION_REVERSE_SIGNATURE).execute(40.7484, -73.9967, 1); - var object = result.data().last().get("results"); + GEOCODING_LOCATION_REVERSE_SIGNATURE).execute(TEST_LON_VALUE, TEST_LAT_VALUE, 1); + var object = result.data().last().get(RESULTS_KEY); assertThat(object).isInstanceOf(List.class); var objects = (ArrayList) object; assertThat(objects).isNotEmpty(); @@ -77,7 +78,7 @@ public void testReverse_ThrowsBpmException(BpmClient bpmClient) throws NoSuchFie getSubProcessWithNameAndPath(bpmClient, GEOCODING_LOCATION_PROCESS_PATH, GEOCODING_LOCATION_REVERSE_SIGNATURE).execute(null, null, 1); } catch (BpmError e) { - assertThat(e.getHttpStatusCode()).isEqualTo(400); + assertThat(e.getHttpStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST); } } }