Search in sources :

Example 1 with HttpNotFoundException

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());
    }
}
Also used : HttpNotFoundException(com.meterware.httpunit.HttpNotFoundException) MongoContentStorage(v7db.files.mongodb.MongoContentStorage) WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) PutMethodWebRequest(com.meterware.httpunit.PutMethodWebRequest) PostMethodWebRequest(com.meterware.httpunit.PostMethodWebRequest) ContentSHA(v7db.files.spi.ContentSHA) ByteArrayInputStream(java.io.ByteArrayInputStream) ServletUnitClient(com.meterware.servletunit.ServletUnitClient) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest)

Example 2 with HttpNotFoundException

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
}
Also used : HttpNotFoundException(com.meterware.httpunit.HttpNotFoundException) PostMethodWebRequest(com.meterware.httpunit.PostMethodWebRequest) ServletUnitClient(com.meterware.servletunit.ServletUnitClient) HttpException(com.meterware.httpunit.HttpException)

Example 3 with HttpNotFoundException

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());
    }
}
Also used : BasicBSONObject(org.bson.BasicBSONObject) HttpNotFoundException(com.meterware.httpunit.HttpNotFoundException) WebResponse(com.meterware.httpunit.WebResponse) WebRequest(com.meterware.httpunit.WebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) PutMethodWebRequest(com.meterware.httpunit.PutMethodWebRequest) ObjectId(org.bson.types.ObjectId) ServletUnitClient(com.meterware.servletunit.ServletUnitClient) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) Date(java.util.Date)

Example 4 with HttpNotFoundException

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
    }
}
Also used : HttpNotFoundException(com.meterware.httpunit.HttpNotFoundException) WebRequest(com.meterware.httpunit.WebRequest) PostMethodWebRequest(com.meterware.httpunit.PostMethodWebRequest) ServletUnitClient(com.meterware.servletunit.ServletUnitClient) Test(org.junit.Test)

Example 5 with HttpNotFoundException

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();
}
Also used : HttpNotFoundException(com.meterware.httpunit.HttpNotFoundException) InputStream(java.io.InputStream) ServletRunner(com.meterware.servletunit.ServletRunner) Before(org.junit.Before)

Aggregations

HttpNotFoundException (com.meterware.httpunit.HttpNotFoundException)7 ServletUnitClient (com.meterware.servletunit.ServletUnitClient)6 PostMethodWebRequest (com.meterware.httpunit.PostMethodWebRequest)5 WebRequest (com.meterware.httpunit.WebRequest)5 GetMethodWebRequest (com.meterware.httpunit.GetMethodWebRequest)4 PutMethodWebRequest (com.meterware.httpunit.PutMethodWebRequest)4 WebResponse (com.meterware.httpunit.WebResponse)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 HttpException (com.meterware.httpunit.HttpException)2 BasicBSONObject (org.bson.BasicBSONObject)2 MongoContentStorage (v7db.files.mongodb.MongoContentStorage)2 ContentSHA (v7db.files.spi.ContentSHA)2 ServletRunner (com.meterware.servletunit.ServletRunner)1 InputStream (java.io.InputStream)1 Date (java.util.Date)1 ObjectId (org.bson.types.ObjectId)1 Before (org.junit.Before)1 Test (org.junit.Test)1