Search in sources :

Example 41 with GetMethodWebRequest

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

the class TestSessionsBase 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 42 with GetMethodWebRequest

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

the class TestSessionsBase method testRegionInvalidate.

/**
   * Test that a session attribute gets removed from the region when the session is invalidated.
   */
@Test
public void testRegionInvalidate() throws Exception {
    String key = "value_testRegionInvalidate";
    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");
    // Invalidate the session
    req.removeParameter("param");
    req.removeParameter("value");
    req.setParameter("cmd", QueryCommand.INVALIDATE.name());
    wc.getResponse(req);
    assertNull("The region should not have an entry for this session", region.get(sessionId));
}
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 GetMethodWebRequest

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

the class TestSessionsBase 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 44 with GetMethodWebRequest

use of com.meterware.httpunit.GetMethodWebRequest in project camel by apache.

the class RestServletVerbTest method testGetAll.

@Test
public void testGetAll() throws Exception {
    WebRequest req = new GetMethodWebRequest(CONTEXT_URL + "/services/users");
    ServletUnitClient client = newClient();
    client.setExceptionsThrownOnErrorStatus(false);
    WebResponse response = client.getResponse(req);
    assertEquals(200, response.getResponseCode());
    assertEquals("[{ \"id\":\"1\", \"name\":\"Scott\" },{ \"id\":\"2\", \"name\":\"Claus\" }]", response.getText());
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) HeaderOnlyWebRequest(com.meterware.httpunit.HeaderOnlyWebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) PutMethodWebRequest(com.meterware.httpunit.PutMethodWebRequest) PostMethodWebRequest(com.meterware.httpunit.PostMethodWebRequest) ServletUnitClient(com.meterware.servletunit.ServletUnitClient) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) Test(org.junit.Test)

Example 45 with GetMethodWebRequest

use of com.meterware.httpunit.GetMethodWebRequest in project camel by apache.

the class RestServletVerbTest method testGetOne.

@Test
public void testGetOne() throws Exception {
    WebRequest req = new GetMethodWebRequest(CONTEXT_URL + "/services/users/1");
    ServletUnitClient client = newClient();
    client.setExceptionsThrownOnErrorStatus(false);
    WebResponse response = client.getResponse(req);
    assertEquals(200, response.getResponseCode());
    assertEquals("{ \"id\":\"1\", \"name\":\"Scott\" }", response.getText());
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) HeaderOnlyWebRequest(com.meterware.httpunit.HeaderOnlyWebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) PutMethodWebRequest(com.meterware.httpunit.PutMethodWebRequest) PostMethodWebRequest(com.meterware.httpunit.PostMethodWebRequest) ServletUnitClient(com.meterware.servletunit.ServletUnitClient) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) Test(org.junit.Test)

Aggregations

GetMethodWebRequest (com.meterware.httpunit.GetMethodWebRequest)76 WebResponse (com.meterware.httpunit.WebResponse)73 WebRequest (com.meterware.httpunit.WebRequest)72 Test (org.junit.Test)55 WebConversation (com.meterware.httpunit.WebConversation)43 ServletUnitClient (com.meterware.servletunit.ServletUnitClient)16 TextBlock (com.meterware.httpunit.TextBlock)14 URL (java.net.URL)14 HttpServletRequest (javax.servlet.http.HttpServletRequest)14 HttpServletResponse (javax.servlet.http.HttpServletResponse)14 HttpSession (javax.servlet.http.HttpSession)9 PostMethodWebRequest (com.meterware.httpunit.PostMethodWebRequest)8 PutMethodWebRequest (com.meterware.httpunit.PutMethodWebRequest)8 WebForm (com.meterware.httpunit.WebForm)7 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)5 HttpNotFoundException (com.meterware.httpunit.HttpNotFoundException)4 WebLink (com.meterware.httpunit.WebLink)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 AuthorizationRequiredException (com.meterware.httpunit.AuthorizationRequiredException)3 WebTable (com.meterware.httpunit.WebTable)3