Skip to content

Commit 2d6fc76

Browse files
authored
SDK-1399 accommodate running scenarios as tests by throwing exception… (#109)
1 parent 7b6a455 commit 2d6fc76

File tree

7 files changed

+24
-26
lines changed

7 files changed

+24
-26
lines changed

examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/booking/AsyncSingleRoomBookScenario.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.expediagroup.sdk.rapid.examples.scenarios.booking;
22

3+
import com.expediagroup.sdk.core.model.Response;
34
import com.expediagroup.sdk.rapid.examples.Constants;
45
import com.expediagroup.sdk.rapid.examples.salesprofiles.RapidPartnerSalesProfile;
56
import com.expediagroup.sdk.rapid.examples.scenarios.RapidScenario;
@@ -35,21 +36,22 @@ public void run() {
3536
logger.info("Async call - Getting property availability for test property: {}", Constants.TEST_PROPERTY_ID);
3637

3738
shopService.asyncGetSingleRoomPropertiesAvailability(this.rapidPartnerSalesProfile)
38-
.thenApply(response -> response.getData())
39+
.thenApply(Response::getData)
3940
.thenCompose(this::checkRoomPrices)
4041
.thenCompose(this::bookRoom)
4142
.thenCompose(this::getItinerary)
4243
.thenAccept(itinerary -> {
43-
if (itinerary != null) {
44-
logger.info("Itinerary: {}", itinerary.getItineraryId());
44+
if (itinerary == null) {
45+
throw new IllegalStateException("Itinerary is null");
4546
}
47+
logger.info("Itinerary: {}", itinerary.getItineraryId());
4648
});
4749

4850
}
4951

5052
private CompletableFuture<Itinerary> getItinerary(ItineraryCreation itineraryCreation) {
5153
if (itineraryCreation == null) {
52-
return CompletableFuture.completedFuture(null);
54+
throw new IllegalStateException("ItineraryCreation is null");
5355
}
5456

5557
logger.info("Booking Success. Itinerary id: {}", itineraryCreation.getItineraryId());
@@ -63,7 +65,7 @@ private CompletableFuture<Itinerary> getItinerary(ItineraryCreation itineraryCre
6365

6466
private CompletableFuture<ItineraryCreation> bookRoom(RoomPriceCheck roomPriceCheck) {
6567
if (roomPriceCheck == null) {
66-
return CompletableFuture.completedFuture(null);
68+
throw new IllegalStateException("Room Price Check is null");
6769
}
6870

6971
logger.info("Room Price Check: {}", roomPriceCheck.getStatus());
@@ -78,21 +80,22 @@ private CompletableFuture<ItineraryCreation> bookRoom(RoomPriceCheck roomPriceCh
7880

7981
private CompletableFuture<RoomPriceCheck> checkRoomPrices(List<Property> propertyAvailabilityList) {
8082
if (propertyAvailabilityList == null || propertyAvailabilityList.isEmpty()) {
81-
logger.error("No property availability found for the test property.");
82-
return CompletableFuture.completedFuture(null);
83+
throw new IllegalStateException("No property availability found for the test property.");
8384
}
8485

8586
logger.info("Property Availability: {}", propertyAvailabilityList.get(0).getStatus());
8687

8788
// Checking room prices for the property
8889
logger.info("Checking room prices for the property: {}...", Constants.TEST_PROPERTY_ID);
8990
Property property = propertyAvailabilityList.get(0);
90-
if (property instanceof PropertyAvailability) {
91-
PropertyAvailability propertyAvailability = (PropertyAvailability) property;
92-
return shopService.asyncCheckRoomPrices(propertyAvailability, 0, 0)
93-
.thenApply(response -> response.getData());
94-
} else {
95-
return CompletableFuture.completedFuture(null);
91+
92+
if (!(property instanceof PropertyAvailability)) {
93+
throw new IllegalStateException("Property is not an instance of PropertyAvailability");
9694
}
95+
96+
PropertyAvailability propertyAvailability = (PropertyAvailability) property;
97+
return shopService.asyncCheckRoomPrices(propertyAvailability, 0, 0)
98+
.thenApply(response -> response.getData());
99+
97100
}
98101
}

examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/booking/CancelHeldBookingScenario.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ public void run() {
3535
List<Property> propertyAvailabilityList = shopService.getSingleRoomPropertiesAvailability(this.rapidPartnerSalesProfile).getData();
3636

3737
if (propertyAvailabilityList == null || propertyAvailabilityList.isEmpty()) {
38-
logger.error("No property availability found for the test property.");
39-
return;
38+
throw new IllegalStateException("No property availability found for the test property.");
4039
}
4140

4241
logger.info("Property Availability: {}", propertyAvailabilityList.get(0).getStatus());
@@ -45,7 +44,7 @@ public void run() {
4544
logger.info("Checking room prices for the property: [{}]...", Constants.TEST_PROPERTY_ID);
4645
Property property = propertyAvailabilityList.get(0);
4746

48-
if (!(property instanceof PropertyAvailability)) throw new RuntimeException();
47+
if (!(property instanceof PropertyAvailability)) throw new IllegalStateException("Property is not of type PropertyAvailability");
4948

5049
PropertyAvailability propertyAvailability = (PropertyAvailability) property;
5150
RoomPriceCheck roomPriceCheck = shopService.checkRoomPrices(propertyAvailability, 0, 0).getData();

examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/booking/MultiRoomHoldAndResumeBookScenario.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ public void run() {
4242
List<Property> propertyAvailabilityList = shopService.getMultipleRoomsPropertiesAvailability(this.rapidPartnerSalesProfile, occupancy).getData();
4343

4444
if (propertyAvailabilityList == null || propertyAvailabilityList.isEmpty()) {
45-
logger.error("No property availability found for the test property.");
46-
return;
45+
throw new IllegalStateException("No property availability found for the test property.");
4746
}
4847

4948
logger.info("Property Availability found for property id: [{}] with status: [{}]",

examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/booking/SingleRoomBookScenario.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ public void run() {
3636
List<Property> propertyAvailabilityList = shopService.getSingleRoomPropertiesAvailability(this.rapidPartnerSalesProfile).getData();
3737

3838
if (propertyAvailabilityList == null || propertyAvailabilityList.isEmpty()) {
39-
logger.error("No property availability found for the test property.");
40-
return;
39+
throw new IllegalStateException("No property availability found for the test property.");
4140
}
4241

4342
logger.info("Property Availability: {}", propertyAvailabilityList.get(0).getStatus());

examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/geography/GetRegionByAncestorIdScenario.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ public void run() {
2828
List<List<Region>> regionsPages = geographyService.getRegionsByAncestor(Constants.TEST_ANCESTOR_ID, this.rapidPartnerSalesProfile);
2929

3030
if (regionsPages == null || regionsPages.isEmpty()) {
31-
logger.error("No regions found for the ancestor id: [{}].", Constants.TEST_ANCESTOR_ID);
32-
return;
31+
throw new IllegalStateException(String.format("No regions found for the ancestor id: [%s].", Constants.TEST_ANCESTOR_ID));
3332
}
3433

3534
logger.info("Regions found for the ancestor id: [{}]:", Constants.TEST_ANCESTOR_ID);

examples/src/main/java/com/expediagroup/sdk/rapid/examples/scenarios/shopping/GetAdditionalAvailabilityOfPropertyScenario.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ public void run() {
3232
List<Property> propertyAvailabilityList = shopService.getSingleRoomPropertiesAvailability(this.rapidPartnerSalesProfile).getData();
3333

3434
if (propertyAvailabilityList == null || propertyAvailabilityList.isEmpty()) {
35-
logger.error("No property availability found for the test property.");
36-
return;
35+
throw new IllegalStateException("No property availability found for the test property.");
3736
}
3837

3938
logger.info("Property Availability: {}", propertyAvailabilityList.get(0).getStatus());

examples/src/main/java/com/expediagroup/sdk/rapid/examples/services/BookService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public Response<Nothing> cancelHeldReservationByItineraryId(ItineraryCreation it
135135
ItineraryCreationLinks itineraryCreationLinks = itineraryCreation.getLinks();
136136
if (itineraryCreationLinks == null) throw new RuntimeException();
137137
Link cancelLink = itineraryCreationLinks.getCancel();
138-
if (cancelLink == null) throw new RuntimeException();
138+
if (cancelLink == null) throw new IllegalStateException("Cancel link not found");
139139

140140
DeleteHeldBookingOperationContext deleteHeldBookingOperationContext =
141141
DeleteHeldBookingOperationContext.builder().customerIp("127.0.0.1").build();
@@ -150,7 +150,7 @@ public CompletableFuture<Response<Itinerary>> asyncGetReservationByItineraryId(I
150150
GetReservationByItineraryIdOperationContext getReservationByItineraryIdOperationContext =
151151
GetReservationByItineraryIdOperationContext.builder().customerIp("127.0.0.1").build();
152152

153-
return rapidClient.executeAsync(new GetReservationByItineraryIdOperation(retrieveLink, getReservationByItineraryIdOperationContext ));
153+
return rapidClient.executeAsync(new GetReservationByItineraryIdOperation(retrieveLink, getReservationByItineraryIdOperationContext));
154154
}
155155

156156
/* Helper methods */

0 commit comments

Comments
 (0)