Skip to content

Commit da42e5f

Browse files
authored
chore: fix integration tests (#67)
1 parent a180d14 commit da42e5f

File tree

10 files changed

+76
-78
lines changed

10 files changed

+76
-78
lines changed

.github/workflows/verify-examples-and-tests.yaml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,4 @@ jobs:
5353
- name: verify integration tests
5454
working-directory: tests/integration
5555
run: |
56-
mvn verify \
57-
-Dcom.expediagroup.xapjavasdk.apikey="${{ secrets.API_KEY }}" \
58-
-Dcom.expediagroup.xapjavasdk.apisecret="${{ secrets.API_SECRET }}" \
59-
-Dcom.expediagroup.xapjavasdk.vrbokey="${{ secrets.VRBO_KEY }}" \
60-
-Dcom.expediagroup.xapjavasdk.vrbosecret="${{ secrets.VRBO_SECRET }}"
56+
mvn verify

tests/integration/pom.xml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,16 @@
3535
<artifactId>xap-sdk</artifactId>
3636
<version>${xap-java-sdk.sdk.version}</version>
3737
</dependency>
38-
3938
<dependency>
4039
<groupId>org.apache.logging.log4j</groupId>
4140
<artifactId>log4j-api</artifactId>
4241
<version>2.24.3</version>
4342
</dependency>
44-
4543
<dependency>
4644
<groupId>org.apache.logging.log4j</groupId>
4745
<artifactId>log4j-slf4j2-impl</artifactId>
4846
<version>2.24.3</version>
4947
</dependency>
50-
5148
<dependency>
5249
<groupId>org.junit.jupiter</groupId>
5350
<artifactId>junit-jupiter</artifactId>
@@ -60,6 +57,12 @@
6057
<version>4.12.0</version>
6158
<scope>test</scope>
6259
</dependency>
60+
<dependency>
61+
<groupId>io.hosuaby</groupId>
62+
<artifactId>inject-resources-junit-jupiter</artifactId>
63+
<version>1.0.0</version>
64+
<scope>test</scope>
65+
</dependency>
6366
</dependencies>
6467

6568
<build>
@@ -117,4 +120,4 @@
117120
</plugin>
118121
</plugins>
119122
</build>
120-
</project>
123+
</project>

tests/integration/src/test/java/com/expediagroup/sdk/xap/integrations/common/XapIntegrationTests.java

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import okhttp3.mockwebserver.MockWebServer;
88
import org.apache.commons.lang3.StringUtils;
99
import org.junit.jupiter.api.AfterAll;
10+
import org.junit.jupiter.api.AfterEach;
1011
import org.junit.jupiter.api.BeforeAll;
12+
import org.junit.jupiter.api.BeforeEach;
1113
import org.junit.jupiter.api.TestInstance;
1214

1315

@@ -17,39 +19,27 @@
1719
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
1820
public abstract class XapIntegrationTests {
1921

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();
22+
protected XapClient xapClient;
23+
protected MockWebServer mockWebServer;
3524

25+
@BeforeEach
26+
void setup() {
3627
mockWebServer = new MockWebServer();
3728

38-
mockClient = XapClient.builder()
29+
xapClient = XapClient.builder()
3930
.key(MOCK_KEY)
4031
.secret(MOCK_SECRET)
4132
.endpoint(mockWebServer.url("/").toString())
4233
.build();
4334
}
4435

45-
@AfterAll
46-
static void tearDown() throws Exception {
36+
@AfterEach
37+
void tearDown() throws Exception {
4738
// Clean everything after each test to ensure clear state
4839
if (mockWebServer != null) {
4940
mockWebServer.shutdown();
5041
mockWebServer = null;
5142
}
5243
xapClient = null;
53-
mockClient = null;
5444
}
5545
}

tests/integration/src/test/java/com/expediagroup/sdk/xap/integrations/lodging/AvailabilityCalendarsIntegrationTests.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
package com.expediagroup.sdk.xap.integrations.lodging;
22

3+
import static com.expediagroup.sdk.xap.integrations.common.Constant.ACCEPT_HOTEL;
34
import static com.expediagroup.sdk.xap.integrations.common.Constant.ACCEPT_LODGING;
45
import static com.expediagroup.sdk.xap.integrations.common.Constant.AUTHORIZATION;
56
import static com.expediagroup.sdk.xap.integrations.common.Constant.MOCK_KEY;
67
import static com.expediagroup.sdk.xap.integrations.common.Constant.PARTNER_TRANSACTION_ID;
78

89
import com.expediagroup.sdk.core.model.Response;
9-
import com.expediagroup.sdk.xap.integrations.common.Constant;
10+
import com.expediagroup.sdk.xap.integrations.common.XapIntegrationTests;
1011
import com.expediagroup.sdk.xap.models.AvailabilityCalendar;
1112
import com.expediagroup.sdk.xap.models.AvailabilityCalendarResponse;
1213
import com.expediagroup.sdk.xap.models.DateRange;
1314
import com.expediagroup.sdk.xap.operations.GetLodgingAvailabilityCalendarsOperation;
1415
import com.expediagroup.sdk.xap.operations.GetLodgingAvailabilityCalendarsOperationParams;
16+
import io.hosuaby.inject.resources.junit.jupiter.GivenTextResource;
17+
import io.hosuaby.inject.resources.junit.jupiter.TestWithResources;
1518
import java.util.Arrays;
1619
import java.util.HashSet;
1720
import java.util.List;
@@ -28,8 +31,8 @@
2831
/**
2932
* This class is used to test the integration of the Lodging Availability Calendars API.
3033
*/
31-
public class AvailabilityCalendarsIntegrationTests extends VrboIntegrationTests {
32-
34+
@TestWithResources
35+
public class AvailabilityCalendarsIntegrationTests extends XapIntegrationTests {
3336
@Test
3437
public void testRequest() {
3538
GetLodgingAvailabilityCalendarsOperationParams availabilityCalendarsOperationParams =
@@ -44,7 +47,7 @@ public void testRequest() {
4447
.setResponseCode(200)
4548
.setBody("{}"));
4649

47-
mockClient.execute(
50+
xapClient.execute(
4851
new GetLodgingAvailabilityCalendarsOperation(availabilityCalendarsOperationParams));
4952
try {
5053
RecordedRequest recordedRequest = mockWebServer.takeRequest();
@@ -69,14 +72,21 @@ public void testRequest() {
6972
}
7073

7174
@Test
72-
public void testResponse() {
75+
public void testResponse(@GivenTextResource("GetLodgingAvailabilityCalendarsResponse.json") String mockedResponse) {
7376
GetLodgingAvailabilityCalendarsOperationParams params =
7477
GetLodgingAvailabilityCalendarsOperationParams.builder()
7578
.partnerTransactionId(PARTNER_TRANSACTION_ID)
7679
.propertyIds(new HashSet<>(Arrays.asList("87704892", "83418323", "75028284",
7780
"75030107", "91799474")))
7881
.build();
7982

83+
mockWebServer.enqueue(
84+
new MockResponse()
85+
.setHeader("Content-Type", ACCEPT_HOTEL)
86+
.setHeader("partner-transaction-id", PARTNER_TRANSACTION_ID)
87+
.setResponseCode(200)
88+
.setBody(mockedResponse));
89+
8090
Response<AvailabilityCalendarResponse> response =
8191
xapClient.execute(new GetLodgingAvailabilityCalendarsOperation(params));
8292
verifyResponse(response);
@@ -87,9 +97,8 @@ private void verifyResponse(Response<AvailabilityCalendarResponse> response) {
8797
Assertions.assertEquals(200, response.getStatusCode());
8898
Map<String, List<String>> headers = response.getHeaders();
8999
Assertions.assertNotNull(headers);
90-
Assertions.assertEquals(Constant.PARTNER_TRANSACTION_ID, headers.get("partner-transaction-id")
100+
Assertions.assertEquals(PARTNER_TRANSACTION_ID, headers.get("partner-transaction-id")
91101
.get(0));
92-
Assertions.assertTrue(headers.containsKey("txnid"));
93102
verifyAvailabilityCalendarResponse(response.getData());
94103
}
95104

tests/integration/src/test/java/com/expediagroup/sdk/xap/integrations/lodging/ListingsIntegrationTests.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
import com.expediagroup.sdk.xap.models.StayDates;
4545
import com.expediagroup.sdk.xap.operations.GetLodgingListingsOperation;
4646
import com.expediagroup.sdk.xap.operations.GetLodgingListingsOperationParams;
47+
import io.hosuaby.inject.resources.junit.jupiter.GivenTextResource;
48+
import io.hosuaby.inject.resources.junit.jupiter.TestWithResources;
4749
import java.time.LocalDate;
4850
import java.util.ArrayList;
4951
import java.util.Arrays;
@@ -62,6 +64,7 @@
6264
/**
6365
* This class is used to test the integration of the Lodging Listings API.
6466
*/
67+
@TestWithResources
6568
public class ListingsIntegrationTests extends XapIntegrationTests {
6669

6770
@Test
@@ -75,8 +78,6 @@ public void testRequest() {
7578
rooms.add(Room.builder().adults(3L).childAges(Arrays.asList(1L, 2L, 3L, 4L, 5L)).build());
7679
rooms.add(Room.builder().adults(2L).childAges(Arrays.asList(1L, 2L, 3L, 4L)).build());
7780
rooms.add(Room.builder().adults(1L).build());
78-
// nine rooms here, the ninth room should be ignored
79-
rooms.add(Room.builder().adults(2L).build());
8081

8182
GetLodgingListingsOperationParams getLodgingListingsOperationParams =
8283
GetLodgingListingsOperationParams.builder()
@@ -131,7 +132,7 @@ public void testRequest() {
131132
.setResponseCode(200)
132133
.setBody("{}"));
133134

134-
mockClient.execute(new GetLodgingListingsOperation(getLodgingListingsOperationParams));
135+
xapClient.execute(new GetLodgingListingsOperation(getLodgingListingsOperationParams));
135136
try {
136137
RecordedRequest recordedRequest = mockWebServer.takeRequest();
137138
// method
@@ -211,7 +212,7 @@ public void testRequest() {
211212
}
212213

213214
@Test
214-
public void testResponse() {
215+
public void testResponse(@GivenTextResource("GetLodgingListingsResponse.json") String mockedResponse) {
215216
GetLodgingListingsOperationParams operationParams = GetLodgingListingsOperationParams.builder()
216217
.partnerTransactionId(Constant.PARTNER_TRANSACTION_ID)
217218
.locationKeyword("Seattle")
@@ -223,8 +224,17 @@ public void testResponse() {
223224
.availOnly(true)
224225
.build();
225226

226-
Response<HotelListingsResponse> response =
227-
xapClient.execute(new GetLodgingListingsOperation(operationParams));
227+
mockWebServer.enqueue(
228+
new MockResponse()
229+
.setHeader("Content-Type", ACCEPT_HOTEL)
230+
.setHeader("Partner-Transaction-Id", Constant.PARTNER_TRANSACTION_ID)
231+
.setResponseCode(200)
232+
.setBody(mockedResponse));
233+
234+
Response<HotelListingsResponse> response = xapClient.execute(
235+
new GetLodgingListingsOperation(operationParams)
236+
);
237+
228238
verifyResponse(response);
229239
}
230240

@@ -235,19 +245,22 @@ private void verifyResponse(Response<HotelListingsResponse> response) {
235245
Assertions.assertNotNull(headers);
236246
Assertions.assertEquals(Constant.PARTNER_TRANSACTION_ID, headers.get("partner-transaction-id")
237247
.get(0));
238-
Assertions.assertTrue(headers.containsKey("txnid"));
239248
verifyHotelListingsResponse(response.getData());
240249
}
241250

242251
private void verifyHotelListingsResponse(
243252
HotelListingsResponse hotelListingsResponse) {
244253
Assertions.assertNotNull(hotelListingsResponse);
245254
Assertions.assertNull(hotelListingsResponse.getWarnings());
255+
Assertions.assertNotNull(hotelListingsResponse.getCount());
246256
Assertions.assertTrue(hotelListingsResponse.getCount() > 0);
257+
Assertions.assertNotNull(hotelListingsResponse.getTotalHotelCount());
247258
Assertions.assertTrue(hotelListingsResponse.getTotalHotelCount() > 0);
248259
Assertions.assertNotNull(hotelListingsResponse.getTransactionId());
249260
Assertions.assertNotNull(hotelListingsResponse.getStayDates());
261+
Assertions.assertNotNull(hotelListingsResponse.getLengthOfStay());
250262
Assertions.assertTrue(hotelListingsResponse.getLengthOfStay() > 0);
263+
Assertions.assertNotNull(hotelListingsResponse.getNumberOfRooms());
251264
Assertions.assertTrue(hotelListingsResponse.getNumberOfRooms() > 0);
252265
Assertions.assertNotNull(hotelListingsResponse.getOccupants());
253266
Assertions.assertFalse(hotelListingsResponse.getOccupants().isEmpty());

tests/integration/src/test/java/com/expediagroup/sdk/xap/integrations/lodging/QuotesIntegrationTests.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.expediagroup.sdk.xap.integrations.lodging;
22

3+
import static com.expediagroup.sdk.xap.integrations.common.Constant.ACCEPT_HOTEL;
34
import static com.expediagroup.sdk.xap.integrations.common.Constant.ACCEPT_LODGING;
45
import static com.expediagroup.sdk.xap.integrations.common.Constant.AUTHORIZATION;
56
import static com.expediagroup.sdk.xap.integrations.common.Constant.MOCK_KEY;
67
import static com.expediagroup.sdk.xap.integrations.common.Constant.PARTNER_TRANSACTION_ID;
78

89
import com.expediagroup.sdk.core.model.Response;
910
import com.expediagroup.sdk.xap.integrations.common.Constant;
11+
import com.expediagroup.sdk.xap.integrations.common.XapIntegrationTests;
1012
import com.expediagroup.sdk.xap.models.LodgingCancellationPolicy;
1113
import com.expediagroup.sdk.xap.models.LodgingQuotesResponse;
1214
import com.expediagroup.sdk.xap.models.LodgingRatePlan;
@@ -16,6 +18,8 @@
1618
import com.expediagroup.sdk.xap.models.Room;
1719
import com.expediagroup.sdk.xap.operations.GetLodgingQuotesOperation;
1820
import com.expediagroup.sdk.xap.operations.GetLodgingQuotesOperationParams;
21+
import io.hosuaby.inject.resources.junit.jupiter.GivenTextResource;
22+
import io.hosuaby.inject.resources.junit.jupiter.TestWithResources;
1923
import java.time.LocalDate;
2024
import java.util.ArrayList;
2125
import java.util.Arrays;
@@ -35,8 +39,8 @@
3539
/**
3640
* This class is used to test the integration of the Lodging Quotes API.
3741
*/
38-
public class QuotesIntegrationTests extends VrboIntegrationTests {
39-
42+
@TestWithResources
43+
public class QuotesIntegrationTests extends XapIntegrationTests {
4044
@Test
4145
public void testRequest() {
4246
ArrayList<Room> rooms = new ArrayList<>();
@@ -48,8 +52,6 @@ public void testRequest() {
4852
rooms.add(Room.builder().adults(3L).childAges(Arrays.asList(1L, 2L, 3L, 4L, 5L)).build());
4953
rooms.add(Room.builder().adults(2L).childAges(Arrays.asList(1L, 2L, 3L, 4L)).build());
5054
rooms.add(Room.builder().adults(1L).build());
51-
// nine rooms here, the ninth room should be ignored
52-
rooms.add(Room.builder().adults(2L).build());
5355

5456
GetLodgingQuotesOperationParams getLodgingQuotesOperationParams =
5557
GetLodgingQuotesOperationParams.builder()
@@ -69,7 +71,7 @@ public void testRequest() {
6971
.setResponseCode(200)
7072
.setBody("{}"));
7173

72-
mockClient.execute(new GetLodgingQuotesOperation(getLodgingQuotesOperationParams));
74+
xapClient.execute(new GetLodgingQuotesOperation(getLodgingQuotesOperationParams));
7375
try {
7476
RecordedRequest recordedRequest = mockWebServer.takeRequest();
7577
// method
@@ -114,17 +116,24 @@ public void testRequest() {
114116
}
115117

116118
@Test
117-
public void testResponse() {
119+
public void testResponse(@GivenTextResource("GetLodgingQuotesResponse.json") String mockedResponse) {
118120
GetLodgingQuotesOperationParams getLodgingQuotesOperationParams =
119121
GetLodgingQuotesOperationParams.builder()
120122
.partnerTransactionId(PARTNER_TRANSACTION_ID)
121123
.propertyIds(new HashSet<>(Arrays.asList("87704892", "83418323", "75028284", "75030107",
122124
"91799474")))
123-
.checkIn(LocalDate.now().plusDays(5))
124-
.checkOut(LocalDate.now().plusDays(10))
125+
.checkIn(LocalDate.now().plusDays(10))
126+
.checkOut(LocalDate.now().plusDays(15))
125127
.links(Collections.singletonList(GetLodgingQuotesOperationParams.Links.WEB))
126128
.build();
127129

130+
mockWebServer.enqueue(
131+
new MockResponse()
132+
.setHeader("Content-Type", ACCEPT_HOTEL)
133+
.setHeader("partner-transaction-id", Constant.PARTNER_TRANSACTION_ID)
134+
.setResponseCode(200)
135+
.setBody(mockedResponse));
136+
128137
Response<LodgingQuotesResponse> response =
129138
xapClient.execute(new GetLodgingQuotesOperation(getLodgingQuotesOperationParams));
130139
verifyResponse(response);
@@ -137,17 +146,19 @@ private void verifyResponse(Response<LodgingQuotesResponse> response) {
137146
Assertions.assertNotNull(headers);
138147
Assertions.assertEquals(Constant.PARTNER_TRANSACTION_ID, headers.get("partner-transaction-id")
139148
.get(0));
140-
Assertions.assertTrue(headers.containsKey("txnid"));
141149
verifyLodgingQuotesResponse(response.getData());
142150
}
143151

144152
private void verifyLodgingQuotesResponse(LodgingQuotesResponse lodgingQuotesResponse) {
145153
Assertions.assertNotNull(lodgingQuotesResponse);
146154
Assertions.assertNull(lodgingQuotesResponse.getWarnings());
155+
Assertions.assertNotNull(lodgingQuotesResponse.getCount());
147156
Assertions.assertTrue(lodgingQuotesResponse.getCount() > 0);
157+
Assertions.assertNotNull(lodgingQuotesResponse.getTotalPropertyCount());
148158
Assertions.assertTrue(lodgingQuotesResponse.getTotalPropertyCount() > 0);
149159
Assertions.assertNotNull(lodgingQuotesResponse.getTransactionId());
150160
Assertions.assertNotNull(lodgingQuotesResponse.getStayDates());
161+
Assertions.assertNotNull(lodgingQuotesResponse.getLengthOfStay());
151162
Assertions.assertTrue(lodgingQuotesResponse.getLengthOfStay() > 0);
152163
Assertions.assertNotNull(lodgingQuotesResponse.getOccupants());
153164
Assertions.assertFalse(lodgingQuotesResponse.getOccupants().isEmpty());

0 commit comments

Comments
 (0)