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

Feature/marp 916 refinement what must be done to implement an end2end test for the axon ivy marketplace #28

Closed
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@v4
secrets:
mvnArgs: -Dopenweather.apitoken=${{ secrets.API_TOKEN }}
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@v4
secrets:
mvnArgs: -Dopenweather.apitoken=${{ secrets.API_TOKEN }}
14 changes: 14 additions & 0 deletions open-weather-connector-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
<version>${tester.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.microsoft.playwright</groupId>
<artifactId>playwright</artifactId>
<version>1.48.0</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
Expand All @@ -61,6 +66,15 @@
<version>${project.build.plugin.version}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<systemPropertyVariables>
<apiToken>${openweather.apitoken}</apiToken>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.axonivy.connector.openweather.test;

import java.util.Map;
import java.util.Objects;

import org.apache.commons.collections4.map.HashedMap;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;

import com.microsoft.playwright.APIRequestContext;
import com.microsoft.playwright.APIResponse;
import com.microsoft.playwright.Playwright;
import com.microsoft.playwright.options.RequestOptions;

public class BaseAPITest {
private static final String DEFAULT_WEATHER_DATA_URL = "https://api.openweathermap.org/data/2.5/forecast";
private static final String DEFAULT_WEATHER_GEO_URL = "https://api.openweathermap.org/data/2.5/forecast";
private static final String APP_ID_QUERRY_PARAM_KEY = "appId";
protected static String appId;
protected APIRequestContext request;
private Playwright playwright;

@BeforeAll
void beforeAll() {
createPlaywright();
appId = System.getProperty("apiToken");
}

@AfterAll
void afterAll() {
disposeAPIRequestContext();
closePlaywright();
}

void createPlaywright() {
playwright = Playwright.create();
createSimpleRequestContext();
}

void createSimpleRequestContext() {
request = playwright.request().newContext();
}

private APIResponse getResponseFromUrlWithQueryParams(String url, RequestOptions queryOptions) {
return request.get(url, queryOptions);
}

protected APIResponse getResponseFromDataUrlWithQueryParams(Map<String, String> queryParams) {
return getResponseFromUrlWithQueryParams(DEFAULT_WEATHER_DATA_URL, createRequestOptionFromQueryParam(queryParams));
}

protected APIResponse getResponseFromGeoUrlWithQueryParams(Map<String, String> queryParams) {
return getResponseFromUrlWithQueryParams(DEFAULT_WEATHER_GEO_URL, createRequestOptionFromQueryParam(queryParams));
}

private RequestOptions createRequestOptionFromQueryParam(Map<String, String> queryParams) {
Objects.requireNonNullElse(queryParams, new HashedMap<>());
RequestOptions requestOptions = RequestOptions.create();
for (Map.Entry<String, String> entry : queryParams.entrySet()) {
requestOptions.setQueryParam(entry.getKey(), entry.getValue());
}
return requestOptions;
}

protected Map<String, String> updateAppIdQueryParam(Map<String, String> params) {
Objects.requireNonNullElse(params, new HashedMap<>());
params.put(APP_ID_QUERRY_PARAM_KEY, appId);
return params;
}

void disposeAPIRequestContext() {
if (request != null) {
request.dispose();
request = null;
}
}

void closePlaywright() {
if (playwright != null) {
playwright.close();
playwright = null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.axonivy.connector.openweather.test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.HashMap;
import java.util.Map;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;

import com.microsoft.playwright.APIResponse;


@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class ForecastWeatherApiTest extends BaseAPITest {
private static final String NEW_YORK_LON_VALUE = "-74.0060152";
private static final String NEW_YORK_LAT_VALUE = "40.7127281";
private static final String LON_QUERRY_PARAM_KEY = "lon";
private static final String LAT_QUERRY_PARAM_KEY = "lat";
private static final String UNITS_QUERRY_PARAM_KEY = "units";
private static final String METRIC_UNIT_VALUE = "metric";
private static final String LOCATION_QUERRY_PARAM_KEY = "q";
private static final String LIMIT_QUERRY_PARAM_KEY = "limit";
private static final String NEW_YORK_LOCATION_VALUE = "New York";

@Test
void shouldReturnOkStatusWhenCallGetNewYorkData() {
APIResponse repsonse = getResponseFromDataUrlWithQueryParams(createNewYorkDataParam());
assertTrue(repsonse.ok());
}

@Test
void shouldReturnNewYorkInResponseWhenCallGetNewYorkGeo() {
APIResponse repsonse = getResponseFromGeoUrlWithQueryParams(createNewYorkLocationParam());
assertTrue(repsonse.ok());
// This test case should be failed
assertEquals("New York County", repsonse.toString());
}

private Map<String, String> createNewYorkDataParam() {
Map<String, String> params = new HashMap<String, String>();
params.put(LON_QUERRY_PARAM_KEY, NEW_YORK_LON_VALUE);
params.put(LAT_QUERRY_PARAM_KEY, NEW_YORK_LAT_VALUE);
params.put(UNITS_QUERRY_PARAM_KEY, METRIC_UNIT_VALUE);
updateAppIdQueryParam(params);
return params;
}

private Map<String, String> createNewYorkLocationParam() {
Map<String, String> params = new HashMap<String, String>();
params.put(LOCATION_QUERRY_PARAM_KEY, NEW_YORK_LOCATION_VALUE);
params.put(LIMIT_QUERRY_PARAM_KEY, "1");
updateAppIdQueryParam(params);
return params;
}
}
Loading