diff --git a/open-weather-connector-test/src/com/axonivy/connector/openweather/test/context/MockServerInvocationContext.java b/open-weather-connector-test/src/com/axonivy/connector/openweather/test/context/MockServerInvocationContext.java index 0616fb6..8b4998e 100644 --- a/open-weather-connector-test/src/com/axonivy/connector/openweather/test/context/MockServerInvocationContext.java +++ b/open-weather-connector-test/src/com/axonivy/connector/openweather/test/context/MockServerInvocationContext.java @@ -30,8 +30,8 @@ public Object resolveParameter(ParameterContext parameterContext, ExtensionConte @Override public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) - throws ParameterResolutionException { - return true; + throws ParameterResolutionException { + return ExtensionContext.class == parameterContext.getParameter().getType(); } }); } diff --git a/open-weather-connector-test/src/com/axonivy/connector/openweather/test/context/RestCallInvocationContext.java b/open-weather-connector-test/src/com/axonivy/connector/openweather/test/context/RestCallInvocationContext.java index 4ae87f9..495ace4 100644 --- a/open-weather-connector-test/src/com/axonivy/connector/openweather/test/context/RestCallInvocationContext.java +++ b/open-weather-connector-test/src/com/axonivy/connector/openweather/test/context/RestCallInvocationContext.java @@ -39,7 +39,7 @@ public Object resolveParameter(ParameterContext parameterContext, ExtensionConte @Override public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { - return true; + return ExtensionContext.class == parameterContext.getParameter().getType(); } }); } diff --git a/open-weather-connector-test/src/com/axonivy/connector/openweather/test/utils/OpenWeatherUtils.java b/open-weather-connector-test/src/com/axonivy/connector/openweather/test/utils/OpenWeatherUtils.java index a15634c..f3be313 100644 --- a/open-weather-connector-test/src/com/axonivy/connector/openweather/test/utils/OpenWeatherUtils.java +++ b/open-weather-connector-test/src/com/axonivy/connector/openweather/test/utils/OpenWeatherUtils.java @@ -11,7 +11,6 @@ import ch.ivyteam.ivy.application.IApplication; import ch.ivyteam.ivy.bpm.engine.client.BpmClient; -import ch.ivyteam.ivy.bpm.engine.client.ExecContext; import ch.ivyteam.ivy.bpm.engine.client.element.BpmProcess; import ch.ivyteam.ivy.bpm.engine.client.sub.SubRequestBuilder; import ch.ivyteam.ivy.environment.AppFixture; @@ -34,11 +33,6 @@ public class OpenWeatherUtils { private static final String GEO_DATA_REST_CLIENT_NAME = "GeocodingCoordinates (Openweathermap geocoding API)"; private static final String WEATHER_DATA_MOCK_ENDPOINT = "{ivy.app.baseurl}/api/weatherDataMock"; private static final String WEATHER_GEO_MOCK_ENDPOINT = "{ivy.app.baseurl}/api/weatherGeoMock"; - private static BpmClient testClient = new BpmClient(new ExecContext(IApplication.current())); - - public static BpmClient getTestBpmClient() { - return testClient; - } @SuppressWarnings("restriction") public static void setUpConfigForMockServer(ExtensionContext context) { @@ -97,7 +91,7 @@ public static void setUpConfigForRestCallTest() { setupClientWithNameAndUrl(clients, GEO_DATA_REST_CLIENT_NAME, weatherGeoUrl, appId); } - public static SubRequestBuilder getSubProcessWithNameAndPath(String subProcessPath, String subProcessName) { - return testClient.start().subProcess(BpmProcess.path(subProcessPath).elementName(subProcessName)); + public static SubRequestBuilder getSubProcessWithNameAndPath(BpmClient client,String subProcessPath, String subProcessName) { + return client.start().subProcess(BpmProcess.path(subProcessPath).elementName(subProcessName)); } } diff --git a/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/AirPollutionProcessTest.java b/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/AirPollutionProcessTest.java index fc19817..bc72004 100644 --- a/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/AirPollutionProcessTest.java +++ b/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/AirPollutionProcessTest.java @@ -20,6 +20,7 @@ import com.axonivy.connector.openweather.test.context.CustomInvocationContextProvider; import com.axonivy.connector.openweather.test.utils.OpenWeatherUtils; +import ch.ivyteam.ivy.bpm.engine.client.BpmClient; import ch.ivyteam.ivy.bpm.engine.client.ExecutionResult; import ch.ivyteam.ivy.bpm.error.BpmError; import ch.ivyteam.ivy.bpm.exec.client.IvyProcessTest; @@ -37,9 +38,9 @@ void beforeEach(ExtensionContext context) { } @TestTemplate - void testGetAirPollutionByGeoCode_ReturnsAirPollution() throws NoSuchFieldException { + void testGetAirPollutionByGeoCode_ReturnsAirPollution(BpmClient client) throws NoSuchFieldException { ExecutionResult result = OpenWeatherUtils - .getSubProcessWithNameAndPath(GET_AIR_POLLUTION_PROCESS_PATH, GET_AIR_POLLUTION_BY_GEOCODE_SIGNATURE) + .getSubProcessWithNameAndPath(client, GET_AIR_POLLUTION_PROCESS_PATH, GET_AIR_POLLUTION_BY_GEOCODE_SIGNATURE) .execute(TEST_LON_VALUE, TEST_LAT_VALUE); Ivy.log().fatal("result " + result); var object = result.data().last().get(RESULT_KEY); @@ -47,10 +48,10 @@ void testGetAirPollutionByGeoCode_ReturnsAirPollution() throws NoSuchFieldExcept } @TestTemplate - void testGetAirPollutionByGeoCode_ThrowsBpmException() throws NoSuchFieldException { + void testGetAirPollutionByGeoCode_ThrowsBpmException(BpmClient client) throws NoSuchFieldException { try { OpenWeatherUtils - .getSubProcessWithNameAndPath(GET_AIR_POLLUTION_PROCESS_PATH, GET_AIR_POLLUTION_BY_GEOCODE_SIGNATURE) + .getSubProcessWithNameAndPath(client, GET_AIR_POLLUTION_PROCESS_PATH, GET_AIR_POLLUTION_BY_GEOCODE_SIGNATURE) .execute(null, null); } catch (BpmError e) { assertThat(e.getHttpStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST); @@ -58,19 +59,19 @@ void testGetAirPollutionByGeoCode_ThrowsBpmException() throws NoSuchFieldExcepti } @TestTemplate - void testGetForecastAirPollutionByGeoCode_ReturnsAirPollution() throws NoSuchFieldException { + void testGetForecastAirPollutionByGeoCode_ReturnsAirPollution(BpmClient client) throws NoSuchFieldException { ExecutionResult result = OpenWeatherUtils - .getSubProcessWithNameAndPath(GET_AIR_POLLUTION_PROCESS_PATH, GET_FORECAST_AIR_POLLUTION_BY_GEOCODE_SIGNATURE) + .getSubProcessWithNameAndPath(client, GET_AIR_POLLUTION_PROCESS_PATH, 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); } @TestTemplate - void testGetForecastAirPollutionByGeoCode_ThrowsBpmException() throws NoSuchFieldException { + void testGetForecastAirPollutionByGeoCode_ThrowsBpmException(BpmClient client) throws NoSuchFieldException { try { OpenWeatherUtils - .getSubProcessWithNameAndPath(GET_AIR_POLLUTION_PROCESS_PATH, GET_FORECAST_AIR_POLLUTION_BY_GEOCODE_SIGNATURE) + .getSubProcessWithNameAndPath(client, GET_AIR_POLLUTION_PROCESS_PATH, GET_FORECAST_AIR_POLLUTION_BY_GEOCODE_SIGNATURE) .execute(null, null); } catch (BpmError e) { assertThat(e.getHttpStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST); @@ -78,22 +79,22 @@ void testGetForecastAirPollutionByGeoCode_ThrowsBpmException() throws NoSuchFiel } @TestTemplate - void testGetHistoricalAirPollutionByGeoCode_ReturnsAirPollution() throws NoSuchFieldException { + void testGetHistoricalAirPollutionByGeoCode_ReturnsAirPollution(BpmClient client) throws NoSuchFieldException { OffsetDateTime now = OffsetDateTime.now(); OffsetDateTime twoDaysLater = now.plus(Duration.ofDays(2)); ExecutionResult result = OpenWeatherUtils - .getSubProcessWithNameAndPath(GET_AIR_POLLUTION_PROCESS_PATH, GET_HISTORICAL_AIR_POLLUTION_BY_GEOCODE_SIGNATURE) + .getSubProcessWithNameAndPath(client, GET_AIR_POLLUTION_PROCESS_PATH, 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); } @TestTemplate - void testGetHistoricalAirPollutionByGeoCode_ThrowsBpmExceptionCanNotGeo() throws NoSuchFieldException { + void testGetHistoricalAirPollutionByGeoCode_ThrowsBpmExceptionCanNotGeo(BpmClient client) throws NoSuchFieldException { OffsetDateTime now = OffsetDateTime.now(); OffsetDateTime twoDaysLater = now.plus(Duration.ofDays(2)); try { - OpenWeatherUtils.getSubProcessWithNameAndPath(GET_AIR_POLLUTION_PROCESS_PATH, + OpenWeatherUtils.getSubProcessWithNameAndPath(client, GET_AIR_POLLUTION_PROCESS_PATH, GET_HISTORICAL_AIR_POLLUTION_BY_GEOCODE_SIGNATURE).execute(null, null, now, twoDaysLater); } catch (BpmError e) { assertThat(e.getHttpStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST); @@ -101,12 +102,12 @@ void testGetHistoricalAirPollutionByGeoCode_ThrowsBpmExceptionCanNotGeo() throws } @TestTemplate - void testGetHistoricalAirPollutionByGeoCode_ThrowsBpmExceptionStartMoreThanEnd() throws NoSuchFieldException { + void testGetHistoricalAirPollutionByGeoCode_ThrowsBpmExceptionStartMoreThanEnd(BpmClient client) throws NoSuchFieldException { OffsetDateTime now = OffsetDateTime.now(); OffsetDateTime twoDaysLater = now.plus(Duration.ofDays(2)); try { OpenWeatherUtils - .getSubProcessWithNameAndPath(GET_AIR_POLLUTION_PROCESS_PATH, + .getSubProcessWithNameAndPath(client, GET_AIR_POLLUTION_PROCESS_PATH, GET_HISTORICAL_AIR_POLLUTION_BY_GEOCODE_SIGNATURE) .execute(TEST_LON_VALUE, TEST_LAT_VALUE, twoDaysLater, now); } catch (BpmError e) { diff --git a/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/CurrentWeatherProcessTest.java b/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/CurrentWeatherProcessTest.java index fad6a97..3879dd8 100644 --- a/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/CurrentWeatherProcessTest.java +++ b/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/CurrentWeatherProcessTest.java @@ -16,6 +16,7 @@ import com.axonivy.connector.openweather.test.context.CustomInvocationContextProvider; import com.axonivy.connector.openweather.test.utils.OpenWeatherUtils; +import ch.ivyteam.ivy.bpm.engine.client.BpmClient; import ch.ivyteam.ivy.bpm.engine.client.ExecutionResult; import ch.ivyteam.ivy.bpm.error.BpmError; import ch.ivyteam.ivy.bpm.exec.client.IvyProcessTest; @@ -33,19 +34,19 @@ void beforeEach(ExtensionContext context) { } @TestTemplate - public void testGetCurrentWeatherByGeoCode_ReturnsCurrentWeather() throws NoSuchFieldException { + public void testGetCurrentWeatherByGeoCode_ReturnsCurrentWeather(BpmClient client) throws NoSuchFieldException { ExecutionResult result = OpenWeatherUtils - .getSubProcessWithNameAndPath(GET_CURRENT_WEATHER_PROCESS_PATH, GET_CURRENT_WEATHER_BY_GEOCODE_SIGNATURE) + .getSubProcessWithNameAndPath(client, GET_CURRENT_WEATHER_PROCESS_PATH, GET_CURRENT_WEATHER_BY_GEOCODE_SIGNATURE) .execute(TEST_LON_VALUE, TEST_LAT_VALUE, StringUtils.EMPTY, StringUtils.EMPTY); var object = result.data().last().get(RESULT_KEY); assertThat(object).isInstanceOf(Current.class); } @TestTemplate - public void testGetCurrentWeatherByGeoCode_ThrowsBpmException() throws NoSuchFieldException { + public void testGetCurrentWeatherByGeoCode_ThrowsBpmException(BpmClient client) throws NoSuchFieldException { try { OpenWeatherUtils - .getSubProcessWithNameAndPath(GET_CURRENT_WEATHER_PROCESS_PATH, GET_CURRENT_WEATHER_BY_GEOCODE_SIGNATURE) + .getSubProcessWithNameAndPath(client, 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(HttpStatus.SC_BAD_REQUEST); diff --git a/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/ForecastWeatherProcessTest.java b/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/ForecastWeatherProcessTest.java index 4bb5cdb..0de43c0 100644 --- a/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/ForecastWeatherProcessTest.java +++ b/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/ForecastWeatherProcessTest.java @@ -16,6 +16,7 @@ import com.axonivy.connector.openweather.test.context.CustomInvocationContextProvider; import com.axonivy.connector.openweather.test.utils.OpenWeatherUtils; +import ch.ivyteam.ivy.bpm.engine.client.BpmClient; import ch.ivyteam.ivy.bpm.engine.client.ExecutionResult; import ch.ivyteam.ivy.bpm.error.BpmError; import ch.ivyteam.ivy.bpm.exec.client.IvyProcessTest; @@ -32,18 +33,18 @@ void beforeEach(ExtensionContext context) { } @TestTemplate - public void testGetForecastWeatherByGeoCode_ReturnsForecast() throws NoSuchFieldException { + public void testGetForecastWeatherByGeoCode_ReturnsForecast(BpmClient client) throws NoSuchFieldException { ExecutionResult result = OpenWeatherUtils - .getSubProcessWithNameAndPath(GET_FORECAST_PROCESS_PATH, GET_FORECAST_BY_GEOCODE_SIGNATURE) + .getSubProcessWithNameAndPath(client, GET_FORECAST_PROCESS_PATH, GET_FORECAST_BY_GEOCODE_SIGNATURE) .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); } @TestTemplate - public void testGetForecastByGeoCode_ThrowsBpmException() throws NoSuchFieldException { + public void testGetForecastByGeoCode_ThrowsBpmException(BpmClient client) throws NoSuchFieldException { try { - OpenWeatherUtils.getSubProcessWithNameAndPath(GET_FORECAST_PROCESS_PATH, GET_FORECAST_BY_GEOCODE_SIGNATURE) + OpenWeatherUtils.getSubProcessWithNameAndPath(client, GET_FORECAST_PROCESS_PATH, GET_FORECAST_BY_GEOCODE_SIGNATURE) .execute(null, null, 1, StringUtils.EMPTY, StringUtils.EMPTY); } catch (BpmError e) { assertThat(e.getHttpStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST); diff --git a/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/GeocodingLocationProcessTest.java b/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/GeocodingLocationProcessTest.java index ce6c3f7..c53e1e4 100644 --- a/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/GeocodingLocationProcessTest.java +++ b/open-weather-connector-test/src_test/com/axonivy/connector/openweather/test/GeocodingLocationProcessTest.java @@ -22,6 +22,7 @@ import com.axonivy.connector.openweather.test.context.CustomInvocationContextProvider; import com.axonivy.connector.openweather.test.utils.OpenWeatherUtils; +import ch.ivyteam.ivy.bpm.engine.client.BpmClient; import ch.ivyteam.ivy.bpm.engine.client.ExecutionResult; import ch.ivyteam.ivy.bpm.error.BpmError; import ch.ivyteam.ivy.bpm.exec.client.IvyProcessTest; @@ -39,9 +40,9 @@ void beforeEach(ExtensionContext context) { } @TestTemplate - public void testGeocodingByName_ReturnsListOfGeoLocations() throws NoSuchFieldException { + public void testGeocodingByName_ReturnsListOfGeoLocations(BpmClient client) throws NoSuchFieldException { ExecutionResult result = OpenWeatherUtils - .getSubProcessWithNameAndPath(GEOCODING_LOCATION_PROCESS_PATH, GEOCODING_LOCATION_BY_NAME_SIGNATURE) + .getSubProcessWithNameAndPath(client, GEOCODING_LOCATION_PROCESS_PATH, GEOCODING_LOCATION_BY_NAME_SIGNATURE) .execute("London", StringUtils.EMPTY, StringUtils.EMPTY, 1); var object = result.data().last().get(RESULTS_KEY); assertThat(object).isInstanceOf(List.class); @@ -51,10 +52,10 @@ public void testGeocodingByName_ReturnsListOfGeoLocations() throws NoSuchFieldEx } @TestTemplate - public void testGeocodingByName_ThrowsBpmException() throws NoSuchFieldException { + public void testGeocodingByName_ThrowsBpmException(BpmClient client) throws NoSuchFieldException { try { OpenWeatherUtils - .getSubProcessWithNameAndPath(GEOCODING_LOCATION_PROCESS_PATH, GEOCODING_LOCATION_BY_NAME_SIGNATURE) + .getSubProcessWithNameAndPath(client, GEOCODING_LOCATION_PROCESS_PATH, GEOCODING_LOCATION_BY_NAME_SIGNATURE) .execute(StringUtils.EMPTY, StringUtils.EMPTY, StringUtils.EMPTY, 1); } catch (BpmError e) { assertThat(e.getHttpStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST); @@ -62,19 +63,19 @@ public void testGeocodingByName_ThrowsBpmException() throws NoSuchFieldException } @TestTemplate - public void testGeocodingByZip_ReturnsGeoLocation() throws NoSuchFieldException { + public void testGeocodingByZip_ReturnsGeoLocation(BpmClient client) throws NoSuchFieldException { ExecutionResult result = OpenWeatherUtils - .getSubProcessWithNameAndPath(GEOCODING_LOCATION_PROCESS_PATH, GEOCODING_LOCATION_BY_ZIP_CODE_SIGNATURE) + .getSubProcessWithNameAndPath(client, GEOCODING_LOCATION_PROCESS_PATH, 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); } @TestTemplate - public void testGeocodingByZip_ThrowsBpmException() throws NoSuchFieldException { + public void testGeocodingByZip_ThrowsBpmException(BpmClient client) throws NoSuchFieldException { try { OpenWeatherUtils - .getSubProcessWithNameAndPath(GEOCODING_LOCATION_PROCESS_PATH, GEOCODING_LOCATION_BY_ZIP_CODE_SIGNATURE) + .getSubProcessWithNameAndPath(client, GEOCODING_LOCATION_PROCESS_PATH, GEOCODING_LOCATION_BY_ZIP_CODE_SIGNATURE) .execute(StringUtils.EMPTY, StringUtils.EMPTY); } catch (BpmError e) { assertThat(e.getHttpStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST); @@ -82,9 +83,9 @@ public void testGeocodingByZip_ThrowsBpmException() throws NoSuchFieldException } @TestTemplate - public void testReverse_ReturnsListOfGeoLocations() throws NoSuchFieldException { + public void testReverse_ReturnsListOfGeoLocations(BpmClient client) throws NoSuchFieldException { ExecutionResult result = OpenWeatherUtils - .getSubProcessWithNameAndPath(GEOCODING_LOCATION_PROCESS_PATH, GEOCODING_LOCATION_REVERSE_SIGNATURE) + .getSubProcessWithNameAndPath(client, GEOCODING_LOCATION_PROCESS_PATH, 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); @@ -94,10 +95,10 @@ public void testReverse_ReturnsListOfGeoLocations() throws NoSuchFieldException } @TestTemplate - public void testReverse_ThrowsBpmException() throws NoSuchFieldException { + public void testReverse_ThrowsBpmException(BpmClient client) throws NoSuchFieldException { try { OpenWeatherUtils - .getSubProcessWithNameAndPath(GEOCODING_LOCATION_PROCESS_PATH, GEOCODING_LOCATION_REVERSE_SIGNATURE) + .getSubProcessWithNameAndPath(client, GEOCODING_LOCATION_PROCESS_PATH, GEOCODING_LOCATION_REVERSE_SIGNATURE) .execute(null, null, 1); } catch (BpmError e) { assertThat(e.getHttpStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST);