Search in sources :

Example 1 with HeaderMatcher

use of com.axway.ats.agent.core.templateactions.model.matchers.HeaderMatcher in project ats-framework by Axway.

the class TemplateActionsResponseVerificationConfigurator method getGlobalHeaderMatchers.

/**
     * Returns new copy because of same multi threaded access
     */
public Set<HeaderMatcher> getGlobalHeaderMatchers() {
    // FIXME - get new instance only for new thread. Use ThreadContext
    // return new instance because referenced headers are modified in merging steps in XmlUtilities.verifyResponseHeaders()
    //long startTime = System.nanoTime();
    Set<HeaderMatcher> newCopy = new HashSet<HeaderMatcher>(globalHeadersMatchers.size());
    for (HeaderMatcher headerMatcher : globalHeadersMatchers) {
        HeaderMatcher newHeaderMatcher = new HeaderMatcher(headerMatcher);
        newCopy.add(newHeaderMatcher);
    }
    // log.debug( "**** TMP FIXME: copy global header matchers with size: " + globalHeadersMatchers.size() + ", done in " + (System.nanoTime()-startTime) + " ms.");
    return newCopy;
}
Also used : HeaderMatcher(com.axway.ats.agent.core.templateactions.model.matchers.HeaderMatcher) HashSet(java.util.HashSet)

Example 2 with HeaderMatcher

use of com.axway.ats.agent.core.templateactions.model.matchers.HeaderMatcher in project ats-framework by Axway.

the class TemplateActionsResponseVerificationConfigurator method apply.

@Override
public void apply() throws ConfigurationException {
    // the configurator has been deserialized, we need to create a new instance here
    TemplateActionsResponseVerificationConfigurator instance = new TemplateActionsResponseVerificationConfigurator(this.queueName);
    instance.verificators = this.verificators;
    for (HeaderMatcher headerMatcher : this.globalHeadersMatchers) {
        instance.globalHeadersMatchers.add(headerMatcher);
    }
}
Also used : HeaderMatcher(com.axway.ats.agent.core.templateactions.model.matchers.HeaderMatcher)

Example 3 with HeaderMatcher

use of com.axway.ats.agent.core.templateactions.model.matchers.HeaderMatcher in project ats-framework by Axway.

the class Test_XmlUtilities method verifyContentLengthZero.

@SuppressWarnings("serial")
@Test
public void verifyContentLengthZero() throws Exception {
    String actionsXmlFileNameWoPath = "verifyContentLengthZero.xml";
    String actionsXml = TEST_ACTIONS_HOME + actionsXmlFileNameWoPath;
    XmlReader xmlReader = new XmlReader(actionsXml);
    // non-zero content
    xmlReader.goToNextAction();
    // empty body of the response/content
    xmlReader.goToNextAction();
    TemplateActionsResponseVerificationConfigurator verificationConfigurator = new TemplateActionsResponseVerificationConfigurator("queue name");
    // add globally applicable header matchers
    final HeaderMatcher globalContentRange = new HeaderMatcher("Content-Length", "100", TemplateHeaderMatchMode.RANGE_OFFSET);
    verificationConfigurator.addGlobalHeaderMatchers(new HashSet<HeaderMatcher>() {

        {
            add(globalContentRange);
        }
    });
    resolveActionName(false);
    // construct the fake client
    MockHttpURLConnection mockHttpURLConnection = new MockHttpURLConnection();
    mockHttpURLConnection.setFakeInputStream(TEST_ACTIONS_HOME, actionName + "_response.bin");
    mockHttpURLConnection.setFakeContentType("text/html");
    //mockHttpURLConnection.setFakeContentEncoding( contentEncoding );
    HttpClient client = Test_HttpClient.getHttpClient(mockHttpURLConnection);
    // add some headers
    Map<String, List<String>> fakeHeaderFields = new HashMap<String, List<String>>();
    List<String> acceptCharset = new ArrayList<String>();
    acceptCharset.add("ISO-8859-1,utf-8;q=0.7,*;q=0.7");
    fakeHeaderFields.put("Accept-Charset", acceptCharset);
    // Content-Length header
    List<String> contentLength = new ArrayList<String>();
    contentLength.add("0");
    fakeHeaderFields.put("Content-Length", contentLength);
    fakeHeaderFields.put("Content-Type", new LinkedList<String>() {

        {
            add("text/html");
        }
    });
    fakeHeaderFields.put("Accept-Ranges", new LinkedList<String>() {

        {
            add("bytes");
        }
    });
    fakeHeaderFields.put("Server", new LinkedList<String>() {

        {
            add("Apache-Coyote/1.1");
        }
    });
    // Status header
    List<String> responseStatusHeaders = new ArrayList<String>();
    responseStatusHeaders.add("HTTP/1.1 200 OK");
    fakeHeaderFields.put(null, responseStatusHeaders);
    mockHttpURLConnection.setFakeHeaderFields(fakeHeaderFields);
    XmlUtilities xmlUtilities = new XmlUtilities();
    ActionParser actionParser = xmlUtilities.readActionResponse(client, getDownloadsFolder() + actionName + ".xml", 1, false);
    Node actualResponseNode = actionParser.getActionNodeWithoutBody();
    String actualResponse = xmlUtilities.xmlNodeToString(actualResponseNode);
    actualResponse = actualResponse.replace("<HTTP_RESPONSE>", "").replace("</HTTP_RESPONSE>", "").trim();
    String expectedResponse = readFileLineByLine(TEST_ACTIONS_HOME + actionName + "_response.xml");
    verifyResponseMatch(expectedResponse, actualResponse, "response body", "response bodies");
    // Verify against HeaderMatchers
    XmlUtilities utils = new XmlUtilities();
    // Output directory for actual response bodies. Ending ".xml" is removed in verifyResponse
    String outDirNamePathWithDotXML = getDownloadsFolder() + AtsSystemProperties.SYSTEM_FILE_SEPARATOR + actionsXmlFileNameWoPath;
    // reset the stop watch interim state - just before reading response
    client.getNetworkingStopWatch().step0_SetNewContext(actionsXmlFileNameWoPath);
    client.getNetworkingStopWatch().setStateFromBeforeStep1ToAfterStep4();
    client.getNetworkingStopWatch().step5_StartInterimTimer();
    utils.verifyResponse(outDirNamePathWithDotXML, "verifyContentLengthZero", 1, xmlReader.getResponse(), client, verificationConfigurator);
}
Also used : HeaderMatcher(com.axway.ats.agent.core.templateactions.model.matchers.HeaderMatcher) HashMap(java.util.HashMap) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) ActionParser(com.axway.ats.agent.core.templateactions.model.objects.ActionParser) TemplateActionsResponseVerificationConfigurator(com.axway.ats.agent.core.configuration.TemplateActionsResponseVerificationConfigurator) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Test(org.junit.Test) TemplateActionsBaseTest(com.axway.ats.agent.core.templateactions.TemplateActionsBaseTest)

Example 4 with HeaderMatcher

use of com.axway.ats.agent.core.templateactions.model.matchers.HeaderMatcher in project ats-framework by Axway.

the class Test_HttpClient method testHeaders_moreThanOneSetCookieHeaders.

@Test
public void testHeaders_moreThanOneSetCookieHeaders() throws Exception {
    // construct the fake client
    MockHttpURLConnection mockHttpURLConnection = new MockHttpURLConnection();
    Map<String, List<String>> fakeHeaderFields = new HashMap<String, List<String>>();
    List<String> setCookieHeaders = new ArrayList<String>();
    setCookieHeaders.add("JSESSIONID=1dst5g74soql2;Path=/ui;HttpOnly");
    setCookieHeaders.add("JSESSIONID=pOsdf4L60Sd;Path=/ui;HttpOnly");
    setCookieHeaders.add("TRANSLATED_SESSIONID=\"ifoauo9iogmh1fzm510nwpd7l\"");
    setCookieHeaders.add("loggedInUserBeforeSessionExpired=admin; TRANSLATED_SESSIONID=\"SDklksdf8324nasdK\"");
    fakeHeaderFields.put("Set-Cookie", setCookieHeaders);
    mockHttpURLConnection.setFakeHeaderFields(fakeHeaderFields);
    HttpClient client = getHttpClient(mockHttpURLConnection);
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document dom = db.newDocument();
    Node responseNode = dom.createElement(TOKEN_HTTP_RESPONSE);
    dom.appendChild(responseNode);
    client.readHeaders(dom, responseNode, 1);
    // verify the new Set-Cookie header merges all the Set-Cookie header in the right order
    XmlUtilities xmlUtilities = new XmlUtilities();
    String newSetCookieHeaderActual = xmlUtilities.getNodeAttribute(responseNode.getChildNodes().item(0), "value");
    String newSetCookieHeaderExpected = "JSESSIONID=1dst5g74soql2;Path=/ui;HttpOnly;JSESSIONID=pOsdf4L60Sd;Path=/ui;HttpOnly;TRANSLATED_SESSIONID=\"ifoauo9iogmh1fzm510nwpd7l\";loggedInUserBeforeSessionExpired=admin; TRANSLATED_SESSIONID=\"SDklksdf8324nasdK\";";
    assertEquals(newSetCookieHeaderExpected, newSetCookieHeaderActual);
    // now check whether we are getting the last cookie value
    HeaderMatcher matcher = new HeaderMatcher(HeaderMatcher.SET_COOKIE_HEADER_NAME, "", TemplateHeaderMatchMode.EXTRACT);
    assertTrue(matcher.performMatch(null, newSetCookieHeaderActual));
    assertEquals("pOsdf4L60Sd", ThreadContext.getAttribute(ThreadContext.COOKIE_VAR_PREFFIX + "JSESSIONID"));
    assertEquals("SDklksdf8324nasdK", ThreadContext.getAttribute(ThreadContext.COOKIE_VAR_PREFFIX + "TRANSLATED_SESSIONID"));
    assertEquals(null, ThreadContext.getAttribute(ThreadContext.COOKIE_VAR_PREFFIX + "Path"));
    assertEquals(null, ThreadContext.getAttribute(ThreadContext.COOKIE_VAR_PREFFIX + "HttpOnly"));
}
Also used : HeaderMatcher(com.axway.ats.agent.core.templateactions.model.matchers.HeaderMatcher) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) HashMap(java.util.HashMap) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) TemplateActionsBaseTest(com.axway.ats.agent.core.templateactions.TemplateActionsBaseTest)

Example 5 with HeaderMatcher

use of com.axway.ats.agent.core.templateactions.model.matchers.HeaderMatcher in project ats-framework by Axway.

the class TemplateLoadClient method checkHeader.

/**
     * Check the specified header for the specified action step
     *
     * @param actionName the name of the action
     * @param stepNumber the action step number
     * @param headerName the header of interest
     * @param headerValueToMatch the expected header value
     * @param matchMode how to match the header value
     * @throws InvalidMatcherException
     */
@PublicAtsApi
public void checkHeader(String actionName, int stepNumber, String headerName, String headerValueToMatch, TemplateHeaderMatchMode matchMode) throws InvalidMatcherException {
    List<HeaderMatcher> stepMatchers = getStepHeaderMatchers(actionName, stepNumber);
    stepMatchers.add(new HeaderMatcher(headerName, headerValueToMatch, matchMode));
}
Also used : HeaderMatcher(com.axway.ats.agent.core.templateactions.model.matchers.HeaderMatcher) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Aggregations

HeaderMatcher (com.axway.ats.agent.core.templateactions.model.matchers.HeaderMatcher)8 Node (org.w3c.dom.Node)4 HashMap (java.util.HashMap)3 TemplateActionsBaseTest (com.axway.ats.agent.core.templateactions.TemplateActionsBaseTest)2 PublicAtsApi (com.axway.ats.common.PublicAtsApi)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Test (org.junit.Test)2 TemplateActionsResponseVerificationConfigurator (com.axway.ats.agent.core.configuration.TemplateActionsResponseVerificationConfigurator)1 InvalidMatcherException (com.axway.ats.agent.core.templateactions.exceptions.InvalidMatcherException)1 XmlUtilitiesException (com.axway.ats.agent.core.templateactions.exceptions.XmlUtilitiesException)1 TemplateHeaderMatchMode (com.axway.ats.agent.core.templateactions.model.matchers.mode.TemplateHeaderMatchMode)1 ActionParser (com.axway.ats.agent.core.templateactions.model.objects.ActionParser)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 Document (org.w3c.dom.Document)1