use of com.meterware.httpunit.WebConversation in project javaee7-samples by javaee-samples.
the class MyResourceTest method testGetSubResourceWithCorrectCredentials.
@Test
public void testGetSubResourceWithCorrectCredentials() throws IOException, SAXException {
WebConversation conv = new WebConversation();
conv.setAuthentication("file", "u1", "p1");
GetMethodWebRequest getRequest = new GetMethodWebRequest(base + "/webresources/myresource/1");
WebResponse response = null;
try {
response = conv.getResponse(getRequest);
} catch (AuthorizationRequiredException e) {
fail(e.getMessage());
}
assertNotNull(response);
assertTrue(response.getText().contains("get1"));
}
use of com.meterware.httpunit.WebConversation in project javaee7-samples by javaee-samples.
the class MyResourceTest method testGetWithIncorrectCredentials.
@Test
public void testGetWithIncorrectCredentials() throws IOException, SAXException {
WebConversation conv = new WebConversation();
conv.setAuthentication("file", "random", "random");
GetMethodWebRequest getRequest = new GetMethodWebRequest(base + "/webresources/myresource");
try {
WebResponse response = conv.getResponse(getRequest);
} catch (AuthorizationRequiredException e) {
assertNotNull(e);
return;
}
fail("GET can be called with incorrect credentials");
}
use of com.meterware.httpunit.WebConversation in project javaee7-samples by javaee-samples.
the class MyResourceTest method testPost.
@Test
public void testPost() throws IOException, SAXException {
WebConversation conv = new WebConversation();
conv.setAuthentication("file", "u1", "p1");
PostMethodWebRequest postRequest = new PostMethodWebRequest(base + "/webresources/myresource");
try {
WebResponse response = conv.getResponse(postRequest);
} catch (HttpException e) {
assertNotNull(e);
assertEquals(403, e.getResponseCode());
return;
}
fail("POST is not authorized and can still be called");
}
use of com.meterware.httpunit.WebConversation in project wildfly by wildfly.
the class RestoreOriginalRequestTestCase method testRedirectOriginalRequest.
@Test
@OperateOnDeployment("service-provider-1")
public void testRedirectOriginalRequest(@ArquillianResource URL serviceProvider1) throws Exception {
WebRequest request = new GetMethodWebRequest(formatUrl(serviceProvider1) + "/savedRequest/savedRequest.html");
WebConversation conversation = new WebConversation();
WebResponse response = conversation.getResponse(request);
WebForm webForm = response.getForms()[0];
webForm.setParameter("j_username", "tomcat");
webForm.setParameter("j_password", "tomcat");
webForm.getSubmitButtons()[0].click();
response = conversation.getCurrentPage();
assertTrue(response.getText().contains("Back to the original requested resource."));
}
use of com.meterware.httpunit.WebConversation in project wildfly by wildfly.
the class RestoreOriginalRequestTestCase method testPostOriginalRequestWithParams.
@Test
@OperateOnDeployment("service-provider-2")
public void testPostOriginalRequestWithParams(@ArquillianResource URL serviceProvider2) throws Exception {
WebRequest request = new GetMethodWebRequest(formatUrl(serviceProvider2) + "/savedRequest/savedRequest.jsp");
request.setParameter("SAVED_PARAM", "Param was saved.");
WebConversation conversation = new WebConversation();
WebResponse response = conversation.getResponse(request);
WebForm webForm = response.getForms()[0];
webForm.setParameter("j_username", "tomcat");
webForm.setParameter("j_password", "tomcat");
webForm.getSubmitButtons()[0].click();
response = conversation.getCurrentPage();
assertTrue(response.getText().contains("Param was saved."));
}
Aggregations