X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=security%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Fusermgt%2Fhibernate%2FHibernateUserAdministrationTest.java;h=d62fbdd6bfafbc702df836cfb7c21d43ed501161;hb=f4d446b84fa1a38ed83cd157f79fdb8233822145;hp=4706e75d6e7604d171057f8ff351672a860a9902;hpb=604319a397eeb71db767a79487f2848dd91e49de;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 4706e75d..d62fbdd6 100644 --- a/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateUserAdministrationTest.java +++ b/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateUserAdministrationTest.java @@ -1,126 +1,199 @@ /* * 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.io.Serializable; -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.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 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. + * 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 { - + /** + * DOCUMENT ME! + */ private static final Log LOG = LogFactory.getLog(HibernateUserAdministrationTest.class); - private DefaultContainer _container; - private Scope _scope; - - private DatabaseTesterComponent _databaseTester; - private EhCache _userCache; - private UserAdministration _userAdmin; - - + /** + * DOCUMENT ME! + */ + private DefaultContainer container; + + /** + * DOCUMENT ME! + */ + private Scope scope; + + /** + * DOCUMENT ME! + */ + private DatabaseTesterComponent databaseTester; + + /** + * DOCUMENT ME! + */ + private EhCache userCache; + + /** + * DOCUMENT ME! + */ + private UserAdministration userAdmin; + /* (non-Javadoc) * @see org.wamblee.usermgt.UserAdministrationImplTest#setUp() */ + /** + * DOCUMENT ME! + * + * @throws Exception DOCUMENT ME! + */ @Override protected void setUp() throws Exception { - - _container = new DefaultContainer("top"); - _container.addComponent(new ExternalDatasourceComponent("datasource")); - _container.addComponent(new UserAdministrationComponent("admin", true)); - - _container.addComponent("databaseTester", DatabaseTesterComponent.class); - - ObjectConfiguration config = new ObjectConfiguration( - HibernateUserAdministrationTest.class); - config.getSetterConfig().clear().add( - "userCache").add("databaseTester").add("userAdmin"); - _container.addComponent("testcase", this, config); - - _scope = _container.start(); - - _databaseTester.cleanDatabase(); - + 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(); } - + + /** + * DOCUMENT ME! + * + * @param aUserCache DOCUMENT ME! + */ public void setUserCache(EhCache aUserCache) { - _userCache = aUserCache; + userCache = aUserCache; } - + + /** + * DOCUMENT ME! + * + * @param aDatabaseTester DOCUMENT ME! + */ public void setDatabaseTester(DatabaseTesterComponent aDatabaseTester) { - _databaseTester = aDatabaseTester; + databaseTester = aDatabaseTester; } - + + /** + * DOCUMENT ME! + * + * @param aUserAdmin DOCUMENT ME! + */ public void setUserAdmin(UserAdministration aUserAdmin) { - _userAdmin = aUserAdmin; + userAdmin = aUserAdmin; + } + + /** + * DOCUMENT ME! + * + * @throws Exception DOCUMENT ME! + */ + @Override + protected void tearDown() throws Exception { + container.stop(scope); + super.tearDown(); } /* * (non-Javadoc) - * + * * @see org.wamblee.usermgt.UserAdministrationImplTest#createAdmin() */ + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ @Override protected UserAdministration createAdmin() { - return _userAdmin; + return userAdmin; } + /** + * DOCUMENT ME! + * + * @throws SQLException DOCUMENT ME! + * @throws RuntimeException DOCUMENT ME! + */ public void testAllTestsInASeparateTransaction() throws SQLException { - Method[] methods = UserAdministrationImplTest.class.getMethods(); + for (final Method method : methods) { if (method.getName().startsWith("test")) { - _databaseTester.cleanDatabase(); + databaseTester.cleanDatabase(); clearUserCache(); - _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"); - } + 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"); + } + } + }); } } } @@ -129,6 +202,6 @@ public class HibernateUserAdministrationTest extends UserAdministrationImplTest * */ private void clearUserCache() { - _userCache.clear(); + userCache.clear(); } }