Search in sources :

Example 96 with WebRequest

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

the class SessionReplicationIntegrationJUnitTest method testInvalidateSession9.

/**
   * Test that invalidating a session throws an exception on subsequent access.
   */
// GEODE-1943
@Category(FlakyTest.class)
@Test
public void testInvalidateSession9() throws Exception {
    Callback c_1 = new Callback() {

        @Override
        public void call(HttpServletRequest request, HttpServletResponse response) throws IOException {
            HttpSession s = request.getSession();
            s.invalidate();
            PrintWriter out = response.getWriter();
            try {
                s.isNew();
            } catch (IllegalStateException iex) {
                out.write("OK");
            }
        }
    };
    tester.setAttribute("callback_1", c_1);
    servletHolder.setInitParameter("test.callback", "callback_1");
    String url = tester.createConnector(true);
    tester.start();
    WebConversation wc = new WebConversation();
    WebRequest req = new GetMethodWebRequest(url + "/test/hello");
    req.setHeaderField("Host", "tester");
    final WebResponse webResponse = wc.getResponse(req);
    assertEquals("OK", webResponse.getResponseMessage());
}
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) PrintWriter(java.io.PrintWriter) Category(org.junit.experimental.categories.Category) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 97 with WebRequest

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

the class TestSessionsTomcat8Base 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 98 with WebRequest

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

the class TestSessionsTomcat8Base method testLastAccessedTime.

/**
   * Test for issue #46 lastAccessedTime is not updated at the start of the request, but only at the
   * end.
   */
@Test
public void testLastAccessedTime() throws Exception {
    Callback c = new Callback() {

        @Override
        public void call(HttpServletRequest request, HttpServletResponse response) throws IOException {
            HttpSession session = request.getSession();
            // Hack to expose the session to our test context
            session.getServletContext().setAttribute("session", session);
            session.setAttribute("lastAccessTime", session.getLastAccessedTime());
            try {
                Thread.sleep(100);
            } catch (InterruptedException ex) {
            }
            session.setAttribute("somethingElse", 1);
            request.getSession();
            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);
    HttpSession session = (HttpSession) servlet.getServletContext().getAttribute("session");
    Long lastAccess = (Long) session.getAttribute("lastAccessTime");
    assertTrue("Last access time not set correctly: " + lastAccess.longValue() + " not <= " + session.getLastAccessedTime(), lastAccess.longValue() <= session.getLastAccessedTime());
}
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 99 with WebRequest

use of com.meterware.httpunit.WebRequest in project maven-plugins by apache.

the class DependencyManagementReportTest method testReport.

/**
     * Test report
     *
     * @throws Exception if any
     */
public void testReport() throws Exception {
    generateReport("dependency-management", "dependency-management-plugin-config.xml");
    assertTrue("Test html generated", getGeneratedReport("dependency-management.html").exists());
    URL reportURL = getGeneratedReport("dependency-management.html").toURI().toURL();
    assertNotNull(reportURL);
    // HTTPUnit
    WebRequest request = new GetMethodWebRequest(reportURL.toString());
    WebResponse response = WEB_CONVERSATION.getResponse(request);
    // Basic HTML tests
    assertTrue(response.isHTML());
    assertTrue(response.getContentLength() > 0);
    // Test the Page title
    String expectedTitle = prepareTitle(getString("report.dependency-management.name"), getString("report.dependency-management.title"));
    assertEquals(expectedTitle, response.getTitle());
    // Test the tables
    WebTable[] webTables = response.getTables();
    assertEquals(webTables.length, 1);
    assertEquals(webTables[0].getColumnCount(), 5);
    assertEquals(webTables[0].getRowCount(), 1 + getTestMavenProject().getDependencyManagement().getDependencies().size());
    // Test the texts
    TextBlock[] textBlocks = response.getTextBlocks();
    assertEquals(getString("report.dependency-management.title"), textBlocks[0].getText());
    assertEquals("test", textBlocks[1].getText());
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) WebTable(com.meterware.httpunit.WebTable) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) TextBlock(com.meterware.httpunit.TextBlock) URL(java.net.URL)

Example 100 with WebRequest

use of com.meterware.httpunit.WebRequest in project maven-plugins by apache.

the class PluginManagementReportTest method testReport.

/**
     * Test report
     *
     * @throws Exception if any
     */
public void testReport() throws Exception {
    generateReport("plugin-management", "plugin-management-plugin-config.xml");
    assertTrue("Test html generated", getGeneratedReport("plugin-management.html").exists());
    URL reportURL = getGeneratedReport("plugin-management.html").toURI().toURL();
    assertNotNull(reportURL);
    // HTTPUnit
    WebRequest request = new GetMethodWebRequest(reportURL.toString());
    WebResponse response = WEB_CONVERSATION.getResponse(request);
    // Basic HTML tests
    assertTrue(response.isHTML());
    assertTrue(response.getContentLength() > 0);
    // Test the Page title
    String expectedTitle = prepareTitle(getString("report.plugin-management.name"), getString("report.plugin-management.title"));
    assertEquals(expectedTitle, response.getTitle());
    // Test the tables
    WebTable[] webTables = response.getTables();
    assertEquals(1, webTables.length);
    assertEquals(3, webTables[0].getColumnCount());
    assertEquals(3, webTables[0].getRowCount());
    // Test the texts
    TextBlock[] textBlocks = response.getTextBlocks();
    assertEquals(getString("report.plugin-management.title"), textBlocks[0].getText());
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) WebTable(com.meterware.httpunit.WebTable) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) TextBlock(com.meterware.httpunit.TextBlock) URL(java.net.URL)

Aggregations

WebRequest (com.meterware.httpunit.WebRequest)113 WebResponse (com.meterware.httpunit.WebResponse)108 GetMethodWebRequest (com.meterware.httpunit.GetMethodWebRequest)90 Test (org.junit.Test)87 ServletUnitClient (com.meterware.servletunit.ServletUnitClient)52 PostMethodWebRequest (com.meterware.httpunit.PostMethodWebRequest)45 WebConversation (com.meterware.httpunit.WebConversation)39 ByteArrayInputStream (java.io.ByteArrayInputStream)27 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)16 PutMethodWebRequest (com.meterware.httpunit.PutMethodWebRequest)14 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)10 HttpSession (javax.servlet.http.HttpSession)9 WebForm (com.meterware.httpunit.WebForm)7 HeaderOnlyWebRequest (com.meterware.httpunit.HeaderOnlyWebRequest)5 HttpNotFoundException (com.meterware.httpunit.HttpNotFoundException)5 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)5