Search in sources :

Example 1 with TextPage

use of com.gargoylesoftware.htmlunit.TextPage in project javaee7-samples by javaee-samples.

the class SecureServletTest method testPostWithCorrectCredentials.

@Test
public void testPostWithCorrectCredentials() throws Exception {
    webClient.setCredentialsProvider(correctCreds);
    WebRequest request = new WebRequest(new URL(base + "SecureServlet"), HttpMethod.POST);
    TextPage page = webClient.getPage(request);
    assertEquals("my POST", page.getContent());
}
Also used : WebRequest(com.gargoylesoftware.htmlunit.WebRequest) TextPage(com.gargoylesoftware.htmlunit.TextPage) URL(java.net.URL) Test(org.junit.Test)

Example 2 with TextPage

use of com.gargoylesoftware.htmlunit.TextPage in project javaee7-samples by javaee-samples.

the class SecureServletTest method testGetWithCorrectCredentials.

@Test
public void testGetWithCorrectCredentials() throws Exception {
    webClient.setCredentialsProvider(correctCreds);
    TextPage page = webClient.getPage(base + "/SecureServlet");
    assertEquals("my GET", page.getContent());
}
Also used : TextPage(com.gargoylesoftware.htmlunit.TextPage) Test(org.junit.Test)

Example 3 with TextPage

use of com.gargoylesoftware.htmlunit.TextPage in project javaee7-samples by javaee-samples.

the class SecureServletTest method testGetMethod.

@Test
public void testGetMethod() throws Exception {
    webClient.setCredentialsProvider(correctCreds);
    TextPage page = webClient.getPage(base + "/SecureServlet");
    assertEquals("my GET", page.getContent());
}
Also used : TextPage(com.gargoylesoftware.htmlunit.TextPage) Test(org.junit.Test)

Example 4 with TextPage

use of com.gargoylesoftware.htmlunit.TextPage in project javaee7-samples by javaee-samples.

the class SecureServletTest method testPutMethod.

@Test
public void testPutMethod() throws Exception {
    webClient.setCredentialsProvider(correctCreds);
    WebRequest request = new WebRequest(new URL(base + "SecureServlet"), HttpMethod.PUT);
    try {
        TextPage p = webClient.getPage(request);
        System.out.println(p.getContent());
    } catch (FailingHttpStatusCodeException e) {
        assertNotNull(e);
        assertEquals(403, e.getStatusCode());
        return;
    }
    fail("PUT method could be called even with deny-unocvered-http-methods");
}
Also used : WebRequest(com.gargoylesoftware.htmlunit.WebRequest) FailingHttpStatusCodeException(com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException) TextPage(com.gargoylesoftware.htmlunit.TextPage) URL(java.net.URL) Test(org.junit.Test)

Example 5 with TextPage

use of com.gargoylesoftware.htmlunit.TextPage in project javaee7-samples by javaee-samples.

the class DynamicServletTest method testChildServlet.

@Test
public void testChildServlet() throws IOException, SAXException {
    TextPage page = webClient.getPage(base + "dynamic");
    assertEquals("dynamic GET", page.getContent());
}
Also used : TextPage(com.gargoylesoftware.htmlunit.TextPage) Test(org.junit.Test)

Aggregations

TextPage (com.gargoylesoftware.htmlunit.TextPage)15 Test (org.junit.Test)14 WebRequest (com.gargoylesoftware.htmlunit.WebRequest)8 URL (java.net.URL)8 FailingHttpStatusCodeException (com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException)2 Matchers.containsString (org.hamcrest.Matchers.containsString)1