Search in sources :

Example 31 with WebConversation

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

the class TestSessionsBase method testSessionExpiration1.

/**
   * Test setting the session expiration
   */
@Test
public void testSessionExpiration1() throws Exception {
    // TestSessions only live for a second
    sessionManager.setMaxInactiveInterval(1);
    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);
    // Sleep a while
    Thread.sleep(2000);
    // The attribute should not be accessible now...
    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)

Example 32 with WebConversation

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

the class TestSessionsBase method testCallback.

/**
   * Test callback functionality. This is here really just as an example. Callbacks are useful to
   * implement per test actions which can be defined within the actual test method instead of in a
   * separate servlet class.
   */
@Test
public void testCallback() throws Exception {
    final String helloWorld = "Hello World";
    Callback c = new Callback() {

        @Override
        public void call(HttpServletRequest request, HttpServletResponse response) throws IOException {
            PrintWriter out = response.getWriter();
            out.write(helloWorld);
        }
    };
    servlet.getServletContext().setAttribute("callback", c);
    WebConversation wc = new WebConversation();
    WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
    req.setParameter("cmd", QueryCommand.CALLBACK.name());
    req.setParameter("param", "callback");
    WebResponse response = wc.getResponse(req);
    assertEquals(helloWorld, 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) HttpServletResponse(javax.servlet.http.HttpServletResponse) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 33 with WebConversation

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

the class TestSessionsBase method testInvalidate.

/**
   * Test that invalidating a session makes it's attributes inaccessible.
   */
@Test
public void testInvalidate() throws Exception {
    String key = "value_testInvalidate";
    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);
    // Invalidate the session
    req.removeParameter("param");
    req.removeParameter("value");
    req.setParameter("cmd", QueryCommand.INVALIDATE.name());
    wc.getResponse(req);
    // The attribute should not be accessible now...
    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)

Example 34 with WebConversation

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

the class TestSessionsBase 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 35 with WebConversation

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

the class TestSessionsBase method testMultipleAttributeUpdates.

/**
   * Test that multiple attribute updates, within the same request result in only the latest one
   * being effective.
   */
@Test
public void testMultipleAttributeUpdates() throws Exception {
    final String key = "value_testMultipleAttributeUpdates";
    Callback c = new Callback() {

        @Override
        public void call(HttpServletRequest request, HttpServletResponse response) throws IOException {
            HttpSession session = request.getSession();
            for (int i = 0; i < 1000; i++) {
                session.setAttribute(key, Integer.toString(i));
            }
        }
    };
    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);
    String sessionId = response.getNewCookieValue("JSESSIONID");
    assertEquals("999", region.get(sessionId).getAttribute(key));
}
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)

Aggregations

WebConversation (com.meterware.httpunit.WebConversation)46 Test (org.junit.Test)46 WebResponse (com.meterware.httpunit.WebResponse)44 GetMethodWebRequest (com.meterware.httpunit.GetMethodWebRequest)43 WebRequest (com.meterware.httpunit.WebRequest)39 HttpServletRequest (javax.servlet.http.HttpServletRequest)14 HttpServletResponse (javax.servlet.http.HttpServletResponse)14 HttpSession (javax.servlet.http.HttpSession)9 WebForm (com.meterware.httpunit.WebForm)7 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)5 AuthorizationRequiredException (com.meterware.httpunit.AuthorizationRequiredException)3 PrintWriter (java.io.PrintWriter)3 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)3 HttpException (com.meterware.httpunit.HttpException)2 WebLink (com.meterware.httpunit.WebLink)2 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)2 PostMethodWebRequest (com.meterware.httpunit.PostMethodWebRequest)1 PutMethodWebRequest (com.meterware.httpunit.PutMethodWebRequest)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 HashSet (java.util.HashSet)1