AirInv Logo  1.00.1
C++ Simulated Airline Inventory Management System library
InventoryTestSuite.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 // StdAir
19 #include <stdair/basic/BasLogParams.hpp>
20 #include <stdair/basic/BasDBParams.hpp>
21 #include <stdair/basic/BasFileMgr.hpp>
22 #include <stdair/bom/TravelSolutionStruct.hpp>
23 #include <stdair/bom/BookingRequestStruct.hpp>
24 #include <stdair/service/Logger.hpp>
25 #include <stdair/stdair_exceptions.hpp>
26 // Airinv
27 #include <airinv/AIRINV_Types.hpp>
30 
31 namespace boost_utf = boost::unit_test;
32 
33 // (Boost) Unit Test XML Report
34 std::ofstream utfReportStream ("InventoryTestSuite_utfresults.xml");
35 
39 struct UnitTestConfig {
41  UnitTestConfig() {
42  boost_utf::unit_test_log.set_stream (utfReportStream);
43 #if BOOST_VERSION >= 105900
44  boost_utf::unit_test_log.set_format (boost_utf::OF_XML);
45 #else
46  boost_utf::unit_test_log.set_format (boost_utf::XML);
47 #endif
48  boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
49  //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
50  }
51 
53  ~UnitTestConfig() {
54  }
55 };
56 
57 // //////////////////////////////////////////////////////////////////////
61 bool testInventoryHelper (const unsigned short iTestFlag,
62  const stdair::Filename_T& iInventoryInputFilename,
63  const stdair::Filename_T& iScheduleInputFilename,
64  const stdair::Filename_T& iODInputFilename,
65  const stdair::Filename_T& iFRAT5InputFilename,
66  const stdair::Filename_T& iFFDisutilityInputFilename,
67  const stdair::Filename_T& iYieldInputFilename,
68  const bool isBuiltin,
69  const bool isForSchedule) {
70 
71  // Output log File
72  std::ostringstream oStr;
73  oStr << "InventoryTestSuite_" << iTestFlag << ".log";
74  const stdair::Filename_T lLogFilename (oStr.str());
75 
76  // Set the log parameters
77  std::ofstream logOutputFile;
78  // Open and clean the log outputfile
79  logOutputFile.open (lLogFilename.c_str());
80  logOutputFile.clear();
81 
82  // Initialise the AirInv service object
83  stdair::BasLogParams lLogParams (stdair::LOG::DEBUG,
84  logOutputFile);
85 
86  // Initialise the inventory service
87  AIRINV::AIRINV_Master_Service airinvService (lLogParams);
88 
89  // Parameters for the sale
90  std::string lSegmentDateKey;
91  stdair::ClassCode_T lClassCode;
92  const stdair::PartySize_T lPartySize (2);
93 
94  // Check wether or not a (CSV) input file should be read
95  if (isBuiltin == true) {
96 
97  // Build the default sample BOM tree (filled with inventories) for AirInv
98  airinvService.buildSampleBom();
99 
100  // Define a specific segment-date key for the sample BOM tree
101  lSegmentDateKey = "BA,9,2011-06-10,LHR,SYD";
102  lClassCode = "Q";
103 
104  } else {
105 
106  if (isForSchedule == true) {
107  // Build the BOM tree from parsing a schedule file (and O&D list)
108  stdair::ScheduleFilePath lScheduleFilePath (iScheduleInputFilename);
109  stdair::ODFilePath lODFilePath (iODInputFilename);
110  stdair::FRAT5FilePath lFRAT5FilePath (iFRAT5InputFilename);
111  stdair::FFDisutilityFilePath lFFDisutilityFilePath (iFFDisutilityInputFilename);
112  AIRRAC::YieldFilePath lYieldFilePath (iYieldInputFilename);
113  airinvService.parseAndLoad (lScheduleFilePath, lODFilePath,
114  lFRAT5FilePath, lFFDisutilityFilePath,
115  lYieldFilePath);
116 
117  // Define a specific segment-date key for the schedule-based inventory
118  lSegmentDateKey = "SQ,11,2010-01-15,SIN,BKK";
119  lClassCode = "Y";
120 
121  } else {
122 
123  // Build the BOM tree from parsing an inventory dump file
124  AIRINV::InventoryFilePath lInventoryFilePath (iInventoryInputFilename);
125  airinvService.parseAndLoad (lInventoryFilePath);
126 
127  // Define a specific segment-date key for the inventory parsed file
128  //const std::string lSegmentDateKey ("SV, 5, 2010-03-11, KBP, JFK, 08:00:00");
129  lSegmentDateKey = "SV, 5, 2010-03-11, KBP, JFK, 08:00:00";
130  lClassCode = "J";
131  }
132 
133  }
134 
135  // Make a booking
136  const bool hasSaleBeenSuccessful =
137  airinvService.sell (lSegmentDateKey, lClassCode, lPartySize);
138 
139  // DEBUG: Display the list of travel solutions
140  const std::string& lCSVDump = airinvService.csvDisplay();
141  STDAIR_LOG_DEBUG (lCSVDump);
142 
143  // Close the log file
144  logOutputFile.close();
145 
146  if (hasSaleBeenSuccessful == false) {
147  STDAIR_LOG_DEBUG ("No sale can be made for '" << lSegmentDateKey
148  << "'");
149  }
150 
151  return hasSaleBeenSuccessful;
152 
153 }
154 
155 // /////////////// Main: Unit Test Suite //////////////
156 
157 // Set the UTF configuration (re-direct the output to a specific file)
158 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
159 
160 // Start the test suite
161 BOOST_AUTO_TEST_SUITE (master_test_suite)
162 
163 
166 BOOST_AUTO_TEST_CASE (airinv_simple_inventory_sell) {
167 
168  // Input file name
169  const stdair::Filename_T lInventoryInputFilename (STDAIR_SAMPLE_DIR
170  "/invdump01.csv");
171 
172  // State whether the BOM tree should be built-in or parsed from an input file
173  const bool isBuiltin = false;
174  // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
175  const bool isForSchedule = false;
176 
177  // Try sell a default segment.
178  bool hasTestBeenSuccessful = false;
179  BOOST_CHECK_NO_THROW (hasTestBeenSuccessful =
180  testInventoryHelper (0, lInventoryInputFilename,
181  " ", " ", " ", " ", " ", isBuiltin, isForSchedule));
182  BOOST_CHECK_EQUAL (hasTestBeenSuccessful, true);
183 
184 }
185 
189 BOOST_AUTO_TEST_CASE (airinv_simple_inventory_sell_built_in) {
190 
191  // State whether the BOM tree should be built-in or parsed from an input file
192  const bool isBuiltin = true;
193  // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
194  const bool isForSchedule = false;
195 
196  // Try sell a default segment.
197  bool hasTestBeenSuccessful = false;
198  BOOST_CHECK_NO_THROW (hasTestBeenSuccessful =
199  testInventoryHelper (1, " ", " ", " ", " ", " ", " ",
200  isBuiltin, isForSchedule));
201  BOOST_CHECK_EQUAL (hasTestBeenSuccessful, true);
202 
203 }
204 
208 BOOST_AUTO_TEST_CASE (airinv_simple_inventory_sell_schedule) {
209 
210  // Input file names
211  const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
212  "/schedule01.csv");
213  const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
214  "/ond01.csv");
215  const stdair::Filename_T lFRAT5InputFilename (STDAIR_SAMPLE_DIR
216  "/frat5.csv");
217  const stdair::Filename_T lFFDisutilityInputFilename (STDAIR_SAMPLE_DIR
218  "/ffDisutility.csv");
219  const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR
220  "/yieldstore01.csv");
221 
222  // State whether the BOM tree should be built-in or parsed from an input file
223  const bool isBuiltin = false;
224  // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
225  const bool isForSchedule = true;
226 
227  // Try sell a default segment.
228  bool hasTestBeenSuccessful = false;
229  BOOST_CHECK_NO_THROW (hasTestBeenSuccessful =
230  testInventoryHelper (2, " ",
231  lScheduleInputFilename,
232  lODInputFilename,
233  lFRAT5InputFilename,
234  lFFDisutilityInputFilename,
235  lYieldInputFilename,
236  isBuiltin, isForSchedule));
237  BOOST_CHECK_EQUAL (hasTestBeenSuccessful, true);
238 
239 }
240 
245 BOOST_AUTO_TEST_CASE (airinv_error_inventory_input_file) {
246 
247  // Inventory input file name
248  const stdair::Filename_T lMissingInventoryFilename (STDAIR_SAMPLE_DIR
249  "/missingFile.csv");
250 
251  // State whether the BOM tree should be built-in or parsed from an input file
252  const bool isBuiltin = false;
253  // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
254  const bool isForSchedule = false;
255 
256  // Try sell a default segment.
257  BOOST_CHECK_THROW (testInventoryHelper (3, lMissingInventoryFilename,
258  " ", " ", " ", " ", " ", isBuiltin, isForSchedule),
260 
261 }
262 
267 BOOST_AUTO_TEST_CASE (airinv_error_schedule_input_file) {
268 
269  // Schedule input file name
270  const stdair::Filename_T lMissingScheduleFilename (STDAIR_SAMPLE_DIR
271  "/missingFile.csv");
272  const stdair::Filename_T lFRAT5InputFilename (STDAIR_SAMPLE_DIR
273  "/frat5.csv");
274  const stdair::Filename_T lFFDisutilityInputFilename (STDAIR_SAMPLE_DIR
275  "/ffDisutility.csv");
276 
277  // State whether the BOM tree should be built-in or parsed from an input file
278  const bool isBuiltin = false;
279  // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
280  const bool isForSchedule = true;
281 
282  // Try sell a default segment.
283  BOOST_CHECK_THROW (testInventoryHelper (4, " ", lMissingScheduleFilename,
284  " ", lFRAT5InputFilename,
285  lFFDisutilityInputFilename, " ",
286  isBuiltin, isForSchedule),
288 
289 }
290 
295 BOOST_AUTO_TEST_CASE (airinv_error_yield_input_file) {
296 
297  // Input file names
298  const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
299  "/schedule01.csv");
300  const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
301  "/ond01.csv");
302  const stdair::Filename_T lFRAT5InputFilename (STDAIR_SAMPLE_DIR
303  "/frat5.csv");
304  const stdair::Filename_T lFFDisutilityInputFilename (STDAIR_SAMPLE_DIR
305  "/ffDisutility.csv");
306  const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR
307  "/missingFile.csv");
308 
309  // State whether the BOM tree should be built-in or parsed from an input file
310  const bool isBuiltin = false;
311  // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
312  const bool isForSchedule = true;
313 
314  // Try sell a default segment.
315  BOOST_CHECK_THROW (testInventoryHelper (5, " ",
316  lScheduleInputFilename,
317  lODInputFilename,
318  lFRAT5InputFilename,
319  lFFDisutilityInputFilename,
320  lYieldInputFilename,
321  isBuiltin, isForSchedule),
322  AIRRAC::YieldInputFileNotFoundException);
323 
324 }
325 
330 BOOST_AUTO_TEST_CASE (airinv_error_flight_date_duplication) {
331 
332  // Input file names
333  const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
334  "/scheduleError01.csv");
335  const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
336  "/ond01.csv");
337  const stdair::Filename_T lFRAT5InputFilename (STDAIR_SAMPLE_DIR
338  "/frat5.csv");
339  const stdair::Filename_T lFFDisutilityInputFilename (STDAIR_SAMPLE_DIR
340  "/ffDisutility.csv");
341  const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR
342  "/missingFile.csv");
343 
344  // State whether the BOM tree should be built-in or parsed from an input file
345  const bool isBuiltin = false;
346  // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
347  const bool isForSchedule = true;
348 
349  // Try sell a default segment.
350  BOOST_CHECK_THROW (testInventoryHelper (6, " ",
351  lScheduleInputFilename,
352  lODInputFilename,
353  lFRAT5InputFilename,
354  lFFDisutilityInputFilename,
355  lYieldInputFilename,
356  isBuiltin, isForSchedule),
358 
359 }
360 
365 BOOST_AUTO_TEST_CASE (airinv_error_schedule_parsing_failed) {
366 
367  // Input file names
368  const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
369  "/scheduleError02.csv");
370  const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
371  "/ond01.csv");
372  const stdair::Filename_T lFRAT5InputFilename (STDAIR_SAMPLE_DIR
373  "/frat5.csv");
374  const stdair::Filename_T lFFDisutilityInputFilename (STDAIR_SAMPLE_DIR
375  "/ffDisutility.csv");
376  const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR
377  "/yieldstore01.csv");
378 
379  // State whether the BOM tree should be built-in or parsed from an input file
380  const bool isBuiltin = false;
381  // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
382  const bool isForSchedule = true;
383 
384  // Try sell a default segment.
385  BOOST_CHECK_THROW (testInventoryHelper (7, " ",
386  lScheduleInputFilename,
387  lODInputFilename,
388  lFRAT5InputFilename,
389  lFFDisutilityInputFilename,
390  lYieldInputFilename,
391  isBuiltin, isForSchedule),
393 
394 }
395 
396 // End the test suite
397 BOOST_AUTO_TEST_SUITE_END()
398 
399 
#define STDAIR_SAMPLE_DIR
Interface for the AIRINV Services.