Skip to content

Commit 1d6b8bf

Browse files
committed
chore: add PR check to verify examples
1 parent 68364cc commit 1d6b8bf

30 files changed

+2202
-1444
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Verify Examples
2+
on:
3+
pull_request:
4+
branches:
5+
- 'main'
6+
jobs:
7+
detect-changes:
8+
runs-on: ubuntu-latest
9+
permissions:
10+
pull-requests: read
11+
outputs:
12+
examples: ${{ steps.filter.outputs.examples }}
13+
steps:
14+
- uses: dorny/paths-filter@v3
15+
id: filter
16+
with:
17+
filters: |
18+
examples:
19+
- 'examples/**'
20+
21+
verify-examples:
22+
needs: detect-changes
23+
if: ${{ needs.detect-changes.outputs.examples == 'true' }}
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v4
27+
- uses: actions/setup-java@v4
28+
with:
29+
java-version: '11'
30+
distribution: 'temurin'
31+
- name: verify examples
32+
working-directory: examples
33+
run: mvn clean install

examples/pom.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,23 @@
4949

5050
<build>
5151
<plugins>
52+
<plugin>
53+
<groupId>org.apache.maven.plugins</groupId>
54+
<artifactId>maven-checkstyle-plugin</artifactId>
55+
<version>3.5.0</version>
56+
<configuration>
57+
<configLocation>google_checks.xml</configLocation>
58+
<consoleOutput>true</consoleOutput>
59+
<violationSeverity>warning</violationSeverity>
60+
</configuration>
61+
<executions>
62+
<execution>
63+
<goals>
64+
<goal>check</goal>
65+
</goals>
66+
</execution>
67+
</executions>
68+
</plugin>
5269
<plugin>
5370
<groupId>org.codehaus.mojo</groupId>
5471
<artifactId>exec-maven-plugin</artifactId>
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
package com.expediagroup.sdk.rapid.examples;
22

3+
/**
4+
* Constants used throughout the application.
5+
*/
36
public class Constants {
4-
public static final String TEST_PROPERTY_ID = "11775754";
7+
public static final String TEST_PROPERTY_ID = "11775754";
58

6-
public static final String TEST_REGION_ID = "178248";
9+
public static final String TEST_REGION_ID = "178248";
710

8-
public static final String TEST_REGION_ID_WITH_MULTIPOLYGON = "553248635740541470";
11+
public static final String TEST_REGION_ID_WITH_MULTIPOLYGON = "553248635740541470";
912

10-
public static final String TEST_ANCESTOR_ID = "602962";
13+
public static final String TEST_ANCESTOR_ID = "602962";
1114

12-
public static final String CUSTOMER_IP = "5.5.5.5";
15+
public static final String CUSTOMER_IP = "5.5.5.5";
1316

14-
public static final String SANDBOX_URL = "https://test.ean.com/";
17+
public static final String SANDBOX_URL = "https://test.ean.com/";
1518

16-
public static final String CUSTOMER_SESSION_ID = "123455656565";
19+
public static final String CUSTOMER_SESSION_ID = "123455656565";
1720
}

examples/src/main/java/com/expediagroup/sdk/rapid/examples/RapidSdkDemoApplication.java

Lines changed: 263 additions & 222 deletions
Large diffs are not rendered by default.
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package com.expediagroup.sdk.rapid.examples.salesprofiles;
22

3-
3+
/**
4+
* Default Rapid Partner Profile.
5+
*/
46
public final class DefaultRapidPartnerProfile extends RapidPartnerSalesProfile {
5-
6-
public DefaultRapidPartnerProfile() {
7-
this.billingTerms = null;
8-
this.paymentTerms = null;
9-
this.partnerPointOfSale = null;
10-
this.platformName = null;
11-
}
7+
/**
8+
* Default constructor.
9+
*/
10+
public DefaultRapidPartnerProfile() {
11+
this.billingTerms = null;
12+
this.paymentTerms = null;
13+
this.partnerPointOfSale = null;
14+
this.platformName = null;
15+
}
1216
}
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
package com.expediagroup.sdk.rapid.examples.salesprofiles;
22

3-
3+
/**
4+
* Rapid Partner Sales Profile.
5+
*/
46
public abstract class RapidPartnerSalesProfile {
57

6-
public String billingTerms;
8+
public String billingTerms;
79

8-
public String paymentTerms;
10+
public String paymentTerms;
911

10-
public String partnerPointOfSale;
12+
public String partnerPointOfSale;
1113

12-
public String platformName;
14+
public String platformName;
1315

1416
}
Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
package com.expediagroup.sdk.rapid.examples.scenarios;
22

33
import com.expediagroup.sdk.rapid.examples.salesprofiles.RapidPartnerSalesProfile;
4-
54
import java.util.concurrent.ExecutionException;
65

6+
/**
7+
* Interface representing a scenario to be executed with a specific sales profile.
8+
*/
79
public interface RapidScenario {
810

9-
void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile);
11+
/**
12+
* Sets the sales profile for the scenario.
13+
*
14+
* @param rapidPartnerSalesProfile the sales profile to be set
15+
*/
16+
void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile);
1017

11-
void run() throws ExecutionException, InterruptedException;
18+
/**
19+
* Executes the scenario.
20+
*
21+
* @throws ExecutionException if an error occurs during execution
22+
* @throws InterruptedException if the execution is interrupted
23+
*/
24+
void run() throws ExecutionException, InterruptedException;
1225
}

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

Lines changed: 103 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -11,93 +11,124 @@
1111
import com.expediagroup.sdk.rapid.models.Property;
1212
import com.expediagroup.sdk.rapid.models.PropertyAvailability;
1313
import com.expediagroup.sdk.rapid.models.RoomPriceCheck;
14-
import org.slf4j.Logger;
15-
import org.slf4j.LoggerFactory;
16-
1714
import java.util.Arrays;
1815
import java.util.List;
1916
import java.util.concurrent.CompletableFuture;
17+
import org.slf4j.Logger;
18+
import org.slf4j.LoggerFactory;
2019

20+
/**
21+
* Scenario for booking a single room asynchronously.
22+
*/
2123
public class AsyncSingleRoomBookScenario implements RapidScenario {
2224

23-
private static final Logger logger = LoggerFactory.getLogger(AsyncSingleRoomBookScenario.class);
24-
private ShopService shopService = new ShopService();
25-
private RapidPartnerSalesProfile rapidPartnerSalesProfile;
26-
27-
@Override
28-
public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) {
29-
this.rapidPartnerSalesProfile = rapidPartnerSalesProfile;
25+
private static final Logger logger = LoggerFactory.getLogger(AsyncSingleRoomBookScenario.class);
26+
private ShopService shopService = new ShopService();
27+
private RapidPartnerSalesProfile rapidPartnerSalesProfile;
28+
29+
/**
30+
* Sets the sales profile for the scenario.
31+
*
32+
* @param rapidPartnerSalesProfile the sales profile to set
33+
*/
34+
@Override
35+
public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) {
36+
this.rapidPartnerSalesProfile = rapidPartnerSalesProfile;
37+
}
38+
39+
/**
40+
* Runs the scenario to book a single room asynchronously.
41+
*/
42+
@Override
43+
public void run() {
44+
45+
logger.info(
46+
"Running Book Single Room Scenario using the default profile in asynchronous manner...");
47+
48+
// Shopping for properties
49+
logger.info("Async call - Getting property availability for test property: {}",
50+
Constants.TEST_PROPERTY_ID);
51+
52+
shopService.asyncGetSingleRoomPropertiesAvailability(this.rapidPartnerSalesProfile)
53+
.thenApply(Response::getData)
54+
.thenCompose(this::checkRoomPrices)
55+
.thenCompose(this::bookRoom)
56+
.thenCompose(this::getItinerary)
57+
.thenAccept(itinerary -> {
58+
if (itinerary == null) {
59+
throw new IllegalStateException("Itinerary is null");
60+
}
61+
logger.info("Itinerary: {}", itinerary.getItineraryId());
62+
});
63+
64+
}
65+
66+
/**
67+
* Retrieves the itinerary for the booking.
68+
*
69+
* @param itineraryCreation the itinerary creation details
70+
* @return a CompletableFuture with the itinerary
71+
*/
72+
private CompletableFuture<Itinerary> getItinerary(ItineraryCreation itineraryCreation) {
73+
if (itineraryCreation == null) {
74+
throw new IllegalStateException("ItineraryCreation is null");
3075
}
3176

32-
@Override
33-
public void run() {
34-
35-
logger.info("Running Book Single Room Scenario using the default profile in asynchronous manner...");
36-
37-
// Shopping for properties
38-
logger.info("Async call - Getting property availability for test property: {}", Constants.TEST_PROPERTY_ID);
39-
40-
shopService.asyncGetSingleRoomPropertiesAvailability(this.rapidPartnerSalesProfile)
41-
.thenApply(Response::getData)
42-
.thenCompose(this::checkRoomPrices)
43-
.thenCompose(this::bookRoom)
44-
.thenCompose(this::getItinerary)
45-
.thenAccept(itinerary -> {
46-
if (itinerary == null) {
47-
throw new IllegalStateException("Itinerary is null");
48-
}
49-
logger.info("Itinerary: {}", itinerary.getItineraryId());
50-
});
51-
77+
logger.info("Booking Success. Itinerary id: {}", itineraryCreation.getItineraryId());
78+
79+
// Manage booking
80+
logger.info("Getting itinerary by itinerary id...");
81+
BookService bookService = new BookService();
82+
return bookService.asyncGetReservation(itineraryCreation)
83+
.thenApply(response -> response.getData());
84+
}
85+
86+
/**
87+
* Books a room based on the room price check.
88+
*
89+
* @param roomPriceCheck the room price check details
90+
* @return a CompletableFuture with the itinerary creation details
91+
*/
92+
private CompletableFuture<ItineraryCreation> bookRoom(RoomPriceCheck roomPriceCheck) {
93+
if (roomPriceCheck == null) {
94+
throw new IllegalStateException("Room Price Check is null");
5295
}
5396

54-
private CompletableFuture<Itinerary> getItinerary(ItineraryCreation itineraryCreation) {
55-
if (itineraryCreation == null) {
56-
throw new IllegalStateException("ItineraryCreation is null");
57-
}
58-
59-
logger.info("Booking Success. Itinerary id: {}", itineraryCreation.getItineraryId());
60-
61-
// Manage booking
62-
logger.info("Getting itinerary by itinerary id...");
63-
BookService bookService = new BookService();
64-
return bookService.asyncGetReservation(itineraryCreation)
65-
.thenApply(response -> response.getData());
97+
logger.info("Room Price Check: {}", roomPriceCheck.getStatus());
98+
99+
// Booking a single room in the property
100+
logger.info("Booking a room in test property: {}...", Constants.TEST_PROPERTY_ID);
101+
102+
BookService bookService = new BookService();
103+
return bookService.asyncCreateBooking(roomPriceCheck, Arrays.asList("2"))
104+
.thenApply(response -> response.getData());
105+
}
106+
107+
/**
108+
* Checks the room prices for the available properties.
109+
*
110+
* @param propertyAvailabilityList the list of available properties
111+
* @return a CompletableFuture with the room price check details
112+
*/
113+
private CompletableFuture<RoomPriceCheck> checkRoomPrices(
114+
List<Property> propertyAvailabilityList) {
115+
if (propertyAvailabilityList == null || propertyAvailabilityList.isEmpty()) {
116+
throw new IllegalStateException("No property availability found for the test property.");
66117
}
67118

68-
private CompletableFuture<ItineraryCreation> bookRoom(RoomPriceCheck roomPriceCheck) {
69-
if (roomPriceCheck == null) {
70-
throw new IllegalStateException("Room Price Check is null");
71-
}
72-
73-
logger.info("Room Price Check: {}", roomPriceCheck.getStatus());
119+
logger.info("Property Availability: {}", propertyAvailabilityList.get(0).getStatus());
74120

75-
// Booking a single room in the property
76-
logger.info("Booking a room in test property: {}...", Constants.TEST_PROPERTY_ID);
121+
// Checking room prices for the property
122+
logger.info("Checking room prices for the property: {}...", Constants.TEST_PROPERTY_ID);
123+
Property property = propertyAvailabilityList.get(0);
77124

78-
BookService bookService = new BookService();
79-
return bookService.asyncCreateBooking(roomPriceCheck, Arrays.asList("2"))
80-
.thenApply(response -> response.getData());
125+
if (!(property instanceof PropertyAvailability)) {
126+
throw new IllegalStateException("Property is not an instance of PropertyAvailability");
81127
}
82128

83-
private CompletableFuture<RoomPriceCheck> checkRoomPrices(List<Property> propertyAvailabilityList) {
84-
if (propertyAvailabilityList == null || propertyAvailabilityList.isEmpty()) {
85-
throw new IllegalStateException("No property availability found for the test property.");
86-
}
129+
PropertyAvailability propertyAvailability = (PropertyAvailability) property;
130+
return shopService.asyncCheckRoomPrices(propertyAvailability, 0, 0)
131+
.thenApply(response -> response.getData());
87132

88-
logger.info("Property Availability: {}", propertyAvailabilityList.get(0).getStatus());
89-
90-
// Checking room prices for the property
91-
logger.info("Checking room prices for the property: {}...", Constants.TEST_PROPERTY_ID);
92-
Property property = propertyAvailabilityList.get(0);
93-
94-
if (!(property instanceof PropertyAvailability)) {
95-
throw new IllegalStateException("Property is not an instance of PropertyAvailability");
96-
}
97-
98-
PropertyAvailability propertyAvailability = (PropertyAvailability) property;
99-
return shopService.asyncCheckRoomPrices(propertyAvailability, 0, 0)
100-
.thenApply(response -> response.getData());
101-
102-
}
133+
}
103134
}

0 commit comments

Comments
 (0)