001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com> and
003: * Steven Grimm <koreth[remove] at midwinter dot com>
004: * Distributed under the terms of either:
005: * - the common development and distribution license (CDDL), v1.0; or
006: * - the GNU Lesser General Public License, v2.1 or later
007: * $Id: TestMemorySessions.java 3308 2006-06-15 18:54:14Z gbevin $
008: */
009: package com.uwyn.rife.authentication.sessionmanagers;
010:
011: import com.uwyn.rife.authentication.SessionManager;
012: import com.uwyn.rife.ioc.HierarchicalProperties;
013: import junit.framework.TestCase;
014:
015: public class TestSimpleSessionManagerFactory extends TestCase {
016: private SimpleSessionManagerFactory mFactory = null;
017: private HierarchicalProperties mProperties = null;
018:
019: public TestSimpleSessionManagerFactory(String name) {
020: super (name);
021: }
022:
023: public void setUp() {
024: // For most of our tests we'll use MemorySessions, so default to that.
025: mProperties = new HierarchicalProperties();
026: mProperties.put(
027: SimpleSessionManagerFactory.PROPERTYNAME_MANAGER_CLASS,
028: MemorySessions.class.getName());
029:
030: mFactory = new SimpleSessionManagerFactory();
031: }
032:
033: public void testInstantiation() {
034: SessionManager sessions = null;
035:
036: sessions = new SimpleSessionManagerFactory()
037: .getManager(mProperties);
038:
039: assertNotNull(sessions);
040: assertTrue(sessions instanceof MemorySessions);
041: }
042:
043: public void testMultipleSessionMangerIds() {
044: SessionManager smA, smA2, smB;
045:
046: mProperties.put("sessionmanager_id", "a");
047: smA = mFactory.getManager(mProperties);
048:
049: mProperties.put(
050: SimpleSessionManagerFactory.PROPERTYNAME_MANAGER_ID,
051: "b");
052: smB = mFactory.getManager(mProperties);
053:
054: assertNotSame(smA, smB);
055:
056: mProperties.put(
057: SimpleSessionManagerFactory.PROPERTYNAME_MANAGER_ID,
058: "a");
059: smA2 = mFactory.getManager(mProperties);
060:
061: assertSame(smA, smA2);
062: }
063:
064: public void testDefaultIdIsBlank() {
065: SessionManager smDefault, smBlank;
066:
067: smDefault = mFactory.getManager(mProperties);
068:
069: mProperties
070: .put(
071: SimpleSessionManagerFactory.PROPERTYNAME_MANAGER_ID,
072: "");
073: smBlank = mFactory.getManager(mProperties);
074:
075: assertSame(smDefault, smBlank);
076: }
077:
078: public void testSeparateNamespacesForDifferentClassesWithDefaultName() {
079: SessionManager smA, smB;
080:
081: smA = mFactory.getManager(mProperties);
082:
083: mProperties.put(
084: SimpleSessionManagerFactory.PROPERTYNAME_MANAGER_CLASS,
085: CustomSessionManager.class.getName());
086: smB = mFactory.getManager(mProperties);
087:
088: assertNotSame(smA, smB);
089: assertTrue(smA instanceof MemorySessions);
090: assertTrue(smB instanceof CustomSessionManager);
091: }
092:
093: public void testSeparateNamespacesForDifferentClassesWithExplicitName() {
094: SessionManager smA, smB;
095:
096: mProperties.put(
097: SimpleSessionManagerFactory.PROPERTYNAME_MANAGER_ID,
098: "x");
099: smA = mFactory.getManager(mProperties);
100:
101: mProperties.put(
102: SimpleSessionManagerFactory.PROPERTYNAME_MANAGER_CLASS,
103: CustomSessionManager.class.getName());
104: smB = mFactory.getManager(mProperties);
105:
106: assertNotSame(smA, smB);
107: assertTrue(smA instanceof MemorySessions);
108: assertTrue(smB instanceof CustomSessionManager);
109: }
110: }
|