Skip to content

Commit

Permalink
chore: add PR check to verify examples
Browse files Browse the repository at this point in the history
  • Loading branch information
anssari1 committed Dec 17, 2024
1 parent 68364cc commit 1d6b8bf
Show file tree
Hide file tree
Showing 30 changed files with 2,202 additions and 1,444 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/verify-examples.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Verify Examples
on:
pull_request:
branches:
- 'main'
jobs:
detect-changes:
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
examples: ${{ steps.filter.outputs.examples }}
steps:
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
examples:
- 'examples/**'
verify-examples:
needs: detect-changes
if: ${{ needs.detect-changes.outputs.examples == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
- name: verify examples
working-directory: examples
run: mvn clean install
17 changes: 17 additions & 0 deletions examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.5.0</version>
<configuration>
<configLocation>google_checks.xml</configLocation>
<consoleOutput>true</consoleOutput>
<violationSeverity>warning</violationSeverity>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package com.expediagroup.sdk.rapid.examples;

/**
* Constants used throughout the application.
*/
public class Constants {
public static final String TEST_PROPERTY_ID = "11775754";
public static final String TEST_PROPERTY_ID = "11775754";

public static final String TEST_REGION_ID = "178248";
public static final String TEST_REGION_ID = "178248";

public static final String TEST_REGION_ID_WITH_MULTIPOLYGON = "553248635740541470";
public static final String TEST_REGION_ID_WITH_MULTIPOLYGON = "553248635740541470";

public static final String TEST_ANCESTOR_ID = "602962";
public static final String TEST_ANCESTOR_ID = "602962";

public static final String CUSTOMER_IP = "5.5.5.5";
public static final String CUSTOMER_IP = "5.5.5.5";

public static final String SANDBOX_URL = "https://test.ean.com/";
public static final String SANDBOX_URL = "https://test.ean.com/";

public static final String CUSTOMER_SESSION_ID = "123455656565";
public static final String CUSTOMER_SESSION_ID = "123455656565";
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.expediagroup.sdk.rapid.examples.salesprofiles;


/**
* Default Rapid Partner Profile.
*/
public final class DefaultRapidPartnerProfile extends RapidPartnerSalesProfile {

public DefaultRapidPartnerProfile() {
this.billingTerms = null;
this.paymentTerms = null;
this.partnerPointOfSale = null;
this.platformName = null;
}
/**
* Default constructor.
*/
public DefaultRapidPartnerProfile() {
this.billingTerms = null;
this.paymentTerms = null;
this.partnerPointOfSale = null;
this.platformName = null;
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.expediagroup.sdk.rapid.examples.salesprofiles;


/**
* Rapid Partner Sales Profile.
*/
public abstract class RapidPartnerSalesProfile {

public String billingTerms;
public String billingTerms;

public String paymentTerms;
public String paymentTerms;

public String partnerPointOfSale;
public String partnerPointOfSale;

public String platformName;
public String platformName;

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
package com.expediagroup.sdk.rapid.examples.scenarios;

import com.expediagroup.sdk.rapid.examples.salesprofiles.RapidPartnerSalesProfile;

import java.util.concurrent.ExecutionException;

/**
* Interface representing a scenario to be executed with a specific sales profile.
*/
public interface RapidScenario {

void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile);
/**
* Sets the sales profile for the scenario.
*
* @param rapidPartnerSalesProfile the sales profile to be set
*/
void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile);

void run() throws ExecutionException, InterruptedException;
/**
* Executes the scenario.
*
* @throws ExecutionException if an error occurs during execution
* @throws InterruptedException if the execution is interrupted
*/
void run() throws ExecutionException, InterruptedException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,93 +11,124 @@
import com.expediagroup.sdk.rapid.models.Property;
import com.expediagroup.sdk.rapid.models.PropertyAvailability;
import com.expediagroup.sdk.rapid.models.RoomPriceCheck;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Scenario for booking a single room asynchronously.
*/
public class AsyncSingleRoomBookScenario implements RapidScenario {

private static final Logger logger = LoggerFactory.getLogger(AsyncSingleRoomBookScenario.class);
private ShopService shopService = new ShopService();
private RapidPartnerSalesProfile rapidPartnerSalesProfile;

@Override
public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) {
this.rapidPartnerSalesProfile = rapidPartnerSalesProfile;
private static final Logger logger = LoggerFactory.getLogger(AsyncSingleRoomBookScenario.class);
private ShopService shopService = new ShopService();
private RapidPartnerSalesProfile rapidPartnerSalesProfile;

/**
* Sets the sales profile for the scenario.
*
* @param rapidPartnerSalesProfile the sales profile to set
*/
@Override
public void setProfile(RapidPartnerSalesProfile rapidPartnerSalesProfile) {
this.rapidPartnerSalesProfile = rapidPartnerSalesProfile;
}

/**
* Runs the scenario to book a single room asynchronously.
*/
@Override
public void run() {

logger.info(
"Running Book Single Room Scenario using the default profile in asynchronous manner...");

// Shopping for properties
logger.info("Async call - Getting property availability for test property: {}",
Constants.TEST_PROPERTY_ID);

shopService.asyncGetSingleRoomPropertiesAvailability(this.rapidPartnerSalesProfile)
.thenApply(Response::getData)
.thenCompose(this::checkRoomPrices)
.thenCompose(this::bookRoom)
.thenCompose(this::getItinerary)
.thenAccept(itinerary -> {
if (itinerary == null) {
throw new IllegalStateException("Itinerary is null");
}
logger.info("Itinerary: {}", itinerary.getItineraryId());
});

}

/**
* Retrieves the itinerary for the booking.
*
* @param itineraryCreation the itinerary creation details
* @return a CompletableFuture with the itinerary
*/
private CompletableFuture<Itinerary> getItinerary(ItineraryCreation itineraryCreation) {
if (itineraryCreation == null) {
throw new IllegalStateException("ItineraryCreation is null");
}

@Override
public void run() {

logger.info("Running Book Single Room Scenario using the default profile in asynchronous manner...");

// Shopping for properties
logger.info("Async call - Getting property availability for test property: {}", Constants.TEST_PROPERTY_ID);

shopService.asyncGetSingleRoomPropertiesAvailability(this.rapidPartnerSalesProfile)
.thenApply(Response::getData)
.thenCompose(this::checkRoomPrices)
.thenCompose(this::bookRoom)
.thenCompose(this::getItinerary)
.thenAccept(itinerary -> {
if (itinerary == null) {
throw new IllegalStateException("Itinerary is null");
}
logger.info("Itinerary: {}", itinerary.getItineraryId());
});

logger.info("Booking Success. Itinerary id: {}", itineraryCreation.getItineraryId());

// Manage booking
logger.info("Getting itinerary by itinerary id...");
BookService bookService = new BookService();
return bookService.asyncGetReservation(itineraryCreation)
.thenApply(response -> response.getData());
}

/**
* Books a room based on the room price check.
*
* @param roomPriceCheck the room price check details
* @return a CompletableFuture with the itinerary creation details
*/
private CompletableFuture<ItineraryCreation> bookRoom(RoomPriceCheck roomPriceCheck) {
if (roomPriceCheck == null) {
throw new IllegalStateException("Room Price Check is null");
}

private CompletableFuture<Itinerary> getItinerary(ItineraryCreation itineraryCreation) {
if (itineraryCreation == null) {
throw new IllegalStateException("ItineraryCreation is null");
}

logger.info("Booking Success. Itinerary id: {}", itineraryCreation.getItineraryId());

// Manage booking
logger.info("Getting itinerary by itinerary id...");
BookService bookService = new BookService();
return bookService.asyncGetReservation(itineraryCreation)
.thenApply(response -> response.getData());
logger.info("Room Price Check: {}", roomPriceCheck.getStatus());

// Booking a single room in the property
logger.info("Booking a room in test property: {}...", Constants.TEST_PROPERTY_ID);

BookService bookService = new BookService();
return bookService.asyncCreateBooking(roomPriceCheck, Arrays.asList("2"))
.thenApply(response -> response.getData());
}

/**
* Checks the room prices for the available properties.
*
* @param propertyAvailabilityList the list of available properties
* @return a CompletableFuture with the room price check details
*/
private CompletableFuture<RoomPriceCheck> checkRoomPrices(
List<Property> propertyAvailabilityList) {
if (propertyAvailabilityList == null || propertyAvailabilityList.isEmpty()) {
throw new IllegalStateException("No property availability found for the test property.");
}

private CompletableFuture<ItineraryCreation> bookRoom(RoomPriceCheck roomPriceCheck) {
if (roomPriceCheck == null) {
throw new IllegalStateException("Room Price Check is null");
}

logger.info("Room Price Check: {}", roomPriceCheck.getStatus());
logger.info("Property Availability: {}", propertyAvailabilityList.get(0).getStatus());

// Booking a single room in the property
logger.info("Booking a room in test property: {}...", Constants.TEST_PROPERTY_ID);
// Checking room prices for the property
logger.info("Checking room prices for the property: {}...", Constants.TEST_PROPERTY_ID);
Property property = propertyAvailabilityList.get(0);

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

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

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

// Checking room prices for the property
logger.info("Checking room prices for the property: {}...", Constants.TEST_PROPERTY_ID);
Property property = propertyAvailabilityList.get(0);

if (!(property instanceof PropertyAvailability)) {
throw new IllegalStateException("Property is not an instance of PropertyAvailability");
}

PropertyAvailability propertyAvailability = (PropertyAvailability) property;
return shopService.asyncCheckRoomPrices(propertyAvailability, 0, 0)
.thenApply(response -> response.getData());

}
}
}
Loading

0 comments on commit 1d6b8bf

Please sign in to comment.