use of com.meterware.servletunit.ServletUnitClient 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.servletunit.ServletUnitClient in project v7files by thiloplanz.
the class BucketsServletTest method testEchoPutGET.
public void testEchoPutGET() throws IOException, SAXException {
ServletUnitClient sc = sr.newClient();
{
WebRequest request = new GetMethodWebRequest("http://test/myServlet/1");
request.setParameter("sha", "1234");
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 GetMethodWebRequest("http://test/myServlet/1");
request.setParameter("sha", "1234");
try {
sc.getResponse(request);
fail("bucket not found => 404");
} catch (HttpNotFoundException e) {
assertEquals("Bucket '1' does not have a file matching digest '1234'", e.getResponseMessage());
}
}
MongoContentStorage storage = new MongoContentStorage(getMongo().getDB("test"));
ContentSHA sha = storage.storeContent(new ByteArrayInputStream("test".getBytes()));
{
WebRequest request = new GetMethodWebRequest("http://test/myServlet/1");
request.setParameter("sha", sha.getDigest());
request.setParameter("filename", "a.txt");
WebResponse response = sc.getResponse(request);
assertEquals("test", response.getText());
assertEquals(sha.getDigest(), response.getHeaderField("ETag"));
assertEquals(4, response.getContentLength());
assertEquals("attachment; filename=\"a.txt\"", response.getHeaderField("Content-Disposition"));
}
{
WebRequest request = new GetMethodWebRequest("http://test/myServlet/1");
request.setParameter("sha", sha.getDigest());
request.setHeaderField("If-None-Match", sha.getDigest());
WebResponse response = sc.getResponse(request);
assertEquals(HttpServletResponse.SC_NOT_MODIFIED, response.getResponseCode());
}
}
use of com.meterware.servletunit.ServletUnitClient 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.servletunit.ServletUnitClient in project v7files by thiloplanz.
the class MiltonServletTest method testGET.
public void testGET() throws IOException, SAXException {
ServletUnitClient sc = sr.newClient();
sc.setAuthentication("V7Files", "admin", "admin");
{
WebRequest request = new GetMethodWebRequest("http://test/myServlet/a.txt");
try {
sc.getResponse(request);
fail("file not found => 404");
} catch (HttpNotFoundException e) {
}
}
prepareMockData("test.v7files.files", new BasicBSONObject("_id", new ObjectId()).append("filename", "a.txt").append("parent", "webdav").append("created_at", new Date()).append("in", "abcd".getBytes()));
assertGET(sc, "http://test/myServlet/a.txt", "abcd");
{
WebRequest request = new GetMethodWebRequest("http://test/myServlet/a.txt");
WebResponse resp = sc.getResponse(request);
String eTag = resp.getHeaderField("Etag");
request.setHeaderField("If-None-Match", eTag);
resp = sc.getResponse(request);
assertEquals(HttpServletResponse.SC_NOT_MODIFIED, resp.getResponseCode());
assertEquals("", resp.getText());
}
}
use of com.meterware.servletunit.ServletUnitClient 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());
}
}
Aggregations