/** * 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)); }
/** * Test that invalidating a session makes it's attributes inaccessible. */ @Test public void testInvalidate() throws Exception { String key = "value_testInvalidate"; 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); // Invalidate the session req.removeParameter("param"); req.removeParameter("value"); req.setParameter("cmd", QueryCommand.INVALIDATE.name()); 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()); }
/** * 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)); }
/** * 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()); }