use of com.testsigma.automator.service.ObjectMapperService in project testsigma by testsigmahq.
the class RestAPIRunTimeDataProcessor method storeRuntimeVariblesJsonPath.
private void storeRuntimeVariblesJsonPath(String expectedStr, String actualStr) throws AutomatorException {
if (StringUtils.isNotBlank(expectedStr) && StringUtils.isNotBlank(actualStr)) {
boolean jsonPathValidationsFailed = false;
List<String> failedJsonPathsList = new ArrayList<>();
Map<String, String> pathMap = new ObjectMapperService().parseJson(expectedStr, new TypeReference<>() {
});
for (Map.Entry<String, String> map : pathMap.entrySet()) {
String name = map.getKey();
String path = map.getValue();
Object pathResult;
try {
if (path.equals(JSON_PATH_ALL)) {
pathResult = actualStr;
} else {
pathResult = JsonPath.parse(actualStr).read(path);
}
new RuntimeDataProvider().storeRuntimeVariable(name, pathResult.toString());
} catch (PathNotFoundException e) {
jsonPathValidationsFailed = true;
failedJsonPathsList.add(path);
log.error("JSON Path Error while saving response to runtime variable.", e);
}
}
if (jsonPathValidationsFailed) {
throw new AutomatorException(String.format(MSG_REST_RESPONSE_JSON_PATH_NOT_EXIST, failedJsonPathsList));
}
}
}
use of com.testsigma.automator.service.ObjectMapperService in project testsigma by testsigmahq.
the class RestApiResponseValidator method validateJsonPath.
private void validateJsonPath(String expectedStr, String actualStr, String msg) throws AutomatorException {
if (StringUtils.isNotBlank(expectedStr)) {
Map<String, String> expectedMap = new ObjectMapperService().parseJson(expectedStr, new TypeReference<>() {
});
for (Map.Entry<String, String> map : expectedMap.entrySet()) {
String path = map.getKey();
String value = map.getValue();
Object pathResult;
try {
pathResult = JsonPath.parse(actualStr).read(path);
} catch (PathNotFoundException e) {
log.error("JSON Path Error while validating response .", e);
throw new AutomatorException(String.format(MSG_REST_RESPONSE_JSON_PATH_NOT_EXIST, path));
}
String pathResultStr;
StringBuilder sb = (testCaseStepResult.getMessage() != null) ? new StringBuilder(testCaseStepResult.getMessage()).append(AutomatorMessages.MSG_SEPARATOR) : new StringBuilder();
if (pathResult instanceof String || pathResult instanceof Number) {
pathResultStr = pathResult.toString();
if (!value.equals(pathResultStr)) {
msg = sb.append(msg).append(AutomatorMessages.MSG_SEPARATOR).append(AutomatorMessages.getMessage(AutomatorMessages.MSG_REST_ERROR_PATH, path)).toString();
testCaseStepResult.setResult(ResultConstant.FAILURE);
testCaseStepResult.setMessage(msg);
}
} else {
pathResultStr = new ObjectMapperService().convertToJson(pathResult);
if (!value.equals(pathResultStr)) {
new ObjectMapperService().parseJson(pathResultStr, Object.class);
validateJson(pathResultStr, value, JSONCompareMode.STRICT.name(), msg);
}
}
}
}
}
use of com.testsigma.automator.service.ObjectMapperService in project testsigma by testsigmahq.
the class RestApiResponseValidator method validateResponse.
public void validateResponse() throws AutomatorException {
List<Integer> compareTypes = restfulStepEntity.getResultCompareTypes();
Integer responseStatus = restApiResponse.getStatusCode();
String responseStr = restApiResponse.getResponseText();
Map<String, String> responseHeadersMap = restApiResponse.getHeadersMap();
String responseHeaders = new ObjectMapperService().convertToJson(responseHeadersMap);
validateStatus(restfulStepEntity, responseStatus);
validateHeaders(restfulStepEntity.getResponseHeaders(), responseHeaders);
validateResponseBody(restfulStepEntity.getResponse(), responseStr, restfulStepEntity.getResponseCompareType(), AutomatorMessages.MSG_REST_ERROR_CONTENT);
}
use of com.testsigma.automator.service.ObjectMapperService in project testsigma by testsigmahq.
the class RestAPIRunTimeDataProcessor method storeResponseData.
public void storeResponseData(HttpResponse<String> response) throws AutomatorException {
String responseStr = response.getResponseText();
Map<String, String> responseHeadersMap = response.getHeadersMap();
String responseHeaders = new ObjectMapperService().convertToJson(responseHeadersMap);
storeRuntimeVariblesJsonPath(restfulStepEntity.getHeaderRuntimeData(), responseHeaders);
storeRuntimeVariblesJsonPath(restfulStepEntity.getBodyRuntimeData(), responseStr);
}
use of com.testsigma.automator.service.ObjectMapperService in project testsigma by testsigmahq.
the class WebserviceUtil method setAuthorizationHeaders.
private void setAuthorizationHeaders(RestfulStepEntity entity, Map<String, String> headers) {
log.debug("Set Authorization headers for entity:" + entity);
log.debug("Set Authorization headers ,headers:" + headers);
if (entity.getAuthorizationType() != null) {
headers = (headers != null) ? headers : new HashMap<>();
Map<String, String> info = new ObjectMapperService().parseJson(entity.getAuthorizationValue(), new TypeReference<>() {
});
if (AuthorizationTypes.BASIC == entity.getAuthorizationType()) {
headers.put(HttpHeaders.AUTHORIZATION, com.testsigma.automator.http.HttpClient.BASIC_AUTHORIZATION + " " + encodedCredentials(info.get("username") + ":" + info.get("password")));
} else if (entity.getAuthorizationType() == AuthorizationTypes.BEARER) {
headers.put("Authorization", "Bearer " + info.get("Bearertoken"));
}
}
}
Aggregations