*/
#include <sstream>
#include <fstream>
#include <string>
#include <cmath>
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN
#define BOOST_TEST_MODULE CRSTestSuite
#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 <simfqt/SIMFQT_Types.hpp>
namespace boost_utf = boost::unit_test;
std::ofstream utfReportStream ("CRSTestSuite_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() {
}
};
BOOST_GLOBAL_FIXTURE (UnitTestConfig);
BOOST_AUTO_TEST_SUITE (master_test_suite)
BOOST_AUTO_TEST_CASE (simcrs_simple_simulation_test) {
"/rds01/schedule.csv");
"/rds01/yield.csv");
"/rds01/fare.csv");
bool doesExistAndIsReadable =
stdair::BasFileMgr::doesExistAndIsReadable (lScheduleInputFilename);
BOOST_CHECK_MESSAGE (doesExistAndIsReadable == true,
"The '" << lScheduleInputFilename
<< "' input file can not be open and read");
doesExistAndIsReadable =
stdair::BasFileMgr::doesExistAndIsReadable (lOnDInputFilename);
BOOST_CHECK_MESSAGE (doesExistAndIsReadable == true,
"The '" << lOnDInputFilename
<< "' input file can not be open and read");
doesExistAndIsReadable =
stdair::BasFileMgr::doesExistAndIsReadable (lYieldInputFilename);
BOOST_CHECK_MESSAGE (doesExistAndIsReadable == true,
"The '" << lYieldInputFilename
<< "' input file can not be open and read");
doesExistAndIsReadable =
stdair::BasFileMgr::doesExistAndIsReadable (lFareInputFilename);
BOOST_CHECK_MESSAGE (doesExistAndIsReadable == true,
"The '" << lFareInputFilename
<< "' input file can not be open and read");
const stdair::Filename_T lLogFilename ("CRSTestSuite.log");
std::ofstream logOutputFile;
logOutputFile.open (lLogFilename.c_str());
logOutputFile.clear();
const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
const SIMFQT::FareFilePath lFareFilePath (lFareInputFilename);
const AIRRAC::YieldFilePath lYieldFilePath (lYieldInputFilename);
simcrsService.parseAndLoad (lScheduleInputFilename, lOnDInputFilename,
lYieldFilePath, lFareFilePath);
const stdair::AirportCode_T lOrigin ("SIN");
const stdair::AirportCode_T lDestination ("BKK");
const stdair::AirportCode_T lPOS ("SIN");
const stdair::Date_T lPreferredDepartureDate(2011, boost::gregorian::Jan, 31);
const stdair::Date_T lRequestDate (2011, boost::gregorian::Jan, 22);
const stdair::Duration_T lRequestTime (boost::posix_time::hours(10));
const stdair::DateTime_T lRequestDateTime (lRequestDate, lRequestTime);
const stdair::CabinCode_T lPreferredCabin ("Eco");
const stdair::PartySize_T lPartySize (3);
const stdair::ChannelLabel_T lChannel ("IN");
const stdair::TripType_T lTripType ("RI");
const stdair::DayDuration_T lStayDuration (7);
const stdair::FrequentFlyer_T lFrequentFlyerType ("M");
const stdair::Duration_T lPreferredDepartureTime (boost::posix_time::hours(10));
const stdair::WTP_T lWTP (1000.0);
const stdair::PriceValue_T lValueOfTime (100.0);
const stdair::BookingRequestStruct lBookingRequest (lOrigin, lDestination,
lPOS,
lPreferredDepartureDate,
lRequestDateTime,
lPreferredCabin,
lPartySize, lChannel,
lTripType, lStayDuration,
lFrequentFlyerType,
lPreferredDepartureTime,
lWTP, lValueOfTime);
stdair::TravelSolutionList_T lTravelSolutionList =
simcrsService.calculateSegmentPathList (lBookingRequest);
simcrsService.fareQuote (lBookingRequest, lTravelSolutionList);
const unsigned int lNbOfTravelSolutions = lTravelSolutionList.size();
const unsigned int lExpectedNbOfTravelSolutions = 1;
std::ostringstream oMessageKeptTS;
oMessageKeptTS << "The number of travel solutions for the booking request '"
<< lBookingRequest.describe() << "' is actually "
<< lNbOfTravelSolutions << ". That number is expected to be "
<< lExpectedNbOfTravelSolutions << ".";
STDAIR_LOG_DEBUG (oMessageKeptTS.str());
BOOST_CHECK_EQUAL (lNbOfTravelSolutions, lExpectedNbOfTravelSolutions);
BOOST_CHECK_MESSAGE (lNbOfTravelSolutions == lExpectedNbOfTravelSolutions,
oMessageKeptTS.str());
stdair::TravelSolutionStruct& lTravelSolution = lTravelSolutionList.front();
const stdair::FareOptionList_T& lFareOptionList =
lTravelSolution.getFareOptionList();
stdair::FareOptionStruct lFareOption = lFareOptionList.front();
lTravelSolution.setChosenFareOption (lFareOption);
const unsigned int lExpectedPrice = 400;
std::ostringstream oMessageKeptFare;
oMessageKeptFare
<< "The price given by the fare quoter for the booking request: '"
<< lBookingRequest.describe() << "' and travel solution: '"
<< lTravelSolution.describe() << "' is actually " << lFareOption.getFare()
<< " Euros. It is expected to be " << lExpectedPrice << " Euros.";
STDAIR_LOG_DEBUG (oMessageKeptFare.str());
BOOST_CHECK_EQUAL (std::floor (lFareOption.getFare() + 0.5), lExpectedPrice);
BOOST_CHECK_MESSAGE (std::floor (lFareOption.getFare() + 0.5)
== lExpectedPrice, oMessageKeptFare.str());
STDAIR_LOG_DEBUG ("A booking will now (attempted to) be made on the "
"travel solution '" << lTravelSolution.describe()
<< "', for a party size of " << lPartySize << ".");
const bool isSellSuccessful =
simcrsService.sell (lTravelSolution, lPartySize);
std::ostringstream oMessageSell;
const std::string isSellSuccessfulStr = (isSellSuccessful == true)?"Yes":"No";
oMessageSell << "Was the sell successful? Answer: " << isSellSuccessfulStr;
STDAIR_LOG_DEBUG (oMessageSell.str());
BOOST_CHECK_EQUAL (isSellSuccessful, true);
BOOST_CHECK_MESSAGE (isSellSuccessful == true, oMessageSell.str());
logOutputFile.close();
}
BOOST_AUTO_TEST_SUITE_END()