Search in sources :

Example 1 with TestsigmaTestdataNotFoundException

use of com.testsigma.automator.exceptions.TestsigmaTestdataNotFoundException in project testsigma by testsigmahq.

the class WebserviceUtil method execute.

public void execute(TestCaseStepEntity testcaseStep, TestCaseStepResult result, Map<String, String> envSettings, TestCaseResult testCaseResult) throws TestsigmaTestdataNotFoundException {
    log.debug("Executing Rest step:" + testcaseStep);
    RestfulStepEntity entity = new ObjectMapper().convertValue(testcaseStep.getAdditionalData().get(TestCaseStepEntity.REST_DETAILS_KEY), RestfulStepEntity.class);
    result.setResult(ResultConstant.SUCCESS);
    try {
        log.debug("Updating Rest step variables for RestStepEntity:" + entity);
        new RestAPIRunTimeDataProcessor(entity, result).processRestAPIStep();
        initializeHttpClient(entity);
        Map<String, String> headers = fetchHeadersFromRestStep(entity);
        setAuthorizationHeaders(entity, headers);
        setDefaultHeaders(entity, headers);
        entity.setUrl(entity.getUrl().replace("\\", "/"));
        HttpResponse<String> response = executeRestCall(entity.getUrl(), RequestMethod.valueOf(entity.getMethod().toUpperCase()), headers, getEntity(entity, envSettings, headers));
        log.debug("Rest Url - " + entity.getUrl() + " Method " + entity.getMethod().toUpperCase() + " Headers - " + new ObjectMapperService().convertToJson(headers) + " PayLoad - " + entity.getPayload());
        result.getMetadata().setReqEntity(entity);
        log.debug("Method - " + entity.getMethod().toUpperCase() + "response - " + new ObjectMapperService().convertToJson(response));
        ((Map<String, Object>) (testcaseStep.getAdditionalData().get(TestCaseStepEntity.REST_DETAILS_KEY))).put("url", entity.getUrl());
        WebserviceResponse resObj = new WebserviceResponse();
        resObj.setStatus(response.getStatusCode());
        if (entity.getStoreMetadata()) {
            resObj.setContent(response.getResponseText());
            resObj.setHeaders(response.getHeadersMap());
        }
        result.getMetadata().setRestResult(resObj);
        new RestApiResponseValidator(entity, result, response).validateResponse();
        new RestAPIRunTimeDataProcessor(entity, result).storeResponseData(response);
    } catch (Exception e) {
        log.error("Error while executing Rest Step:" + testcaseStep, e);
        String genericExceptionMessage = getExceptionSpecificMessage(e, result);
        result.setResult(ResultConstant.FAILURE);
        result.setMessage(genericExceptionMessage);
    }
    log.debug("Test Step Result :: " + new ObjectMapperService().convertToJson(result));
}
Also used : ObjectMapperService(com.testsigma.automator.service.ObjectMapperService) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ProtocolException(org.apache.http.ProtocolException) ClientProtocolException(org.apache.http.client.ClientProtocolException) TestsigmaTestdataNotFoundException(com.testsigma.automator.exceptions.TestsigmaTestdataNotFoundException) IOException(java.io.IOException) TestsigmaFileNotFoundException(com.testsigma.automator.exceptions.TestsigmaFileNotFoundException) UnknownHostException(java.net.UnknownHostException) CircularRedirectException(org.apache.http.client.CircularRedirectException) PathNotFoundException(com.jayway.jsonpath.PathNotFoundException)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 PathNotFoundException (com.jayway.jsonpath.PathNotFoundException)1 TestsigmaFileNotFoundException (com.testsigma.automator.exceptions.TestsigmaFileNotFoundException)1 TestsigmaTestdataNotFoundException (com.testsigma.automator.exceptions.TestsigmaTestdataNotFoundException)1 ObjectMapperService (com.testsigma.automator.service.ObjectMapperService)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ProtocolException (org.apache.http.ProtocolException)1 CircularRedirectException (org.apache.http.client.CircularRedirectException)1 ClientProtocolException (org.apache.http.client.ClientProtocolException)1