From da9f9b076d235d96adb7513d3004697bfc91293b Mon Sep 17 00:00:00 2001 From: Erik Brakkee Date: Tue, 13 May 2008 21:14:23 +0000 Subject: [PATCH 1/1] HibernateGroupSet no longer depends on SpringTestCase. --- .../wamblee/usermgt/InMemoryGroupSetTest.java | 13 +---- .../wamblee/usermgt/InMemoryUserSetTest.java | 9 --- .../hibernate/HibernateGroupSetTest.java | 58 ++++++++++++++----- .../hibernate/HibernateUserSetTest.java | 14 +---- 4 files changed, 48 insertions(+), 46 deletions(-) diff --git a/security/src/test/java/org/wamblee/usermgt/InMemoryGroupSetTest.java b/security/src/test/java/org/wamblee/usermgt/InMemoryGroupSetTest.java index 100fad37..3fe6c5a8 100644 --- a/security/src/test/java/org/wamblee/usermgt/InMemoryGroupSetTest.java +++ b/security/src/test/java/org/wamblee/usermgt/InMemoryGroupSetTest.java @@ -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 aSprings, - Class aMappings) { - super(aSprings, aMappings); - } /** * This method must be overriden in subclasses. diff --git a/security/src/test/java/org/wamblee/usermgt/InMemoryUserSetTest.java b/security/src/test/java/org/wamblee/usermgt/InMemoryUserSetTest.java index 23cfb24e..e41a318c 100644 --- a/security/src/test/java/org/wamblee/usermgt/InMemoryUserSetTest.java +++ b/security/src/test/java/org/wamblee/usermgt/InMemoryUserSetTest.java @@ -40,15 +40,6 @@ public class InMemoryUserSetTest extends TestCase { private Group _group; - public InMemoryUserSetTest() { - super(); - } - - protected InMemoryUserSetTest(Class aSprings, - Class aMappings) { - super(); - } - /** * This method must be overriden in subclasses. * @return New user set object. diff --git a/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateGroupSetTest.java b/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateGroupSetTest.java index 5e5871e4..be27a629 100644 --- a/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateGroupSetTest.java +++ b/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateGroupSetTest.java @@ -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 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 res = new HashMap(); - 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; } } 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 30a7acc4..22ed9cd5 100644 --- a/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateUserSetTest.java +++ b/security/src/test/java/org/wamblee/usermgt/hibernate/HibernateUserSetTest.java @@ -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 _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; } -- 2.31.1