use of com.meterware.httpunit.HttpNotFoundException 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.httpunit.HttpNotFoundException 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.HttpNotFoundException 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.httpunit.HttpNotFoundException in project cxf by apache.
the class SpringServletTest method testIgnoreServiceList.
@Test
public void testIgnoreServiceList() throws Exception {
ServletUnitClient client = newClient();
client.setExceptionsThrownOnErrorStatus(true);
WebRequest req = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/");
try {
client.getResponse(req);
fail();
} catch (HttpNotFoundException ex) {
// expected
}
}
use of com.meterware.httpunit.HttpNotFoundException in project cxf by apache.
the class AbstractServletTest method setUp.
@Before
public void setUp() throws Exception {
InputStream configurationStream = getResourceAsStream(getConfiguration());
sr = new ServletRunner(configurationStream, CONTEXT);
try {
sr.newClient().getResponse(CONTEXT_URL + "/services");
} catch (HttpNotFoundException e) {
// ignore, we just want to boot up the servlet
}
HttpUnitOptions.setExceptionsThrownOnErrorStatus(true);
configurationStream.close();
}
Aggregations