use of com.meterware.httpunit.WebResponse in project camel by apache.
the class RestServletVerbTest method testPost.
@Test
public void testPost() throws Exception {
final String body = "{ \"id\":\"1\", \"name\":\"Scott\" }";
MockEndpoint mock = getMockEndpoint("mock:create");
mock.expectedBodiesReceived(body);
mock.expectedHeaderReceived(Exchange.HTTP_METHOD, "POST");
WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/users", new ByteArrayInputStream(body.getBytes()), "application/json");
ServletUnitClient client = newClient();
client.setExceptionsThrownOnErrorStatus(false);
WebResponse response = client.getResponse(req);
assertEquals(200, response.getResponseCode());
assertMockEndpointsSatisfied();
}
use of com.meterware.httpunit.WebResponse in project camel by apache.
the class RestServletVerbTest method testDelete.
@Test
public void testDelete() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:delete");
mock.expectedHeaderReceived("id", "1");
mock.expectedHeaderReceived(Exchange.HTTP_METHOD, "DELETE");
WebRequest req = new HeaderOnlyWebRequest(CONTEXT_URL + "/services/users/1") {
@Override
public String getMethod() {
return "DELETE";
}
};
ServletUnitClient client = newClient();
client.setExceptionsThrownOnErrorStatus(false);
WebResponse response = client.getResponse(req);
assertEquals(200, response.getResponseCode());
assertMockEndpointsSatisfied();
}
use of com.meterware.httpunit.WebResponse in project camel by apache.
the class HttpClientRouteTest method testHttpUnicodeResponseWithObjectResponse.
@Test
public void testHttpUnicodeResponseWithObjectResponse() throws Exception {
WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/testUnicodeWithObjectResponse", 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", UNICODE_TEXT, response.getText());
}
use of com.meterware.httpunit.WebResponse in project camel by apache.
the class HttpClientRouteTest method testHttpUnicodeResponseWithStringResponse.
@Test
public void testHttpUnicodeResponseWithStringResponse() throws Exception {
WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/testUnicodeWithStringResponse", 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", UNICODE_TEXT, response.getText());
}
use of com.meterware.httpunit.WebResponse in project camel by apache.
the class HttpClientRouteTest method testHttpRestricMethod.
@Test
public void testHttpRestricMethod() throws Exception {
WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/testHttpMethodRestrict", new ByteArrayInputStream(POST_DATA.getBytes()), "text/xml; charset=UTF-8");
ServletUnitClient client = newClient();
WebResponse response = client.getResponse(req);
assertEquals("The response message is wrong ", "OK", response.getResponseMessage());
assertEquals("The response body is wrong", POST_DATA, response.getText());
// Send other web method request
req = new GetMethodWebRequest(CONTEXT_URL + "/services/testHttpMethodRestrict");
try {
response = client.getResponse(req);
fail("Expect the exception here");
} catch (Exception ex) {
HttpException httpException = (HttpException) ex;
assertEquals("Get a wrong response code", 405, httpException.getResponseCode());
}
}
Aggregations