Now the HibernateUserTest is uses components to connect the different parts together...
authorerik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Mon, 12 May 2008 23:20:22 +0000 (23:20 +0000)
committererik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Mon, 12 May 2008 23:20:22 +0000 (23:20 +0000)
Next step is to create a component for the current functionality of SpringTestCase and to use that instead of SpringTestCase.

trunk/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateComponent.java
trunk/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateUserSetTest.java
trunk/security/src/test/java/org/wamblee/usermgt/hibernate/UserGroupRepositoryComponent.java

index b4c69ea728c9b066c5c0349f6ef2681190c540ac..bbe1aefd5e8eecf9d7ffccbcd6f3d3ca0bdc4c23 100644 (file)
@@ -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<RequiredInterface, String> createRequired() {
-        Map<RequiredInterface,String> required = new TreeMap<RequiredInterface, String>();
-        required.put(new DefaultRequiredInterface("datasource", DataSource.class), "datasource");
+        Map<RequiredInterface,String> required = new HashMap<RequiredInterface, String>();
+        required.put(new DefaultRequiredInterface("datasource", DataSource.class), "dataSource");
+        required.put(new DefaultRequiredInterface("mappingFiles", HibernateMappingFiles.class), 
+                "hibernateMappingFiles");
         return required;
     }
 
     private static Map<String, ProvidedInterface> createProvided() {
-        Map<String,ProvidedInterface> provided = new TreeMap<String,ProvidedInterface>(); 
+        Map<String,ProvidedInterface> provided = new HashMap<String,ProvidedInterface>(); 
         
         provided.put("transactionManager", new DefaultProvidedInterface(
                 "transactionMgr", PlatformTransactionManager.class));
index 23403cc8f505f2aa429795088dbc63c7ea933b3b..f7fc0c0f7f85faba7a8579112f05fa1b43560ab8 100644 (file)
@@ -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 {
index 3c406ea90b7b59f75ef1eef029dfd80ce746f909..31350fc933759e5b468fdd5c0fc4f011a8e04da5 100644 (file)
  */ 
 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<RequiredInterface, String> createRequired() {
-        Map<RequiredInterface, String> required = new TreeMap<RequiredInterface, String>();
+        Map<RequiredInterface, String> required = new HashMap<RequiredInterface, String>();
         required.put(new DefaultRequiredInterface("sessionFactory", SessionFactory.class), "sessionFactory");
         return required;
     }
 
     private static Map<String, ProvidedInterface> createProvided() {
-        Map<String,ProvidedInterface> provided = new TreeMap<String,ProvidedInterface>(); 
+        Map<String,ProvidedInterface> provided = new HashMap<String,ProvidedInterface>();
+        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;