*/
#include <sstream>
#include <fstream>
#include <string>
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN
#define BOOST_TEST_MODULE TravelCCMTest
#include <boost/test/unit_test.hpp>
#include <stdair/basic/BasLogParams.hpp>
#include <stdair/basic/BasDBParams.hpp>
#include <stdair/basic/BasFileMgr.hpp>
#include <stdair/basic/PassengerChoiceModel.hpp>
#include <stdair/bom/TravelSolutionStruct.hpp>
#include <stdair/bom/BookingRequestStruct.hpp>
#include <stdair/service/Logger.hpp>
#include <travelccm/config/travelccm-paths.hpp>
namespace boost_utf = boost::unit_test;
std::ofstream utfReportStream ("TravelChoiceTestSuite_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() {
  }
};
void testTravelCCMHelper (const unsigned short iTestFlag,
                          const stdair::PassengerChoiceModel::EN_PassengerChoiceModel& iPassengerChoiceModel,
                          const unsigned int iExpectedPrice) {
  
  std::ostringstream oStr;
  oStr << "TravelChoiceTestSuite_" << iTestFlag << ".log";
  const stdair::Filename_T lLogFilename (oStr.str());
    
  
  std::ofstream logOutputFile;
  
  logOutputFile.open (lLogFilename.c_str());
  logOutputFile.clear();
  
  
  const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
  
  
  travelccmService.buildSampleBom ();
  
  STDAIR_LOG_DEBUG ("Welcome to TravelCCM");
  
  const stdair::BookingRequestStruct& lBookingRequest =
    travelccmService.buildSampleBookingRequest();
  
  STDAIR_LOG_DEBUG ("Booking request: " << lBookingRequest.display());
  
  stdair::TravelSolutionList_T lTSList;
  travelccmService.buildSampleTravelSolutions (lTSList);
  
  const std::string& lCSVDump = travelccmService.csvDisplay (lTSList);
  STDAIR_LOG_DEBUG (lCSVDump);
  
  
  const stdair::TravelSolutionStruct* lTS_ptr =
    travelccmService.chooseTravelSolution (lTSList, lBookingRequest, iPassengerChoiceModel);
  
  BOOST_REQUIRE_MESSAGE (lTS_ptr != NULL,
                         "No travel solution can be found for "
                         << lBookingRequest.display()
                         << " within the following list of travel solutions. "
                         << lCSVDump);
  STDAIR_LOG_DEBUG (lTS_ptr->describe());
  
  stdair::FareOptionStruct lFareOption = lTS_ptr->getChosenFareOption();
  
  std::ostringstream oMessageExpectedPrice;
  oMessageExpectedPrice << "The price chosen by the passenger is: "
                        << lFareOption.getFare() << " Euros. It is expected to be "
                        << iExpectedPrice << " Euros.";
  STDAIR_LOG_DEBUG (oMessageExpectedPrice.str());
  
  BOOST_CHECK_EQUAL (std::floor (lFareOption.getFare() + 0.5), iExpectedPrice);
  BOOST_CHECK_MESSAGE (std::floor (lFareOption.getFare() + 0.5)
                       == iExpectedPrice, oMessageExpectedPrice.str());
  
  logOutputFile.close();
}
BOOST_GLOBAL_FIXTURE (UnitTestConfig);
BOOST_AUTO_TEST_SUITE (master_test_suite)
BOOST_AUTO_TEST_CASE (simple_hard_restriction_model_test) {
  const unsigned int lExpectedPrice = 1000;
  
  BOOST_CHECK_NO_THROW (testTravelCCMHelper
                        (0,
                         stdair::PassengerChoiceModel::HARD_RESTRICTION,
                         lExpectedPrice));
}
BOOST_AUTO_TEST_CASE (simple_price_oriented_model_test) {
  const unsigned int lExpectedPrice = 900;
  
  BOOST_CHECK_NO_THROW (testTravelCCMHelper
                        (1,
                         stdair::PassengerChoiceModel::PRICE_ORIENTED,
                         lExpectedPrice));
}
BOOST_AUTO_TEST_CASE (simple_hybrid_model_test) {
  const unsigned int lExpectedPrice = 920;
  
  BOOST_CHECK_NO_THROW (testTravelCCMHelper
                        (2,
                         stdair::PassengerChoiceModel::HYBRID,
                         lExpectedPrice));
}
BOOST_AUTO_TEST_SUITE_END()