/*
- * Copyright 2005 the original author or authors.
+ * Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.wamblee.usermgt.hibernate;
+import org.wamblee.system.adapters.DefaultContainer;
+import org.wamblee.system.adapters.ObjectConfiguration;
+import org.wamblee.system.core.Scope;
+import org.wamblee.system.spring.component.DatabaseTesterComponent;
+
+import org.wamblee.test.spring.TestTransactionCallback;
+
+import org.wamblee.usermgt.GroupSet;
+import org.wamblee.usermgt.InMemoryGroupSetTest;
+
import java.sql.ResultSet;
import java.sql.SQLException;
+
import java.util.HashMap;
import java.util.Map;
-import org.wamblee.general.BeanKernel;
-import org.wamblee.test.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}
+ * Tests for {@link org.wamblee.usermgt.hibernate.HibernateGroupSet}
+ *
+ * @author Erik Brakkee
*/
public class HibernateGroupSetTest extends InMemoryGroupSetTest {
-
- private static final String GROUP_TABLE = "GROUPS";
-
- private static final String GROUP_QUERY = "select * from " + GROUP_TABLE + " where name = ?";
-
- public HibernateGroupSetTest() {
- super(UsermgtSpringConfigFiles.class, UsermgtHibernateMappingFiles.class);
+ private static final String GROUP_TABLE = "GROUPS";
+
+ private static final String GROUP_QUERY = "select * from " + GROUP_TABLE +
+ " where name = ?";
+
+ 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("setGroupSet").add(
+ "setDatabaseTester");
+ container.addComponent("testcase", this, config);
+
+ scope = container.start();
+
+ databaseTester.cleanDatabase();
+ super.setUp();
}
- /* (non-Javadoc)
+ @Override
+ protected void tearDown() throws Exception {
+ container.stop(scope);
+ super.tearDown();
+ }
+
+ public void setDatabaseTester(DatabaseTesterComponent aDatabaseTester) {
+ databaseTester = aDatabaseTester;
+ }
+
+ public void setGroupSet(GroupSet aGroupSet) {
+ groupSet = aGroupSet;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
* @see org.wamblee.usermgt.InMemoryGroupSetTest#checkGroupCount(int)
*/
@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)
- * @see org.wamblee.usermgt.InMemoryGroupSetTest#checkGroupExists(java.lang.String)
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.wamblee.usermgt.InMemoryGroupSetTest#checkGroupExists(java.lang.String
+ * )
*/
@Override
protected void checkGroupExists(final String aGroup) throws SQLException {
- flush();
- Map<String,Integer> result =
- executeTransaction(new TestTransactionCallback() {
- /* (non-Javadoc)
- * @see org.wamblee.test.TestTransactionCallback#execute()
- */
- @Override
- public Map execute() throws Exception {
- ResultSet result = executeQuery(GROUP_QUERY, aGroup);
- Map<String,Integer> res = new HashMap<String,Integer>();
- res.put("result", countResultSet(result));
- return res;
- }
- });
-
+ databaseTester.flush();
+
+ Map<String, Integer> result = databaseTester
+ .executeTransaction(new TestTransactionCallback() {
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.wamblee.test.TestTransactionCallback#execute()
+ */
+ @Override
+ public Map execute() throws Exception {
+ ResultSet result = databaseTester.executeQuery(GROUP_QUERY,
+ aGroup);
+ Map<String, Integer> res = new HashMap<String, Integer>();
+ res.put("result", databaseTester.countResultSet(result));
+
+ return res;
+ }
+ });
+
int count = result.get("result");
assertEquals(1, count);
}
-
- /* (non-Javadoc)
- * @see org.wamblee.usermgt.InMemoryGroupSetTest#checkGroupNotExists(java.lang.String)
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.wamblee.usermgt.InMemoryGroupSetTest#checkGroupNotExists(java.lang
+ * .String)
*/
@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)
+
+ /*
+ * (non-Javadoc)
+ *
* @see org.wamblee.usermgt.InMemoryGroupSetTest#createGroupSet()
*/
@Override
protected GroupSet createGroupSet() {
- return BeanKernel.getBeanFactory().find(GroupSet.class);
+ return groupSet;
}
-
}