use of com.meterware.httpunit.PostMethodWebRequest in project camel by apache.
the class RestServletBindingModeJsonTest method testBindingModeWrong.
@Test
public void testBindingModeWrong() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:input");
mock.expectedMessageCount(0);
String body = "<user name=\"Donald Duck\" id=\"123\"></user>";
WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/users/new", new ByteArrayInputStream(body.getBytes()), "application/xml");
ServletUnitClient client = newClient();
client.setExceptionsThrownOnErrorStatus(false);
WebResponse response = client.getResponse(req);
assertEquals(500, response.getResponseCode());
assertMockEndpointsSatisfied();
}
use of com.meterware.httpunit.PostMethodWebRequest in project camel by apache.
the class RestServletBindingModeOffWithContractTest method testBindingModeOffWithContract.
@Test
public void testBindingModeOffWithContract() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:input");
mock.expectedMessageCount(1);
mock.message(0).body().isInstanceOf(UserPojoEx.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());
String answer = response.getText();
assertTrue("Unexpected response: " + answer, answer.contains("\"active\":true"));
assertMockEndpointsSatisfied();
Object obj = mock.getReceivedExchanges().get(0).getIn().getBody();
assertEquals(UserPojoEx.class, obj.getClass());
UserPojoEx user = (UserPojoEx) obj;
assertNotNull(user);
assertEquals(123, user.getId());
assertEquals("Donald Duck", user.getName());
assertEquals(true, user.isActive());
}
use of com.meterware.httpunit.PostMethodWebRequest in project camel by apache.
the class RestServletPojoInOutTest method testServletPojoInOut.
@Test
public void testServletPojoInOut() throws Exception {
String body = "{\"id\": 123, \"name\": \"Donald Duck\"}";
WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/users/lives", new ByteArrayInputStream(body.getBytes()), "application/json");
ServletUnitClient client = newClient();
client.setExceptionsThrownOnErrorStatus(false);
WebResponse response = client.getResponse(req);
assertEquals(200, response.getResponseCode());
String out = response.getText();
assertNotNull(out);
assertEquals("{\"iso\":\"EN\",\"country\":\"England\"}", out);
}
use of com.meterware.httpunit.PostMethodWebRequest in project camel by apache.
the class RestServletPostJsonJaxbPojoTest 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.httpunit.PostMethodWebRequest in project camel by apache.
the class RestServletPostJsonPojoListTest method testPostJaxbPojo.
@Test
public void testPostJaxbPojo() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:input");
mock.expectedMessageCount(1);
String body = "[ {\"id\": 123, \"name\": \"Donald Duck\"}, {\"id\": 456, \"name\": \"John Doe\"} ]";
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());
assertEquals("application/json", response.getContentType());
assertMockEndpointsSatisfied();
List list = mock.getReceivedExchanges().get(0).getIn().getBody(List.class);
assertNotNull(list);
assertEquals(2, list.size());
UserPojo user = (UserPojo) list.get(0);
assertEquals(123, user.getId());
assertEquals("Donald Duck", user.getName());
user = (UserPojo) list.get(1);
assertEquals(456, user.getId());
assertEquals("John Doe", user.getName());
}
Aggregations