KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > terracotta > session > SessionEventTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
3  * notice. All rights reserved.
4  */

5 package com.terracotta.session;
6
7 import com.terracotta.session.util.ContextMgr;
8 import com.terracotta.session.util.DefaultIdGenerator;
9 import com.terracotta.session.util.MockContextMgr;
10 import com.terracotta.session.util.MockLifecycleEventMgr;
11 import com.terracotta.session.util.SessionIdGenerator;
12
13 import junit.framework.TestCase;
14
15 public class SessionEventTest extends TestCase {
16
17   private String JavaDoc serverId;
18   private SessionId sessionId;
19   private MockLifecycleEventMgr eventMgr;
20   private ContextMgr contextMgr;
21   private SessionData session;
22   private int maxIdleSeconds;
23   private SessionIdGenerator idGenerator;
24
25   protected void setUp() throws Exception JavaDoc {
26     maxIdleSeconds = 123;
27     serverId = "someServerId";
28     idGenerator = new DefaultIdGenerator(20, serverId);
29     sessionId = idGenerator.generateNewId();
30     eventMgr = new MockLifecycleEventMgr();
31     contextMgr = new MockContextMgr();
32     session = new SessionData(maxIdleSeconds);
33     session.associate(sessionId, eventMgr, contextMgr);
34   }
35
36   public final void testEvents() {
37     final String JavaDoc name = "someName";
38     session.setAttribute(name, name);
39     assertEquals("setAttribute", eventMgr.getLastMethod());
40     assertSame(session, eventMgr.getSession());
41     assertSame(name, eventMgr.getName());
42     assertSame(name, eventMgr.getValue());
43     eventMgr.clear();
44
45     session.setAttribute(name, name);
46     assertEquals("replaceAttribute", eventMgr.getLastMethod());
47     assertSame(session, eventMgr.getSession());
48     assertSame(name, eventMgr.getName());
49     assertSame(name, eventMgr.getValue());
50     eventMgr.clear();
51
52     session.removeAttribute(name);
53     assertEquals("removeAttribute", eventMgr.getLastMethod());
54     assertSame(session, eventMgr.getSession());
55     assertSame(name, eventMgr.getName());
56     assertSame(name, eventMgr.getValue());
57     eventMgr.clear();
58
59     session.removeAttribute(name);
60     assertNull(eventMgr.getLastMethod());
61     assertNull(eventMgr.getSession());
62     assertNull(eventMgr.getName());
63     assertNull(eventMgr.getValue());
64     eventMgr.clear();
65
66     session.invalidate();
67     assertEquals("fireSessionDestroyedEvent", eventMgr.getLastMethod());
68     assertSame(session, eventMgr.getSession());
69     eventMgr.clear();
70   }
71 }
72
Popular Tags