2 * Copyright 2005-2010 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;
20 import org.junit.Ignore;
22 import org.wamblee.cache.EhCache;
24 import org.wamblee.system.adapters.ClassConfiguration;
25 import org.wamblee.system.adapters.DefaultContainer;
26 import org.wamblee.system.adapters.ObjectConfiguration;
27 import org.wamblee.system.components.DatabaseComponentFactory;
28 import org.wamblee.system.core.Scope;
29 import org.wamblee.system.spring.component.DatabaseTesterComponent;
30 import org.wamblee.system.spring.component.DatasourceComponent;
32 import org.wamblee.test.spring.TestTransactionCallbackWithoutResult;
34 import org.wamblee.usermgt.UserAdministration;
35 import org.wamblee.usermgt.UserAdministrationImplTest;
37 import java.io.Serializable;
39 import java.lang.reflect.Method;
41 import java.sql.SQLException;
44 * User administration tests with persistence based on Hibernate. This executes
45 * the same test cases as {@link org.wamblee.usermgt.UserAdministrationImplTest}
46 * with in addition, one test case that executes all Hibernate test cases
47 * separately with each test case in its own transaction.
49 * @author Erik Brakkee
52 public class HibernateUserAdministrationTest extends UserAdministrationImplTest {
53 private static final Log LOG = LogFactory
54 .getLog(HibernateUserAdministrationTest.class);
56 private DefaultContainer container;
60 private DatabaseTesterComponent databaseTester;
62 private EhCache<Serializable, Serializable> userCache;
64 private UserAdministration userAdmin;
69 * @see org.wamblee.usermgt.UserAdministrationImplTest#setUp()
72 protected void setUp() throws Exception {
73 container = new DefaultContainer("top");
74 DatabaseComponentFactory.addDatabaseConfig(container);
75 container.addComponent(new DatasourceComponent("datasource"));
76 container.addComponent(new UserAdministrationComponent("admin", true));
78 ClassConfiguration dbtesterConfig = new ClassConfiguration(
79 DatabaseTesterComponent.class);
80 dbtesterConfig.getObjectConfig().getSetterConfig().initAllSetters();
81 container.addComponent("databaseTester", dbtesterConfig);
83 ObjectConfiguration config = new ObjectConfiguration(
84 HibernateUserAdministrationTest.class);
85 config.getSetterConfig().clear().add("setUserCache").add(
86 "setDatabaseTester").add("setUserAdmin");
87 container.addComponent("testcase", this, config);
89 scope = container.start();
91 databaseTester.cleanDatabase();
97 public void setUserCache(EhCache<Serializable, Serializable> aUserCache) {
98 userCache = aUserCache;
101 public void setDatabaseTester(DatabaseTesterComponent aDatabaseTester) {
102 databaseTester = aDatabaseTester;
105 public void setUserAdmin(UserAdministration aUserAdmin) {
106 userAdmin = aUserAdmin;
110 protected void tearDown() throws Exception {
111 container.stop(scope);
118 * @see org.wamblee.usermgt.UserAdministrationImplTest#createAdmin()
121 protected UserAdministration createAdmin() {
125 public void testAllTestsInASeparateTransaction() throws SQLException {
126 Method[] methods = UserAdministrationImplTest.class.getMethods();
128 for (final Method method : methods) {
129 if (method.getName().startsWith("test")) {
130 databaseTester.cleanDatabase();
133 .executeTransaction(new TestTransactionCallbackWithoutResult() {
134 public void execute() throws Exception {
135 LOG.info("Running test " + method.getName());
139 .invoke(HibernateUserAdministrationTest.this);
140 } catch (Throwable t) {
141 LOG.error("Test " + method.getName() +
143 throw new RuntimeException(t.getMessage(), t);
145 LOG.info("Test " + method.getName() +
154 private void clearUserCache() {