X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=security%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Fusermgt%2Fhibernate%2FHibernateUserAdministrationTest.java;h=074a5eac8eb7f550d501767d0d31b82716f11f31;hb=17775e14ecfb286e59f67117e5cee7e21e95ab1f;hp=e9aa46889f1bad74755aa4bbb501d83e24b83b37;hpb=884550fe9a315a5d17bcafcaebbe9a22452bd0c2;p=utils diff --git a/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateUserAdministrationTest.java b/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateUserAdministrationTest.java index e9aa4688..074a5eac 100644 --- a/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateUserAdministrationTest.java +++ b/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateUserAdministrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005 the original author or authors. + * Copyright 2005-2010 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. @@ -12,48 +12,104 @@ * 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.cache.EhCache; + +import org.wamblee.system.adapters.ClassConfiguration; +import org.wamblee.system.adapters.DefaultContainer; +import org.wamblee.system.adapters.ObjectConfiguration; +import org.wamblee.system.components.DatabaseComponentFactory; +import org.wamblee.system.core.Scope; +import org.wamblee.system.spring.component.DatabaseTesterComponent; +import org.wamblee.system.spring.component.DatasourceComponent; + import org.wamblee.test.spring.TestTransactionCallbackWithoutResult; + import org.wamblee.usermgt.UserAdministration; import org.wamblee.usermgt.UserAdministrationImplTest; -import org.wamblee.usermgt.UsermgtSpringConfigFiles; + +import java.io.Serializable; + +import java.lang.reflect.Method; + +import java.sql.SQLException; /** * 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); + private static final Log LOG = LogFactory + .getLog(HibernateUserAdministrationTest.class); - public HibernateUserAdministrationTest() { - super(UsermgtSpringConfigFiles.class, - UsermgtHibernateMappingFiles.class); - } - - /* (non-Javadoc) + private DefaultContainer container; + + private Scope scope; + + private DatabaseTesterComponent databaseTester; + + private EhCache userCache; + + private UserAdministration userAdmin; + + /* + * (non-Javadoc) + * * @see org.wamblee.usermgt.UserAdministrationImplTest#setUp() */ @Override protected void setUp() throws Exception { + container = new DefaultContainer("top"); + DatabaseComponentFactory.addDatabaseConfig(container); + container.addComponent(new DatasourceComponent("datasource")); + container.addComponent(new UserAdministrationComponent("admin", true)); + + ClassConfiguration dbtesterConfig = new ClassConfiguration( + DatabaseTesterComponent.class); + dbtesterConfig.getObjectConfig().getSetterConfig().initAllSetters(); + container.addComponent("databaseTester", dbtesterConfig); + + ObjectConfiguration config = new ObjectConfiguration( + HibernateUserAdministrationTest.class); + config.getSetterConfig().clear().add("setUserCache").add( + "setDatabaseTester").add("setUserAdmin"); + container.addComponent("testcase", this, config); + + scope = container.start(); + + databaseTester.cleanDatabase(); + super.setUp(); clearUserCache(); } + public void setUserCache(EhCache aUserCache) { + userCache = aUserCache; + } + + public void setDatabaseTester(DatabaseTesterComponent aDatabaseTester) { + databaseTester = aDatabaseTester; + } + + public void setUserAdmin(UserAdministration aUserAdmin) { + userAdmin = aUserAdmin; + } + + @Override + protected void tearDown() throws Exception { + container.stop(scope); + super.tearDown(); + } + /* * (non-Javadoc) * @@ -61,39 +117,39 @@ public class HibernateUserAdministrationTest extends UserAdministrationImplTest */ @Override protected UserAdministration createAdmin() { - return BeanKernel.getBeanFactory().find(UserAdministration.class); + return userAdmin; } public void testAllTestsInASeparateTransaction() throws SQLException { - Method[] methods = UserAdministrationImplTest.class.getMethods(); + for (final Method method : methods) { if (method.getName().startsWith("test")) { - cleanDatabase(); + databaseTester.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"); - } + databaseTester + .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(); + userCache.clear(); } }