00001
00005
00006
00007
00008
00009 #include <sstream>
00010 #include <fstream>
00011 #include <string>
00012
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
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
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
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
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& iYieldInputFilename,
00061 const bool isBuiltin,
00062 const bool isForSchedule) {
00063
00064
00065 std::ostringstream oStr;
00066 oStr << "InventoryTestSuite_" << iTestFlag << ".log";
00067 const stdair::Filename_T lLogFilename (oStr.str());
00068
00069
00070 std::ofstream logOutputFile;
00071
00072 logOutputFile.open (lLogFilename.c_str());
00073 logOutputFile.clear();
00074
00075
00076 const bool lForceMultipleInit = true;
00077 stdair::BasLogParams lLogParams (stdair::LOG::DEBUG,
00078 logOutputFile,
00079 lForceMultipleInit);
00080
00081
00082 AIRINV::AIRINV_Master_Service airinvService (lLogParams);
00083
00084
00085 std::string lSegmentDateKey;
00086 stdair::ClassCode_T lClassCode;
00087 const stdair::PartySize_T lPartySize (2);
00088
00089
00090 if (isBuiltin == true) {
00091
00092
00093 airinvService.buildSampleBom();
00094
00095
00096 lSegmentDateKey = "BA,9,2011-06-10,LHR,SYD";
00097 lClassCode = "Q";
00098
00099 } else {
00100
00101 if (isForSchedule == true) {
00102
00103 AIRRAC::YieldFilePath lYieldFilePath (iYieldInputFilename);
00104 airinvService.parseAndLoad (iScheduleInputFilename, iODInputFilename,
00105 lYieldFilePath);
00106
00107
00108 lSegmentDateKey = "SQ,11,2010-01-15,SIN,BKK";
00109 lClassCode = "Y";
00110
00111 } else {
00112
00113
00114 airinvService.parseAndLoad (iInventoryInputFilename);
00115
00116
00117
00118 lSegmentDateKey = "SV, 5, 2010-03-11, KBP, JFK, 08:00:00";
00119 lClassCode = "J";
00120 }
00121
00122 }
00123
00124
00125 const bool hasSaleBeenSuccessful =
00126 airinvService.sell (lSegmentDateKey, lClassCode, lPartySize);
00127
00128
00129 const std::string& lCSVDump = airinvService.csvDisplay();
00130 STDAIR_LOG_DEBUG (lCSVDump);
00131
00132
00133 logOutputFile.close();
00134
00135 if (hasSaleBeenSuccessful == false) {
00136 STDAIR_LOG_DEBUG ("No sale can be made for '" << lSegmentDateKey
00137 << "'");
00138 }
00139
00140 return hasSaleBeenSuccessful;
00141
00142 }
00143
00144
00145
00146
00147 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
00148
00149
00150 BOOST_AUTO_TEST_SUITE (master_test_suite)
00151
00152
00155 BOOST_AUTO_TEST_CASE (airinv_simple_inventory_sell) {
00156
00157
00158 const stdair::Filename_T lInventoryInputFilename (STDAIR_SAMPLE_DIR
00159 "/invdump01.csv");
00160
00161
00162 const bool isBuiltin = false;
00163
00164 const bool isForSchedule = false;
00165
00166
00167 bool hasTestBeenSuccessful = false;
00168 BOOST_CHECK_NO_THROW (hasTestBeenSuccessful =
00169 testInventoryHelper (0, lInventoryInputFilename,
00170 " ", " ", " ", isBuiltin, isForSchedule));
00171 BOOST_CHECK_EQUAL (hasTestBeenSuccessful, true);
00172
00173 }
00174
00178 BOOST_AUTO_TEST_CASE (airinv_simple_inventory_sell_built_in) {
00179
00180
00181 const bool isBuiltin = true;
00182
00183 const bool isForSchedule = false;
00184
00185
00186 bool hasTestBeenSuccessful = false;
00187 BOOST_CHECK_NO_THROW (hasTestBeenSuccessful =
00188 testInventoryHelper (1, " ", " ", " ", " ",
00189 isBuiltin, isForSchedule));
00190 BOOST_CHECK_EQUAL (hasTestBeenSuccessful, true);
00191
00192 }
00193
00197 BOOST_AUTO_TEST_CASE (airinv_simple_inventory_sell_schedule) {
00198
00199
00200 const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
00201 "/schedule01.csv");
00202 const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
00203 "/ond01.csv");
00204 const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR
00205 "/yieldstore01.csv");
00206
00207
00208 const bool isBuiltin = false;
00209
00210 const bool isForSchedule = true;
00211
00212
00213 bool hasTestBeenSuccessful = false;
00214 BOOST_CHECK_NO_THROW (hasTestBeenSuccessful =
00215 testInventoryHelper (2, " ",
00216 lScheduleInputFilename,
00217 lODInputFilename,
00218 lYieldInputFilename,
00219 isBuiltin, isForSchedule));
00220 BOOST_CHECK_EQUAL (hasTestBeenSuccessful, true);
00221
00222 }
00223
00228 BOOST_AUTO_TEST_CASE (airinv_error_inventory_input_file) {
00229
00230
00231 const stdair::Filename_T lMissingInventoryFilename (STDAIR_SAMPLE_DIR
00232 "/missingFile.csv");
00233
00234
00235 const bool isBuiltin = false;
00236
00237 const bool isForSchedule = false;
00238
00239
00240 BOOST_CHECK_THROW (testInventoryHelper (3, lMissingInventoryFilename,
00241 " ", " ", " ", isBuiltin, isForSchedule),
00242 AIRINV::InventoryInputFileNotFoundException);
00243
00244 }
00245
00250 BOOST_AUTO_TEST_CASE (airinv_error_schedule_input_file) {
00251
00252
00253 const stdair::Filename_T lMissingScheduleFilename (STDAIR_SAMPLE_DIR
00254 "/missingFile.csv");
00255
00256
00257 const bool isBuiltin = false;
00258
00259 const bool isForSchedule = true;
00260
00261
00262 BOOST_CHECK_THROW (testInventoryHelper (4, " ", lMissingScheduleFilename,
00263 " ", " ", isBuiltin, isForSchedule),
00264 AIRINV::ScheduleInputFileNotFoundException);
00265
00266 }
00267
00272 BOOST_AUTO_TEST_CASE (airinv_error_yield_input_file) {
00273
00274
00275 const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
00276 "/schedule01.csv");
00277 const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
00278 "/ond01.csv");
00279 const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR
00280 "/missingFile.csv");
00281
00282
00283 const bool isBuiltin = false;
00284
00285 const bool isForSchedule = true;
00286
00287
00288 BOOST_CHECK_THROW (testInventoryHelper (5, " ",
00289 lScheduleInputFilename,
00290 lODInputFilename,
00291 lYieldInputFilename,
00292 isBuiltin, isForSchedule),
00293 AIRRAC::YieldInputFileNotFoundException);
00294
00295 }
00296
00301 BOOST_AUTO_TEST_CASE (airinv_error_flight_date_duplication) {
00302
00303
00304 const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
00305 "/scheduleError01.csv");
00306 const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
00307 "/ond01.csv");
00308 const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR
00309 "/missingFile.csv");
00310
00311
00312 const bool isBuiltin = false;
00313
00314 const bool isForSchedule = true;
00315
00316
00317 BOOST_CHECK_THROW (testInventoryHelper (6, " ",
00318 lScheduleInputFilename,
00319 lODInputFilename,
00320 lYieldInputFilename,
00321 isBuiltin, isForSchedule),
00322 AIRINV::FlightDateDuplicationException);
00323
00324 }
00325
00330 BOOST_AUTO_TEST_CASE (airinv_error_schedule_parsing_failed) {
00331
00332
00333 const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
00334 "/scheduleError02.csv");
00335 const stdair::Filename_T lODInputFilename (STDAIR_SAMPLE_DIR
00336 "/ond01.csv");
00337 const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR
00338 "/yieldstore01.csv");
00339
00340
00341 const bool isBuiltin = false;
00342
00343 const bool isForSchedule = true;
00344
00345
00346 BOOST_CHECK_THROW (testInventoryHelper (7, " ",
00347 lScheduleInputFilename,
00348 lODInputFilename,
00349 lYieldInputFilename,
00350 isBuiltin, isForSchedule),
00351 AIRINV::ScheduleFileParsingFailedException);
00352
00353 }
00354
00355
00356 BOOST_AUTO_TEST_SUITE_END()
00357
00358