use of com.meterware.httpunit.PutMethodWebRequest in project camel by apache.
the class RestServletVerbTest method testPut.
@Test
public void testPut() throws Exception {
final String body = "{ \"id\":\"1\", \"name\":\"Scott\" }";
MockEndpoint mock = getMockEndpoint("mock:update");
mock.expectedBodiesReceived(body);
mock.expectedHeaderReceived("id", "1");
mock.expectedHeaderReceived(Exchange.HTTP_METHOD, "PUT");
WebRequest req = new PutMethodWebRequest(CONTEXT_URL + "/services/users/1", 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.PutMethodWebRequest in project v7files by thiloplanz.
the class MiltonServletTest method testSimpleScenario.
public void testSimpleScenario() throws IOException, SAXException {
ServletUnitClient sc = sr.newClient();
sc.setAuthentication("V7Files", "admin", "admin");
{
WebRequest request = new MkColWebRequest("http://test/myServlet/1");
WebResponse resp = sc.getResponse(request);
assertEquals(HttpServletResponse.SC_CREATED, resp.getResponseCode());
}
{
WebRequest request = new PutMethodWebRequest("http://test/myServlet/1/test.txt", new ByteArrayInputStream("testPUT".getBytes()), "text/plain");
WebResponse resp = sc.getResponse(request);
assertEquals(HttpServletResponse.SC_CREATED, resp.getResponseCode());
}
assertExists(sc, "http://test/myServlet/1/test.txt");
{
WebRequest request = new MoveWebRequest("http://test/myServlet/1", "/myServlet/2");
WebResponse resp = sc.getResponse(request);
assertEquals(HttpServletResponse.SC_CREATED, resp.getResponseCode());
}
}
use of com.meterware.httpunit.PutMethodWebRequest in project v7files by thiloplanz.
the class BucketsServletTest method testEchoPutPUT.
public void testEchoPutPUT() throws IOException, SAXException {
ServletUnitClient sc = sr.newClient();
{
WebRequest request = new PutMethodWebRequest("http://test/myServlet/1", new ByteArrayInputStream("testPUT".getBytes()), "text/plain");
try {
sc.getResponse(request);
fail("bucket not found => 404");
} catch (HttpNotFoundException e) {
assertEquals("Bucket '1' not found", e.getResponseMessage());
}
}
prepareBucket("1", "EchoPut", null, null);
{
WebRequest request = new PutMethodWebRequest("http://test/myServlet/1", new ByteArrayInputStream("testPUT".getBytes()), "text/plain");
request.setParameter("sha", "1234");
try {
sc.getResponse(request);
fail("uploads not allowed => 405");
} catch (HttpException e) {
assertEquals(HttpServletResponse.SC_METHOD_NOT_ALLOWED, e.getResponseCode());
}
}
prepareBucket("2", "EchoPut", null, "EchoPut");
{
WebRequest request = new PutMethodWebRequest("http://test/myServlet/2", new ByteArrayInputStream("testPUT".getBytes()), "text/plain");
WebResponse response = sc.getResponse(request);
assertEquals(DigestUtils.shaHex("testPUT".getBytes()), response.getText());
assertMockMongoContainsDocument("test.v7files.content", DigestUtils.sha("testPUT".getBytes()));
WebRequest get = new GetMethodWebRequest("http://test/myServlet/2");
get.setParameter("sha", response.getText());
assertEquals("testPUT", sc.getResponse(get).getText());
}
}
use of com.meterware.httpunit.PutMethodWebRequest in project v7files by thiloplanz.
the class MiltonServletTest method testCOPYFolder.
public void testCOPYFolder() throws IOException, SAXException {
ServletUnitClient sc = sr.newClient();
sc.setAuthentication("V7Files", "admin", "admin");
{
WebRequest request = new MkColWebRequest("http://test/myServlet/1");
WebResponse resp = sc.getResponse(request);
assertEquals(HttpServletResponse.SC_CREATED, resp.getResponseCode());
}
{
WebRequest request = new PutMethodWebRequest("http://test/myServlet/1/test.txt", new ByteArrayInputStream("testPUT".getBytes()), "text/plain");
WebResponse resp = sc.getResponse(request);
assertEquals(HttpServletResponse.SC_CREATED, resp.getResponseCode());
}
{
WebRequest request = new CopyWebRequest("http://test/myServlet/1", "/myServlet/2");
WebResponse resp = sc.getResponse(request);
assertEquals(HttpServletResponse.SC_CREATED, resp.getResponseCode());
}
assertExists(sc, "http://test/myServlet/2/test.txt");
}
Aggregations