Search in sources :

Example 1 with ResponseMatcher

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");
}
Also used : ActionParser(com.axway.ats.agent.core.templateactions.model.objects.ActionParser) ResponseMatcher(com.axway.ats.agent.core.templateactions.model.matchers.ResponseMatcher) XPathBodyMatcher(com.axway.ats.agent.core.templateactions.model.matchers.XPathBodyMatcher) XmlUtilitiesException(com.axway.ats.agent.core.templateactions.exceptions.XmlUtilitiesException) ArrayList(java.util.ArrayList)

Example 2 with ResponseMatcher

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));
}
Also used : ResponseMatcher(com.axway.ats.agent.core.templateactions.model.matchers.ResponseMatcher) TextBodyMatcher(com.axway.ats.agent.core.templateactions.model.matchers.TextBodyMatcher) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 3 with ResponseMatcher

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));
}
Also used : ResponseMatcher(com.axway.ats.agent.core.templateactions.model.matchers.ResponseMatcher) XPathBodyMatcher(com.axway.ats.agent.core.templateactions.model.matchers.XPathBodyMatcher) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 4 with ResponseMatcher

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));
}
Also used : ResponseMatcher(com.axway.ats.agent.core.templateactions.model.matchers.ResponseMatcher) TextBodyMatcher(com.axway.ats.agent.core.templateactions.model.matchers.TextBodyMatcher) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Aggregations

ResponseMatcher (com.axway.ats.agent.core.templateactions.model.matchers.ResponseMatcher)4 PublicAtsApi (com.axway.ats.common.PublicAtsApi)3 TextBodyMatcher (com.axway.ats.agent.core.templateactions.model.matchers.TextBodyMatcher)2 XPathBodyMatcher (com.axway.ats.agent.core.templateactions.model.matchers.XPathBodyMatcher)2 XmlUtilitiesException (com.axway.ats.agent.core.templateactions.exceptions.XmlUtilitiesException)1 ActionParser (com.axway.ats.agent.core.templateactions.model.objects.ActionParser)1 ArrayList (java.util.ArrayList)1