/* * Copyright 2005 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.wamblee.usermgt.hibernate; import java.lang.reflect.Method; import java.sql.SQLException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wamblee.cache.Cache; import org.wamblee.general.BeanKernel; import org.wamblee.test.spring.TestTransactionCallbackWithoutResult; import org.wamblee.usermgt.UserAdministration; import org.wamblee.usermgt.UserAdministrationImplTest; import org.wamblee.usermgt.UsermgtSpringConfigFiles; /** * User administration tests with persistence based on Hibernate. This executes * the same test cases as {@link org.wamblee.usermgt.UserAdministrationImplTest} * with in addition, one test case that executes all Hibernate test cases * separately with each test case in its own transaction. * * @author Erik Brakkee */ public class HibernateUserAdministrationTest extends UserAdministrationImplTest { private static final Log LOG = LogFactory.getLog(HibernateUserAdministrationTest.class); public HibernateUserAdministrationTest() { super(UsermgtSpringConfigFiles.class, UsermgtHibernateMappingFiles.class); } /* (non-Javadoc) * @see org.wamblee.usermgt.UserAdministrationImplTest#setUp() */ @Override protected void setUp() throws Exception { super.setUp(); clearUserCache(); } /* * (non-Javadoc) * * @see org.wamblee.usermgt.UserAdministrationImplTest#createAdmin() */ @Override protected UserAdministration createAdmin() { return BeanKernel.getBeanFactory().find(UserAdministration.class); } public void testAllTestsInASeparateTransaction() throws SQLException { Method[] methods = UserAdministrationImplTest.class.getMethods(); for (final Method method : methods) { if (method.getName().startsWith("test")) { cleanDatabase(); clearUserCache(); executeTransaction(new TestTransactionCallbackWithoutResult() { public void execute() throws Exception { LOG.info("Running test " + method.getName()); try { method.invoke(HibernateUserAdministrationTest.this); } catch (Throwable t) { LOG.error("Test " + method.getName() + " failed"); throw new RuntimeException(t.getMessage(), t); } finally { LOG.info("Test " + method.getName() + " finished"); } } }); } } } /** * */ private void clearUserCache() { BeanKernel.getBeanFactory().find("userCache", Cache.class).clear(); } }