use of com.meterware.servletunit.ServletUnitClient in project camel by apache.
the class RestServletPostXmlJaxbPojoTest method testPostJaxbPojo.
@Test
public void testPostJaxbPojo() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:input");
mock.expectedMessageCount(1);
mock.message(0).body().isInstanceOf(UserJaxbPojo.class);
String body = "{\"id\": 123, \"name\": \"Donald Duck\"}";
WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/users/new", new ByteArrayInputStream(body.getBytes()), "application/json");
ServletUnitClient client = newClient();
client.setExceptionsThrownOnErrorStatus(false);
WebResponse response = client.getResponse(req);
assertEquals(200, response.getResponseCode());
assertMockEndpointsSatisfied();
UserJaxbPojo user = mock.getReceivedExchanges().get(0).getIn().getBody(UserJaxbPojo.class);
assertNotNull(user);
assertEquals(123, user.getId());
assertEquals("Donald Duck", user.getName());
}
use of com.meterware.servletunit.ServletUnitClient 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.servletunit.ServletUnitClient 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.servletunit.ServletUnitClient 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.servletunit.ServletUnitClient 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();
}
Aggregations