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));
}
Aggregations