2 * Copyright 2005 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.wamblee.usermgt.hibernate;
18 import org.apache.commons.logging.Log;
19 import org.apache.commons.logging.LogFactory;
21 import org.wamblee.cache.EhCache;
23 import org.wamblee.system.adapters.ClassConfiguration;
24 import org.wamblee.system.adapters.DefaultContainer;
25 import org.wamblee.system.adapters.ObjectConfiguration;
26 import org.wamblee.system.components.DatabaseComponentFactory;
27 import org.wamblee.system.core.Scope;
28 import org.wamblee.system.spring.component.DatabaseTesterComponent;
29 import org.wamblee.system.spring.component.DatasourceComponent;
31 import org.wamblee.test.spring.TestTransactionCallbackWithoutResult;
33 import org.wamblee.usermgt.UserAdministration;
34 import org.wamblee.usermgt.UserAdministrationImplTest;
36 import java.io.Serializable;
38 import java.lang.reflect.Method;
40 import java.sql.SQLException;
44 * User administration tests with persistence based on Hibernate. This
45 * executes the same test cases as {@link
46 * org.wamblee.usermgt.UserAdministrationImplTest} with in addition, one test
47 * case that executes all Hibernate test cases separately with each test case
48 * in its own transaction.
50 * @author Erik Brakkee
52 public class HibernateUserAdministrationTest extends UserAdministrationImplTest {
56 private static final Log LOG = LogFactory.getLog(HibernateUserAdministrationTest.class);
61 private DefaultContainer container;
71 private DatabaseTesterComponent databaseTester;
76 private EhCache<Serializable, Serializable> userCache;
81 private UserAdministration userAdmin;
84 * @see org.wamblee.usermgt.UserAdministrationImplTest#setUp()
89 * @throws Exception DOCUMENT ME!
92 protected void setUp() throws Exception {
93 container = new DefaultContainer("top");
94 DatabaseComponentFactory.addDatabaseConfig(container);
95 container.addComponent(new DatasourceComponent("datasource"));
96 container.addComponent(new UserAdministrationComponent("admin", true));
98 ClassConfiguration dbtesterConfig = new ClassConfiguration(DatabaseTesterComponent.class);
99 dbtesterConfig.getObjectConfig().getSetterConfig().initAllSetters();
100 container.addComponent("databaseTester", dbtesterConfig);
102 ObjectConfiguration config = new ObjectConfiguration(HibernateUserAdministrationTest.class);
103 config.getSetterConfig().clear().add("setUserCache")
104 .add("setDatabaseTester").add("setUserAdmin");
105 container.addComponent("testcase", this, config);
107 scope = container.start();
109 databaseTester.cleanDatabase();
118 * @param aUserCache DOCUMENT ME!
120 public void setUserCache(EhCache<Serializable, Serializable> aUserCache) {
121 userCache = aUserCache;
127 * @param aDatabaseTester DOCUMENT ME!
129 public void setDatabaseTester(DatabaseTesterComponent aDatabaseTester) {
130 databaseTester = aDatabaseTester;
136 * @param aUserAdmin DOCUMENT ME!
138 public void setUserAdmin(UserAdministration aUserAdmin) {
139 userAdmin = aUserAdmin;
145 * @throws Exception DOCUMENT ME!
148 protected void tearDown() throws Exception {
149 container.stop(scope);
156 * @see org.wamblee.usermgt.UserAdministrationImplTest#createAdmin()
161 * @return DOCUMENT ME!
164 protected UserAdministration createAdmin() {
171 * @throws SQLException DOCUMENT ME!
172 * @throws RuntimeException DOCUMENT ME!
174 public void testAllTestsInASeparateTransaction() throws SQLException {
175 Method[] methods = UserAdministrationImplTest.class.getMethods();
177 for (final Method method : methods) {
178 if (method.getName().startsWith("test")) {
179 databaseTester.cleanDatabase();
181 databaseTester.executeTransaction(new TestTransactionCallbackWithoutResult() {
182 public void execute() throws Exception {
183 LOG.info("Running test " + method.getName());
186 method.invoke(HibernateUserAdministrationTest.this);
187 } catch (Throwable t) {
188 LOG.error("Test " + method.getName()
190 throw new RuntimeException(t.getMessage(), t);
192 LOG.info("Test " + method.getName()
204 private void clearUserCache() {