KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ivata > groupware > GroupwareTestCase


1 /*
2  * Copyright (c) 2001 - 2005 ivata limited.
3  * All rights reserved.
4  * -----------------------------------------------------------------------------
5  * ivata groupware may be redistributed under the GNU General Public
6  * License as published by the Free Software Foundation;
7  * version 2 of the License.
8  *
9  * These programs are free software; you can redistribute them and/or
10  * modify them under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; version 2 of the License.
12  *
13  * These programs are distributed in the hope that they will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  * See the GNU General Public License in the file LICENSE.txt for more
18  * details.
19  *
20  * If you would like a copy of the GNU General Public License write to
21  *
22  * Free Software Foundation, Inc.
23  * 59 Temple Place - Suite 330
24  * Boston, MA 02111-1307, USA.
25  *
26  *
27  * To arrange commercial support and licensing, contact ivata at
28  * http://www.ivata.com/contact.jsp
29  * -----------------------------------------------------------------------------
30  * $Log: GroupwareTestCase.java,v $
31  * Revision 1.3 2005/04/10 20:09:39 colinmacleod
32  * Added new themes.
33  * Changed id type to String.
34  * Changed i tag to em and b tag to strong.
35  * Improved PicoContainerFactory with NanoContainer scripts.
36  *
37  * Revision 1.2 2005/04/09 17:19:11 colinmacleod
38  * Changed copyright text to GPL v2 explicitly.
39  *
40  * Revision 1.1.1.1 2005/03/10 17:50:13 colinmacleod
41  * Restructured ivata op around Hibernate/PicoContainer.
42  * Renamed ivata groupware.
43  *
44  * Revision 1.1 2004/07/13 19:41:17 colinmacleod
45  * Moved project to POJOs from EJBs.
46  * Applied PicoContainer to services layer (replacing session EJBs).
47  * Applied Hibernate to persistence layer (replacing entity EJBs).
48  * -----------------------------------------------------------------------------
49  */

50 package com.ivata.groupware;
51
52 import java.util.HashMap JavaDoc;
53 import java.util.Map JavaDoc;
54
55 import junit.framework.TestCase;
56 import net.sf.hibernate.Interceptor;
57 import net.sf.hibernate.Session;
58 import net.sf.hibernate.SessionFactory;
59 import net.sf.hibernate.cfg.Configuration;
60
61 import com.ivata.groupware.admin.security.server.SecuritySession;
62 import com.ivata.groupware.admin.security.server.TestSecuritySession;
63 import com.ivata.groupware.admin.security.user.UserDO;
64 import com.ivata.groupware.container.persistence.hibernate.HibernateInterceptor;
65 import com.ivata.groupware.container.persistence.hibernate.HibernateManager;
66 import com.ivata.groupware.container.persistence.hibernate.HibernateQueryFactory;
67 import com.ivata.groupware.container.persistence.hibernate.HibernateSession;
68 import com.ivata.mask.persistence.right.DefaultPersistenceRights;
69
70 /**
71  * @author Colin MacLeod
72  * <a HREF='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
73  * @since Jun 2, 2004
74  * @version $Revision: 1.3 $
75  */

76 public class GroupwareTestCase extends TestCase {
77
78     /**
79      * <p>
80      * Hibernate persistence manager.
81      * </p>
82      */

83     private static HibernateManager hibernateManager;
84     /**
85      * <p>
86      * Hibernate session - used to access hibernate.
87      * </p>
88      */

89     private static HibernateSession hibernateSession;
90
91     /**
92      * <p>
93      * Fake security session - gives you admin rights.
94      * </p>
95      */

96     private static SecuritySession securitySession;
97     /**
98      * @return
99      */

100     protected static HibernateManager getHibernateManager() {
101         return hibernateManager;
102     }
103     /**
104      * @return
105      */

106     protected static HibernateSession getHibernateSession() {
107         return hibernateSession;
108     }
109
110     /**
111      * @return
112      */

113     protected static SecuritySession getSecuritySession() {
114         return securitySession;
115     }
116
117     /**
118      * <p>
119      * Hibernate configuration to use to configure the hibernate session.
120      * </p>
121      */

122     Configuration hibernateConfiguration;
123
124     /**
125      * Constructor for AddressBookImplTest.
126      * @param arg0
127      */

128     public GroupwareTestCase(Configuration hibernateConfiguration, String JavaDoc arg0) {
129         super(arg0);
130         this.hibernateConfiguration = hibernateConfiguration;
131     }
132
133     /*
134      * @see TestCase#setUp()
135      */

136     protected synchronized void setUp() throws Exception JavaDoc {
137         super.setUp();
138
139         if (hibernateSession == null) {
140             // set up the hibernate session
141
SessionFactory sessionFactory = hibernateConfiguration.buildSessionFactory();
142
143             Map JavaDoc queryMap = new HashMap JavaDoc();
144             Map JavaDoc queryArgumentsMap = new HashMap JavaDoc();
145
146             hibernateManager = new HibernateManager(sessionFactory,
147                         new HibernateQueryFactory(queryMap, queryArgumentsMap),
148                         new DefaultPersistenceRights());
149             Interceptor interceptor = new HibernateInterceptor(hibernateManager,
150                     sessionFactory);
151             Session wrappedSession = sessionFactory.openSession(interceptor);
152             hibernateSession = new HibernateSession(wrappedSession,
153                     wrappedSession.beginTransaction(), null);
154
155             // create a fake security session for admin
156
UserDO adminUser = (UserDO)hibernateManager.findByPrimaryKey(hibernateSession,
157                 UserDO.class, new Integer JavaDoc(1));
158             securitySession = new TestSecuritySession(adminUser);
159         }
160     }
161
162     /*
163      * @see TestCase#tearDown()
164      */

165     protected void tearDown() throws Exception JavaDoc {
166         super.tearDown();
167     }
168 }
169
Popular Tags