use of com.axway.ats.agent.core.templateactions.model.matchers.ResponseMatcher in project ats-framework by Axway.
the class XmlUtilities method verifyResponse.
/**
* Verify the expected and actual responses match
*
* @param expectedHttpResponseObject
* @param currentActionRequestNumber current request/response step in this action/xml (starts from 1)
* @throws Exception
*/
public void verifyResponse(String actionsXml, String actionName, int currentActionRequestNumber, ActionResponseObject expectedHttpResponseObject, HttpClient httpClient, TemplateActionsResponseVerificationConfigurator responseVerificationConfigurator) throws Exception {
ActionParser actualHttpResponse = readActionResponse(httpClient, actionsXml, currentActionRequestNumber, false);
if (HttpClient.log.isTraceEnabled()) {
String causeMsg = "Print response for debugging purposes";
logActualResponse(causeMsg, actionName, currentActionRequestNumber, actualHttpResponse, false);
}
// stepMatchers now are after reading response so not to influence StopWatches
// list with all body matchers
List<ResponseMatcher> stepMatchers = new ArrayList<ResponseMatcher>();
// add all matchers from the XML file
List<XPathBodyMatcher> xpathBodyMatchers = applyUserParameters(expectedHttpResponseObject.getXpathBodyMatchers());
stepMatchers.addAll(xpathBodyMatchers);
// add all matchers from the test case
TemplateActionResponseVerificator responseVerificator = responseVerificationConfigurator.getActionVerificator(actionName);
if (responseVerificator != null) {
// there is a verificator for this action
stepMatchers.addAll(responseVerificator.getStepBodyMatchers(currentActionRequestNumber));
}
try {
// Compare HTTP response code
String expectedResponseResult = expectedHttpResponseObject.getResponseResult();
String actualResponseResult = getFirstChildNode(actualHttpResponse.getActionNodeWithoutBody(), TOKEN_HTTP_RESPONSE_RESULT).getTextContent();
if (!expectedResponseResult.equalsIgnoreCase(actualResponseResult)) {
String causeMsg = "Expected response result '" + expectedResponseResult + "' is different than the actual '" + actualResponseResult + "'.";
logActualResponse(causeMsg, actionName, currentActionRequestNumber, actualHttpResponse, true);
throw new XmlUtilitiesException(causeMsg);
}
// Compare response headers. It extracts any user parameters if present in the headers.
verifyResponseHeaders(actionName, currentActionRequestNumber, expectedHttpResponseObject.getHttpHeaderMatchers(), actualHttpResponse, responseVerificationConfigurator);
// Compare response files
verifyResponseFile(expectedHttpResponseObject, actualHttpResponse.getActionNodeWithoutBody());
if (!stepMatchers.isEmpty()) {
// TODO verify the response body here
}
} finally {
actualHttpResponse.cleanupMembers();
}
log.info(actionName + "[" + currentActionRequestNumber + "] -> " + "Verified HTTP response");
}
use of com.axway.ats.agent.core.templateactions.model.matchers.ResponseMatcher in project ats-framework by Axway.
the class TemplateLoadClient method checkBodyByContainedText.
/**
* Verify the body contains the provided text
*
* @param actionName the name of the action
* @param stepNumber the action step number
* @param searchedText the text to find
* @param isRegEx should searched text be interpreted as RegEx
*/
@PublicAtsApi
public void checkBodyByContainedText(String actionName, int stepNumber, String searchedText, boolean isRegEx) {
List<ResponseMatcher> stepMatchers = getStepBodyMatchers(actionName, stepNumber);
stepMatchers.add(new TextBodyMatcher(searchedText, isRegEx));
}
use of com.axway.ats.agent.core.templateactions.model.matchers.ResponseMatcher in project ats-framework by Axway.
the class TemplateLoadClient method checkBodyNode.
/**
* Verify the value of a specified response body node
*
* @param actionName the name of the action
* @param stepNumber the action step number
* @param nodeXPath XPath specifying the node
* @param valueToMatch the expected value
* @param matchMode the match mode
*
* @throws InvalidMatcherException
*/
@PublicAtsApi
public void checkBodyNode(String actionName, int stepNumber, String nodeXPath, String valueToMatch, TemplateBodyNodeMatchMode matchMode) throws InvalidMatcherException {
List<ResponseMatcher> stepMatchers = getStepBodyMatchers(actionName, stepNumber);
stepMatchers.add(new XPathBodyMatcher(nodeXPath, valueToMatch, matchMode));
}
use of com.axway.ats.agent.core.templateactions.model.matchers.ResponseMatcher in project ats-framework by Axway.
the class TemplateLoadClient method checkBodyForNotContainedText.
/**
* Verify the body DOES NOT contain the provided text
*
* @param actionName the name of the action
* @param stepNumber the action step number
* @param searchedText the text to find
*/
@PublicAtsApi
public void checkBodyForNotContainedText(String actionName, int stepNumber, String searchedText, boolean isRegex) {
List<ResponseMatcher> stepMatchers = getStepBodyMatchers(actionName, stepNumber);
stepMatchers.add(new TextBodyMatcher(searchedText, isRegex, true));
}
Aggregations