use of com.meterware.httpunit.AuthorizationRequiredException in project javaee7-samples by javaee-samples.
the class MyResourceTest method testGetWithCorrectCredentials.
@Test
public void testGetWithCorrectCredentials() throws IOException, SAXException {
WebConversation conv = new WebConversation();
conv.setAuthentication("file", "u1", "p1");
GetMethodWebRequest getRequest = new GetMethodWebRequest(base + "/webresources/myresource");
WebResponse response = null;
try {
response = conv.getResponse(getRequest);
} catch (AuthorizationRequiredException e) {
fail(e.getMessage());
}
assertNotNull(response);
assertTrue(response.getText().contains("get"));
}
use of com.meterware.httpunit.AuthorizationRequiredException 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.AuthorizationRequiredException 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");
}
Aggregations