/* * Copyright 2013, The Sporting Exchange Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ // Originally from UpdatedComponentTests/ErrorCodes/Rest/Rest_Get_WotsitExceptions_CLOSED.xls; package com.betfair.cougar.tests.updatedcomponenttests.errorcodes.rest; import com.betfair.testing.utils.cougar.misc.XMLHelpers; import com.betfair.testing.utils.cougar.assertions.AssertionUtils; import com.betfair.testing.utils.cougar.beans.HttpCallBean; import com.betfair.testing.utils.cougar.beans.HttpResponseBean; import com.betfair.testing.utils.cougar.enums.CougarMessageProtocolRequestTypeEnum; import com.betfair.testing.utils.cougar.manager.CougarManager; import org.testng.annotations.Test; import org.w3c.dom.Document; import java.sql.Timestamp; import java.util.HashMap; import java.util.Map; /** * Ensure that Cougar can correctly throw a wotsit exception with error code: CLOSED. */ public class RestGetWotsitExceptionsCLOSEDTest { @Test public void doTest() throws Exception { CougarManager cougarManager1 = CougarManager.getInstance(); HttpCallBean getNewHttpCallBean1 = cougarManager1.getNewHttpCallBean("87.248.113.14"); cougarManager1 = cougarManager1; cougarManager1.setCougarFaultControllerJMXMBeanAttrbiute("DetailedFaults", "false"); // Get the cougar log attribute for getting log entries later getNewHttpCallBean1.setOperationName("testExceptionQA"); getNewHttpCallBean1.setServiceName("baseline", "cougarBaseline"); getNewHttpCallBean1.setVersion("v2"); // Set the query parameter to tell the operation which exception to throw (CLOSED) Map map2 = new HashMap(); map2.put("message","CLOSED"); getNewHttpCallBean1.setQueryParams(map2); // 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 (the required exception) XMLHelpers xMLHelpers4 = new XMLHelpers(); Document createAsDocument10 = xMLHelpers4.getXMLObjectFromString("<fault><faultcode>Client</faultcode><faultstring>WEX-0001</faultstring><detail><exceptionname>WotsitException</exceptionname><WotsitException><errorCode>CLOSED</errorCode><type>SPICY</type><clientMessage>CLOSED</clientMessage></WotsitException></detail></fault>"); // Convert the expected response to the various REST types for comparison Map<CougarMessageProtocolRequestTypeEnum, Object> convertResponseToRestTypes11 = cougarManager1.convertResponseToRestTypes(createAsDocument10, getNewHttpCallBean1); // Check the 4 responses are as expected (correct error returned) HttpResponseBean response5 = getNewHttpCallBean1.getResponseObjectsByEnum(com.betfair.testing.utils.cougar.enums.CougarMessageProtocolResponseTypeEnum.RESTXMLXML); AssertionUtils.multiAssertEquals(convertResponseToRestTypes11.get(CougarMessageProtocolRequestTypeEnum.RESTXML), response5.getResponseObject()); AssertionUtils.multiAssertEquals((int) 403, response5.getHttpStatusCode()); AssertionUtils.multiAssertEquals("Forbidden", response5.getHttpStatusText()); HttpResponseBean response6 = getNewHttpCallBean1.getResponseObjectsByEnum(com.betfair.testing.utils.cougar.enums.CougarMessageProtocolResponseTypeEnum.RESTJSONJSON); AssertionUtils.multiAssertEquals(convertResponseToRestTypes11.get(CougarMessageProtocolRequestTypeEnum.RESTJSON), response6.getResponseObject()); AssertionUtils.multiAssertEquals((int) 403, response6.getHttpStatusCode()); AssertionUtils.multiAssertEquals("Forbidden", response6.getHttpStatusText()); HttpResponseBean response7 = getNewHttpCallBean1.getResponseObjectsByEnum(com.betfair.testing.utils.cougar.enums.CougarMessageProtocolResponseTypeEnum.RESTXMLJSON); AssertionUtils.multiAssertEquals(convertResponseToRestTypes11.get(CougarMessageProtocolRequestTypeEnum.RESTJSON), response7.getResponseObject()); AssertionUtils.multiAssertEquals((int) 403, response7.getHttpStatusCode()); AssertionUtils.multiAssertEquals("Forbidden", response7.getHttpStatusText()); HttpResponseBean response8 = getNewHttpCallBean1.getResponseObjectsByEnum(com.betfair.testing.utils.cougar.enums.CougarMessageProtocolResponseTypeEnum.RESTJSONXML); AssertionUtils.multiAssertEquals(convertResponseToRestTypes11.get(CougarMessageProtocolRequestTypeEnum.RESTXML), response8.getResponseObject()); AssertionUtils.multiAssertEquals((int) 403, response8.getHttpStatusCode()); AssertionUtils.multiAssertEquals("Forbidden", response8.getHttpStatusText()); // Check the log entries are as expected } }