use of com.meterware.httpunit.WebResponse in project geode by apache.
the class TestSessionsTomcat8Base method testRemoveAttribute.
/**
* Test that removing a session attribute also removes it from the region
*/
@Test
public void testRemoveAttribute() throws Exception {
String key = "value_testRemoveAttribute";
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");
// Implicitly remove the attribute
req.removeParameter("value");
wc.getResponse(req);
// The attribute should not be accessible now...
req.setParameter("cmd", QueryCommand.GET.name());
req.setParameter("param", key);
response = wc.getResponse(req);
assertEquals("", response.getText());
assertNull(region.get(sessionId).getAttribute(key));
}
use of com.meterware.httpunit.WebResponse in project geode by apache.
the class TestSessionsTomcat8Base method testMultipleAttributeUpdates.
/**
* Test that multiple attribute updates, within the same request result in only the latest one
* being effective.
*/
@Test
public void testMultipleAttributeUpdates() throws Exception {
final String key = "value_testMultipleAttributeUpdates";
Callback c = new Callback() {
@Override
public void call(HttpServletRequest request, HttpServletResponse response) throws IOException {
HttpSession session = request.getSession();
for (int i = 0; i < 1000; i++) {
session.setAttribute(key, Integer.toString(i));
}
}
};
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);
String sessionId = response.getNewCookieValue("JSESSIONID");
assertEquals("999", region.get(sessionId).getAttribute(key));
}
use of com.meterware.httpunit.WebResponse in project geode by apache.
the class TestSessionsTomcat8Base method testSanity.
/**
* Check that the basics are working
*/
@Test
public void testSanity() throws Exception {
WebConversation wc = new WebConversation();
WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
req.setParameter("cmd", QueryCommand.GET.name());
req.setParameter("param", "null");
WebResponse response = wc.getResponse(req);
assertEquals("JSESSIONID", response.getNewCookieNames()[0]);
}
use of com.meterware.httpunit.WebResponse in project geode by apache.
the class TestSessionsBase method testRemoveAttribute.
/**
* Test that removing a session attribute also removes it from the region
*/
@Test
public void testRemoveAttribute() throws Exception {
String key = "value_testRemoveAttribute";
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");
// Implicitly remove the attribute
req.removeParameter("value");
wc.getResponse(req);
// The attribute should not be accessible now...
req.setParameter("cmd", QueryCommand.GET.name());
req.setParameter("param", key);
response = wc.getResponse(req);
assertEquals("", response.getText());
assertNull(region.get(sessionId).getAttribute(key));
}
use of com.meterware.httpunit.WebResponse in project geode by apache.
the class TestSessionsBase 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