use of com.gargoylesoftware.htmlunit.WebRequest in project javaee7-samples by javaee-samples.
the class SecureServletTest method testPostWithNoCredentials.
@Test
public void testPostWithNoCredentials() throws Exception {
WebRequest request = new WebRequest(new URL(base + "SecureServlet"), POST);
TextPage page = webClient.getPage(request);
assertEquals("my POST", page.getContent());
}
use of com.gargoylesoftware.htmlunit.WebRequest 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"), POST);
TextPage page = webClient.getPage(request);
assertEquals("my POST", page.getContent());
}
use of com.gargoylesoftware.htmlunit.WebRequest 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"), POST);
try {
webClient.getPage(request);
} catch (FailingHttpStatusCodeException e) {
assertNotNull(e);
assertEquals(401, e.getStatusCode());
return;
}
fail("/SecureServlet could be accessed without proper security credentials");
}
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);
TextPage page = webClient.getPage(request);
assertEquals("my POST", page.getContent());
}
use of com.gargoylesoftware.htmlunit.WebRequest in project javaee7-samples by javaee-samples.
the class MyResourceTest method testPost.
@Test
public void testPost() throws IOException, SAXException {
webClient.setCredentialsProvider(correctCreds);
try {
WebRequest postRequest = new WebRequest(toUrlUnsafe(base + "webresources/myresource"), POST);
postRequest.setRequestBody("name=myname");
webClient.getPage(postRequest);
} catch (FailingHttpStatusCodeException e) {
assertEquals(403, e.getStatusCode());
return;
}
// All methods are excluded except for GET
fail("POST is not authorized and can still be called");
}
Aggregations