001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.test;
019:
020: import java.util.ArrayList;
021: import java.util.List;
022:
023: import junit.framework.TestCase;
024: import de.finix.contelligent.CallData;
025: import de.finix.contelligent.ComponentManager;
026: import de.finix.contelligent.ComponentPath;
027: import de.finix.contelligent.Contelligent;
028: import de.finix.contelligent.Session;
029: import de.finix.contelligent.core.ContelligentImpl;
030: import de.finix.contelligent.core.security.ContelligentSecurityManager;
031: import de.finix.contelligent.core.security.User;
032: import de.finix.contelligent.util.ThreadedMem;
033:
034: /**
035: * This is the base class for all JUnit tests concerning Contelligent. Its main
036: * purpose is to provide utility methods such as access to logging or JNDI but
037: * currently there aren't any such methods so if you need one feel free to
038: * implement it ...
039: */
040: public class ContelligentTestCase extends TestCase {
041: final static public ComponentPath TEST_ROOT_DIR = new ComponentPath(
042: "/contelligent/test/");
043:
044: final static public ComponentPath TEST_WORK_DIR = TEST_ROOT_DIR
045: .append("work");
046:
047: final static public ComponentPath TEST_PAGES_DIR = TEST_ROOT_DIR
048: .append("pages");
049:
050: final static public String ALLPROPS_TYPE_NAME = "contelligent.test.TypeWithAllPropertyTypes";
051:
052: final static public String FOLDER_TYPE_NAME = ComponentManager.DEFAULT_FOLDER_TYPE;
053:
054: final Contelligent contelligentSystem;
055:
056: public ContelligentTestCase(String s) {
057: super (s);
058: contelligentSystem = ContelligentImpl.getInstance();
059: }
060:
061: // ==============================================================================
062: // non-public util methods:
063: // ==============================================================================
064:
065: protected Contelligent getContelligent() {
066: return contelligentSystem;
067: }
068:
069: protected Session beginSession(String userId, String groupId,
070: String password) throws Exception {
071: return contelligentSystem.beginSession(userId, groupId,
072: password);
073: }
074:
075: protected void endSession(Session session) {
076: contelligentSystem.invalidateSession(session);
077: }
078:
079: protected void beginTx(CallData callData) throws Exception {
080: ThreadedMem.setCallData(callData);
081: ThreadedMem.setActualManager(callData.getActualManager());
082: contelligentSystem.beginTx();
083: }
084:
085: protected void commitTx() throws Exception {
086: contelligentSystem.commitTx();
087: }
088:
089: protected void rollbackTx() throws Exception {
090: contelligentSystem.rollbackTx();
091: }
092:
093: protected CallData createCallData(Session session) {
094: return contelligentSystem.createCallData(session);
095: }
096:
097: protected void deleteComponent(ComponentPath target, String name,
098: CallData callData) throws Exception {
099: ComponentManager cm = callData.getActualManager();
100:
101: beginTx(callData);
102: cm.lockComponent(target, callData);
103: cm.deleteComponentTree(callData, target.append(name));
104: cm.unlockComponent(target, callData);
105: commitTx();
106: }
107:
108: protected List createList(Object obj1) {
109: ArrayList list = new ArrayList();
110: list.add(obj1);
111: return list;
112: }
113:
114: protected void changeCM(CallData callData, ComponentManager manager) {
115: contelligentSystem.changeCM(callData, manager);
116: }
117:
118: protected User getSystemUser() {
119: return ContelligentSecurityManager.getSystemUser();
120: }
121: }
|