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;
* 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.
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}
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)
*/
@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)
*/
@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;
}
});
*/
@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)
*/
@Override
protected GroupSet createGroupSet() {
- return BeanKernel.getBeanFactory().find(GroupSet.class);
+ return _groupSet;
}
}
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;
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);
super.setUp();
}
- public void setDatasource(DataSource aDatasource) {
- _datasource = aDatasource;
- }
-
public void setUserset(UserSet aUserset) {
_userset = aUserset;
}