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