Skip to content

Commit 5a6efad

Browse files
committed
chore: fix integration tests
1 parent 0526692 commit 5a6efad

File tree

9 files changed

+74
-66
lines changed

9 files changed

+74
-66
lines changed

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: 6 additions & 16 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,22 +19,11 @@
1719
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
1820
public abstract class XapIntegrationTests {
1921

20-
protected static XapClient xapClient;
2122
protected static XapClient mockClient;
2223
protected static MockWebServer mockWebServer;
2324

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-
25+
@BeforeEach
26+
void setup() {
3627
mockWebServer = new MockWebServer();
3728

3829
mockClient = XapClient.builder()
@@ -42,14 +33,13 @@ static void setup() {
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
}
52-
xapClient = null;
5343
mockClient = null;
5444
}
5545
}

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

Lines changed: 17 additions & 6 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 =
@@ -69,16 +72,24 @@ public void testRequest() {
6972
}
7073

7174
@Test
72-
public void testResponse() {
75+
public void testResponse(@GivenTextResource("GetLodgingAvailabilityCalendars.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+
.setHeader("txnid", UUID.randomUUID().toString())
88+
.setResponseCode(200)
89+
.setBody(mockedResponse));
90+
8091
Response<AvailabilityCalendarResponse> response =
81-
xapClient.execute(new GetLodgingAvailabilityCalendarsOperation(params));
92+
mockClient.execute(new GetLodgingAvailabilityCalendarsOperation(params));
8293
verifyResponse(response);
8394
}
8495

@@ -87,7 +98,7 @@ private void verifyResponse(Response<AvailabilityCalendarResponse> response) {
8798
Assertions.assertEquals(200, response.getStatusCode());
8899
Map<String, List<String>> headers = response.getHeaders();
89100
Assertions.assertNotNull(headers);
90-
Assertions.assertEquals(Constant.PARTNER_TRANSACTION_ID, headers.get("partner-transaction-id")
101+
Assertions.assertEquals(PARTNER_TRANSACTION_ID, headers.get("partner-transaction-id")
91102
.get(0));
92103
Assertions.assertTrue(headers.containsKey("txnid"));
93104
verifyAvailabilityCalendarResponse(response.getData());

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

Lines changed: 20 additions & 5 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()
@@ -211,7 +212,7 @@ public void testRequest() {
211212
}
212213

213214
@Test
214-
public void testResponse() {
215+
public void testResponse(@GivenTextResource("GetLodgingListings.json") String mockedResponse) {
215216
GetLodgingListingsOperationParams operationParams = GetLodgingListingsOperationParams.builder()
216217
.partnerTransactionId(Constant.PARTNER_TRANSACTION_ID)
217218
.locationKeyword("Seattle")
@@ -223,8 +224,18 @@ 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+
.setHeader("txnid", UUID.randomUUID().toString())
232+
.setResponseCode(200)
233+
.setBody(mockedResponse));
234+
235+
Response<HotelListingsResponse> response = mockClient.execute(
236+
new GetLodgingListingsOperation(operationParams)
237+
);
238+
228239
verifyResponse(response);
229240
}
230241

@@ -243,11 +254,15 @@ private void verifyHotelListingsResponse(
243254
HotelListingsResponse hotelListingsResponse) {
244255
Assertions.assertNotNull(hotelListingsResponse);
245256
Assertions.assertNull(hotelListingsResponse.getWarnings());
257+
Assertions.assertNotNull(hotelListingsResponse.getCount());
246258
Assertions.assertTrue(hotelListingsResponse.getCount() > 0);
259+
Assertions.assertNotNull(hotelListingsResponse.getTotalHotelCount());
247260
Assertions.assertTrue(hotelListingsResponse.getTotalHotelCount() > 0);
248261
Assertions.assertNotNull(hotelListingsResponse.getTransactionId());
249262
Assertions.assertNotNull(hotelListingsResponse.getStayDates());
263+
Assertions.assertNotNull(hotelListingsResponse.getLengthOfStay());
250264
Assertions.assertTrue(hotelListingsResponse.getLengthOfStay() > 0);
265+
Assertions.assertNotNull(hotelListingsResponse.getNumberOfRooms());
251266
Assertions.assertTrue(hotelListingsResponse.getNumberOfRooms() > 0);
252267
Assertions.assertNotNull(hotelListingsResponse.getOccupants());
253268
Assertions.assertFalse(hotelListingsResponse.getOccupants().isEmpty());

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

Lines changed: 21 additions & 8 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()
@@ -114,19 +116,27 @@ public void testRequest() {
114116
}
115117

116118
@Test
117-
public void testResponse() {
119+
public void testResponse(@GivenTextResource("GetLodgingQuotes.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+
.setHeader("txnid", UUID.randomUUID().toString())
135+
.setResponseCode(200)
136+
.setBody(mockedResponse));
137+
128138
Response<LodgingQuotesResponse> response =
129-
xapClient.execute(new GetLodgingQuotesOperation(getLodgingQuotesOperationParams));
139+
mockClient.execute(new GetLodgingQuotesOperation(getLodgingQuotesOperationParams));
130140
verifyResponse(response);
131141
}
132142

@@ -144,10 +154,13 @@ private void verifyResponse(Response<LodgingQuotesResponse> response) {
144154
private void verifyLodgingQuotesResponse(LodgingQuotesResponse lodgingQuotesResponse) {
145155
Assertions.assertNotNull(lodgingQuotesResponse);
146156
Assertions.assertNull(lodgingQuotesResponse.getWarnings());
157+
Assertions.assertNotNull(lodgingQuotesResponse.getCount());
147158
Assertions.assertTrue(lodgingQuotesResponse.getCount() > 0);
159+
Assertions.assertNotNull(lodgingQuotesResponse.getTotalPropertyCount());
148160
Assertions.assertTrue(lodgingQuotesResponse.getTotalPropertyCount() > 0);
149161
Assertions.assertNotNull(lodgingQuotesResponse.getTransactionId());
150162
Assertions.assertNotNull(lodgingQuotesResponse.getStayDates());
163+
Assertions.assertNotNull(lodgingQuotesResponse.getLengthOfStay());
151164
Assertions.assertTrue(lodgingQuotesResponse.getLengthOfStay() > 0);
152165
Assertions.assertNotNull(lodgingQuotesResponse.getOccupants());
153166
Assertions.assertFalse(lodgingQuotesResponse.getOccupants().isEmpty());

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

Lines changed: 0 additions & 27 deletions
This file was deleted.

tests/integration/src/test/resources/GetLodgingAvailabilityCalendars.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

tests/integration/src/test/resources/GetLodgingListings.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"Count":4,"TotalPropertyCount":5,"TransactionId":"5da99559-b548-49e5-840f-5ec749b00881","StayDates":{"CheckInDate":"2025-02-16","CheckOutDate":"2025-02-21"},"LengthOfStay":5,"Occupants":[{"Adults":2}],"Properties":[{"Id":"75030107","Status":"NOT_AVAILABLE"},{"Id":"87704892","Status":"NOT_AVAILABLE"},{"Id":"83418323","Status":"AVAILABLE","RoomTypes":[{"RatePlans":[{"CancellationPolicy":{"Refundable":true,"FreeCancellation":false,"CancellationPenaltyRules":[{"PenaltyPercentOfStay":"50.00","PenaltyStartDateTime":"2025-02-05T15:59:00-08:00","PenaltyEndDateTime":"2025-02-09T23:59:00-08:00"},{"PenaltyPercentOfStay":"100","PenaltyStartDateTime":"2025-02-09T23:59:00-08:00","PenaltyEndDateTime":"2025-02-16T00:00:00-08:00"}]}}],"Price":{"BaseRate":{"Value":"338.10","Currency":"USD"},"TaxesAndFees":{"Value":"218.86","Currency":"USD"},"TotalPrice":{"Value":"556.96","Currency":"USD"},"AvgNightlyRate":{"Value":"67.62","Currency":"USD"},"AvgNightlyRateWithFees":{"Value":"111.39","Currency":"USD"},"TotalPriceWithPropertyFees":{"Value":"556.96","Currency":"USD"}},"Links":{"WebSearchResult":{"Method":"GET","Href":"https://www.vrbo.com/search?mpd=USD&tpid=9001&endDate=2025-02-21&adults=2&eapid=1&selected=83418323&startDate=2025-02-16&mpb=218.86&mpa=338.10"},"WebDetails":{"Method":"GET","Href":"https://www.vrbo.com/2930936?mpd=USD&mpe=1738846806&endDate=2025-02-21&adults=2&startDate=2025-02-16&mpb=218.86&mpa=338.10"}}}]},{"Id":"91799474","Status":"NOT_AVAILABLE"}]}

0 commit comments

Comments
 (0)