Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MARP-1703 end2 end testing tryout with adding a new test to call to real endpoint #35

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ on:
jobs:
build:
uses: axonivy-market/github-workflows/.github/workflows/ci.yml@v5
secrets:
mvnArgs: -Dopenweather.appId=${{ secrets.APP_ID }} -Dopenweather.weatherDataUrl=${{ secrets.WEATHER_DATA_URL }} -Dopenweather.weatherGeoUrl=${{ secrets.WEATHER_GEO_URL }}
2 changes: 2 additions & 0 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ on:
jobs:
build:
uses: axonivy-market/github-workflows/.github/workflows/dev.yml@v5
secrets:
mvnArgs: -Dopenweather.appId=${{ secrets.APP_ID }} -Dopenweather.weatherDataUrl=${{ secrets.WEATHER_DATA_URL }} -Dopenweather.weatherGeoUrl=${{ secrets.WEATHER_GEO_URL }}
2 changes: 2 additions & 0 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
1 change: 1 addition & 0 deletions open-weather-connector-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<packaging>iar</packaging>
<properties>
<project.build.plugin.version>12.0.0</project.build.plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<pluginRepositories>
<pluginRepository>
Expand Down
2 changes: 1 addition & 1 deletion open-weather-connector-test/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src_wsproc">
<classpathentry kind="src" path="src_wsproc">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
13 changes: 12 additions & 1 deletion open-weather-connector-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<packaging>iar</packaging>
<properties>
<project.build.plugin.version>12.0.0</project.build.plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<tester.version>12.0.0</tester.version>
</properties>
<pluginRepositories>
Expand Down Expand Up @@ -38,7 +39,6 @@
<groupId>com.axonivy.ivy.test</groupId>
<artifactId>unit-tester</artifactId>
<version>${tester.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
Expand All @@ -55,6 +55,17 @@
</pluginManagement>
<testSourceDirectory>src_test</testSourceDirectory>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<systemPropertyVariables>
<appId>${openweather.appId}</appId>
<weatherDataUrl>${openweather.weatherDataUrl}</weatherDataUrl>
<weatherGeoUrl>${openweather.weatherGeoUrl}</weatherGeoUrl>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>com.axonivy.ivy.ci</groupId>
<artifactId>project-build-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.axonivy.connector.openweather.test.constant;

public class OpenWeatherCommonConstants {
public static final String RESULT_KEY = "result";
public static final String RESULTS_KEY = "results";
public static final String REAL_CALL_CONTEXT_DISPLAY_NAME = "Real Server Test";
public static final String MOCK_SERVER_CONTEXT_DISPLAY_NAME = "Mock Server Test";
public static final String GET_FORECAST_PROCESS_PATH = "connector/ForecastWeather";
public static final String GET_AIR_POLLUTION_PROCESS_PATH = "connector/AirPollution";
public static final String GET_CURRENT_WEATHER_PROCESS_PATH = "connector/CurrentWeather";
public static final String GEOCODING_LOCATION_PROCESS_PATH = "connector/GeocodingLocation";
public static final String GEOCODING_LOCATION_REVERSE_SIGNATURE = "reverse(Double,Double,Integer)";
public static final String GET_AIR_POLLUTION_BY_GEOCODE_SIGNATURE = "getCurrentAirPollution(Double,Double)";
public static final String GEOCODING_LOCATION_BY_ZIP_CODE_SIGNATURE = "getCoordinatesByZipCode(String,String)";
public static final String GET_FORECAST_AIR_POLLUTION_BY_GEOCODE_SIGNATURE = "getForecastAirPollution(Double,Double)";
public static final String GET_CURRENT_WEATHER_BY_GEOCODE_SIGNATURE = "getCurrentWeather(Double,Double,String,String)";
public static final String GET_FORECAST_BY_GEOCODE_SIGNATURE = "getForecastWeather(Double,Double,Integer,String,String)";
public static final String GEOCODING_LOCATION_BY_NAME_SIGNATURE = "getCoordinatesByLocationName(String,String,String,Integer)";
public static final String GET_HISTORICAL_AIR_POLLUTION_BY_GEOCODE_SIGNATURE = "getHistoricalAirPollution(Double,Double,OffsetDateTime,OffsetDateTime)";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.axonivy.connector.openweather.test.context;

import java.util.stream.Stream;

import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestTemplateInvocationContext;
import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider;

import com.axonivy.connector.openweather.test.constant.OpenWeatherCommonConstants;

public class MultiEnvironmentContextProvider implements TestTemplateInvocationContextProvider {

@Override
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) {
return Stream.of(new TestEnironmentInvocationContext(OpenWeatherCommonConstants.REAL_CALL_CONTEXT_DISPLAY_NAME),
new TestEnironmentInvocationContext(OpenWeatherCommonConstants.MOCK_SERVER_CONTEXT_DISPLAY_NAME));
}

@Override
public boolean supportsTestTemplate(ExtensionContext context) {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.axonivy.connector.openweather.test.context;

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;;

public class TestEnironmentInvocationContext implements TestTemplateInvocationContext {
private String contextDisplayName;

public TestEnironmentInvocationContext(String contextDisplayName) {
super();
this.contextDisplayName = contextDisplayName;
}

@Override
public String getDisplayName(int invocationIndex) {
return contextDisplayName;
}

@Override
public List<Extension> 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();
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.axonivy.connector.openweather.test.utils;

import java.io.IOException;
import java.util.List;
import java.util.Properties;

import org.apache.commons.lang3.StringUtils;

import com.axonivy.connector.openweather.test.constant.OpenWeatherCommonConstants;

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;

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 WEATHER_DATA_URL_KEY = "weatherDataUrl";
private static final String LOCAL_CREDENTIALS_FILE_PATH = "credentials.properties";
private static final String OPEN_WEATHER_CONNECTOR_PREFIX = "openWeatherConnector.";
private static final String JSON_FEATURES = "ch.ivyteam.ivy.rest.client.mapper.JsonFeature";
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)";
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";

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(String contextName, AppFixture fixture) {
switch (contextName) {
case OpenWeatherCommonConstants.REAL_CALL_CONTEXT_DISPLAY_NAME:
setUpConfigForApiTest(fixture);
break;
case OpenWeatherCommonConstants.MOCK_SERVER_CONTEXT_DISPLAY_NAME:
setUpConfigForMockServer(fixture);
break;
default:
break;
}
}

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)) {
if (in != null) {
Properties props = new Properties();
props.load(in);
appId = props.getProperty(APP_ID_KEY);
weatherDataUrl = props.getProperty(WEATHER_DATA_URL_KEY);
weatherGeoUrl = props.getProperty(WEATHER_GEO_URL_KEY);
}
} catch (IOException e) {
Ivy.log().warn("Can't get credential from local file with path: {0}", LOCAL_CREDENTIALS_FILE_PATH);
}
}

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) {
return client.start().subProcess(BpmProcess.path(subProcessPath).elementName(subProcessName));
}
}
Loading
Loading