use of com.meterware.httpunit.WebRequest 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.WebRequest 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());
}
}
use of com.meterware.httpunit.WebRequest in project camel by apache.
the class RestServletPostJsonPojoTest method testPostJaxbPojo.
@Test
public void testPostJaxbPojo() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:input");
mock.expectedMessageCount(1);
mock.message(0).body().isInstanceOf(UserPojo.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();
UserPojo user = mock.getReceivedExchanges().get(0).getIn().getBody(UserPojo.class);
assertNotNull(user);
assertEquals(123, user.getId());
assertEquals("Donald Duck", user.getName());
}
use of com.meterware.httpunit.WebRequest in project camel by apache.
the class RestServletBindingModeAutoWithXmlTest method testServletProducerGet.
@Test
public void testServletProducerGet() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:input");
mock.expectedMessageCount(1);
mock.message(0).body().isInstanceOf(UserJaxbPojo.class);
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(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.WebRequest in project camel by apache.
the class RestServletBindingModeJsonWithContractTest method testBindingModeJsonWithContract.
@Test
public void testBindingModeJsonWithContract() 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());
}
Aggregations