Skip to content

Commit 1ffc44b

Browse files
Simon-Wong-hjzSimon Jingzhe Huang
andauthored
chore: add integration test (#27)
Co-authored-by: Simon Jingzhe Huang <[email protected]>
1 parent 9d77371 commit 1ffc44b

File tree

10 files changed

+1179
-0
lines changed

10 files changed

+1179
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Integration Test
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
jdk:
7+
description: 'JDK version to use'
8+
required: true
9+
type: string
10+
distribution:
11+
description: 'JDK distribution to use'
12+
required: false
13+
type: string
14+
default: 'corretto'
15+
branch:
16+
description: 'Branch to build SDK and run integration tests from'
17+
required: true
18+
type: string
19+
20+
jobs:
21+
integration-tests:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Checkout repo
25+
uses: actions/checkout@v4
26+
with:
27+
repository: 'ExpediaGroup/xap-java-sdk'
28+
ref: ${{ inputs.branch }}
29+
path: sdk-repo
30+
31+
- name: Parse SDK version
32+
id: parse-sdk-version
33+
working-directory: sdk-repo/code
34+
shell: python -u {0}
35+
run: |
36+
import os
37+
import xml.etree.ElementTree as ET
38+
39+
tree = ET.parse("pom.xml")
40+
root = tree.getroot()
41+
version = root.find("{*}version").text
42+
43+
with open(os.getenv("GITHUB_OUTPUT"), "a") as GITHUB_OUTPUT:
44+
print(f"version={version}", file=GITHUB_OUTPUT)
45+
46+
- name: Set up JDK
47+
uses: actions/setup-java@v4
48+
with:
49+
java-version: ${{ inputs.jdk }}
50+
distribution: ${{ inputs.distribution }}
51+
52+
- name: Install SDK
53+
working-directory: sdk-repo/code
54+
run: |
55+
mvn clean install
56+
57+
- name: Run Integration Tests
58+
working-directory: sdk-repo/integrations
59+
run: |
60+
mvn verify \
61+
-Dcom.expediagroup.xapjavasdk.apikey="${{ secrets.API_KEY }}" \
62+
-Dcom.expediagroup.xapjavasdk.apisecret="${{ secrets.API_SECRET }}" \
63+
-Dcom.expediagroup.xapjavasdk.vrbokey="${{ secrets.VRBO_KEY }}" \
64+
-Dcom.expediagroup.xapjavasdk.vrbosecret="${{ secrets.VRBO_SECRET }}" \
65+
-Dxap-java-sdk.sdk.version="${{ steps.parse-sdk-version.outputs.version }}"

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ and less on the technical details of the API.
1616

1717
You can find code examples for multiple use cases in the [examples](examples) directory.
1818

19+
### Integration Tests
20+
Integration tests are placed in the [integrations](integrations) directory.
21+
1922
---
2023

2124
## Support

integrations/README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# XAP Java SDK Integrations
2+
3+
This repository contains integration tests of the Expedia Group XAP Java SDK.
4+
5+
_**The following instructions apply if you want to run the integration tests locally.**_
6+
7+
## Requirements
8+
9+
- Ensure you have a valid API key and secret from Expedia Group.
10+
Check [Getting started with XAP](https://developers.expediagroup.com/xap/products/xap/set-up/getting-started)
11+
for more info.
12+
- Java 1.8 or higher
13+
- Maven
14+
15+
## Setup
16+
17+
1. Clone the repository.
18+
2. Navigate to the project directory `integrations`.
19+
3. Run `mvn clean install` to build the project and install the dependencies including the XAP SDK.
20+
21+
## Running the Integration Tests
22+
23+
### Run with IntelliJ IDEA
24+
25+
1. Navigate to the test class you want to run
26+
2. Right-click on the class name and select `More Run/Debug` -> `Modify Run Configuration`
27+
3. Check the `Modify options` -> `Add VM options` and add the following VM options:
28+
```
29+
-Dcom.expediagroup.xapjavasdk.apikey="{API_KEY}"
30+
-Dcom.expediagroup.xapjavasdk.apisecret="{API_SECRET}"
31+
```
32+
Replace `{API_KEY}` and `{API_SECRET}` with your actual API key and secret.
33+
> **Note:** If you are running the tests for Vrbo, you would need the following VM options
34+
instead:
35+
> ```
36+
> -Dcom.expediagroup.xapjavasdk.vrbokey="{VRBO_KEY}"
37+
> -Dcom.expediagroup.xapjavasdk.vrbosecret="{VRBO_SECRET}"
38+
> ```
39+
> The key you use must be enabled for Vrbo brand. If you are not sure, please reach out to your
40+
account manager.
41+
4. Click `OK` and then run the test class.
42+
43+
### Run with Command Line
44+
45+
Run the following command to run all integration tests:
46+
47+
```
48+
mvn failsafe:integration-test \
49+
-Dcom.expediagroup.xapjavasdk.apikey="{API_KEY}" \
50+
-Dcom.expediagroup.xapjavasdk.apisecret="{API_SECRET}" \
51+
-Dcom.expediagroup.xapjavasdk.vrbokey="{VRBO_KEY}" \
52+
-Dcom.expediagroup.xapjavasdk.vrbosecret="{VRBO_SECRET}" \
53+
-f pom.xml
54+
```
55+
56+
If your key is enabled for both Expedia and Vrbo brands, you may use the same key and secret
57+
pair for the placeholders. Otherwise, you may run the tests separately by providing only the
58+
required key and secret. For example:
59+
60+
```
61+
mvn failsafe:integration-test \
62+
-Dit.test=TestClassName#testMethodName \
63+
-Dcom.expediagroup.xapjavasdk.apikey="{API_KEY}" \
64+
-Dcom.expediagroup.xapjavasdk.apisecret="{API_SECRET}" \
65+
-f pom.xml
66+
```
67+
68+
Replace `TestClassName` and `testMethodName` with the actual test class name and method name,
69+
and `{API_KEY}` and `{API_SECRET}` with your actual API key and secret.
70+
> If `#testMethodName` is omitted, all test methods in the class will be executed.
71+
72+
If you are running the tests for Vrbo, you should use the following command instead:
73+
74+
```
75+
mvn failsafe:integration-test \
76+
-Dit.test=TestClassName#testMethodName \
77+
-Dcom.expediagroup.xapjavasdk.vrbokey="{VRBO_KEY}" \
78+
-Dcom.expediagroup.xapjavasdk.vrbosecret="{VRBO_SECRET}"
79+
-f pom.xml
80+
```
81+
82+
The key you use must be enabled for Vrbo brand. If you are not sure, please reach out to your
83+
account manager.
84+
85+
## License
86+
87+
This project is licensed under the Apache License v2.0 - see the [LICENSE](../LICENSE) for details.

integrations/pom.xml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.expediagroup</groupId>
8+
<artifactId>xap-java-sdk-integrations</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<properties>
12+
<java.version>1.8</java.version>
13+
<maven.compiler.source>1.8</maven.compiler.source>
14+
<maven.compiler.target>1.8</maven.compiler.target>
15+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16+
<xap-java-sdk.sdk.version>0.0.17-SNAPSHOT</xap-java-sdk.sdk.version>
17+
</properties>
18+
19+
<repositories>
20+
<repository>
21+
<id>oss.sonatype.org-snapshot</id>
22+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
23+
<releases>
24+
<enabled>false</enabled>
25+
</releases>
26+
<snapshots>
27+
<enabled>true</enabled>
28+
</snapshots>
29+
</repository>
30+
</repositories>
31+
32+
<dependencies>
33+
<dependency>
34+
<groupId>com.expediagroup</groupId>
35+
<artifactId>xap-sdk</artifactId>
36+
<version>${xap-java-sdk.sdk.version}</version>
37+
</dependency>
38+
39+
<dependency>
40+
<groupId>org.apache.logging.log4j</groupId>
41+
<artifactId>log4j-api</artifactId>
42+
<version>2.23.1</version>
43+
</dependency>
44+
45+
<dependency>
46+
<groupId>org.apache.logging.log4j</groupId>
47+
<artifactId>log4j-slf4j2-impl</artifactId>
48+
<version>2.23.1</version>
49+
</dependency>
50+
51+
<dependency>
52+
<groupId>org.junit.jupiter</groupId>
53+
<artifactId>junit-jupiter</artifactId>
54+
<version>5.11.3</version>
55+
<scope>test</scope>
56+
</dependency>
57+
<dependency>
58+
<groupId>com.squareup.okhttp3</groupId>
59+
<artifactId>mockwebserver</artifactId>
60+
<version>4.12.0</version>
61+
<scope>test</scope>
62+
</dependency>
63+
</dependencies>
64+
65+
<build>
66+
<plugins>
67+
<plugin>
68+
<groupId>org.apache.maven.plugins</groupId>
69+
<artifactId>maven-checkstyle-plugin</artifactId>
70+
<version>3.5.0</version>
71+
<configuration>
72+
<configLocation>google_checks.xml</configLocation>
73+
<consoleOutput>true</consoleOutput>
74+
<violationSeverity>error</violationSeverity>
75+
<includeTestSourceDirectory>true</includeTestSourceDirectory>
76+
</configuration>
77+
<executions>
78+
<execution>
79+
<goals>
80+
<goal>check</goal>
81+
</goals>
82+
</execution>
83+
</executions>
84+
</plugin>
85+
<plugin>
86+
<groupId>org.apache.maven.plugins</groupId>
87+
<artifactId>maven-failsafe-plugin</artifactId>
88+
<version>3.5.0</version>
89+
<executions>
90+
<execution>
91+
<id>integration-tests</id>
92+
<goals>
93+
<goal>integration-test</goal>
94+
<goal>verify</goal>
95+
</goals>
96+
<configuration>
97+
<includes>
98+
<include>**/*IT.java</include>
99+
</includes>
100+
</configuration>
101+
</execution>
102+
</executions>
103+
</plugin>
104+
<plugin>
105+
<groupId>org.apache.maven.plugins</groupId>
106+
<artifactId>maven-surefire-report-plugin</artifactId>
107+
<version>3.5.0</version>
108+
<executions>
109+
<execution>
110+
<id>report</id>
111+
<phase>integration-test</phase>
112+
<goals>
113+
<goal>failsafe-report-only</goal>
114+
</goals>
115+
</execution>
116+
</executions>
117+
</plugin>
118+
</plugins>
119+
</build>
120+
</project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.expediagroup.sdk.xap.integrations.common;
2+
3+
import java.util.Base64;
4+
import java.util.UUID;
5+
6+
/**
7+
* Constants used in the integration tests.
8+
*/
9+
public class Constant {
10+
public static final String PARTNER_TRANSACTION_ID = "xap-sdk-integration-test";
11+
public static final String MOCK_KEY = UUID.randomUUID().toString();
12+
public static final String MOCK_SECRET = "mock";
13+
public static final String AUTHORIZATION = "Basic " + Base64.getEncoder()
14+
.encodeToString((MOCK_KEY + ":" + MOCK_SECRET).getBytes());
15+
public static final String ACCEPT_HOTEL = "application/vnd.exp-hotel.v3+json";
16+
public static final String ACCEPT_LODGING = "application/vnd.exp-lodging.v3+json";
17+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.expediagroup.sdk.xap.integrations.common;
2+
3+
import static com.expediagroup.sdk.xap.integrations.common.Constant.MOCK_KEY;
4+
import static com.expediagroup.sdk.xap.integrations.common.Constant.MOCK_SECRET;
5+
6+
import com.expediagroup.sdk.xap.client.XapClient;
7+
import okhttp3.mockwebserver.MockWebServer;
8+
import org.apache.commons.lang3.StringUtils;
9+
import org.junit.jupiter.api.AfterAll;
10+
import org.junit.jupiter.api.BeforeAll;
11+
import org.junit.jupiter.api.TestInstance;
12+
13+
14+
/**
15+
* Extension for setting up the required components for testing.
16+
*/
17+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
18+
public abstract class XapIT {
19+
20+
protected static XapClient xapClient;
21+
protected static XapClient mockClient;
22+
protected static MockWebServer mockWebServer;
23+
24+
@BeforeAll
25+
static void setup() {
26+
String key = System.getProperty("com.expediagroup.xapjavasdk.apikey");
27+
String secret = System.getProperty("com.expediagroup.xapjavasdk.apisecret");
28+
if (StringUtils.isBlank(key) || StringUtils.isBlank(secret)) {
29+
throw new IllegalStateException("Key and secret must be set");
30+
}
31+
xapClient = XapClient.builder()
32+
.key(key)
33+
.secret(secret)
34+
.build();
35+
36+
mockWebServer = new MockWebServer();
37+
38+
mockClient = XapClient.builder()
39+
.key(MOCK_KEY)
40+
.secret(MOCK_SECRET)
41+
.endpoint(mockWebServer.url("/").toString())
42+
.build();
43+
}
44+
45+
@AfterAll
46+
static void tearDown() throws Exception {
47+
// Clean everything after each test to ensure clear state
48+
if (mockWebServer != null) {
49+
mockWebServer.shutdown();
50+
mockWebServer = null;
51+
}
52+
xapClient = null;
53+
mockClient = null;
54+
}
55+
}

0 commit comments

Comments
 (0)