Skip to content

Commit

Permalink
Update parameter resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
ntqdinh-axonivy committed Jan 6, 2025
1 parent ed0d10b commit 015c8d0
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,76 +38,76 @@ 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);
assertThat(object).isInstanceOf(AirPollution.class);
}

@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);
}
}

@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);
}
}

@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);
}
}

@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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -51,40 +52,40 @@ 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);
}
}

@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);
}
}

@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);
Expand All @@ -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);
Expand Down

0 comments on commit 015c8d0

Please sign in to comment.