use of com.meterware.httpunit.WebRequest in project camel by apache.
the class RestServletVerbTest method testGetAll.
@Test
public void testGetAll() throws Exception {
WebRequest req = new GetMethodWebRequest(CONTEXT_URL + "/services/users");
ServletUnitClient client = newClient();
client.setExceptionsThrownOnErrorStatus(false);
WebResponse response = client.getResponse(req);
assertEquals(200, response.getResponseCode());
assertEquals("[{ \"id\":\"1\", \"name\":\"Scott\" },{ \"id\":\"2\", \"name\":\"Claus\" }]", response.getText());
}
use of com.meterware.httpunit.WebRequest in project camel by apache.
the class RestServletVerbTest method testGetOne.
@Test
public void testGetOne() throws Exception {
WebRequest req = new GetMethodWebRequest(CONTEXT_URL + "/services/users/1");
ServletUnitClient client = newClient();
client.setExceptionsThrownOnErrorStatus(false);
WebResponse response = client.getResponse(req);
assertEquals(200, response.getResponseCode());
assertEquals("{ \"id\":\"1\", \"name\":\"Scott\" }", response.getText());
}
use of com.meterware.httpunit.WebRequest 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.WebRequest 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.WebRequest 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());
}
Aggregations