use of com.meterware.httpunit.WebConversation in project javaee7-samples by javaee-samples.
the class MyResourceTest method testPut.
@Test
public void testPut() throws IOException, SAXException {
WebConversation conv = new WebConversation();
conv.setAuthentication("file", "u1", "p1");
byte[] bytes = new byte[8];
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
PutMethodWebRequest putRequest = new PutMethodWebRequest(base + "/webresources/myresource", bais, "text/plain");
try {
WebResponse response = conv.getResponse(putRequest);
} catch (HttpException e) {
assertNotNull(e);
assertEquals(403, e.getResponseCode());
return;
}
fail("PUT is not authorized and can still be called");
}
use of com.meterware.httpunit.WebConversation in project javaee7-samples by javaee-samples.
the class MyResourceTest method testGetWithCorrectCredentials.
@Test
public void testGetWithCorrectCredentials() throws IOException, SAXException {
WebConversation conv = new WebConversation();
conv.setAuthentication("file", "u1", "p1");
GetMethodWebRequest getRequest = new GetMethodWebRequest(base + "/webresources/myresource");
WebResponse response = null;
try {
response = conv.getResponse(getRequest);
} catch (AuthorizationRequiredException e) {
fail(e.getMessage());
}
assertNotNull(response);
assertTrue(response.getText().contains("get"));
}
use of com.meterware.httpunit.WebConversation in project geode by apache.
the class TestSessionsTomcat8Base method testSessionPersists1.
/**
* Check that our session persists. The values we pass in as query params are used to set
* attributes on the session.
*/
@Test
public void testSessionPersists1() throws Exception {
String key = "value_testSessionPersists1";
String value = "Foo";
WebConversation wc = new WebConversation();
WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
req.setParameter("cmd", QueryCommand.SET.name());
req.setParameter("param", key);
req.setParameter("value", value);
WebResponse response = wc.getResponse(req);
String sessionId = response.getNewCookieValue("JSESSIONID");
assertNotNull("No apparent session cookie", sessionId);
// The request retains the cookie from the prior response...
req.setParameter("cmd", QueryCommand.GET.name());
req.setParameter("param", key);
req.removeParameter("value");
response = wc.getResponse(req);
assertEquals(value, response.getText());
}
use of com.meterware.httpunit.WebConversation in project geode by apache.
the class TestSessionsTomcat8Base method testBasicRegion.
/**
* Test that a session attribute gets set into the region too.
*/
@Test
public void testBasicRegion() throws Exception {
String key = "value_testBasicRegion";
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);
String sessionId = response.getNewCookieValue("JSESSIONID");
assertEquals(value, region.get(sessionId).getAttribute(key));
}
use of com.meterware.httpunit.WebConversation in project geode by apache.
the class TestSessionsTomcat8Base method testCommitSessionValveInvalidSession.
/*
* Test for issue #38 CommitSessionValve throws exception on invalidated sessions
*/
@Test
public void testCommitSessionValveInvalidSession() throws Exception {
Callback c = new Callback() {
@Override
public void call(HttpServletRequest request, HttpServletResponse response) throws IOException {
HttpSession session = request.getSession();
session.invalidate();
response.getWriter().write("done");
}
};
servlet.getServletContext().setAttribute("callback", c);
WebConversation wc = new WebConversation();
WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
// Execute the callback
req.setParameter("cmd", QueryCommand.CALLBACK.name());
req.setParameter("param", "callback");
WebResponse response = wc.getResponse(req);
assertEquals("done", response.getText());
}
Aggregations