use of com.meterware.httpunit.GetMethodWebRequest 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.GetMethodWebRequest in project v7files by thiloplanz.
the class MiltonServletTest method assertGET.
private void assertGET(ServletUnitClient sc, String url, String contents) throws IOException, SAXException {
WebRequest request = new GetMethodWebRequest(url);
WebResponse resp = sc.getResponse(request);
assertEquals(contents, resp.getText());
assertEquals(HttpServletResponse.SC_OK, resp.getResponseCode());
}
use of com.meterware.httpunit.GetMethodWebRequest in project wildfly by wildfly.
the class RestoreOriginalRequestTestCase method testRedirectOriginalRequest.
@Test
@OperateOnDeployment("service-provider-1")
public void testRedirectOriginalRequest(@ArquillianResource URL serviceProvider1) throws Exception {
WebRequest request = new GetMethodWebRequest(formatUrl(serviceProvider1) + "/savedRequest/savedRequest.html");
WebConversation conversation = new WebConversation();
WebResponse response = conversation.getResponse(request);
WebForm webForm = response.getForms()[0];
webForm.setParameter("j_username", "tomcat");
webForm.setParameter("j_password", "tomcat");
webForm.getSubmitButtons()[0].click();
response = conversation.getCurrentPage();
assertTrue(response.getText().contains("Back to the original requested resource."));
}
use of com.meterware.httpunit.GetMethodWebRequest in project wildfly by wildfly.
the class RestoreOriginalRequestTestCase method testPostOriginalRequestWithParams.
@Test
@OperateOnDeployment("service-provider-2")
public void testPostOriginalRequestWithParams(@ArquillianResource URL serviceProvider2) throws Exception {
WebRequest request = new GetMethodWebRequest(formatUrl(serviceProvider2) + "/savedRequest/savedRequest.jsp");
request.setParameter("SAVED_PARAM", "Param was saved.");
WebConversation conversation = new WebConversation();
WebResponse response = conversation.getResponse(request);
WebForm webForm = response.getForms()[0];
webForm.setParameter("j_username", "tomcat");
webForm.setParameter("j_password", "tomcat");
webForm.getSubmitButtons()[0].click();
response = conversation.getCurrentPage();
assertTrue(response.getText().contains("Param was saved."));
}
use of com.meterware.httpunit.GetMethodWebRequest in project geode by apache.
the class TestSessionsBase method testSessionExpiration1.
/**
* Test setting the session expiration
*/
@Test
public void testSessionExpiration1() throws Exception {
// TestSessions only live for a second
sessionManager.setMaxInactiveInterval(1);
String key = "value_testSessionExpiration1";
String value = "Foo";
WebConversation wc = new WebConversation();
WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
// Set an attribute
req.setParameter("cmd", QueryCommand.SET.name());
req.setParameter("param", key);
req.setParameter("value", value);
WebResponse response = wc.getResponse(req);
// Sleep a while
Thread.sleep(2000);
// The attribute should not be accessible now...
req.setParameter("cmd", QueryCommand.GET.name());
req.setParameter("param", key);
response = wc.getResponse(req);
assertEquals("", response.getText());
}
Aggregations