AirTSP Logo  1.01.2
C++ Simulated Airline Travel Solution Provider (TSP) Library
AirlineScheduleTestSuite.cpp
Go to the documentation of this file.
1 
5 // //////////////////////////////////////////////////////////////////////
6 // Import section
7 // //////////////////////////////////////////////////////////////////////
8 // STL
9 #include <sstream>
10 #include <fstream>
11 #include <string>
12 // Boost Unit Test Framework (UTF)
13 #define BOOST_TEST_DYN_LINK
14 #define BOOST_TEST_MAIN
15 #define BOOST_TEST_MODULE InventoryTestSuite
16 #include <boost/test/unit_test.hpp>
17 #include <boost/version.hpp>
18 // Boost Date-Time
19 #include <boost/date_time/gregorian/gregorian.hpp>
20 // StdAir
21 #include <stdair/basic/BasFileMgr.hpp>
22 #include <stdair/basic/BasLogParams.hpp>
23 #include <stdair/basic/BasDBParams.hpp>
24 #include <stdair/basic/BasFileMgr.hpp>
25 #include <stdair/bom/TravelSolutionStruct.hpp>
26 #include <stdair/bom/BookingRequestStruct.hpp>
27 #include <stdair/service/Logger.hpp>
28 // AirTSP
29 #include <airtsp/AIRTSP_Types.hpp>
31 #include <airtsp/config/airtsp-paths.hpp>
32 
33 namespace boost_utf = boost::unit_test;
34 
35 // (Boost) Unit Test XML Report
36 std::ofstream utfReportStream ("AirlineScheduleTestSuite_utfresults.xml");
37 
41 struct UnitTestConfig {
43  UnitTestConfig() {
44  boost_utf::unit_test_log.set_stream (utfReportStream);
45 #if BOOST_VERSION >= 105900
46  boost_utf::unit_test_log.set_format (boost_utf::OF_XML);
47 #else
48  boost_utf::unit_test_log.set_format (boost_utf::XML);
49 #endif
50  boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
51  //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
52  }
53 
55  ~UnitTestConfig() {
56  }
57 };
58 
59 // //////////////////////////////////////////////////////////////////////
63  const unsigned int testScheduleHelper (const unsigned short iTestFlag,
64  const stdair::Filename_T& iScheduleInputFilename,
65  const stdair::Filename_T& iODInputFilename,
66  const bool isBuiltin,
67  const bool isWithOnD) {
68 
69  // Output log File
70  std::ostringstream oStr;
71  oStr << "AirlineScheduleTestSuite_" << iTestFlag << ".log";
72  const stdair::Filename_T lLogFilename (oStr.str());
73 
74  // Set the log parameters
75  std::ofstream logOutputFile;
76  // Open and clean the log outputfile
77  logOutputFile.open (lLogFilename.c_str());
78  logOutputFile.clear();
79 
80  // Instantiate the AirTSP service
81  const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
82  AIRTSP::AIRTSP_Service airtspService (lLogParams);
83 
84  stdair::AirportCode_T lOrigin;
85  stdair::AirportCode_T lDestination;
86  stdair::AirportCode_T lPOS;
87  stdair::Date_T lPreferredDepartureDate;;
88  stdair::Date_T lRequestDate;
89 
90  // Check wether or not a (CSV) input file should be read
91  if (isBuiltin == true) {
92 
93  // Build the default sample BOM tree (filled with schedules)
94  airtspService.buildSampleBom();
95 
96  lOrigin = "SIN";
97  lDestination = "BKK";
98  lPOS = "SIN";
99  lPreferredDepartureDate = boost::gregorian::from_string ("2010/02/08");
100  lRequestDate = boost::gregorian::from_string ("2010/01/21");
101 
102  } else {
103 
104  if (isWithOnD == false) {
105 
106  // Build the BOM tree from parsing input files
107  const stdair::ScheduleFilePath lScheduleFilePath (iScheduleInputFilename);
108  airtspService.parseAndLoad (lScheduleFilePath);
109 
110  lOrigin = "NCE";
111  lDestination = "BKK";
112  lPOS = "NCE";
113  lPreferredDepartureDate = boost::gregorian::from_string ("2007/04/21");
114  lRequestDate = boost::gregorian::from_string ("2007/03/21");
115 
116  } else {
117 
118  // Build the BOM tree from parsing input files
119  const stdair::ScheduleFilePath lScheduleFilePath (iScheduleInputFilename);
120  const stdair::ODFilePath lODFilePath (iODInputFilename);
121  airtspService.parseAndLoad (lScheduleFilePath,
122  lODFilePath);
123 
124  lOrigin = "SIN";
125  lDestination = "BKK";
126  lPOS = "SIN";
127  lPreferredDepartureDate = boost::gregorian::from_string ("2012/06/04");
128  lRequestDate = boost::gregorian::from_string ("2012/01/01");
129  }
130 
131  }
132 
133  // Create a booking request structure
134  const stdair::Duration_T lRequestTime (boost::posix_time::hours(8));
135  const stdair::DateTime_T lRequestDateTime (lRequestDate, lRequestTime);
136  const stdair::CabinCode_T lPreferredCabin ("Bus");
137  const stdair::PartySize_T lPartySize (3);
138  const stdair::ChannelLabel_T lChannel ("DF");
139  const stdair::TripType_T lTripType ("RO");
140  const stdair::DayDuration_T lStayDuration (5);
141  const stdair::FrequentFlyer_T lFrequentFlyerType ("NONE");
142  const stdair::Duration_T lPreferredDepartureTime (boost::posix_time::hours(10));
143  const stdair::WTP_T lWTP (2000.0);
144  const stdair::PriceValue_T lValueOfTime (20.0);
145  const stdair::ChangeFees_T lChangeFees (true);
146  const stdair::Disutility_T lChangeFeeDisutility (50);
147  const stdair::NonRefundable_T lNonRefundable (true);
148  const stdair::Disutility_T lNonRefundableDisutility (50);
149 
150  const stdair::BookingRequestStruct lBookingRequest (lOrigin, lDestination,
151  lPOS,
152  lPreferredDepartureDate,
153  lRequestDateTime,
154  lPreferredCabin,
155  lPartySize, lChannel,
156  lTripType, lStayDuration,
157  lFrequentFlyerType,
158  lPreferredDepartureTime,
159  lWTP, lValueOfTime,
160  lChangeFees,
161  lChangeFeeDisutility,
162  lNonRefundable,
163  lNonRefundableDisutility);
164 
165  // Build the segment path list
166  stdair::TravelSolutionList_T lTravelSolutionList;
167  airtspService.buildSegmentPathList (lTravelSolutionList, lBookingRequest);
168  const unsigned int lNbOfTravelSolutions = lTravelSolutionList.size();
169 
170  STDAIR_LOG_DEBUG ("The number of travel solutions for the booking request '"
171  << lBookingRequest.describe() << "' is equal to "
172  << lNbOfTravelSolutions << ".");
173 
174  // Close the Log outputFile
175  logOutputFile.close();
176 
177  return lNbOfTravelSolutions;
178 }
179 
180 
181 // /////////////// Main: Unit Test Suite //////////////
182 
183 // Set the UTF configuration (re-direct the output to a specific file)
184 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
185 
186 // Start the test suite
187 BOOST_AUTO_TEST_SUITE (master_test_suite)
188 
189 
192 BOOST_AUTO_TEST_CASE (airtsp_simple_build) {
193 
194  // Input file name
195  const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
196  "/schedule03.csv");
197 
198  // State whether the BOM tree should be built-in or parsed from input files
199  const bool isBuiltin = false;
200  const bool isWithOnD = false;
201 
202  // Try to build a travel solution list
203  unsigned int lNbOfTravelSolutions = 0;
204  BOOST_CHECK_NO_THROW (lNbOfTravelSolutions =
205  testScheduleHelper (0, lScheduleInputFilename, " ",
206  isBuiltin, isWithOnD));
207 
208  // Check the size of the travel solution list
209  const unsigned int lExpectedNbOfTravelSolutions = 4;
210  BOOST_CHECK_MESSAGE(lNbOfTravelSolutions == lExpectedNbOfTravelSolutions,
211  "The number of travel solutions is "
212  << lNbOfTravelSolutions << ", but it should be equal to "
213  << lExpectedNbOfTravelSolutions);
214 
215 }
216 
220 BOOST_AUTO_TEST_CASE (airtsp_default_bom_tree_simple_build) {
221 
222  // State whether the BOM tree should be built-in or parsed from input files
223  const bool isBuiltin = true;
224  const bool isWithOnD = false;
225 
226  // Try to build a travel solution list
227  unsigned int lNbOfTravelSolutions = 0;
228  BOOST_CHECK_NO_THROW (lNbOfTravelSolutions =
229  testScheduleHelper (1, " ", " ", isBuiltin, isWithOnD));
230 
231  // Check the size of the travel solution list
232  const unsigned int lExpectedNbOfTravelSolutions = 1;
233  BOOST_CHECK_MESSAGE(lNbOfTravelSolutions == lExpectedNbOfTravelSolutions,
234  "The number of travel solutions is "
235  << lNbOfTravelSolutions << ", but it should be equal to "
236  << lExpectedNbOfTravelSolutions);
237 
238 }
239 
243 BOOST_AUTO_TEST_CASE (airtsp_OnD_input_file) {
244 
245  // Input file names
246  const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
247  "/rds01/schedule05.csv");
248  const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
249  "/ond01.csv");
250 
251  // State whether the BOM tree should be built-in or parsed from input files
252  const bool isBuiltin = false;
253  const bool isWithOnD = true;
254 
255  // Try to build a travel solution list
256  unsigned int lNbOfTravelSolutions = 0;
257  BOOST_CHECK_NO_THROW (lNbOfTravelSolutions =
258  testScheduleHelper (2, lScheduleInputFilename,
259  lODInputFilename,
260  isBuiltin, isWithOnD));
261 
262  // Check the size of the travel solution list
263  const unsigned int lExpectedNbOfTravelSolutions = 1;
264  BOOST_CHECK_MESSAGE(lNbOfTravelSolutions == lExpectedNbOfTravelSolutions,
265  "The number of travel solutions is "
266  << lNbOfTravelSolutions << ", but it should be equal to "
267  << lExpectedNbOfTravelSolutions);
268 }
269 
273 BOOST_AUTO_TEST_CASE (airtsp_missing_OnD_input_file) {
274 
275  // Input file names
276  const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
277  "/schedule03.csv");
278  const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
279  "/missingFiles.csv");
280 
281  // State whether the BOM tree should be built-in or parsed from input files
282  const bool isBuiltin = false;
283  const bool isWithOnD = true;
284 
285  // Try to build a travel solution list
286  BOOST_CHECK_THROW (testScheduleHelper (3, lScheduleInputFilename,
287  lODInputFilename,
288  isBuiltin, isWithOnD),
290 }
291 
295 BOOST_AUTO_TEST_CASE (airtsp_missing_schedule_input_file) {
296 
297  // Input file name
298  const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
299  "/missingFiles.csv");
300 
301  // State whether the BOM tree should be built-in or parsed from input files
302  const bool isBuiltin = false;
303  const bool isWithOnD = false;
304 
305  // Try to build a travel solution list
306  BOOST_CHECK_THROW (testScheduleHelper (4, lScheduleInputFilename, " ",
307  isBuiltin, isWithOnD),
309 
310 }
311 
315 BOOST_AUTO_TEST_CASE (airtsp_segment_date_not_found) {
316 
317  // Input file name
318  const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
319  "/scheduleError03.csv");
320 
321  // State whether the BOM tree should be built-in or parsed from input files
322  const bool isBuiltin = false;
323  const bool isWithOnD = false;
324 
325  // Try to build a travel solution list
326  BOOST_CHECK_THROW (testScheduleHelper (5, lScheduleInputFilename,
327  " " ,
328  isBuiltin, isWithOnD),
330 
331 
332 }
333 
334 
335 // End the test suite
336 BOOST_AUTO_TEST_SUITE_END()
337 
338 
Interface for the Airtsp Services.