shiro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lhazlew...@apache.org
Subject svn commit: r798692 - in /incubator/shiro/trunk/core/src: main/java/org/apache/shiro/session/SessionListenerAdapter.java test/java/org/apache/shiro/session/mgt/DefaultSessionManagerTest.java
Date Tue, 28 Jul 2009 19:58:52 GMT
Author: lhazlewood
Date: Tue Jul 28 19:58:52 2009
New Revision: 798692

URL: http://svn.apache.org/viewvc?rev=798692&view=rev
Log:
Added SessionListenerAdapter, created more unit tests to verify SessionListener notification
works as expected.

Added:
    incubator/shiro/trunk/core/src/main/java/org/apache/shiro/session/SessionListenerAdapter.java
Modified:
    incubator/shiro/trunk/core/src/test/java/org/apache/shiro/session/mgt/DefaultSessionManagerTest.java

Added: incubator/shiro/trunk/core/src/main/java/org/apache/shiro/session/SessionListenerAdapter.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/main/java/org/apache/shiro/session/SessionListenerAdapter.java?rev=798692&view=auto
==============================================================================
--- incubator/shiro/trunk/core/src/main/java/org/apache/shiro/session/SessionListenerAdapter.java
(added)
+++ incubator/shiro/trunk/core/src/main/java/org/apache/shiro/session/SessionListenerAdapter.java
Tue Jul 28 19:58:52 2009
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.session;
+
+/**
+ * Simple adapter implementation of the {@link SessionListener} interface, effectively providing
+ * no-op implementations of all methods.
+ *
+ * @since 1.0
+ */
+public class SessionListenerAdapter implements SessionListener {
+
+    /**
+     * Adapter no-op implemenation - does nothing and returns immediately.
+     *
+     * @param session the session that has started.
+     */
+    public void onStart(Session session) {
+        //no-op
+    }
+
+    /**
+     * Adapter no-op implemenation - does nothing and returns immediately.
+     *
+     * @param session the session that has stopped.
+     */
+    public void onStop(Session session) {
+        //no-op
+    }
+
+    /**
+     * Adapter no-op implemenation - does nothing and returns immediately.
+     *
+     * @param session the session that has expired.
+     */
+    public void onExpiration(Session session) {
+        //no-op
+    }
+}

Modified: incubator/shiro/trunk/core/src/test/java/org/apache/shiro/session/mgt/DefaultSessionManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/test/java/org/apache/shiro/session/mgt/DefaultSessionManagerTest.java?rev=798692&r1=798691&r2=798692&view=diff
==============================================================================
--- incubator/shiro/trunk/core/src/test/java/org/apache/shiro/session/mgt/DefaultSessionManagerTest.java
(original)
+++ incubator/shiro/trunk/core/src/test/java/org/apache/shiro/session/mgt/DefaultSessionManagerTest.java
Tue Jul 28 19:58:52 2009
@@ -18,8 +18,7 @@
  */
 package org.apache.shiro.session.mgt;
 
-import org.apache.shiro.session.ExpiredSessionException;
-import org.apache.shiro.session.Session;
+import org.apache.shiro.session.*;
 import org.apache.shiro.session.mgt.eis.SessionDAO;
 import org.apache.shiro.util.ThreadContext;
 import static org.easymock.EasyMock.*;
@@ -70,6 +69,54 @@
     }
 
     @Test
+    public void testSessionListenerStartNotification() {
+        final boolean[] started = new boolean[1];
+        SessionListener listener = new SessionListenerAdapter() {
+            public void onStart(Session session) {
+                started[0] = true;
+            }
+        };
+        sm.add(listener);
+        sm.start((Map) null);
+        assertTrue(started[0]);
+    }
+
+    @Test
+    public void testSessionListenerStopNotification() {
+        final boolean[] stopped = new boolean[1];
+        SessionListener listener = new SessionListenerAdapter() {
+            public void onStop(Session session) {
+                stopped[0] = true;
+            }
+        };
+        sm.add(listener);
+        Serializable id = sm.start((Map) null);
+        sm.stop(id);
+        assertTrue(stopped[0]);
+    }
+
+    @Test
+    public void testSessionListenerExpiredNotification() {
+        final boolean[] expired = new boolean[1];
+        SessionListener listener = new SessionListenerAdapter() {
+            public void onExpiration(Session session) {
+                expired[0] = true;
+            }
+        };
+        sm.add(listener);
+        sm.setGlobalSessionTimeout(100);
+        Serializable id = sm.start((Map) null);
+        sleep(150);
+        try {
+            sm.checkValid(id);
+            fail("check should have thrown an exception.");
+        } catch (InvalidSessionException expected) {
+            //do nothing - expected.
+        }
+        assertTrue(expired[0]);
+    }
+
+    @Test
     public void testSessionDeleteOnExpiration() {
 
         sm.setAutoCreateWhenInvalid(false);



Mime
View raw message