Skip to content

Commit 1768611

Browse files
author
reejoseph
committed
test(flight-details): validate Flight Details SDK
1 parent d77dd78 commit 1768611

File tree

1 file changed

+260
-0
lines changed

1 file changed

+260
-0
lines changed
Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
/*
2+
* Copyright (C) 2025 Expedia, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.expediagroup.sdk.xap.examples.scenarios.flight;
18+
19+
import com.expediagroup.sdk.xap.client.XapClient;
20+
import com.expediagroup.sdk.xap.examples.scenarios.XapScenario;
21+
import com.expediagroup.sdk.xap.models.FlightDetailsResponse;
22+
import com.expediagroup.sdk.xap.operations.GetFlightDetailsOperation;
23+
import com.expediagroup.sdk.xap.operations.GetFlightDetailsOperationParams;
24+
import java.time.LocalDate;
25+
import java.util.Arrays;
26+
import org.slf4j.Logger;
27+
import org.slf4j.LoggerFactory;
28+
29+
/**
30+
* This example demonstrates how to make Details API Call to get extended information about
31+
* fare, charges, fees, other terms associated with booking an airline ticket.
32+
*/
33+
34+
public class FlightDetailsExample implements XapScenario {
35+
36+
private static final Logger LOGGER =
37+
LoggerFactory.getLogger(FlightDetailsExample.class);
38+
39+
40+
public static void main(String[] args) {
41+
new FlightDetailsExample().run();
42+
System.exit(0);
43+
}
44+
45+
@Override
46+
public void run() {
47+
LOGGER.info(
48+
"========= Running FlightDetailsQuickStartScenario =============");
49+
50+
LOGGER.info(
51+
"============= Executing GetFlightDetailsOperation =========");
52+
53+
GetFlightDetailsOperationParams detailsOperationParams = GetFlightDetailsOperationParams
54+
.builder()
55+
.offerToken("v5-sos-f7f6baebb159423791c2583b1dfd22b7-14-1~8.S~AQoECL"
56+
+ "-kBBIICNQEEAEYwB8oAlgBcAB6BXNhYnJliAHczsZQqgEHCgNMQVgQALIBB"
57+
+ "woDU0VBEAA~AQotCisIwaYBEgQxMzA1GIu4ASCSASiUuPoCML25-gI4T0AA"
58+
+ "WAFyCE9IMk9YVU1OEgoIARABGAEqAkFTGAEiBAgBEAEoAigDKAQwAg")
59+
.partnerTransactionID("txn-123-4")
60+
.price("123.31")
61+
.locale("en_US")
62+
.build();
63+
XapClient xapClient = createClient();
64+
65+
FlightDetailsResponse flightDetailsResponse =
66+
xapClient.execute(new GetFlightDetailsOperation(detailsOperationParams))
67+
.getData();
68+
69+
LOGGER.info("========= GetFlightDetailsOperation Executed ========");
70+
71+
LOGGER.info("Transaction ID: {}", flightDetailsResponse.getTransactionId());
72+
73+
if (flightDetailsResponse.getSegments() != null) {
74+
flightDetailsResponse.getSegments().forEach(segment -> {
75+
LOGGER.info("======================== Flight Segment Start ========================");
76+
LOGGER.info("Segment ID: {}", segment.getSegmentId());
77+
LOGGER.info("Flight Duration: {}", segment.getFlightDuration());
78+
LOGGER.info("Total Stops: {}", segment.getTotalStops());
79+
LOGGER.info("Departure Arrival Day Difference: {}",
80+
segment.getDepartureArrivalDayDifference());
81+
LOGGER.info("Fare Type: {}", segment.getFareType());
82+
LOGGER.info("Airport Change: {}", segment.getAirportChange());
83+
84+
if (segment.getLegs() != null) {
85+
segment.getLegs().forEach(leg -> {
86+
LOGGER.info("-------------------- Leg Start --------------------");
87+
88+
if (leg.getDepartureAirport() != null) {
89+
LOGGER.info("Departure Airport Code: {}",
90+
leg.getDepartureAirport().getCode());
91+
}
92+
93+
if (leg.getArrivalAirport() != null) {
94+
LOGGER.info("Arrival Airport Code: {}",
95+
leg.getArrivalAirport().getCode());
96+
}
97+
LOGGER.info("Departure Date Time: {}",
98+
leg.getDepartureDateTime());
99+
LOGGER.info("Arrival Date Time: {}",
100+
leg.getArrivalDateTime());
101+
LOGGER.info("Flight Number: {}",
102+
leg.getFlightNumber());
103+
LOGGER.info("Marketing Airline Code: {}",
104+
leg.getMarketingAirlineCode());
105+
LOGGER.info("Marketing Airline Name: {}",
106+
leg.getMarketingAirlineName());
107+
LOGGER.info("Equipment Code: {}",
108+
leg.getEquipmentCode());
109+
LOGGER.info("Flight On Time Percentage: {}",
110+
leg.getFlightOnTimePercentage());
111+
LOGGER.info("Equipment Name: {}",
112+
leg.getEquipmentName());
113+
LOGGER.info("Flight Duration (Leg): {}",
114+
leg.getFlightDuration());
115+
116+
if (leg.getFlightDistance() != null) {
117+
LOGGER.info("Flight Distance Value: {}",
118+
leg.getFlightDistance().getValue());
119+
LOGGER.info("Flight Distance Unit: {}",
120+
leg.getFlightDistance().getUnit());
121+
}
122+
LOGGER.info("Booking Code: {}",
123+
leg.getBookingCode());
124+
LOGGER.info("Cabin Class: {}",
125+
leg.getCabinClass());
126+
LOGGER.info("Fare Basis Code: {}",
127+
leg.getFareBasisCode());
128+
LOGGER.info("Meal Options: {}",
129+
leg.getMealOptions());
130+
LOGGER.info("Amenities: {}",
131+
leg.getAmenities());
132+
LOGGER.info("---------- Leg End ----------");
133+
});
134+
}
135+
LOGGER.info("=========== Flight Segment End ============");
136+
});
137+
}
138+
139+
if (flightDetailsResponse.getOffer() != null) {
140+
LOGGER.info("======================== Flight Offer Start ========================");
141+
142+
if (flightDetailsResponse.getOffer().getLinks() != null) {
143+
flightDetailsResponse.getOffer().getLinks().forEach((key, value) ->
144+
LOGGER.info("Link [{}]: {}", key, value));
145+
}
146+
147+
LOGGER.info("Segment IDs: {}", flightDetailsResponse.getOffer().getSegmentIds());
148+
LOGGER.info("Refundable: {}", flightDetailsResponse.getOffer().getRefundable());
149+
LOGGER.info("International: {}", flightDetailsResponse.getOffer().getInternational());
150+
LOGGER.info("UndisclosedGenderSupported: {}",
151+
flightDetailsResponse.getOffer().getUndisclosedGenderSupported());
152+
LOGGER.info("UnspecifiedGenderSupported: {}",
153+
flightDetailsResponse.getOffer().getUnspecifiedGenderSupported());
154+
155+
if (flightDetailsResponse.getOffer().getOfferPrice() != null) {
156+
157+
if (flightDetailsResponse.getOffer().getOfferPrice().getTotalPrice() != null) {
158+
LOGGER.info("Total Price Value: {}",
159+
flightDetailsResponse.getOffer().getOfferPrice().getTotalPrice().getValue());
160+
LOGGER.info("Total Price Currency: {}",
161+
flightDetailsResponse.getOffer().getOfferPrice().getTotalPrice().getCurrency());
162+
}
163+
164+
if (flightDetailsResponse.getOffer().getOfferPrice().getBasePrice() != null) {
165+
LOGGER.info("Base Price Value: {}",
166+
flightDetailsResponse.getOffer().getOfferPrice().getBasePrice().getValue());
167+
LOGGER.info("Base Price Currency: {}",
168+
flightDetailsResponse.getOffer().getOfferPrice().getBasePrice().getCurrency());
169+
}
170+
171+
if (flightDetailsResponse.getOffer().getOfferPrice().getTotalTaxes() != null) {
172+
LOGGER.info("Total Taxes Value: {}",
173+
flightDetailsResponse.getOffer().getOfferPrice().getTotalTaxes().getValue());
174+
LOGGER.info("Total Taxes Currency: {}",
175+
flightDetailsResponse.getOffer().getOfferPrice().getTotalTaxes().getCurrency());
176+
}
177+
178+
if (flightDetailsResponse.getOffer().getOfferPrice().getTotalTaxesAndFees() != null) {
179+
LOGGER.info("Total Taxes and Fees Value: {}",
180+
flightDetailsResponse.getOffer()
181+
.getOfferPrice().getTotalTaxesAndFees().getValue());
182+
LOGGER.info("Total Taxes and Fees Currency: {}",
183+
flightDetailsResponse.getOffer()
184+
.getOfferPrice().getTotalTaxesAndFees().getCurrency());
185+
}
186+
187+
if (flightDetailsResponse.getOffer().getOfferPrice().getAveragePricePerTicket() != null) {
188+
LOGGER.info("Average Price Per Ticket Value: {}",
189+
flightDetailsResponse.getOffer()
190+
.getOfferPrice().getAveragePricePerTicket().getValue());
191+
LOGGER.info("Average Price Per Ticket Currency: {}",
192+
flightDetailsResponse.getOffer()
193+
.getOfferPrice().getAveragePricePerTicket().getCurrency());
194+
LOGGER.info("Average Price Per Ticket Count: {}",
195+
flightDetailsResponse.getOffer()
196+
.getOfferPrice().getAveragePricePerTicket().getCount());
197+
}
198+
199+
if (flightDetailsResponse.getOffer()
200+
.getOfferPrice().getPricePerPassengerCategory() != null) {
201+
flightDetailsResponse.getOffer().getOfferPrice().getPricePerPassengerCategory()
202+
.forEach(categoryPrice -> {
203+
LOGGER.info("---- Passenger Category Price Start ----");
204+
LOGGER.info("Category: {}", categoryPrice.getCategory());
205+
LOGGER.info("Count: {}", categoryPrice.getCount());
206+
207+
if (categoryPrice.getTotalPrice() != null) {
208+
LOGGER.info("Total Price Value: {}",
209+
categoryPrice.getTotalPrice().getValue());
210+
LOGGER.info("Total Price Currency: {}",
211+
categoryPrice.getTotalPrice().getCurrency());
212+
}
213+
214+
if (categoryPrice.getBasePrice() != null) {
215+
LOGGER.info("Base Price Value: {}",
216+
categoryPrice.getBasePrice().getValue());
217+
LOGGER.info("Base Price Currency: {}",
218+
categoryPrice.getBasePrice().getCurrency());
219+
}
220+
221+
if (categoryPrice.getTotalTaxes() != null) {
222+
LOGGER.info("Total Taxes Value: {}",
223+
categoryPrice.getTotalTaxes().getValue());
224+
LOGGER.info("Total Taxes Currency: {}",
225+
categoryPrice.getTotalTaxes().getCurrency());
226+
}
227+
LOGGER.info("---- Passenger Category Price End ----");
228+
});
229+
}
230+
}
231+
232+
233+
LOGGER.info("Ticket Type: {}", flightDetailsResponse.getOffer().getTicketType());
234+
LOGGER.info("======================== Flight Offer End ========================");
235+
}
236+
237+
if (flightDetailsResponse.getValidFormsOfPayment() != null) {
238+
flightDetailsResponse.getValidFormsOfPayment().forEach((value) -> {
239+
LOGGER.info("========== Valid Forms of Payment End [{}] ============");
240+
LOGGER.info("---- Payment Method Start ----");
241+
LOGGER.info("Payment Method: {}", value.getPaymentMethod());
242+
LOGGER.info("Name: {}", value.getName());
243+
LOGGER.info("Fee: {}", value.getFee());
244+
LOGGER.info("Currency: {}", value.getCurrency());
245+
LOGGER.info("---- Payment Method End ----");
246+
LOGGER.info("========== Valid Forms of Payment End [{}] ============");
247+
});
248+
}
249+
250+
LOGGER.info(
251+
"===================== End FlightListingsQuickStartScenario ====================");
252+
}
253+
254+
}
255+
256+
257+
258+
259+
260+

0 commit comments

Comments
 (0)