use of com.meterware.httpunit.WebResponse in project geode by apache.
the class TestSessionsBase method testRegionInvalidate.
/**
* Test that a session attribute gets removed from the region when the session is invalidated.
*/
@Test
public void testRegionInvalidate() throws Exception {
String key = "value_testRegionInvalidate";
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");
// Invalidate the session
req.removeParameter("param");
req.removeParameter("value");
req.setParameter("cmd", QueryCommand.INVALIDATE.name());
wc.getResponse(req);
assertNull("The region should not have an entry for this session", region.get(sessionId));
}
use of com.meterware.httpunit.WebResponse in project geode by apache.
the class TestSessionsBase method testExtraSessionsNotCreated.
/**
* Test for issue #45 Sessions are being created for every request
*/
@Test
public void testExtraSessionsNotCreated() throws Exception {
Callback c = new Callback() {
@Override
public void call(HttpServletRequest request, HttpServletResponse response) throws IOException {
// Do nothing with sessions
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());
assertEquals("The region should be empty", 0, region.size());
}
use of com.meterware.httpunit.WebResponse in project geode by apache.
the class TestSessionsTomcat8Base method testRegionInvalidate.
/**
* Test that a session attribute gets removed from the region when the session is invalidated.
*/
@Test
public void testRegionInvalidate() throws Exception {
String key = "value_testRegionInvalidate";
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");
// Invalidate the session
req.removeParameter("param");
req.removeParameter("value");
req.setParameter("cmd", QueryCommand.INVALIDATE.name());
wc.getResponse(req);
assertNull("The region should not have an entry for this session", region.get(sessionId));
}
use of com.meterware.httpunit.WebResponse in project geode by apache.
the class TestSessionsTomcat8Base 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(65000);
// The attribute should not be accessible now...
req.setParameter("cmd", QueryCommand.GET.name());
req.setParameter("param", key);
response = wc.getResponse(req);
assertEquals("", response.getText());
}
use of com.meterware.httpunit.WebResponse in project geode by apache.
the class TestSessionsTomcat8Base method testCallback.
/**
* Test callback functionality. This is here really just as an example. Callbacks are useful to
* implement per test actions which can be defined within the actual test method instead of in a
* separate servlet class.
*/
@Test
public void testCallback() throws Exception {
final String helloWorld = "Hello World";
Callback c = new Callback() {
@Override
public void call(HttpServletRequest request, HttpServletResponse response) throws IOException {
PrintWriter out = response.getWriter();
out.write(helloWorld);
}
};
servlet.getServletContext().setAttribute("callback", c);
WebConversation wc = new WebConversation();
WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port));
req.setParameter("cmd", QueryCommand.CALLBACK.name());
req.setParameter("param", "callback");
WebResponse response = wc.getResponse(req);
assertEquals(helloWorld, response.getText());
}
Aggregations