01: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
02: *
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software
10: * distributed under the License is distributed on an "AS IS" BASIS,
11: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: * See the License for the specific language governing permissions and
13: * limitations under the License.
14: */
15:
16: package org.acegisecurity.ui.session;
17:
18: import junit.framework.TestCase;
19: import org.springframework.mock.web.MockHttpSession;
20: import org.springframework.mock.web.MockServletContext;
21: import org.springframework.web.context.support.StaticWebApplicationContext;
22:
23: import javax.servlet.http.HttpSessionEvent;
24:
25: /**
26: * The HttpSessionEventPublisher tests
27: *
28: * @author Ray Krueger
29: * @version $Id: HttpSessionEventPublisherTests.java 1764 2006-11-20 19:35:11Z raykrueger $
30: */
31: public class HttpSessionEventPublisherTests extends TestCase {
32: //~ Methods ========================================================================================================
33:
34: /**
35: * It's not that complicated so we'll just run it straight through here.
36: */
37: public void testPublisher() {
38: HttpSessionEventPublisher publisher = new HttpSessionEventPublisher();
39:
40: StaticWebApplicationContext context = new StaticWebApplicationContext();
41:
42: MockServletContext servletContext = new MockServletContext();
43: servletContext
44: .setAttribute(
45: StaticWebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
46: context);
47:
48: context.setServletContext(servletContext);
49: context.registerSingleton("listener", TestListener.class, null);
50: context.refresh();
51:
52: MockHttpSession session = new MockHttpSession(servletContext);
53: TestListener listener = (TestListener) context
54: .getBean("listener");
55:
56: HttpSessionEvent event = new HttpSessionEvent(session);
57:
58: publisher.sessionCreated(event);
59:
60: assertNotNull(listener.getCreatedEvent());
61: assertNull(listener.getDestroyedEvent());
62: assertEquals(session, listener.getCreatedEvent().getSession());
63:
64: listener.setCreatedEvent(null);
65: listener.setDestroyedEvent(null);
66:
67: publisher.sessionDestroyed(event);
68: assertNotNull(listener.getDestroyedEvent());
69: assertNull(listener.getCreatedEvent());
70: assertEquals(session, listener.getDestroyedEvent().getSession());
71:
72: }
73: }
|