/*
* Copyright (c) 2001 - 2005 ivata limited.
* All rights reserved.
* -----------------------------------------------------------------------------
* ivata groupware may be redistributed under the GNU General Public
* License as published by the Free Software Foundation;
* version 2 of the License.
*
* These programs are free software; you can redistribute them and/or
* modify them under the terms of the GNU General Public License
* as published by the Free Software Foundation; version 2 of the License.
*
* These programs are distributed in the hope that they will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License in the file LICENSE.txt for more
* details.
*
* If you would like a copy of the GNU General Public License write to
*
* Free Software Foundation, Inc.
* 59 Temple Place - Suite 330
* Boston, MA 02111-1307, USA.
*
*
* To arrange commercial support and licensing, contact ivata at
* http://www.ivata.com/contact.jsp
* -----------------------------------------------------------------------------
* $Log: GroupwareTestCase.java,v $
* Revision 1.6 2005/10/11 18:53:08 colinmacleod
* Fixed some checkstyle and javadoc issues.
*
* Revision 1.5 2005/09/29 14:17:03 colinmacleod
* Split UserGroupDO off from GroupDO.
* Moved UserGroupDO, Right classes to security subproject (from
* addressbook).
* Centralized user right handling into Rights and RightsImpl.
*
* Revision 1.4 2005/09/15 10:23:23 colinmacleod
* Upgraded Maven to 1.1 (beta-2).
* Upgraded Hibernate to 3.0.5.
*
* Revision 1.3 2005/04/10 20:09:39 colinmacleod
* Added new themes.
* Changed id type to String.
* Changed i tag to em and b tag to strong.
* Improved PicoContainerFactory with NanoContainer scripts.
*
* Revision 1.2 2005/04/09 17:19:11 colinmacleod
* Changed copyright text to GPL v2 explicitly.
*
* Revision 1.1.1.1 2005/03/10 17:50:13 colinmacleod
* Restructured ivata op around Hibernate/PicoContainer.
* Renamed ivata groupware.
*
* Revision 1.1 2004/07/13 19:41:17 colinmacleod
* Moved project to POJOs from EJBs.
* Applied PicoContainer to services layer (replacing session EJBs).
* Applied Hibernate to persistence layer (replacing entity EJBs).
* -----------------------------------------------------------------------------
*/
package com.ivata.groupware;
import java.util.HashMap;
import java.util.Map;
import junit.framework.TestCase;
import org.hibernate.Interceptor;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import com.ivata.groupware.admin.security.server.SecuritySession;
import com.ivata.groupware.admin.security.server.TestSecuritySession;
import com.ivata.groupware.admin.security.user.UserDO;
import com.ivata.groupware.container.persistence.hibernate.HibernateInterceptor;
import com.ivata.groupware.container.persistence.hibernate.HibernateManager;
import com.ivata.groupware.container.persistence.hibernate
.HibernateQueryFactory;
import com.ivata.groupware.container.persistence.hibernate.HibernateSession;
/**
* General test case. TODO
*
* @author Colin MacLeod
* <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
* @since ivata groupware 0.10 (Jun 2, 2004)
* @version $Revision: 1.6 $
*/
public class GroupwareTestCase extends TestCase {
/**
* <p>
* Hibernate persistence manager.
* </p>
*/
private static HibernateManager hibernateManager;
/**
* <p>
* Hibernate session - used to access hibernate.
* </p>
*/
private static HibernateSession hibernateSession;
/**
* <p>
* Fake security session - gives you admin rights.
* </p>
*/
private static SecuritySession securitySession;
/**
* Get the hibernate manager used for test persistence.
*
* @return hibernate manager used for test persistence.
*/
protected static HibernateManager getHibernateManager() {
return hibernateManager;
}
/**
* Get a hibernate session to test persistence.
*
* @return hibernate session to test persistence.
*/
protected static HibernateSession getHibernateSession() {
return hibernateSession;
}
/**
* Get a security session for testing.
*
* @return test security session.
*/
protected static SecuritySession getSecuritySession() {
return securitySession;
}
/**
* <p>
* Hibernate configuration to use to configure the hibernate session.
* </p>
*/
private Configuration hibernateConfiguration;
/**
* Constructor.
*
* @param hibernateConfigurationParam Used to initialize a hibernate
* session for testing.
* @param arg0 {@inheritDoc}.
*/
public GroupwareTestCase(
final Configuration hibernateConfigurationParam,
final String arg0) {
super(arg0);
this.hibernateConfiguration = hibernateConfigurationParam;
}
/**
* {@inheritDoc}
*
* @throws Exception {@inheritDoc}
*/
protected synchronized void setUp() throws Exception {
super.setUp();
if (hibernateSession == null) {
// set up the hibernate session
SessionFactory sessionFactory =
hibernateConfiguration.buildSessionFactory();
Map queryMap = new HashMap();
Map queryArgumentsMap = new HashMap();
hibernateManager = new HibernateManager(sessionFactory,
new HibernateQueryFactory(queryMap, queryArgumentsMap));
Interceptor interceptor = new HibernateInterceptor(hibernateManager,
sessionFactory);
Session wrappedSession = sessionFactory.openSession(interceptor);
hibernateSession = new HibernateSession(wrappedSession,
wrappedSession.beginTransaction(), null);
// create a fake security session for admin
UserDO adminUser = (UserDO)
hibernateManager.findByPrimaryKey(hibernateSession,
UserDO.class, new Integer(1));
securitySession = new TestSecuritySession(adminUser);
}
}
/**
* {@inheritDoc}
*
* @throws Exception {@inheritDoc}
*/
protected void tearDown() throws Exception {
super.tearDown();
}
}
|