use of com.meterware.httpunit.WebResponse in project javaee7-samples by javaee-samples.
the class MyResourceTest method testPut.
@Test
public void testPut() throws IOException, SAXException {
WebConversation conv = new WebConversation();
conv.setAuthentication("file", "u1", "p1");
byte[] bytes = new byte[8];
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
PutMethodWebRequest putRequest = new PutMethodWebRequest(base + "/webresources/myresource", bais, "text/plain");
try {
WebResponse response = conv.getResponse(putRequest);
} catch (HttpException e) {
assertNotNull(e);
assertEquals(403, e.getResponseCode());
return;
}
fail("PUT is not authorized and can still be called");
}
use of com.meterware.httpunit.WebResponse 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.WebResponse in project camel by apache.
the class HttpClientRouteExampleSpringTest method testHttpRestricMethod.
@Test
public void testHttpRestricMethod() throws Exception {
ServletUnitClient client = newClient();
// Send a web get method request
WebRequest req = new GetMethodWebRequest(CONTEXT_URL + "/services/hello");
WebResponse response = client.getResponse(req);
assertEquals("Get a wrong response message.", "OK", response.getResponseMessage());
assertEquals("Get a wrong response text.", "Add a name parameter to uri, eg ?name=foo", response.getText());
req = new GetMethodWebRequest(CONTEXT_URL + "/services/hello?name=Willem");
response = client.getResponse(req);
assertEquals("Get a wrong response text.", "Hello Willem how are you?", response.getText());
}
use of com.meterware.httpunit.WebResponse in project camel by apache.
the class HttpClientRouteTest method testHttpConverter.
@Test
public void testHttpConverter() throws Exception {
WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/testConverter", new ByteArrayInputStream(POST_DATA.getBytes()), "text/xml; charset=UTF-8");
ServletUnitClient client = newClient();
client.setExceptionsThrownOnErrorStatus(false);
WebResponse response = client.getResponse(req);
assertEquals("The response message is wrong ", "OK", response.getResponseMessage());
assertEquals("The response body is wrong", "Bye World", response.getText());
}
use of com.meterware.httpunit.WebResponse in project camel by apache.
the class HttpClientRouteTest method testHttpClient.
@Test
public void testHttpClient() throws Exception {
WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/hello", new ByteArrayInputStream(POST_DATA.getBytes()), CONTENT_TYPE);
ServletUnitClient client = newClient();
WebResponse response = client.getResponse(req);
assertEquals("Get wrong content type", "text/xml", response.getContentType());
assertTrue("UTF-8".equalsIgnoreCase(response.getCharacterSet()));
assertEquals("Get a wrong message header", "/hello", response.getHeaderField("PATH"));
assertEquals("The response message is wrong ", "OK", response.getResponseMessage());
req = new PostMethodWebRequest(CONTEXT_URL + "/services/helloworld", new ByteArrayInputStream(POST_DATA.getBytes()), CONTENT_TYPE);
response = client.getResponse(req);
assertEquals("Get wrong content type", "text/xml", response.getContentType());
assertTrue("UTF-8".equalsIgnoreCase(response.getCharacterSet()));
assertEquals("Get a wrong message header", "/helloworld", response.getHeaderField("PATH"));
assertEquals("The response message is wrong ", "OK", response.getResponseMessage());
client.setExceptionsThrownOnErrorStatus(false);
}
Aggregations