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.
17 package org.wamblee.usermgt.hibernate;
19 import java.lang.reflect.Method;
20 import java.sql.SQLException;
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.wamblee.cache.Cache;
25 import org.wamblee.general.BeanKernel;
26 import org.wamblee.test.TestTransactionCallbackWithoutResult;
27 import org.wamblee.usermgt.UserAdministration;
28 import org.wamblee.usermgt.UserAdministrationImplTest;
29 import org.wamblee.usermgt.UsermgtHibernateMappingFiles;
30 import org.wamblee.usermgt.UsermgtSpringConfigFiles;
33 * User administration tests with persistence based on Hibernate. This executes
34 * the same test cases as {@link org.wamblee.usermgt.UserAdministrationImplTest}
35 * with in addition, one test case that executes all Hibernate test cases
36 * separately with each test case in its own transaction.
38 public class HibernateUserAdministrationTest extends UserAdministrationImplTest {
40 private static final Log LOG = LogFactory.getLog(HibernateUserAdministrationTest.class);
42 public HibernateUserAdministrationTest() {
43 super(UsermgtSpringConfigFiles.class,
44 UsermgtHibernateMappingFiles.class);
48 * @see org.wamblee.usermgt.UserAdministrationImplTest#setUp()
51 protected void setUp() throws Exception {
59 * @see org.wamblee.usermgt.UserAdministrationImplTest#createAdmin()
62 protected UserAdministration createAdmin() {
63 return BeanKernel.getBeanFactory().find(UserAdministration.class);
66 public void testAllTestsInASeparateTransaction() throws SQLException {
68 Method[] methods = UserAdministrationImplTest.class.getMethods();
69 for (final Method method : methods) {
70 if (method.getName().startsWith("test")) {
73 executeTransaction(new TestTransactionCallbackWithoutResult() {
74 public void execute() throws Exception {
75 LOG.info("Running test " + method.getName());
77 method.invoke(HibernateUserAdministrationTest.this);
78 } catch (Throwable t) {
79 LOG.error("Test " + method.getName() + " failed");
80 throw new RuntimeException(t.getMessage(), t);
83 LOG.info("Test " + method.getName() + " finished");
95 private void clearUserCache() {
96 BeanKernel.getBeanFactory().find("userCache", Cache.class).clear();