use of com.meterware.httpunit.PostMethodWebRequest in project camel by apache.
the class RestServletPostXmlJaxbPojoTest method testPostJaxbPojoNoContentType.
@Test
public void testPostJaxbPojoNoContentType() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:input");
mock.expectedMessageCount(1);
mock.message(0).body().isInstanceOf(UserJaxbPojo.class);
String body = "<user name=\"Donald Duck\" id=\"456\"></user>";
WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/users/new", new ByteArrayInputStream(body.getBytes()), "foo");
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(456, user.getId());
assertEquals("Donald Duck", user.getName());
}
use of com.meterware.httpunit.PostMethodWebRequest in project v7files by thiloplanz.
the class BucketsServletTest method testFormPostPOST.
public void testFormPostPOST() throws IOException, SAXException {
ServletUnitClient sc = sr.newClient();
{
PostMethodWebRequest request = new PostMethodWebRequest("http://test/myServlet/1");
try {
sc.getResponse(request);
fail("bucket not found => 404");
} catch (HttpNotFoundException e) {
assertEquals("Bucket '1' not found", e.getResponseMessage());
}
}
prepareBucket("1", "FormPost", null, null);
{
PostMethodWebRequest request = new PostMethodWebRequest("http://test/myServlet/1");
try {
sc.getResponse(request);
fail("uploads not allowed => 405");
} catch (HttpException e) {
assertEquals(HttpServletResponse.SC_METHOD_NOT_ALLOWED, e.getResponseCode());
}
}
//
// TODO: an actual POST, see
// http://stackoverflow.com/questions/10891247/file-upload-post-request-with-servletunit
}
use of com.meterware.httpunit.PostMethodWebRequest in project javaee7-samples by javaee-samples.
the class MyResourceTest method testPost.
@Test
public void testPost() throws IOException, SAXException {
WebConversation conv = new WebConversation();
conv.setAuthentication("file", "u1", "p1");
PostMethodWebRequest postRequest = new PostMethodWebRequest(base + "/webresources/myresource");
try {
WebResponse response = conv.getResponse(postRequest);
} catch (HttpException e) {
assertNotNull(e);
assertEquals(403, e.getResponseCode());
return;
}
fail("POST is not authorized and can still be called");
}
use of com.meterware.httpunit.PostMethodWebRequest 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.httpunit.PostMethodWebRequest 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();
}
Aggregations