@Test
  public void testThomas1() {
    try {
      RequestParams requestParams =
          JsonUtilities.readFromInputStream(RequestParams.class, "/json/thomas1.json");
      OdigeoRequestBuilder odigeoRequestBuilder = new OdigeoRequestBuilder();
      Map<String, Search> search = odigeoRequestBuilder.buildRequest(requestParams);
      String builtString = JsonUtilities.getGson().toJson(search);

      String savedString = JsonUtilities.inputStreamToString("/json/thomas1Search.json");
      assertEquals(
          savedString.replaceAll("46.31.194.10", ProchainvolUtilities.getMyIPAddress()),
          builtString);

    } catch (Exception e) {
      JunitConstants.reportError(e);
    }
  }
  @Override
  public List<SearchStatusResponse> execService(Map<String, Search> searchList)
      throws ProchainvolException {
    counter = searchList.size();
    try {
      ItinerarySearch itinerarySearch =
          new ItinerarySearch(new URL(Constants.ODIGEO_WSDL_URL), Constants.ODIGEO_SERVICE_NAME);
      ItinerarySearchService service = itinerarySearch.getItinerarySearchServicePort();
      for (Search search : searchList.values()) {
        AsyncHandler<SearchResponse> asyncHandler =
            new AsyncHandler<SearchResponse>() {

              @Override
              public void handleResponse(Response<SearchResponse> res) {
                putResponse(res);
              }
            };
        service.searchAsync(
            search.getPreferences(),
            search.getSearchRequest(),
            search.getMetasearchEngineCode(),
            asyncHandler);
      }
    } catch (MalformedURLException e) {
      logger.error(e);
      throw new ProchainvolException(e);
    }

    while (true) {
      if (isFinished()) {
        break;
      }
    }
    if (exceptions.size() > 0) {
      String mess = "Execution interrompue";
      logger.error(mess, exceptions.get(0));
      throw new ProchainvolException(mess);
    }
    logger.debug("execService response is : " + JsonUtilities.getGsonPretty().toJson(result));
    return result;
  }
public class OdigeoRequestBuilderTest {

  private static RequestParams ONE_MONTH_TOGO_TEST_VALUES;
  final Gson gson = JsonUtilities.getGsonPretty();

  @BeforeClass
  public static void setUpBeforeClass() throws Exception {
    ONE_MONTH_TOGO_TEST_VALUES = TestConstants.oneMonthToGoRequestParamFromJson;
    GregorianCalendar gregorianCalendarForTest =
        new DateTime(ONE_MONTH_TOGO_TEST_VALUES.getDepartureDate()).toGregorianCalendar();
  }

  @AfterClass
  public static void tearDownAfterClass() throws Exception {}

  @Before
  public void setUp() throws Exception {}

  @After
  public void tearDown() throws Exception {}

  @Test
  public void testBuildRequestRequestParams() {
    try {
      RequestBuilderInterface<Search> odigeoRequestBuilder = new OdigeoRequestBuilder();
      RequestParams params = TestConstants.oneMonthToGoRequestParamFromJson;
      Route route = params.getRouteAsList().get(0);
      Map<String, Search> searchList = odigeoRequestBuilder.buildRequest(params);
      Search search = searchList.get(route.getKey());
      String json = gson.toJson(search);
      //			System.out.println(json);
      Search search1 = gson.fromJson(json, Search.class);
      assertEquals(
          search
              .getSearchRequest()
              .getItinerarySearchRequest()
              .getSegmentRequests()
              .get(0)
              .getDate(),
          search1
              .getSearchRequest()
              .getItinerarySearchRequest()
              .getSegmentRequests()
              .get(0)
              .getDate());
      checkPreferences(search);

    } catch (Exception e) {
      JunitConstants.reportError(e);
    }
  }

  @Test
  public void testBuildRequest() {
    try {
      OdigeoRequestBuilder odigeoRequestBuilder = new OdigeoRequestBuilder();
      Search search = odigeoRequestBuilder.buildRequest();
      checkPreferences(search);

    } catch (Exception e) {
      JunitConstants.reportError(e);
    }
  }

  @Test
  public void testSerializeDeserializeSearch() {
    try {
      OdigeoRequestBuilder odigeoRequestBuilder = new OdigeoRequestBuilder();
      Search search = odigeoRequestBuilder.buildRequest();
      checkPreferences(search);
      String json = gson.toJson(search);
      Search search1 = gson.fromJson(json, Search.class);
      String json1 = gson.toJson(search1);
      System.out.println(json);
      assertEquals(json, json1);
      XMLGregorianCalendar date =
          search
              .getSearchRequest()
              .getItinerarySearchRequest()
              .getSegmentRequests()
              .get(0)
              .getDate();
      XMLGregorianCalendar date1 =
          search1
              .getSearchRequest()
              .getItinerarySearchRequest()
              .getSegmentRequests()
              .get(0)
              .getDate();
      System.out.println(date);
      System.out.println(date1);
      assertEquals(date, date1);

    } catch (Exception e) {
      JunitConstants.reportError(e);
    }
  }

  @Test
  public void testThomas1() {
    try {
      RequestParams requestParams =
          JsonUtilities.readFromInputStream(RequestParams.class, "/json/thomas1.json");
      OdigeoRequestBuilder odigeoRequestBuilder = new OdigeoRequestBuilder();
      Map<String, Search> search = odigeoRequestBuilder.buildRequest(requestParams);
      String builtString = JsonUtilities.getGson().toJson(search);

      String savedString = JsonUtilities.inputStreamToString("/json/thomas1Search.json");
      assertEquals(
          savedString.replaceAll("46.31.194.10", ProchainvolUtilities.getMyIPAddress()),
          builtString);

    } catch (Exception e) {
      JunitConstants.reportError(e);
    }
  }

  public void checkPreferences(Search search) {
    PreferencesRequest preferences = search.getPreferences();
    assertEquals(OdigeoRequestBuilder.domainCode, preferences.getDomainCode());
    assertEquals(OdigeoRequestBuilder.locale, preferences.getLocale());
    assertEquals(ProchainvolUtilities.getMyIPAddress(), preferences.getRealUserIP());
    assertEquals(OdigeoRequestBuilder.userAgent, preferences.getUserAgent());

    assertEquals(OdigeoRequestBuilder.metasearchEngineCode, search.getMetasearchEngineCode());

    SearchRequest searchRequest = search.getSearchRequest();
    assertEquals(OdigeoRequestBuilder.maxSize, searchRequest.getMaxSize());

    ItinerarySearchRequest itinerarySearchRequest = searchRequest.getItinerarySearchRequest();
    assertEquals(OdigeoRequestBuilder.cabinClassTourist, itinerarySearchRequest.getCabinClass());

    ItinerarySegmentRequest itinerarySegmentRequest =
        itinerarySearchRequest.getSegmentRequests().get(0);
    assertEquals(
        ONE_MONTH_TOGO_TEST_VALUES.getDepartureAirportIata()[0],
        itinerarySegmentRequest.getDeparture().getIataCode());
    assertEquals(
        ONE_MONTH_TOGO_TEST_VALUES.getArrivalAirportIata()[0],
        itinerarySegmentRequest.getDestination().getIataCode());
    assertEquals(TestConstants.oneMonthToGoMonth + 1, itinerarySegmentRequest.getDate().getMonth());
    assertEquals(TestConstants.oneMonthToGoDayOfMonth, itinerarySegmentRequest.getDate().getDay());
  }
}
 @Override
 public RequestResult call() throws Exception {
   RequestResult response = service.service(params);
   logger.trace("response = " + JsonUtilities.getGsonPretty().toJson(response));
   return response;
 }