Search in sources :

Example 41 with WebResponse

use of com.meterware.httpunit.WebResponse in project geode by apache.

the class TestSessionsTomcat8Base method testSessionPersists1.

/**
   * Check that our session persists. The values we pass in as query params are used to set
   * attributes on the session.
   */
@Test
public void testSessionPersists1() throws Exception {
    String key = "value_testSessionPersists1";
    String value = "Foo";
    WebConversation wc = new WebConversation();
    WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
    req.setParameter("cmd", QueryCommand.SET.name());
    req.setParameter("param", key);
    req.setParameter("value", value);
    WebResponse response = wc.getResponse(req);
    String sessionId = response.getNewCookieValue("JSESSIONID");
    assertNotNull("No apparent session cookie", sessionId);
    // The request retains the cookie from the prior response...
    req.setParameter("cmd", QueryCommand.GET.name());
    req.setParameter("param", key);
    req.removeParameter("value");
    response = wc.getResponse(req);
    assertEquals(value, response.getText());
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebConversation(com.meterware.httpunit.WebConversation) WebRequest(com.meterware.httpunit.WebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) Test(org.junit.Test)

Example 42 with WebResponse

use of com.meterware.httpunit.WebResponse in project geode by apache.

the class TestSessionsTomcat8Base method testBasicRegion.

/**
   * Test that a session attribute gets set into the region too.
   */
@Test
public void testBasicRegion() throws Exception {
    String key = "value_testBasicRegion";
    String value = "Foo";
    WebConversation wc = new WebConversation();
    WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
    // Set an attribute
    req.setParameter("cmd", QueryCommand.SET.name());
    req.setParameter("param", key);
    req.setParameter("value", value);
    WebResponse response = wc.getResponse(req);
    String sessionId = response.getNewCookieValue("JSESSIONID");
    assertEquals(value, region.get(sessionId).getAttribute(key));
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebConversation(com.meterware.httpunit.WebConversation) WebRequest(com.meterware.httpunit.WebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) Test(org.junit.Test)

Example 43 with WebResponse

use of com.meterware.httpunit.WebResponse in project geode by apache.

the class TestSessionsTomcat8Base method testCommitSessionValveInvalidSession.

/*
   * Test for issue #38 CommitSessionValve throws exception on invalidated sessions
   */
@Test
public void testCommitSessionValveInvalidSession() throws Exception {
    Callback c = new Callback() {

        @Override
        public void call(HttpServletRequest request, HttpServletResponse response) throws IOException {
            HttpSession session = request.getSession();
            session.invalidate();
            response.getWriter().write("done");
        }
    };
    servlet.getServletContext().setAttribute("callback", c);
    WebConversation wc = new WebConversation();
    WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
    // Execute the callback
    req.setParameter("cmd", QueryCommand.CALLBACK.name());
    req.setParameter("param", "callback");
    WebResponse response = wc.getResponse(req);
    assertEquals("done", response.getText());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WebResponse(com.meterware.httpunit.WebResponse) WebConversation(com.meterware.httpunit.WebConversation) WebRequest(com.meterware.httpunit.WebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) HttpSession(javax.servlet.http.HttpSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) Test(org.junit.Test)

Example 44 with WebResponse

use of com.meterware.httpunit.WebResponse in project geode by apache.

the class TestSessionsTomcat8Base method testExtraSessionsNotCreated.

/**
   * Test for issue #45 Sessions are being created for every request
   */
@Test
public void testExtraSessionsNotCreated() throws Exception {
    Callback c = new Callback() {

        @Override
        public void call(HttpServletRequest request, HttpServletResponse response) throws IOException {
            // Do nothing with sessions
            response.getWriter().write("done");
        }
    };
    servlet.getServletContext().setAttribute("callback", c);
    WebConversation wc = new WebConversation();
    WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
    // Execute the callback
    req.setParameter("cmd", QueryCommand.CALLBACK.name());
    req.setParameter("param", "callback");
    WebResponse response = wc.getResponse(req);
    assertEquals("done", response.getText());
    assertEquals("The region should be empty", 0, region.size());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WebResponse(com.meterware.httpunit.WebResponse) WebConversation(com.meterware.httpunit.WebConversation) WebRequest(com.meterware.httpunit.WebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) Test(org.junit.Test)

Example 45 with WebResponse

use of com.meterware.httpunit.WebResponse in project geode by apache.

the class TestSessionsTomcat8Base method testSessionExpirationByContainer.

/**
   * Test expiration of a session by the tomcat container, rather than gemfire expiration
   */
@Test
public void testSessionExpirationByContainer() throws Exception {
    String key = "value_testSessionExpiration1";
    String value = "Foo";
    WebConversation wc = new WebConversation();
    WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
    // Set an attribute
    req.setParameter("cmd", QueryCommand.SET.name());
    req.setParameter("param", key);
    req.setParameter("value", value);
    WebResponse response = wc.getResponse(req);
    // Set the session timeout of this one session.
    req.setParameter("cmd", QueryCommand.SET_MAX_INACTIVE.name());
    req.setParameter("value", "1");
    response = wc.getResponse(req);
    // Wait until the session should expire
    Thread.sleep(2000);
    // Do a request, which should cause the session to be expired
    req.setParameter("cmd", QueryCommand.GET.name());
    req.setParameter("param", key);
    response = wc.getResponse(req);
    assertEquals("", response.getText());
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebConversation(com.meterware.httpunit.WebConversation) WebRequest(com.meterware.httpunit.WebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) Test(org.junit.Test)

Aggregations

WebResponse (com.meterware.httpunit.WebResponse)121 WebRequest (com.meterware.httpunit.WebRequest)108 Test (org.junit.Test)93 GetMethodWebRequest (com.meterware.httpunit.GetMethodWebRequest)91 ServletUnitClient (com.meterware.servletunit.ServletUnitClient)56 WebConversation (com.meterware.httpunit.WebConversation)44 PostMethodWebRequest (com.meterware.httpunit.PostMethodWebRequest)42 ByteArrayInputStream (java.io.ByteArrayInputStream)28 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)16 PutMethodWebRequest (com.meterware.httpunit.PutMethodWebRequest)15 TextBlock (com.meterware.httpunit.TextBlock)14 URL (java.net.URL)14 HttpServletRequest (javax.servlet.http.HttpServletRequest)14 HttpServletResponse (javax.servlet.http.HttpServletResponse)14 Document (org.w3c.dom.Document)12 HttpSession (javax.servlet.http.HttpSession)9 WebLink (com.meterware.httpunit.WebLink)8 WebForm (com.meterware.httpunit.WebForm)7 HeaderOnlyWebRequest (com.meterware.httpunit.HeaderOnlyWebRequest)5 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)5