Search in sources :

Example 11 with TextPage

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

the class SecureServletTest method testPostWithIncorrectCredentials.

@Test
public void testPostWithIncorrectCredentials() throws Exception {
    webClient.setCredentialsProvider(incorrectCreds);
    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 12 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)

Example 13 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 14 with TextPage

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

the class SecureServletTest method testPostMethod.

@Test
public void testPostMethod() throws Exception {
    webClient.setCredentialsProvider(correctCreds);
    WebRequest request = new WebRequest(new URL(base + "SecureServlet"), HttpMethod.POST);
    try {
        TextPage p = webClient.getPage(request);
        System.out.println(p.getContent());
    } catch (FailingHttpStatusCodeException e) {
        assertNotNull(e);
        assertEquals(403, e.getStatusCode());
        return;
    }
    fail("POST 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 15 with TextPage

use of com.gargoylesoftware.htmlunit.TextPage in project sling by apache.

the class ITWebConsoleRemote method tailerGrep.

@Test
public void tailerGrep() throws Exception {
    TextPage page = webClient.getPage(prepareUrl("slinglog/tailer.txt?name=FILE&tail=-1"));
    String text = page.getContent();
    assertThat(text, containsString(WebConsoleTestActivator.FOO_LOG));
    assertThat(text, containsString(WebConsoleTestActivator.BAR_LOG));
    page = webClient.getPage(prepareUrl("slinglog/tailer.txt?name=FILE&tail=1000&grep=" + WebConsoleTestActivator.FOO_LOG));
    text = page.getContent();
    //With grep pattern specified we should only see foo and not bar
    assertThat(text, containsString(WebConsoleTestActivator.FOO_LOG));
    assertThat(text, not(containsString(WebConsoleTestActivator.BAR_LOG)));
}
Also used : TextPage(com.gargoylesoftware.htmlunit.TextPage) Matchers.containsString(org.hamcrest.Matchers.containsString) 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