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); } }
@Test public void doTest() throws Exception { // Set up the Http Call Bean to make the request CougarManager cougarManager1 = CougarManager.getInstance(); HttpCallBean getNewHttpCallBean1 = cougarManager1.getNewHttpCallBean("87.248.113.14"); cougarManager1 = cougarManager1; getNewHttpCallBean1.setOperationName("testParameterStylesQA"); getNewHttpCallBean1.setServiceName("baseline", "cougarBaseline"); getNewHttpCallBean1.setVersion("v2"); Map map2 = new HashMap(); map2.put("HeaderParam", "Foo"); getNewHttpCallBean1.setHeaderParams(map2); // Set the query parameter to a string containing encoded : Map map3 = new HashMap(); map3.put("queryParam", "colon%3A"); map3.put("dateQueryParam", "2009-06-01T13:50:00.0Z"); getNewHttpCallBean1.setQueryParams(map3); CougarHelpers cougarHelpers4 = new CougarHelpers(); Date convertedDate1 = cougarHelpers4.convertToSystemTimeZone("2009-06-01T13:50:00.0Z"); // Get current time for getting log entries later Timestamp getTimeAsTimeStamp8 = new Timestamp(System.currentTimeMillis()); // Make the 4 REST calls to the operation cougarManager1.makeRestCougarHTTPCalls(getNewHttpCallBean1); // Create the expected response as an XML document XMLHelpers xMLHelpers6 = new XMLHelpers(); Document createAsDocument10 = xMLHelpers6.createAsDocument( DocumentBuilderFactory.newInstance() .newDocumentBuilder() .parse( new ByteArrayInputStream( ("<SimpleResponse><message>headerParam=Foo,queryParam=colon:,dateQueryParam=" + cougarHelpers4.dateInUTC(convertedDate1) + "</message></SimpleResponse>") .getBytes()))); // Convert the expected response to REST types for comparison with actual responses Map<CougarMessageProtocolRequestTypeEnum, Object> convertResponseToRestTypes11 = cougarManager1.convertResponseToRestTypes(createAsDocument10, getNewHttpCallBean1); // Check the 4 responses are as expected HttpResponseBean response7 = getNewHttpCallBean1.getResponseObjectsByEnum( com.betfair.testing.utils.cougar.enums.CougarMessageProtocolResponseTypeEnum .RESTXMLXML); AssertionUtils.multiAssertEquals( convertResponseToRestTypes11.get(CougarMessageProtocolRequestTypeEnum.RESTXML), response7.getResponseObject()); AssertionUtils.multiAssertEquals((int) 200, response7.getHttpStatusCode()); AssertionUtils.multiAssertEquals("OK", response7.getHttpStatusText()); HttpResponseBean response8 = getNewHttpCallBean1.getResponseObjectsByEnum( com.betfair.testing.utils.cougar.enums.CougarMessageProtocolResponseTypeEnum .RESTJSONJSON); AssertionUtils.multiAssertEquals( convertResponseToRestTypes11.get(CougarMessageProtocolRequestTypeEnum.RESTJSON), response8.getResponseObject()); AssertionUtils.multiAssertEquals((int) 200, response8.getHttpStatusCode()); AssertionUtils.multiAssertEquals("OK", response8.getHttpStatusText()); HttpResponseBean response9 = getNewHttpCallBean1.getResponseObjectsByEnum( com.betfair.testing.utils.cougar.enums.CougarMessageProtocolResponseTypeEnum .RESTXMLJSON); AssertionUtils.multiAssertEquals( convertResponseToRestTypes11.get(CougarMessageProtocolRequestTypeEnum.RESTJSON), response9.getResponseObject()); AssertionUtils.multiAssertEquals((int) 200, response9.getHttpStatusCode()); AssertionUtils.multiAssertEquals("OK", response9.getHttpStatusText()); HttpResponseBean response10 = getNewHttpCallBean1.getResponseObjectsByEnum( com.betfair.testing.utils.cougar.enums.CougarMessageProtocolResponseTypeEnum .RESTJSONXML); AssertionUtils.multiAssertEquals( convertResponseToRestTypes11.get(CougarMessageProtocolRequestTypeEnum.RESTXML), response10.getResponseObject()); AssertionUtils.multiAssertEquals((int) 200, response10.getHttpStatusCode()); AssertionUtils.multiAssertEquals("OK", response10.getHttpStatusText()); // generalHelpers.pauseTest(500L); // Check the log entries are as expected cougarManager1.verifyRequestLogEntriesAfterDate( getTimeAsTimeStamp8, new RequestLogRequirement("2.8", "testParameterStylesQA"), new RequestLogRequirement("2.8", "testParameterStylesQA"), new RequestLogRequirement("2.8", "testParameterStylesQA"), new RequestLogRequirement("2.8", "testParameterStylesQA")); }
@Test public void doTest() throws Exception { // Create the HttpCallBean CougarManager cougarManager1 = CougarManager.getInstance(); HttpCallBean httpCallBeanBaseline = cougarManager1.getNewHttpCallBean(); CougarManager cougarManagerBaseline = cougarManager1; // Get the cougar logging attribute for getting log entries later // Point the created HttpCallBean at the correct service httpCallBeanBaseline.setServiceName("baseline", "cougarBaseline"); httpCallBeanBaseline.setVersion("v2"); // Set up the Http Call Bean to make the request CougarManager cougarManager2 = CougarManager.getInstance(); HttpCallBean getNewHttpCallBean2 = cougarManager2.getNewHttpCallBean("87.248.113.14"); cougarManager2 = cougarManager2; cougarManager2.setCougarFaultControllerJMXMBeanAttrbiute("DetailedFaults", "false"); getNewHttpCallBean2.setOperationName("i32Operation"); getNewHttpCallBean2.setServiceName("baseline", "cougarBaseline"); getNewHttpCallBean2.setVersion("v2"); // Set the Integer header parameter to an out of range Integer Map map3 = new HashMap(); map3.put("HeaderParam", "21474836470"); getNewHttpCallBean2.setHeaderParams(map3); Map map4 = new HashMap(); map4.put("queryParam", "43523434"); getNewHttpCallBean2.setQueryParams(map4); getNewHttpCallBean2.setRestPostQueryObjects( DocumentBuilderFactory.newInstance() .newDocumentBuilder() .parse( new ByteArrayInputStream( "<message><bodyParameter>-50</bodyParameter></message>".getBytes()))); // Get current time for getting log entries later Timestamp getTimeAsTimeStamp11 = new Timestamp(System.currentTimeMillis()); // Make the 4 REST calls to the operation cougarManager2.makeRestCougarHTTPCalls(getNewHttpCallBean2); // Create the expected response as an XML document (Fault) XMLHelpers xMLHelpers6 = new XMLHelpers(); Document createAsDocument13 = xMLHelpers6.getXMLObjectFromString( "<fault><faultcode>Client</faultcode><faultstring>DSC-0009</faultstring><detail/></fault>"); // Convert the expected response to REST types for comparison with actual responses Map<CougarMessageProtocolRequestTypeEnum, Object> convertResponseToRestTypes14 = cougarManager2.convertResponseToRestTypes(createAsDocument13, getNewHttpCallBean2); // Check the 4 responses are as expected (Bad Request) HttpResponseBean response7 = getNewHttpCallBean2.getResponseObjectsByEnum( com.betfair.testing.utils.cougar.enums.CougarMessageProtocolResponseTypeEnum .RESTXMLXML); AssertionUtils.multiAssertEquals( convertResponseToRestTypes14.get(CougarMessageProtocolRequestTypeEnum.RESTXML), response7.getResponseObject()); AssertionUtils.multiAssertEquals((int) 400, response7.getHttpStatusCode()); AssertionUtils.multiAssertEquals("Bad Request", response7.getHttpStatusText()); HttpResponseBean response8 = getNewHttpCallBean2.getResponseObjectsByEnum( com.betfair.testing.utils.cougar.enums.CougarMessageProtocolResponseTypeEnum .RESTJSONJSON); AssertionUtils.multiAssertEquals( convertResponseToRestTypes14.get(CougarMessageProtocolRequestTypeEnum.RESTJSON), response8.getResponseObject()); AssertionUtils.multiAssertEquals((int) 400, response8.getHttpStatusCode()); AssertionUtils.multiAssertEquals("Bad Request", response8.getHttpStatusText()); HttpResponseBean response9 = getNewHttpCallBean2.getResponseObjectsByEnum( com.betfair.testing.utils.cougar.enums.CougarMessageProtocolResponseTypeEnum .RESTXMLJSON); AssertionUtils.multiAssertEquals( convertResponseToRestTypes14.get(CougarMessageProtocolRequestTypeEnum.RESTJSON), response9.getResponseObject()); AssertionUtils.multiAssertEquals((int) 400, response9.getHttpStatusCode()); AssertionUtils.multiAssertEquals("Bad Request", response9.getHttpStatusText()); HttpResponseBean response10 = getNewHttpCallBean2.getResponseObjectsByEnum( com.betfair.testing.utils.cougar.enums.CougarMessageProtocolResponseTypeEnum .RESTJSONXML); AssertionUtils.multiAssertEquals( convertResponseToRestTypes14.get(CougarMessageProtocolRequestTypeEnum.RESTXML), response10.getResponseObject()); AssertionUtils.multiAssertEquals((int) 400, response10.getHttpStatusCode()); AssertionUtils.multiAssertEquals("Bad Request", response10.getHttpStatusText()); // Check the log entries are as expected CougarManager cougarManager12 = CougarManager.getInstance(); cougarManager12.verifyAccessLogEntriesAfterDate( getTimeAsTimeStamp11, new AccessLogRequirement("87.248.113.14", "/cougarBaseline/v2/i32Operation", "BadRequest"), new AccessLogRequirement("87.248.113.14", "/cougarBaseline/v2/i32Operation", "BadRequest"), new AccessLogRequirement("87.248.113.14", "/cougarBaseline/v2/i32Operation", "BadRequest"), new AccessLogRequirement("87.248.113.14", "/cougarBaseline/v2/i32Operation", "BadRequest")); }
@Test public void doTest() throws Exception { // Create the HttpCallBean CougarManager cougarManager1 = CougarManager.getInstance(); HttpCallBean httpCallBeanBaseline = cougarManager1.getNewHttpCallBean(); CougarManager cougarManagerBaseline = cougarManager1; // Get the cougar logging attribute for getting log entries later // Point the created HttpCallBean at the correct service httpCallBeanBaseline.setServiceName("baseline", "cougarBaseline"); httpCallBeanBaseline.setVersion("v2"); // Set up the Http Call Bean to make the request CougarManager cougarManager2 = CougarManager.getInstance(); HttpCallBean getNewHttpCallBean2 = cougarManager2.getNewHttpCallBean("87.248.113.14"); cougarManager2 = cougarManager2; cougarManager2.setCougarFaultControllerJMXMBeanAttrbiute("DetailedFaults", "false"); getNewHttpCallBean2.setOperationName("floatOperation"); getNewHttpCallBean2.setServiceName("baseline", "cougarBaseline"); getNewHttpCallBean2.setVersion("v2"); Map map3 = new HashMap(); map3.put("HeaderParam", "5.43"); getNewHttpCallBean2.setHeaderParams(map3); Map map4 = new HashMap(); map4.put("queryParam", "3455.54"); getNewHttpCallBean2.setQueryParams(map4); // Set the Float body parameter as a non Float getNewHttpCallBean2.setRestPostQueryObjects( DocumentBuilderFactory.newInstance() .newDocumentBuilder() .parse( new ByteArrayInputStream( "<message><bodyParameter>dfdsfsf</bodyParameter></message>".getBytes()))); // Get current time for getting log entries later Timestamp getTimeAsTimeStamp11 = new Timestamp(System.currentTimeMillis()); // Make the 4 REST calls to the operation cougarManager2.makeRestCougarHTTPCalls(getNewHttpCallBean2); // Create the expected response to XML requests as an XML document (XML Fault) XMLHelpers xMLHelpers6 = new XMLHelpers(); Document createAsDocument13 = xMLHelpers6.getXMLObjectFromString( "<fault><faultcode>Client</faultcode><faultstring>DSC-0044</faultstring><detail/></fault>"); // Create the expected response to JSON requests as an XML document (JSON Fault) XMLHelpers xMLHelpers7 = new XMLHelpers(); Document createAsDocument14 = xMLHelpers7.getXMLObjectFromString( "<fault><faultcode>Client</faultcode><faultstring>DSC-0044</faultstring><detail/></fault>"); // Convert expected response to XML requests to JSON object JSONHelpers jSONHelpers8 = new JSONHelpers(); JSONObject convertXMLDocumentToJSONObjectRemoveRootElement15 = jSONHelpers8.convertXMLDocumentToJSONObjectRemoveRootElement(createAsDocument13); // Convert expected response to JSON requests to JSON object JSONHelpers jSONHelpers9 = new JSONHelpers(); JSONObject convertXMLDocumentToJSONObjectRemoveRootElement16 = jSONHelpers9.convertXMLDocumentToJSONObjectRemoveRootElement(createAsDocument14); // Check the 4 responses are as expected (Bad Request) HttpResponseBean response10 = getNewHttpCallBean2.getResponseObjectsByEnum( com.betfair.testing.utils.cougar.enums.CougarMessageProtocolResponseTypeEnum .RESTXMLXML); AssertionUtils.multiAssertEquals(createAsDocument13, response10.getResponseObject()); AssertionUtils.multiAssertEquals((int) 400, response10.getHttpStatusCode()); AssertionUtils.multiAssertEquals("Bad Request", response10.getHttpStatusText()); HttpResponseBean response11 = getNewHttpCallBean2.getResponseObjectsByEnum( com.betfair.testing.utils.cougar.enums.CougarMessageProtocolResponseTypeEnum .RESTJSONJSON); AssertionUtils.multiAssertEquals( convertXMLDocumentToJSONObjectRemoveRootElement16, response11.getResponseObject()); AssertionUtils.multiAssertEquals((int) 400, response11.getHttpStatusCode()); AssertionUtils.multiAssertEquals("Bad Request", response11.getHttpStatusText()); HttpResponseBean response12 = getNewHttpCallBean2.getResponseObjectsByEnum( com.betfair.testing.utils.cougar.enums.CougarMessageProtocolResponseTypeEnum .RESTXMLJSON); AssertionUtils.multiAssertEquals( convertXMLDocumentToJSONObjectRemoveRootElement15, response12.getResponseObject()); AssertionUtils.multiAssertEquals((int) 400, response12.getHttpStatusCode()); AssertionUtils.multiAssertEquals("Bad Request", response12.getHttpStatusText()); HttpResponseBean response13 = getNewHttpCallBean2.getResponseObjectsByEnum( com.betfair.testing.utils.cougar.enums.CougarMessageProtocolResponseTypeEnum .RESTJSONXML); AssertionUtils.multiAssertEquals(createAsDocument14, response13.getResponseObject()); AssertionUtils.multiAssertEquals((int) 400, response13.getHttpStatusCode()); AssertionUtils.multiAssertEquals("Bad Request", response13.getHttpStatusText()); // Check the log entries are as expected CougarManager cougarManager15 = CougarManager.getInstance(); cougarManager15.verifyAccessLogEntriesAfterDate( getTimeAsTimeStamp11, new AccessLogRequirement( "87.248.113.14", "/cougarBaseline/v2/floatOperation", "BadRequest"), new AccessLogRequirement( "87.248.113.14", "/cougarBaseline/v2/floatOperation", "BadRequest"), new AccessLogRequirement( "87.248.113.14", "/cougarBaseline/v2/floatOperation", "BadRequest"), new AccessLogRequirement( "87.248.113.14", "/cougarBaseline/v2/floatOperation", "BadRequest")); }