예제 #1
0
  private HttpResponseBean buildHttpResponseBean(
      HttpResponse httpResponse, String response, Date requestTime, Date responseTime) {

    HttpResponseBean httpResponseBean = new HttpResponseBean();

    Header[] headersArray = httpResponse.getAllHeaders();
    Map<String, String> headersMap = new HashMap<String, String>();
    for (Header header : headersArray) {
      String[] headerAttributes = header.toString().split(": ");
      headersMap.put(headerAttributes[0], headerAttributes[1].replace("\r\n", ""));
    }
    httpResponseBean.setResponseHeaders(headersMap);

    httpResponseBean.setHttpStatusCode(httpResponse.getStatusLine().getStatusCode());
    httpResponseBean.setHttpStatusText(httpResponse.getStatusLine().getReasonPhrase());

    httpResponseBean.setRequestTime(new Timestamp(requestTime.getTime()));
    httpResponseBean.setResponseTime(new Timestamp(responseTime.getTime()));

    if ((response != null) && (!response.equalsIgnoreCase(""))) {
      httpResponseBean.setResponseObject(response);
    } else {
      httpResponseBean.setResponseObject(null);
    }

    return httpResponseBean;
  }
    public void buildCalls(CougarMessageContentTypeEnum responseContentTypeEnum) {

      for (int i = 0; i < numberOfRequests + 1; i++) {
        // Setup call beans
        HttpCallBean callBean = new HttpCallBean();
        callBean.setServiceName("baseline", "cougarBaseline");
        callBean.setVersion("v2");
        callBean.setOperationName("testParameterStylesQA");

        Map<String, String> headerParams = new HashMap<String, String>();
        headerParams.put("headerParam", "Foo");
        callBean.setHeaderParams(headerParams);

        Map<String, String> queryParams = new HashMap<String, String>();
        String queryParameter = "queryParameter-" + identifier + "-" + i;
        queryParams.put("queryParam", queryParameter);
        String dateQueryParameter = "2009-06-01T13:50:00.0Z";
        queryParams.put("dateQueryParam", dateQueryParameter);
        callBean.setQueryParams(queryParams);

        httpCallBeans.add(callBean);

        Map<String, String> acceptProtocols = new HashMap<String, String>();
        switch (responseContentTypeEnum) {
          case JSON:
            acceptProtocols.put("application/json", "");
            break;
          case XML:
            acceptProtocols.put("application/xml", "");
            break;
        }
        callBean.setAcceptProtocols(acceptProtocols);

        // Store expected responses
        HttpResponseBean responseBean = new HttpResponseBean();
        String responseXmlString =
            "<SimpleResponse><message>headerParam=Foo,queryParam="
                + queryParameter
                + ",dateQueryParam=Mon Jun 01 13:50:00 UTC 2009</message></SimpleResponse>";
        Document responseBaseObject = xHelpers.getXMLObjectFromString(responseXmlString);
        Map<CougarMessageProtocolRequestTypeEnum, Object> builtExpectedResponse =
            cougarManager.convertResponseToRestTypes(responseBaseObject, callBean);
        switch (responseContentTypeEnum) {
          case XML:
            responseBean.setResponseObject(
                builtExpectedResponse.get(CougarMessageProtocolRequestTypeEnum.RESTXML));
            break;
          case JSON:
            responseBean.setResponseObject(
                builtExpectedResponse.get(CougarMessageProtocolRequestTypeEnum.RESTJSON));
            break;
        }
        responseBean.setHttpStatusCode(OK_STATUS_CODE);
        responseBean.setHttpStatusText("OK");

        expectedResponses.put(identifier + RESPONSE + i, responseBean);
      }
    }
    public void buildCalls(CougarMessageContentTypeEnum responseContentTypeEnum) {

      for (int i = 0; i < numberOfRequests + 1; i++) {
        // Setup call beans
        HttpCallBean callBean = new HttpCallBean();
        callBean.setServiceName("baseline", "cougarBaseline");
        callBean.setVersion("v2");
        callBean.setOperationName("testComplexMutator", "complex");

        Map<String, String> acceptProtocols = new HashMap<String, String>();
        switch (responseContentTypeEnum) {
          case JSON:
            acceptProtocols.put("application/json", "");
            break;
          case XML:
            acceptProtocols.put("application/xml", "");
            break;
        }
        callBean.setAcceptProtocols(acceptProtocols);

        String requestXmlString = "";
        requestXmlString =
            "<message><name>sum</name><value1> "
                + i
                + "</value1><value2>"
                + i
                + "</value2></message>";
        Document requestDocument = xHelpers.getXMLObjectFromString(requestXmlString);
        callBean.setRestPostQueryObjects(requestDocument);
        httpCallBeans.add(callBean);

        // Store expected responses
        HttpResponseBean responseBean = new HttpResponseBean();
        String responseXmlString =
            "<SimpleResponse><message>sum = " + i * 2 + "</message></SimpleResponse>";
        Document responseBaseObject = xHelpers.getXMLObjectFromString(responseXmlString);
        Map<CougarMessageProtocolRequestTypeEnum, Object> builtExpectedResponse =
            cougarManager.convertResponseToRestTypes(responseBaseObject, callBean);
        switch (responseContentTypeEnum) {
          case XML:
            responseBean.setResponseObject(
                builtExpectedResponse.get(CougarMessageProtocolRequestTypeEnum.RESTXML));
            break;
          case JSON:
            responseBean.setResponseObject(
                builtExpectedResponse.get(CougarMessageProtocolRequestTypeEnum.RESTJSON));
            break;
        }
        responseBean.setHttpStatusCode(OK_STATUS_CODE);
        responseBean.setHttpStatusText("OK");

        expectedResponses.put(identifier + RESPONSE + i, responseBean);
      }
    }