*/
#include <sstream>
#include <fstream>
#include <string>
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN
#define BOOST_TEST_MODULE InventoryTestSuite
#include <boost/test/unit_test.hpp>
#include <stdair/basic/BasLogParams.hpp>
#include <stdair/basic/BasDBParams.hpp>
#include <stdair/basic/BasFileMgr.hpp>
#include <stdair/bom/TravelSolutionStruct.hpp>
#include <stdair/bom/BookingRequestStruct.hpp>
#include <stdair/service/Logger.hpp>
#include <stdair/stdair_exceptions.hpp>
#include <airinv/config/airinv-paths.hpp>
namespace boost_utf = boost::unit_test;
std::ofstream utfReportStream ("InventoryTestSuite_utfresults.xml");
struct UnitTestConfig {
UnitTestConfig() {
boost_utf::unit_test_log.set_stream (utfReportStream);
boost_utf::unit_test_log.set_format (boost_utf::XML);
boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
}
~UnitTestConfig() {
}
};
bool testInventoryHelper (const unsigned short iTestFlag,
const stdair::Filename_T& iInventoryInputFilename,
const stdair::Filename_T& iScheduleInputFilename,
const stdair::Filename_T& iODInputFilename,
const stdair::Filename_T& iFRAT5InputFilename,
const stdair::Filename_T& iFFDisutilityInputFilename,
const stdair::Filename_T& iYieldInputFilename,
const bool isBuiltin,
const bool isForSchedule) {
std::ostringstream oStr;
oStr << "InventoryTestSuite_" << iTestFlag << ".log";
const stdair::Filename_T lLogFilename (oStr.str());
std::ofstream logOutputFile;
logOutputFile.open (lLogFilename.c_str());
logOutputFile.clear();
stdair::BasLogParams lLogParams (stdair::LOG::DEBUG,
logOutputFile);
std::string lSegmentDateKey;
stdair::ClassCode_T lClassCode;
const stdair::PartySize_T lPartySize (2);
if (isBuiltin == true) {
airinvService.buildSampleBom();
lSegmentDateKey = "BA,9,2011-06-10,LHR,SYD";
lClassCode = "Q";
} else {
if (isForSchedule == true) {
stdair::ScheduleFilePath lScheduleFilePath (iScheduleInputFilename);
stdair::ODFilePath lODFilePath (iODInputFilename);
stdair::FRAT5FilePath lFRAT5FilePath (iFRAT5InputFilename);
stdair::FFDisutilityFilePath lFFDisutilityFilePath (iFFDisutilityInputFilename);
AIRRAC::YieldFilePath lYieldFilePath (iYieldInputFilename);
airinvService.parseAndLoad (lScheduleFilePath, lODFilePath,
lFRAT5FilePath, lFFDisutilityFilePath,
lYieldFilePath);
lSegmentDateKey = "SQ,11,2010-01-15,SIN,BKK";
lClassCode = "Y";
} else {
airinvService.parseAndLoad (lInventoryFilePath);
lSegmentDateKey = "SV, 5, 2010-03-11, KBP, JFK, 08:00:00";
lClassCode = "J";
}
}
const bool hasSaleBeenSuccessful =
airinvService.sell (lSegmentDateKey, lClassCode, lPartySize);
const std::string& lCSVDump = airinvService.csvDisplay();
STDAIR_LOG_DEBUG (lCSVDump);
logOutputFile.close();
if (hasSaleBeenSuccessful == false) {
STDAIR_LOG_DEBUG ("No sale can be made for '" << lSegmentDateKey
<< "'");
}
return hasSaleBeenSuccessful;
}
BOOST_GLOBAL_FIXTURE (UnitTestConfig);
BOOST_AUTO_TEST_SUITE (master_test_suite)
BOOST_AUTO_TEST_CASE (airinv_simple_inventory_sell) {
"/invdump01.csv");
const bool isBuiltin = false;
const bool isForSchedule = false;
bool hasTestBeenSuccessful = false;
BOOST_CHECK_NO_THROW (hasTestBeenSuccessful =
testInventoryHelper (0, lInventoryInputFilename,
" ", " ", " ", " ", " ", isBuiltin, isForSchedule));
BOOST_CHECK_EQUAL (hasTestBeenSuccessful, true);
}
BOOST_AUTO_TEST_CASE (airinv_simple_inventory_sell_built_in) {
const bool isBuiltin = true;
const bool isForSchedule = false;
bool hasTestBeenSuccessful = false;
BOOST_CHECK_NO_THROW (hasTestBeenSuccessful =
testInventoryHelper (1, " ", " ", " ", " ", " ", " ",
isBuiltin, isForSchedule));
BOOST_CHECK_EQUAL (hasTestBeenSuccessful, true);
}
BOOST_AUTO_TEST_CASE (airinv_simple_inventory_sell_schedule) {
"/schedule01.csv");
"/ond01.csv");
"/frat5.csv");
"/ffDisutility.csv");
"/yieldstore01.csv");
const bool isBuiltin = false;
const bool isForSchedule = true;
bool hasTestBeenSuccessful = false;
BOOST_CHECK_NO_THROW (hasTestBeenSuccessful =
testInventoryHelper (2, " ",
lScheduleInputFilename,
lODInputFilename,
lFRAT5InputFilename,
lFFDisutilityInputFilename,
lYieldInputFilename,
isBuiltin, isForSchedule));
BOOST_CHECK_EQUAL (hasTestBeenSuccessful, true);
}
BOOST_AUTO_TEST_CASE (airinv_error_inventory_input_file) {
"/missingFile.csv");
const bool isBuiltin = false;
const bool isForSchedule = false;
BOOST_CHECK_THROW (testInventoryHelper (3, lMissingInventoryFilename,
" ", " ", " ", " ", " ", isBuiltin, isForSchedule),
}
BOOST_AUTO_TEST_CASE (airinv_error_schedule_input_file) {
"/missingFile.csv");
"/frat5.csv");
"/ffDisutility.csv");
const bool isBuiltin = false;
const bool isForSchedule = true;
BOOST_CHECK_THROW (testInventoryHelper (4, " ", lMissingScheduleFilename,
" ", lFRAT5InputFilename,
lFFDisutilityInputFilename, " ",
isBuiltin, isForSchedule),
}
BOOST_AUTO_TEST_CASE (airinv_error_yield_input_file) {
"/schedule01.csv");
"/ond01.csv");
"/frat5.csv");
"/ffDisutility.csv");
"/missingFile.csv");
const bool isBuiltin = false;
const bool isForSchedule = true;
BOOST_CHECK_THROW (testInventoryHelper (5, " ",
lScheduleInputFilename,
lODInputFilename,
lFRAT5InputFilename,
lFFDisutilityInputFilename,
lYieldInputFilename,
isBuiltin, isForSchedule),
AIRRAC::YieldInputFileNotFoundException);
}
BOOST_AUTO_TEST_CASE (airinv_error_flight_date_duplication) {
"/scheduleError01.csv");
"/ond01.csv");
"/frat5.csv");
"/ffDisutility.csv");
"/missingFile.csv");
const bool isBuiltin = false;
const bool isForSchedule = true;
BOOST_CHECK_THROW (testInventoryHelper (6, " ",
lScheduleInputFilename,
lODInputFilename,
lFRAT5InputFilename,
lFFDisutilityInputFilename,
lYieldInputFilename,
isBuiltin, isForSchedule),
}
BOOST_AUTO_TEST_CASE (airinv_error_schedule_parsing_failed) {
"/scheduleError02.csv");
"/ond01.csv");
"/frat5.csv");
"/ffDisutility.csv");
"/yieldstore01.csv");
const bool isBuiltin = false;
const bool isForSchedule = true;
BOOST_CHECK_THROW (testInventoryHelper (7, " ",
lScheduleInputFilename,
lODInputFilename,
lFRAT5InputFilename,
lFFDisutilityInputFilename,
lYieldInputFilename,
isBuiltin, isForSchedule),
}
BOOST_AUTO_TEST_SUITE_END()