From: Erik Brakkee Date: Mon, 12 May 2008 23:20:22 +0000 (+0000) Subject: Now the HibernateUserTest is uses components to connect the different parts together... X-Git-Tag: wamblee-utils-0.7~749 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=20ce6fb629be65ed66d290fb758b9cb22921956d;hp=5230835ae5a8401f3a4d75ce395b8ee901e91a5d;p=utils Now the HibernateUserTest is uses components to connect the different parts together and to obtain the test objects. Next step is to create a component for the current functionality of SpringTestCase and to use that instead of SpringTestCase. --- diff --git a/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateComponent.java b/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateComponent.java index b4c69ea7..bbe1aefd 100644 --- a/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateComponent.java +++ b/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateComponent.java @@ -16,6 +16,7 @@ package org.wamblee.usermgt.hibernate; import java.io.IOException; +import java.util.HashMap; import java.util.Map; import java.util.Properties; import java.util.TreeMap; @@ -26,6 +27,7 @@ import org.hibernate.SessionFactory; import org.springframework.core.io.ClassPathResource; import org.springframework.orm.hibernate3.HibernateTemplate; import org.springframework.transaction.PlatformTransactionManager; +import org.wamblee.persistence.hibernate.HibernateMappingFiles; import org.wamblee.system.core.DefaultProvidedInterface; import org.wamblee.system.core.DefaultRequiredInterface; import org.wamblee.system.core.ProvidedInterface; @@ -47,13 +49,15 @@ public class HibernateComponent extends SpringComponent { } private static Map createRequired() { - Map required = new TreeMap(); - required.put(new DefaultRequiredInterface("datasource", DataSource.class), "datasource"); + Map required = new HashMap(); + required.put(new DefaultRequiredInterface("datasource", DataSource.class), "dataSource"); + required.put(new DefaultRequiredInterface("mappingFiles", HibernateMappingFiles.class), + "hibernateMappingFiles"); return required; } private static Map createProvided() { - Map provided = new TreeMap(); + Map provided = new HashMap(); provided.put("transactionManager", new DefaultProvidedInterface( "transactionMgr", PlatformTransactionManager.class)); diff --git a/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateUserSetTest.java b/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateUserSetTest.java index 23403cc8..f7fc0c0f 100644 --- a/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateUserSetTest.java +++ b/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateUserSetTest.java @@ -57,7 +57,9 @@ public class HibernateUserSetTest extends InMemoryUserSetTest { private DefaultContainer _container; private Scope _scope; - private DataSource _datasource; + private DataSource _datasource; + private UserSet _userset; + private GroupSet _groupset; /* (non-Javadoc) * @see org.wamblee.usermgt.InMemoryUserSetTest#setUp() @@ -67,15 +69,16 @@ public class HibernateUserSetTest extends InMemoryUserSetTest { super.setUp(); _container = new DefaultContainer("top"); - Component ds = new ExternalDatasourceComponent("datasource"); - _container.addComponent(ds); + _container.addComponent(new ExternalDatasourceComponent("datasource")); + _container.addComponent("mappingFiles", new UsermgtHibernateMappingFiles()); + _container.addComponent(new HibernateComponent("hibernate")); + _container.addComponent(new UserGroupRepositoryComponent("usersgroups")); ObjectConfiguration config = new ObjectConfiguration(HibernateUserSetTest.class); - config.getSetterConfig().clear().add("datasource"); + config.getSetterConfig().clear().add("datasource").add("userset").add("groupset"); _container.addComponent("testcase", this, config); - _scope = _container.start(); - Object my = _scope.getInterfaceImplementation(ds.getProvidedInterfaces()[0], Object.class); + _scope = _container.start(); clearUserCache(); } @@ -84,6 +87,13 @@ public class HibernateUserSetTest extends InMemoryUserSetTest { _datasource = aDatasource; } + public void setUserset(UserSet aUserset) { + _userset = aUserset; + } + + public void setGroupset(GroupSet aGroupset) { + _groupset = aGroupset; + } @Override protected void tearDown() throws Exception { diff --git a/security/src/test/java/org/wamblee/usermgt/hibernate/UserGroupRepositoryComponent.java b/security/src/test/java/org/wamblee/usermgt/hibernate/UserGroupRepositoryComponent.java index 3c406ea9..31350fc9 100644 --- a/security/src/test/java/org/wamblee/usermgt/hibernate/UserGroupRepositoryComponent.java +++ b/security/src/test/java/org/wamblee/usermgt/hibernate/UserGroupRepositoryComponent.java @@ -15,10 +15,14 @@ */ package org.wamblee.usermgt.hibernate; +import java.util.HashMap; import java.util.Map; import java.util.TreeMap; +import net.sf.ehcache.Ehcache; + import org.hibernate.SessionFactory; +import org.wamblee.cache.EhCache; import org.wamblee.system.core.DefaultProvidedInterface; import org.wamblee.system.core.DefaultRequiredInterface; import org.wamblee.system.core.ProvidedInterface; @@ -36,13 +40,14 @@ public class UserGroupRepositoryComponent extends SpringComponent { } private static Map createRequired() { - Map required = new TreeMap(); + Map required = new HashMap(); required.put(new DefaultRequiredInterface("sessionFactory", SessionFactory.class), "sessionFactory"); return required; } private static Map createProvided() { - Map provided = new TreeMap(); + Map provided = new HashMap(); + provided.put("userCache", new DefaultProvidedInterface("cache", EhCache.class)); provided.put(UserSet.class.getName(), new DefaultProvidedInterface("userset", UserSet.class)); provided.put(GroupSet.class.getName(), new DefaultProvidedInterface("groupset", GroupSet.class)); return provided;