Search in sources :

Example 36 with WebRequest

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

the class DependencyConvergenceReportTest method testReport.

/**
     * Test report
     *
     * @throws Exception if any
     */
public void testReport() throws Exception {
    generateReport("dependency-convergence", "dependency-convergence-plugin-config.xml");
    assertTrue("Test html generated", getGeneratedReport("dependency-convergence.html").exists());
    URL reportURL = getGeneratedReport("dependency-convergence.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-convergence.name"), getString("report.dependency-convergence.reactor.title"));
    assertEquals(expectedTitle, response.getTitle());
    // Test the texts
    TextBlock[] textBlocks = response.getTextBlocks();
    assertEquals(getString("report.dependency-convergence.reactor.name"), textBlocks[0].getText());
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) TextBlock(com.meterware.httpunit.TextBlock) URL(java.net.URL)

Example 37 with WebRequest

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

the class LicensesReportTest method testReport.

/**
     * Test report
     *
     * @throws Exception if any
     */
public void testReport() throws Exception {
    generateReport("license", "licenses-plugin-config.xml");
    assertTrue("Test html generated", getGeneratedReport("license.html").exists());
    URL reportURL = getGeneratedReport("license.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.licenses.name"), getString("report.licenses.title"));
    assertEquals(expectedTitle, response.getTitle());
    // Test the texts
    TextBlock[] textBlocks = response.getTextBlocks();
    assertEquals(getString("report.licenses.overview.title"), textBlocks[0].getText());
    assertEquals(getString("report.licenses.overview.intro"), textBlocks[1].getText());
    assertEquals(getString("report.licenses.title"), textBlocks[2].getText());
    assertEquals("The Apache Software License, Version 2.0", textBlocks[3].getText());
    // only 1 link in default report
    final WebLink[] links = response.getLinks();
    assertEquals(1, links.length);
    assertEquals("http://maven.apache.org/", links[0].getURLString());
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) TextBlock(com.meterware.httpunit.TextBlock) URL(java.net.URL) WebLink(com.meterware.httpunit.WebLink)

Example 38 with WebRequest

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

the class MailingListsReportTest method testReport.

/**
     * Test report
     *
     * @throws Exception if any
     */
public void testReport() throws Exception {
    generateReport("mailing-list", "mailing-lists-plugin-config.xml");
    assertTrue("Test html generated", getGeneratedReport("mail-lists.html").exists());
    URL reportURL = getGeneratedReport("mail-lists.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.mailing-lists.name"), getString("report.mailing-lists.title"));
    assertEquals(expectedTitle, response.getTitle());
    // Test the texts
    TextBlock[] textBlocks = response.getTextBlocks();
    assertEquals(getString("report.mailing-lists.title"), textBlocks[0].getText());
    assertEquals(getString("report.mailing-lists.intro"), textBlocks[1].getText());
}
Also used : WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) TextBlock(com.meterware.httpunit.TextBlock) URL(java.net.URL)

Example 39 with WebRequest

use of com.meterware.httpunit.WebRequest 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 40 with WebRequest

use of com.meterware.httpunit.WebRequest 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)

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