From 62989267734a7a6dadf67c4e4c2d0db3234c1717 Mon Sep 17 00:00:00 2001 From: Dinh Nguyen Date: Tue, 7 Jan 2025 14:59:17 +0700 Subject: [PATCH] refactor test code - Create generic TestTemplateInvocationContext - Only change var when env change --- ...a => MultiEnvironmentContextProvider.java} | 7 ++- .../context/RestCallInvocationContext.java | 46 ------------------- ...a => TestEnironmentInvocationContext.java} | 13 ++++-- .../test/utils/OpenWeatherUtils.java | 39 +++++----------- .../test/AirPollutionProcessTest.java | 30 ++++++------ .../test/CurrentWeatherProcessTest.java | 17 +++---- .../test/ForecastWeatherProcessTest.java | 12 +++-- .../test/GeocodingLocationProcessTest.java | 14 +++--- 8 files changed, 64 insertions(+), 114 deletions(-) rename open-weather-connector-test/src/com/axonivy/connector/openweather/test/context/{CustomInvocationContextProvider.java => MultiEnvironmentContextProvider.java} (60%) delete mode 100644 open-weather-connector-test/src/com/axonivy/connector/openweather/test/context/RestCallInvocationContext.java rename open-weather-connector-test/src/com/axonivy/connector/openweather/test/context/{MockServerInvocationContext.java => TestEnironmentInvocationContext.java} (79%) diff --git a/open-weather-connector-test/src/com/axonivy/connector/openweather/test/context/CustomInvocationContextProvider.java b/open-weather-connector-test/src/com/axonivy/connector/openweather/test/context/MultiEnvironmentContextProvider.java similarity index 60% rename from open-weather-connector-test/src/com/axonivy/connector/openweather/test/context/CustomInvocationContextProvider.java rename to open-weather-connector-test/src/com/axonivy/connector/openweather/test/context/MultiEnvironmentContextProvider.java index d7b02f0..1cf1116 100644 --- a/open-weather-connector-test/src/com/axonivy/connector/openweather/test/context/CustomInvocationContextProvider.java +++ b/open-weather-connector-test/src/com/axonivy/connector/openweather/test/context/MultiEnvironmentContextProvider.java @@ -6,11 +6,14 @@ import org.junit.jupiter.api.extension.TestTemplateInvocationContext; import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider; -public class CustomInvocationContextProvider implements TestTemplateInvocationContextProvider { +import com.axonivy.connector.openweather.test.constant.OpenWeatherCommonConstants; + +public class MultiEnvironmentContextProvider implements TestTemplateInvocationContextProvider { @Override public Stream provideTestTemplateInvocationContexts(ExtensionContext context) { - return Stream.of(new MockServerInvocationContext(), new RestCallInvocationContext()); + return Stream.of(new TestEnironmentInvocationContext(OpenWeatherCommonConstants.REAL_CALL_CONTEXT_DISPLAY_NAME), + new TestEnironmentInvocationContext(OpenWeatherCommonConstants.MOCK_SERVER_CONTEXT_DISPLAY_NAME)); } @Override 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 deleted file mode 100644 index 495ace4..0000000 --- a/open-weather-connector-test/src/com/axonivy/connector/openweather/test/context/RestCallInvocationContext.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.axonivy.connector.openweather.test.context; - -import static com.axonivy.connector.openweather.test.constant.OpenWeatherCommonConstants.REAL_CALL_CONTEXT_DISPLAY_NAME; - -import java.io.IOException; -import java.util.Collections; -import java.util.List; - -import org.junit.jupiter.api.extension.Extension; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.jupiter.api.extension.ParameterContext; -import org.junit.jupiter.api.extension.ParameterResolutionException; -import org.junit.jupiter.api.extension.ParameterResolver; -import org.junit.jupiter.api.extension.TestTemplateInvocationContext; - -import com.axonivy.connector.openweather.test.utils.OpenWeatherUtils; - -public class RestCallInvocationContext implements TestTemplateInvocationContext { - - @Override - public String getDisplayName(int invocationIndex) { - return REAL_CALL_CONTEXT_DISPLAY_NAME; - } - - public void setUp() throws IOException { - OpenWeatherUtils.setUpConfigForRestCallTest(); - } - - @Override - public List getAdditionalExtensions() { - return Collections.singletonList(new ParameterResolver() { - - @Override - public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) - throws ParameterResolutionException { - return extensionContext; - } - - @Override - public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) - throws ParameterResolutionException { - return ExtensionContext.class == parameterContext.getParameter().getType(); - } - }); - } -} 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/TestEnironmentInvocationContext.java similarity index 79% rename from open-weather-connector-test/src/com/axonivy/connector/openweather/test/context/MockServerInvocationContext.java rename to open-weather-connector-test/src/com/axonivy/connector/openweather/test/context/TestEnironmentInvocationContext.java index 8b4998e..8765572 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/TestEnironmentInvocationContext.java @@ -1,7 +1,5 @@ package com.axonivy.connector.openweather.test.context; -import static com.axonivy.connector.openweather.test.constant.OpenWeatherCommonConstants.MOCK_SERVER_CONTEXT_DISPLAY_NAME; - import java.util.Collections; import java.util.List; @@ -12,10 +10,17 @@ import org.junit.jupiter.api.extension.ParameterResolver; import org.junit.jupiter.api.extension.TestTemplateInvocationContext;; -public class MockServerInvocationContext implements TestTemplateInvocationContext { +public class TestEnironmentInvocationContext implements TestTemplateInvocationContext { + private String contextDisplayName; + + public TestEnironmentInvocationContext(String contextDisplayName) { + super(); + this.contextDisplayName = contextDisplayName; + } + @Override public String getDisplayName(int invocationIndex) { - return MOCK_SERVER_CONTEXT_DISPLAY_NAME; + return contextDisplayName; } @Override 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 f3be313..0ecc946 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 @@ -5,26 +5,20 @@ import java.util.Properties; import org.apache.commons.lang3.StringUtils; -import org.junit.jupiter.api.extension.ExtensionContext; import com.axonivy.connector.openweather.test.constant.OpenWeatherCommonConstants; -import ch.ivyteam.ivy.application.IApplication; import ch.ivyteam.ivy.bpm.engine.client.BpmClient; import ch.ivyteam.ivy.bpm.engine.client.element.BpmProcess; import ch.ivyteam.ivy.bpm.engine.client.sub.SubRequestBuilder; import ch.ivyteam.ivy.environment.AppFixture; import ch.ivyteam.ivy.environment.Ivy; -import ch.ivyteam.ivy.rest.client.RestClient; -import ch.ivyteam.ivy.rest.client.RestClients; -import ch.ivyteam.ivy.server.internal.test.AppFixtureJu5Context; public class OpenWeatherUtils { private static final String APP_ID_KEY = "appId"; private static final String FEATURE_SUFFIX = ".Features"; private static final String REST_CLIENT_PREFIX = "RestClients."; private static final String WEATHER_GEO_URL_KEY = "weatherGeoUrl"; - private static final String APP_ID_PROP_KEY = "AUTH." + APP_ID_KEY; private static final String WEATHER_DATA_URL_KEY = "weatherDataUrl"; private static final String LOCAL_CREDENTIALS_FILE_PATH = "credentials.properties"; private static final String OPEN_WEATHER_CONNECTOR_PREFIX = "openWeatherConnector."; @@ -34,43 +28,33 @@ public class OpenWeatherUtils { 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"; - @SuppressWarnings("restriction") - public static void setUpConfigForMockServer(ExtensionContext context) { - AppFixture fixture = AppFixtureJu5Context.get(context).getFixture(); + public static void setUpConfigForMockServer(AppFixture fixture) { // Disable OAuth feature for mock rest service fixture.config(REST_CLIENT_PREFIX + WEATHER_DATA_REST_CLIENT_NAME + FEATURE_SUFFIX, List.of(JSON_FEATURES)); fixture.config(REST_CLIENT_PREFIX + GEO_DATA_REST_CLIENT_NAME + FEATURE_SUFFIX, List.of(JSON_FEATURES)); + fixture.var(OPEN_WEATHER_CONNECTOR_PREFIX + WEATHER_DATA_URL_KEY, WEATHER_DATA_MOCK_ENDPOINT); fixture.var(OPEN_WEATHER_CONNECTOR_PREFIX + WEATHER_GEO_URL_KEY, WEATHER_GEO_MOCK_ENDPOINT); } - public static void setUpConfigForContext(ExtensionContext context) { - switch (context.getDisplayName()) { + public static void setUpConfigForContext(String contextName, AppFixture fixture) { + switch (contextName) { case OpenWeatherCommonConstants.REAL_CALL_CONTEXT_DISPLAY_NAME: - setUpConfigForRestCallTest(); + setUpConfigForApiTest(fixture); break; case OpenWeatherCommonConstants.MOCK_SERVER_CONTEXT_DISPLAY_NAME: - setUpConfigForMockServer(context); + setUpConfigForMockServer(fixture); break; default: break; } } - private static void setupClientWithNameAndUrl(RestClients clients, String clientName, String clientDefaultUri, - String appIdValue) { - RestClient client = clients.find(clientName); - System.out.println("client == null: "+client == null); - client = client.toBuilder().uri(clientDefaultUri).property(APP_ID_PROP_KEY, appIdValue).toRestClient(); - clients.set(client); - } - - public static void setUpConfigForRestCallTest() { + public static void setUpConfigForApiTest(AppFixture fixture) { String appId = System.getProperty(APP_ID_KEY); String weatherDataUrl = System.getProperty(WEATHER_DATA_URL_KEY); String weatherGeoUrl = System.getProperty(WEATHER_GEO_URL_KEY); - // Local setup for testing if (StringUtils.isAnyBlank(new String[] { appId, weatherDataUrl, weatherGeoUrl })) { try (var in = OpenWeatherUtils.class.getResourceAsStream(LOCAL_CREDENTIALS_FILE_PATH)) { @@ -86,12 +70,13 @@ public static void setUpConfigForRestCallTest() { } } - RestClients clients = RestClients.of(IApplication.current()); - setupClientWithNameAndUrl(clients, WEATHER_DATA_REST_CLIENT_NAME, weatherDataUrl, appId); - setupClientWithNameAndUrl(clients, GEO_DATA_REST_CLIENT_NAME, weatherGeoUrl, appId); + fixture.var(OPEN_WEATHER_CONNECTOR_PREFIX + WEATHER_DATA_URL_KEY, weatherDataUrl); + fixture.var(OPEN_WEATHER_CONNECTOR_PREFIX + WEATHER_GEO_URL_KEY, weatherGeoUrl); + fixture.var(OPEN_WEATHER_CONNECTOR_PREFIX + APP_ID_KEY, appId); } - public static SubRequestBuilder getSubProcessWithNameAndPath(BpmClient client,String subProcessPath, String 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 bc72004..58ac535 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 @@ -17,24 +17,24 @@ import org.junit.jupiter.api.extension.ExtensionContext; import org.openweathermap.api.data2_5.client.AirPollution; -import com.axonivy.connector.openweather.test.context.CustomInvocationContextProvider; +import com.axonivy.connector.openweather.test.context.MultiEnvironmentContextProvider; 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; -import ch.ivyteam.ivy.environment.Ivy; +import ch.ivyteam.ivy.environment.AppFixture; @IvyProcessTest(enableWebServer = true) -@ExtendWith(CustomInvocationContextProvider.class) +@ExtendWith(MultiEnvironmentContextProvider.class) public class AirPollutionProcessTest { private final Double TEST_LON_VALUE = 40.7484; private final Double TEST_LAT_VALUE = -73.9967; @BeforeEach - void beforeEach(ExtensionContext context) { - OpenWeatherUtils.setUpConfigForContext(context); + void beforeEach(ExtensionContext context, AppFixture fixture) { + OpenWeatherUtils.setUpConfigForContext(context.getDisplayName(), fixture); } @TestTemplate @@ -42,7 +42,6 @@ void testGetAirPollutionByGeoCode_ReturnsAirPollution(BpmClient client) throws N ExecutionResult result = OpenWeatherUtils .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); assertThat(object).isInstanceOf(AirPollution.class); } @@ -60,9 +59,8 @@ void testGetAirPollutionByGeoCode_ThrowsBpmException(BpmClient client) throws No @TestTemplate void testGetForecastAirPollutionByGeoCode_ReturnsAirPollution(BpmClient client) throws NoSuchFieldException { - ExecutionResult result = OpenWeatherUtils - .getSubProcessWithNameAndPath(client, GET_AIR_POLLUTION_PROCESS_PATH, GET_FORECAST_AIR_POLLUTION_BY_GEOCODE_SIGNATURE) - .execute(TEST_LON_VALUE, TEST_LAT_VALUE); + ExecutionResult result = OpenWeatherUtils.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); } @@ -70,9 +68,8 @@ void testGetForecastAirPollutionByGeoCode_ReturnsAirPollution(BpmClient client) @TestTemplate void testGetForecastAirPollutionByGeoCode_ThrowsBpmException(BpmClient client) throws NoSuchFieldException { try { - OpenWeatherUtils - .getSubProcessWithNameAndPath(client, GET_AIR_POLLUTION_PROCESS_PATH, GET_FORECAST_AIR_POLLUTION_BY_GEOCODE_SIGNATURE) - .execute(null, null); + OpenWeatherUtils.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); } @@ -83,14 +80,16 @@ void testGetHistoricalAirPollutionByGeoCode_ReturnsAirPollution(BpmClient client OffsetDateTime now = OffsetDateTime.now(); OffsetDateTime twoDaysLater = now.plus(Duration.ofDays(2)); ExecutionResult result = OpenWeatherUtils - .getSubProcessWithNameAndPath(client, 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(BpmClient client) throws NoSuchFieldException { + void testGetHistoricalAirPollutionByGeoCode_ThrowsBpmExceptionCanNotGeo(BpmClient client) + throws NoSuchFieldException { OffsetDateTime now = OffsetDateTime.now(); OffsetDateTime twoDaysLater = now.plus(Duration.ofDays(2)); try { @@ -102,7 +101,8 @@ void testGetHistoricalAirPollutionByGeoCode_ThrowsBpmExceptionCanNotGeo(BpmClien } @TestTemplate - void testGetHistoricalAirPollutionByGeoCode_ThrowsBpmExceptionStartMoreThanEnd(BpmClient client) throws NoSuchFieldException { + void testGetHistoricalAirPollutionByGeoCode_ThrowsBpmExceptionStartMoreThanEnd(BpmClient client) + throws NoSuchFieldException { OffsetDateTime now = OffsetDateTime.now(); OffsetDateTime twoDaysLater = now.plus(Duration.ofDays(2)); try { 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 3879dd8..6fa79ab 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 @@ -13,30 +13,32 @@ import org.junit.jupiter.api.extension.ExtensionContext; import org.openweathermap.api.data2_5.client.Current; -import com.axonivy.connector.openweather.test.context.CustomInvocationContextProvider; +import com.axonivy.connector.openweather.test.context.MultiEnvironmentContextProvider; 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; +import ch.ivyteam.ivy.environment.AppFixture; @IvyProcessTest(enableWebServer = true) -@ExtendWith(CustomInvocationContextProvider.class) +@ExtendWith(MultiEnvironmentContextProvider.class) public class CurrentWeatherProcessTest { private final Double TEST_LON_VALUE = 40.7484; private final Double TEST_LAT_VALUE = -73.9967; @BeforeEach - void beforeEach(ExtensionContext context) { - OpenWeatherUtils.setUpConfigForContext(context); + void beforeEach(ExtensionContext context, AppFixture fixture) { + OpenWeatherUtils.setUpConfigForContext(context.getDisplayName(), fixture); } @TestTemplate public void testGetCurrentWeatherByGeoCode_ReturnsCurrentWeather(BpmClient client) throws NoSuchFieldException { ExecutionResult result = OpenWeatherUtils - .getSubProcessWithNameAndPath(client, 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); @@ -45,9 +47,8 @@ public void testGetCurrentWeatherByGeoCode_ReturnsCurrentWeather(BpmClient clien @TestTemplate public void testGetCurrentWeatherByGeoCode_ThrowsBpmException(BpmClient client) throws NoSuchFieldException { try { - OpenWeatherUtils - .getSubProcessWithNameAndPath(client, GET_CURRENT_WEATHER_PROCESS_PATH, GET_CURRENT_WEATHER_BY_GEOCODE_SIGNATURE) - .execute(null, null, StringUtils.EMPTY, StringUtils.EMPTY); + OpenWeatherUtils.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 0de43c0..001bec7 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 @@ -13,23 +13,24 @@ import org.junit.jupiter.api.extension.ExtensionContext; import org.openweathermap.api.data2_5.client.Forecast; -import com.axonivy.connector.openweather.test.context.CustomInvocationContextProvider; +import com.axonivy.connector.openweather.test.context.MultiEnvironmentContextProvider; 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; +import ch.ivyteam.ivy.environment.AppFixture; @IvyProcessTest(enableWebServer = true) -@ExtendWith(CustomInvocationContextProvider.class) +@ExtendWith(MultiEnvironmentContextProvider.class) public class ForecastWeatherProcessTest { private final Double TEST_LON_VALUE = 40.7484; private final Double TEST_LAT_VALUE = -73.9967; @BeforeEach - void beforeEach(ExtensionContext context) { - OpenWeatherUtils.setUpConfigForContext(context); + void beforeEach(ExtensionContext context, AppFixture fixture) { + OpenWeatherUtils.setUpConfigForContext(context.getDisplayName(), fixture); } @TestTemplate @@ -44,7 +45,8 @@ public void testGetForecastWeatherByGeoCode_ReturnsForecast(BpmClient client) th @TestTemplate public void testGetForecastByGeoCode_ThrowsBpmException(BpmClient client) throws NoSuchFieldException { try { - OpenWeatherUtils.getSubProcessWithNameAndPath(client, 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 c53e1e4..fe07371 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 @@ -19,24 +19,25 @@ import org.junit.jupiter.api.extension.ExtensionContext; import org.openweathermap.api.geo1_0.client.GeoLocation; -import com.axonivy.connector.openweather.test.context.CustomInvocationContextProvider; +import com.axonivy.connector.openweather.test.context.MultiEnvironmentContextProvider; 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; +import ch.ivyteam.ivy.environment.AppFixture; @IvyProcessTest(enableWebServer = true) -@ExtendWith(CustomInvocationContextProvider.class) +@ExtendWith(MultiEnvironmentContextProvider.class) public class GeocodingLocationProcessTest { private final Double TEST_LON_VALUE = 40.7484; private final Double TEST_LAT_VALUE = -73.9967; private final String TEST_ZIPCODE_VALUE = "10001"; @BeforeEach - void beforeEach(ExtensionContext context) { - OpenWeatherUtils.setUpConfigForContext(context); + void beforeEach(ExtensionContext context, AppFixture fixture) { + OpenWeatherUtils.setUpConfigForContext(context.getDisplayName(), fixture); } @TestTemplate @@ -74,9 +75,8 @@ public void testGeocodingByZip_ReturnsGeoLocation(BpmClient client) throws NoSuc @TestTemplate public void testGeocodingByZip_ThrowsBpmException(BpmClient client) throws NoSuchFieldException { try { - OpenWeatherUtils - .getSubProcessWithNameAndPath(client, GEOCODING_LOCATION_PROCESS_PATH, GEOCODING_LOCATION_BY_ZIP_CODE_SIGNATURE) - .execute(StringUtils.EMPTY, StringUtils.EMPTY); + OpenWeatherUtils.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); }