Search in sources :

Example 71 with WebRequest

use of com.gargoylesoftware.htmlunit.WebRequest 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"), POST);
    HtmlPage page = webClient.getPage(request);
    assertEquals("Servlet Security Annotated - Basic Auth with File-base Realm", page.getTitleText());
}
Also used : WebRequest(com.gargoylesoftware.htmlunit.WebRequest) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) URL(java.net.URL) Test(org.junit.Test)

Example 72 with WebRequest

use of com.gargoylesoftware.htmlunit.WebRequest 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"), PUT);
    TextPage page = null;
    try {
        page = webClient.getPage(request);
        System.out.println(page.getContent());
    } catch (FailingHttpStatusCodeException e) {
        assertNotEquals("PUT denied, but should be allowed", 403, e.getStatusCode());
        throw e;
    }
}
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 73 with WebRequest

use of com.gargoylesoftware.htmlunit.WebRequest 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"), POST);
    TextPage page = null;
    try {
        page = webClient.getPage(request);
        System.out.println(page.getContent());
        assertTrue("POST method could not be called even without deny-uncovered-http-methods", page.getContent().contains("my POST"));
    } catch (FailingHttpStatusCodeException e) {
        assertNotEquals("Post denied, but should be allowed", 403, e.getStatusCode());
        throw e;
    }
}
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 74 with WebRequest

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

the class SimpleServletTest method testPost.

@Test
public void testPost() throws IOException, SAXException {
    WebRequest request = new WebRequest(new URL(base + "SimpleServlet"), 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 75 with WebRequest

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

the class TestServletTest method testPost.

@Test
public void testPost() throws IOException, SAXException {
    WebRequest request = new WebRequest(new URL(base + "TestServlet"), 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)

Aggregations

WebRequest (com.gargoylesoftware.htmlunit.WebRequest)84 Test (org.junit.Test)65 WebResponse (com.gargoylesoftware.htmlunit.WebResponse)49 URL (java.net.URL)31 Path (java.nio.file.Path)31 FailingHttpStatusCodeException (com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException)12 TextPage (com.gargoylesoftware.htmlunit.TextPage)12 InputStream (java.io.InputStream)7 MkColMethodWebRequest (org.apache.archiva.webdav.httpunit.MkColMethodWebRequest)7 JenkinsRule (org.jvnet.hudson.test.JenkinsRule)7 WebClient (com.gargoylesoftware.htmlunit.WebClient)5 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)5 IOException (java.io.IOException)5 FreeStyleProject (hudson.model.FreeStyleProject)4 Page (com.gargoylesoftware.htmlunit.Page)3 NameValuePair (com.gargoylesoftware.htmlunit.util.NameValuePair)3 HashMap (java.util.HashMap)3 Issue (org.jvnet.hudson.test.Issue)3 SeleniumOperationException (com.axway.ats.uiengine.exceptions.SeleniumOperationException)2 IncorrectnessListener (com.gargoylesoftware.htmlunit.IncorrectnessListener)2