$treeview $search $mathjax
AirInv Logo  1.00.1
$projectbrief
$projectbrief
$searchbox

InventoryTestSuite.cpp

Go to the documentation of this file.
00001 
00005 // //////////////////////////////////////////////////////////////////////
00006 // Import section
00007 // //////////////////////////////////////////////////////////////////////
00008 // STL
00009 #include <sstream>
00010 #include <fstream>
00011 #include <string>
00012 // Boost Unit Test Framework (UTF)
00013 #define BOOST_TEST_DYN_LINK
00014 #define BOOST_TEST_MAIN
00015 #define BOOST_TEST_MODULE InventoryTestSuite
00016 #include <boost/test/unit_test.hpp>
00017 // StdAir
00018 #include <stdair/basic/BasLogParams.hpp>
00019 #include <stdair/basic/BasDBParams.hpp>
00020 #include <stdair/basic/BasFileMgr.hpp>
00021 #include <stdair/bom/TravelSolutionStruct.hpp>
00022 #include <stdair/bom/BookingRequestStruct.hpp>
00023 #include <stdair/service/Logger.hpp>
00024 #include <stdair/stdair_exceptions.hpp>
00025 // Airinv
00026 #include <airinv/AIRINV_Types.hpp>
00027 #include <airinv/AIRINV_Master_Service.hpp>
00028 #include <airinv/config/airinv-paths.hpp>
00029 
00030 namespace boost_utf = boost::unit_test;
00031 
00032 // (Boost) Unit Test XML Report
00033 std::ofstream utfReportStream ("InventoryTestSuite_utfresults.xml");
00034 
00038 struct UnitTestConfig {
00040   UnitTestConfig() {
00041     boost_utf::unit_test_log.set_stream (utfReportStream);
00042     boost_utf::unit_test_log.set_format (boost_utf::XML);
00043     boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
00044     //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
00045   }
00046 
00048   ~UnitTestConfig() {
00049   }
00050 };
00051 
00052 // //////////////////////////////////////////////////////////////////////
00056 bool testInventoryHelper (const unsigned short iTestFlag,
00057                           const stdair::Filename_T& iInventoryInputFilename,  
00058                           const stdair::Filename_T& iScheduleInputFilename,
00059                           const stdair::Filename_T& iODInputFilename,
00060                           const stdair::Filename_T& iFRAT5InputFilename,
00061                           const stdair::Filename_T& iFFDisutilityInputFilename,
00062                           const stdair::Filename_T& iYieldInputFilename,
00063                           const bool isBuiltin,
00064                           const bool isForSchedule) {
00065 
00066   // Output log File
00067   std::ostringstream oStr;
00068   oStr << "InventoryTestSuite_" << iTestFlag << ".log";
00069   const stdair::Filename_T lLogFilename (oStr.str());
00070 
00071   // Set the log parameters
00072   std::ofstream logOutputFile;
00073   // Open and clean the log outputfile
00074   logOutputFile.open (lLogFilename.c_str());
00075   logOutputFile.clear();
00076   
00077   // Initialise the AirInv service object
00078   stdair::BasLogParams lLogParams (stdair::LOG::DEBUG,
00079                                    logOutputFile);
00080 
00081   // Initialise the inventory service
00082   AIRINV::AIRINV_Master_Service airinvService (lLogParams);
00083   
00084   // Parameters for the sale
00085   std::string lSegmentDateKey;
00086   stdair::ClassCode_T lClassCode;
00087   const stdair::PartySize_T lPartySize (2);
00088 
00089   // Check wether or not a (CSV) input file should be read
00090   if (isBuiltin == true) {
00091 
00092     // Build the default sample BOM tree (filled with inventories) for AirInv
00093    airinvService.buildSampleBom();
00094 
00095    // Define a specific segment-date key for the sample BOM tree
00096    lSegmentDateKey = "BA,9,2011-06-10,LHR,SYD";
00097    lClassCode = "Q";
00098 
00099   } else {
00100 
00101     if (isForSchedule == true) {
00102       // Build the BOM tree from parsing a schedule file (and O&D list)
00103       stdair::ScheduleFilePath lScheduleFilePath (iScheduleInputFilename);
00104       stdair::ODFilePath lODFilePath (iODInputFilename);
00105       stdair::FRAT5FilePath lFRAT5FilePath (iFRAT5InputFilename);
00106       stdair::FFDisutilityFilePath lFFDisutilityFilePath (iFFDisutilityInputFilename);
00107       AIRRAC::YieldFilePath lYieldFilePath (iYieldInputFilename);
00108       airinvService.parseAndLoad (lScheduleFilePath, lODFilePath,
00109                                   lFRAT5FilePath, lFFDisutilityFilePath,
00110                                   lYieldFilePath);
00111 
00112       // Define a specific segment-date key for the schedule-based inventory
00113       lSegmentDateKey = "SQ,11,2010-01-15,SIN,BKK";
00114       lClassCode = "Y";
00115 
00116     } else {
00117 
00118       // Build the BOM tree from parsing an inventory dump file
00119       AIRINV::InventoryFilePath lInventoryFilePath (iInventoryInputFilename);
00120       airinvService.parseAndLoad (lInventoryFilePath);
00121 
00122       // Define a specific segment-date key for the inventory parsed file
00123       //const std::string lSegmentDateKey ("SV, 5, 2010-03-11, KBP, JFK, 08:00:00");
00124       lSegmentDateKey =  "SV, 5, 2010-03-11, KBP, JFK, 08:00:00";
00125       lClassCode = "J";
00126     }
00127 
00128   }
00129 
00130   // Make a booking
00131   const bool hasSaleBeenSuccessful =
00132     airinvService.sell (lSegmentDateKey, lClassCode, lPartySize);
00133 
00134   // DEBUG: Display the list of travel solutions
00135   const std::string& lCSVDump = airinvService.csvDisplay();
00136   STDAIR_LOG_DEBUG (lCSVDump);
00137 
00138   // Close the log file
00139   logOutputFile.close();
00140 
00141   if (hasSaleBeenSuccessful == false) {
00142     STDAIR_LOG_DEBUG ("No sale can be made for '" << lSegmentDateKey
00143                       << "'");
00144   }
00145   
00146   return hasSaleBeenSuccessful;
00147 
00148 }
00149 
00150 // /////////////// Main: Unit Test Suite //////////////
00151 
00152 // Set the UTF configuration (re-direct the output to a specific file)
00153 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
00154 
00155 // Start the test suite
00156 BOOST_AUTO_TEST_SUITE (master_test_suite)
00157 
00158 
00161 BOOST_AUTO_TEST_CASE (airinv_simple_inventory_sell) {
00162 
00163   // Input file name
00164   const stdair::Filename_T lInventoryInputFilename (STDAIR_SAMPLE_DIR
00165                                                     "/invdump01.csv");
00166   
00167   // State whether the BOM tree should be built-in or parsed from an input file
00168   const bool isBuiltin = false;
00169   // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
00170   const bool isForSchedule = false;
00171 
00172   // Try sell a default segment.
00173   bool hasTestBeenSuccessful = false;
00174   BOOST_CHECK_NO_THROW (hasTestBeenSuccessful =
00175                         testInventoryHelper (0, lInventoryInputFilename,
00176                                              " ", " ", " ", " ", " ", isBuiltin, isForSchedule));
00177   BOOST_CHECK_EQUAL (hasTestBeenSuccessful, true);
00178 
00179 }
00180 
00184 BOOST_AUTO_TEST_CASE (airinv_simple_inventory_sell_built_in) {
00185   
00186   // State whether the BOM tree should be built-in or parsed from an input file
00187   const bool isBuiltin = true;
00188   // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
00189   const bool isForSchedule = false;
00190 
00191   // Try sell a default segment.
00192   bool hasTestBeenSuccessful = false;
00193   BOOST_CHECK_NO_THROW (hasTestBeenSuccessful =
00194                         testInventoryHelper (1, " ", " ", " ", " ", " ", " ",
00195                                              isBuiltin, isForSchedule));
00196   BOOST_CHECK_EQUAL (hasTestBeenSuccessful, true);
00197 
00198 }
00199 
00203 BOOST_AUTO_TEST_CASE (airinv_simple_inventory_sell_schedule) {
00204 
00205   // Input file names
00206   const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
00207                                                    "/schedule01.csv");
00208   const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
00209                                              "/ond01.csv");
00210   const stdair::Filename_T lFRAT5InputFilename (STDAIR_SAMPLE_DIR
00211                                                "/frat5.csv");
00212   const stdair::Filename_T lFFDisutilityInputFilename (STDAIR_SAMPLE_DIR
00213                                                        "/ffDisutility.csv");
00214   const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR
00215                                                 "/yieldstore01.csv");
00216   
00217   // State whether the BOM tree should be built-in or parsed from an input file
00218   const bool isBuiltin = false;
00219   // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
00220   const bool isForSchedule = true;
00221 
00222   // Try sell a default segment.
00223   bool hasTestBeenSuccessful = false;
00224   BOOST_CHECK_NO_THROW (hasTestBeenSuccessful =
00225                         testInventoryHelper (2, " ",
00226                                              lScheduleInputFilename,
00227                                              lODInputFilename,
00228                                              lFRAT5InputFilename,
00229                                              lFFDisutilityInputFilename,
00230                                              lYieldInputFilename,
00231                                              isBuiltin, isForSchedule));
00232   BOOST_CHECK_EQUAL (hasTestBeenSuccessful, true);
00233 
00234 }
00235 
00240 BOOST_AUTO_TEST_CASE (airinv_error_inventory_input_file) {
00241 
00242   // Inventory input file name
00243   const stdair::Filename_T lMissingInventoryFilename (STDAIR_SAMPLE_DIR
00244                                                       "/missingFile.csv");
00245   
00246   // State whether the BOM tree should be built-in or parsed from an input file
00247   const bool isBuiltin = false;
00248   // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
00249   const bool isForSchedule = false;
00250 
00251   // Try sell a default segment.
00252   BOOST_CHECK_THROW (testInventoryHelper (3, lMissingInventoryFilename,
00253                                           " ", " ", " ", " ", " ", isBuiltin, isForSchedule),
00254                      AIRINV::InventoryInputFileNotFoundException);
00255 
00256 }
00257 
00262 BOOST_AUTO_TEST_CASE (airinv_error_schedule_input_file) {
00263 
00264   // Schedule input file name
00265   const stdair::Filename_T lMissingScheduleFilename (STDAIR_SAMPLE_DIR
00266                                                      "/missingFile.csv");
00267   const stdair::Filename_T lFRAT5InputFilename (STDAIR_SAMPLE_DIR
00268                                                "/frat5.csv");
00269   const stdair::Filename_T lFFDisutilityInputFilename (STDAIR_SAMPLE_DIR
00270                                                        "/ffDisutility.csv");
00271   
00272   // State whether the BOM tree should be built-in or parsed from an input file
00273   const bool isBuiltin = false;
00274   // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
00275   const bool isForSchedule = true;
00276 
00277   // Try sell a default segment.
00278   BOOST_CHECK_THROW (testInventoryHelper (4, " ", lMissingScheduleFilename,
00279                                           " ", lFRAT5InputFilename,
00280                                           lFFDisutilityInputFilename, " ",
00281                                           isBuiltin, isForSchedule),
00282                      AIRINV::ScheduleInputFileNotFoundException);
00283 
00284 }
00285 
00290 BOOST_AUTO_TEST_CASE (airinv_error_yield_input_file) {
00291   
00292   // Input file names
00293   const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
00294                                                    "/schedule01.csv");
00295   const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
00296                                              "/ond01.csv");
00297   const stdair::Filename_T lFRAT5InputFilename (STDAIR_SAMPLE_DIR
00298                                                "/frat5.csv");
00299   const stdair::Filename_T lFFDisutilityInputFilename (STDAIR_SAMPLE_DIR
00300                                                        "/ffDisutility.csv");
00301   const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR
00302                                                 "/missingFile.csv");
00303   
00304   // State whether the BOM tree should be built-in or parsed from an input file
00305   const bool isBuiltin = false;
00306   // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
00307   const bool isForSchedule = true;
00308 
00309   // Try sell a default segment.
00310   BOOST_CHECK_THROW (testInventoryHelper (5, " ",
00311                                           lScheduleInputFilename,
00312                                           lODInputFilename,
00313                                           lFRAT5InputFilename,
00314                                           lFFDisutilityInputFilename,
00315                                           lYieldInputFilename,
00316                                           isBuiltin, isForSchedule),
00317                      AIRRAC::YieldInputFileNotFoundException);
00318 
00319 }
00320 
00325 BOOST_AUTO_TEST_CASE (airinv_error_flight_date_duplication) {
00326   
00327   // Input file names
00328   const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
00329                                                    "/scheduleError01.csv");
00330   const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
00331                                              "/ond01.csv");
00332   const stdair::Filename_T lFRAT5InputFilename (STDAIR_SAMPLE_DIR
00333                                                "/frat5.csv");
00334   const stdair::Filename_T lFFDisutilityInputFilename (STDAIR_SAMPLE_DIR
00335                                                        "/ffDisutility.csv");
00336   const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR
00337                                                 "/missingFile.csv");
00338   
00339   // State whether the BOM tree should be built-in or parsed from an input file
00340   const bool isBuiltin = false;
00341   // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
00342   const bool isForSchedule = true;
00343 
00344   // Try sell a default segment.
00345   BOOST_CHECK_THROW (testInventoryHelper (6, " ",
00346                                           lScheduleInputFilename,
00347                                           lODInputFilename,
00348                                           lFRAT5InputFilename,
00349                                           lFFDisutilityInputFilename,
00350                                           lYieldInputFilename,
00351                                           isBuiltin, isForSchedule),
00352                      AIRINV::FlightDateDuplicationException);
00353 
00354 }
00355 
00360 BOOST_AUTO_TEST_CASE (airinv_error_schedule_parsing_failed) {
00361   
00362   // Input file names
00363   const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
00364                                                    "/scheduleError02.csv");
00365   const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
00366                                              "/ond01.csv");
00367   const stdair::Filename_T lFRAT5InputFilename (STDAIR_SAMPLE_DIR
00368                                                "/frat5.csv");
00369   const stdair::Filename_T lFFDisutilityInputFilename (STDAIR_SAMPLE_DIR
00370                                                        "/ffDisutility.csv");
00371   const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR
00372                                                 "/yieldstore01.csv");
00373   
00374   // State whether the BOM tree should be built-in or parsed from an input file
00375   const bool isBuiltin = false;
00376   // State whether the BOM tree should be built from a schedule file (instead of from an inventory dump)
00377   const bool isForSchedule = true;
00378 
00379   // Try sell a default segment.
00380   BOOST_CHECK_THROW (testInventoryHelper (7, " ",
00381                                           lScheduleInputFilename,
00382                                           lODInputFilename,
00383                                           lFRAT5InputFilename,
00384                                           lFFDisutilityInputFilename,
00385                                           lYieldInputFilename,
00386                                           isBuiltin, isForSchedule),
00387                      AIRINV::ScheduleFileParsingFailedException);
00388 
00389 }
00390 
00391 // End the test suite
00392 BOOST_AUTO_TEST_SUITE_END()
00393 
00394