HibernateGroupSet no longer depends on SpringTestCase.
authorerik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Tue, 13 May 2008 21:14:23 +0000 (21:14 +0000)
committererik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Tue, 13 May 2008 21:14:23 +0000 (21:14 +0000)
security/src/test/java/org/wamblee/usermgt/InMemoryGroupSetTest.java
security/src/test/java/org/wamblee/usermgt/InMemoryUserSetTest.java
security/src/test/java/org/wamblee/usermgt/hibernate/HibernateGroupSetTest.java
security/src/test/java/org/wamblee/usermgt/hibernate/HibernateUserSetTest.java

index 100fad370439897447bb84c73755d60b9f05ee03..3fe6c5a87e1761b722de2b113fb516e2c84790ed 100644 (file)
@@ -19,6 +19,8 @@ package org.wamblee.usermgt;
 import java.sql.SQLException;
 import java.util.Set;
 
+import junit.framework.TestCase;
+
 import org.wamblee.persistence.hibernate.HibernateMappingFiles;
 import org.wamblee.test.spring.SpringTestCase;
 import org.wamblee.test.spring.SpringConfigFiles;
@@ -27,18 +29,9 @@ import org.wamblee.test.spring.SpringConfigFiles;
  * Tests the inmemory group set. Intended to be subclassed for other
  * implementations of group set. 
  */
-public class InMemoryGroupSetTest extends SpringTestCase {
+public class InMemoryGroupSetTest extends TestCase {
     
     protected GroupSet _groups; 
-    
-    public InMemoryGroupSetTest() { 
-        super(SpringConfigFiles.class, HibernateMappingFiles.class);
-    }
-    
-    protected InMemoryGroupSetTest(Class<? extends SpringConfigFiles> aSprings, 
-            Class<? extends HibernateMappingFiles> aMappings) { 
-        super(aSprings, aMappings); 
-    }
    
     /**
      * This method must be overriden in subclasses. 
index 23cfb24e349dfce3c8401b27b90ee120b8d7692d..e41a318c1fccd027048cff454cca2d5503bae872 100644 (file)
@@ -40,15 +40,6 @@ public class InMemoryUserSetTest extends TestCase {
     
     private Group _group; 
     
-    public InMemoryUserSetTest() { 
-        super();
-    }
-    
-    protected InMemoryUserSetTest(Class<? extends SpringConfigFiles> aSprings, 
-            Class<? extends HibernateMappingFiles> aMappings) { 
-        super(); 
-    }
-   
     /**
      * This method must be overriden in subclasses. 
      * @return New user set object. 
index 5e5871e4687bbc2d5446533c23f56b3ab39f11a1..be27a6299a6c9e9849645d79d05e9992257411f1 100644 (file)
@@ -21,12 +21,13 @@ import java.sql.SQLException;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.wamblee.general.BeanKernel;
+import org.wamblee.system.adapters.DefaultContainer;
+import org.wamblee.system.adapters.ObjectConfiguration;
+import org.wamblee.system.core.Scope;
+import org.wamblee.system.spring.DatabaseTesterComponent;
 import org.wamblee.test.spring.TestTransactionCallback;
 import org.wamblee.usermgt.GroupSet;
 import org.wamblee.usermgt.InMemoryGroupSetTest;
-import org.wamblee.usermgt.UsermgtHibernateMappingFiles;
-import org.wamblee.usermgt.UsermgtSpringConfigFiles;
 
 /**
  * Tests for {@link org.wamblee.usermgt.hibernate.HibernateGroupSet} 
@@ -39,8 +40,35 @@ public class HibernateGroupSetTest extends InMemoryGroupSetTest {
     
     private static final String GROUP_QUERY = "select * from " + GROUP_TABLE + " where name = ?";
     
-    public HibernateGroupSetTest() { 
-        super(UsermgtSpringConfigFiles.class, UsermgtHibernateMappingFiles.class);
+    private DefaultContainer _container;
+    private Scope _scope;
+    
+    private DatabaseTesterComponent _databaseTester;
+    private GroupSet _groupSet; 
+    
+    @Override
+    protected void setUp() throws Exception {
+        
+        _container = new UserMgtRepositoryTestContainer("top");
+        
+        ObjectConfiguration config = new ObjectConfiguration(
+                HibernateGroupSetTest.class);
+        config.getSetterConfig().clear().add(
+                "groupSet").add("databaseTester");
+        _container.addComponent("testcase", this, config);
+
+        _scope = _container.start();
+
+        _databaseTester.cleanDatabase();
+        super.setUp();
+    }
+    
+    public void setDatabaseTester(DatabaseTesterComponent aDatabaseTester) {
+        _databaseTester = aDatabaseTester;
+    }
+   
+    public void setGroupSet(GroupSet aGroupSet) {
+        _groupSet = aGroupSet;
     }
 
     /* (non-Javadoc)
@@ -48,9 +76,9 @@ public class HibernateGroupSetTest extends InMemoryGroupSetTest {
      */
     @Override
     protected void checkGroupCount(int aSize) throws SQLException {
-        super.flush(); 
+        _databaseTester.flush(); 
         super.checkGroupCount(aSize);
-        assertEquals(aSize, getTableSize(GROUP_TABLE));
+        assertEquals(aSize, _databaseTester.getTableSize(GROUP_TABLE));
     }
     
     /* (non-Javadoc)
@@ -58,17 +86,17 @@ public class HibernateGroupSetTest extends InMemoryGroupSetTest {
      */
     @Override
     protected void checkGroupExists(final String aGroup) throws SQLException {
-        flush();
+        _databaseTester.flush();
         Map<String,Integer> result = 
-        executeTransaction(new TestTransactionCallback()  { 
+        _databaseTester.executeTransaction(new TestTransactionCallback()  { 
             /* (non-Javadoc)
              * @see org.wamblee.test.TestTransactionCallback#execute()
              */
             @Override
             public Map execute() throws Exception {
-                ResultSet result = executeQuery(GROUP_QUERY, aGroup);
+                ResultSet result = _databaseTester.executeQuery(GROUP_QUERY, aGroup);
                 Map<String,Integer> res = new HashMap<String,Integer>(); 
-                res.put("result", countResultSet(result));
+                res.put("result", _databaseTester.countResultSet(result));
                 return res; 
             }
         }); 
@@ -82,9 +110,9 @@ public class HibernateGroupSetTest extends InMemoryGroupSetTest {
      */
     @Override
     protected void checkGroupNotExists(String aGroup) throws SQLException {
-       flush(); 
-       ResultSet result = executeQuery(GROUP_QUERY, aGroup); 
-       assertEquals(0, countResultSet(result));
+       _databaseTester.flush(); 
+       ResultSet result = _databaseTester.executeQuery(GROUP_QUERY, aGroup); 
+       assertEquals(0, _databaseTester.countResultSet(result));
     }
     
     /* (non-Javadoc)
@@ -92,7 +120,7 @@ public class HibernateGroupSetTest extends InMemoryGroupSetTest {
      */
     @Override
     protected GroupSet createGroupSet() {
-        return BeanKernel.getBeanFactory().find(GroupSet.class)
+        return _groupSet
     }
     
 }
index 30a7acc4b7e8191ec0358b320304bb036ded4b8e..22ed9cd524636dca999759fa85365bc54177aba8 100644 (file)
@@ -54,15 +54,9 @@ public class HibernateUserSetTest extends InMemoryUserSetTest {
     private static final String GROUP_QUERY = "select * from " + GROUP_TABLE
             + " where name = ?";
 
-    public HibernateUserSetTest() {
-        super(UsermgtSpringConfigFiles.class,
-                UsermgtHibernateMappingFiles.class);
-    }
-
     private DefaultContainer _container;
     private Scope _scope;
-
-    private DataSource _datasource;
+    
     private UserSet _userset;
     private GroupSet _groupset;
     private EhCache<Serializable, Serializable> _userCache;
@@ -80,7 +74,7 @@ public class HibernateUserSetTest extends InMemoryUserSetTest {
        
         ObjectConfiguration config = new ObjectConfiguration(
                 HibernateUserSetTest.class);
-        config.getSetterConfig().clear().add("datasource").add("userset").add(
+        config.getSetterConfig().clear().add("userset").add(
                 "groupset").add("databaseTester").add("userCache");
         _container.addComponent("testcase", this, config);
 
@@ -92,10 +86,6 @@ public class HibernateUserSetTest extends InMemoryUserSetTest {
         super.setUp();
     }
 
-    public void setDatasource(DataSource aDatasource) {
-        _datasource = aDatasource;
-    }
-
     public void setUserset(UserSet aUserset) {
         _userset = aUserset;
     }