use of com.meterware.httpunit.HttpException 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.HttpException in project camel by apache.
the class HttpClientRouteTest method testHttpRestricMethod.
@Test
public void testHttpRestricMethod() throws Exception {
WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/testHttpMethodRestrict", new ByteArrayInputStream(POST_DATA.getBytes()), "text/xml; charset=UTF-8");
ServletUnitClient client = newClient();
WebResponse response = client.getResponse(req);
assertEquals("The response message is wrong ", "OK", response.getResponseMessage());
assertEquals("The response body is wrong", POST_DATA, response.getText());
// Send other web method request
req = new GetMethodWebRequest(CONTEXT_URL + "/services/testHttpMethodRestrict");
try {
response = client.getResponse(req);
fail("Expect the exception here");
} catch (Exception ex) {
HttpException httpException = (HttpException) ex;
assertEquals("Get a wrong response code", 405, httpException.getResponseCode());
}
}
use of com.meterware.httpunit.HttpException 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());
}
}
Aggregations