001: /*
002: * CoadunationLib: The coaduntion implementation library.
003: * Copyright (C) 2007 Rift IT Contracting
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
018: *
019: * AuditTrailTest.java
020: * JUnit based test
021: */
022:
023: // package path
024: package com.rift.coad.lib.audit;
025:
026: // java imports
027: import java.util.HashSet;
028: import java.util.Set;
029:
030: // junit import
031: import junit.framework.*;
032:
033: // log4j
034: import org.apache.log4j.Logger;
035: import org.apache.log4j.BasicConfigurator;
036:
037: // coadunation imports
038: import com.rift.coad.lib.security.SessionManager;
039: import com.rift.coad.lib.configuration.Configuration;
040: import com.rift.coad.lib.configuration.ConfigurationFactory;
041: import com.rift.coad.lib.interceptor.credentials.Credential;
042: import com.rift.coad.lib.interceptor.credentials.Login;
043: import com.rift.coad.lib.interceptor.credentials.Session;
044: import com.rift.coad.lib.interceptor.authenticator.SessionAuthenticator;
045: import com.rift.coad.lib.security.AuthorizationException;
046: import com.rift.coad.lib.security.RoleManager;
047: import com.rift.coad.lib.security.ThreadsPermissionContainer;
048: import com.rift.coad.lib.security.ThreadPermissionSession;
049: import com.rift.coad.lib.security.UserSession;
050: import com.rift.coad.lib.security.user.UserSessionManager;
051: import com.rift.coad.lib.security.user.UserStoreManager;
052: import com.rift.coad.lib.security.SessionManager;
053: import com.rift.coad.lib.security.login.LoginManager;
054: import com.rift.coad.lib.thread.CoadunationThreadGroup;
055:
056: /**
057: * The testing of the audit trail test.
058: *
059: * @author brett chaldecott
060: */
061: public class AuditTrailTest extends TestCase {
062:
063: public AuditTrailTest(String testName) {
064: super (testName);
065: BasicConfigurator.configure();
066: }
067:
068: protected void setUp() throws Exception {
069: }
070:
071: protected void tearDown() throws Exception {
072: }
073:
074: /**
075: * Test of getAudit method, of class com.rift.coad.lib.audit.AuditTrail.
076: */
077: public void testGetAudit() throws Exception {
078: System.out.println("getAudit");
079:
080: // init the session information
081: ThreadsPermissionContainer permissions = new ThreadsPermissionContainer();
082: SessionManager.init(permissions);
083: UserStoreManager userStoreManager = new UserStoreManager();
084: UserSessionManager sessionManager = new UserSessionManager(
085: permissions, userStoreManager);
086: LoginManager.init(sessionManager, userStoreManager);
087: // instanciate the thread manager
088: CoadunationThreadGroup threadGroup = new CoadunationThreadGroup(
089: sessionManager, userStoreManager);
090:
091: // add a user to the session for the current thread
092: RoleManager.getInstance();
093:
094: // setup the audit trail class
095: Class target = AuditTrailTest.class;
096:
097: AuditTrail result = AuditTrail.getAudit(target);
098:
099: // log an res
100: result.logEvent("test");
101: result.logEvent("test", new Exception("Test"));
102:
103: // setup the user
104: Set set = new HashSet();
105: set.add("test");
106: set.add("test1");
107: set.add("test2");
108: set.add("test3");
109: UserSession user = new UserSession("test", set);
110: ThreadPermissionSession currentSession = new ThreadPermissionSession(
111: new Long(Thread.currentThread().getId()), user);
112: permissions.putSession(
113: new Long(Thread.currentThread().getId()),
114: currentSession);
115:
116: result.logEvent("test2");
117: result.logEvent("test2", new Exception("Test2"));
118:
119: }
120:
121: }
|