--- /dev/null
+package org.wamblee.usermgt.jpa;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.junit.After;
+import org.junit.Before;
+import org.wamblee.support.persistence.JpaTester;
+import org.wamblee.support.persistence.TransactionProxyFactory;
+import org.wamblee.support.persistence.DatabaseUtils.JdbcUnitOfWork;
+import org.wamblee.usermgt.GroupSet;
+import org.wamblee.usermgt.InMemoryGroupSetTest;
+
+public class JpaGroupSetTest extends InMemoryGroupSetTest {
+
+ private static final String GROUP_TABLE = "SEC_GROUP";
+
+ private static final String GROUP_QUERY = "select * from " + GROUP_TABLE +
+ " where name = ?";
+
+ private JpaTester jpaTester;
+
+ @Before
+ public void setUp() throws Exception {
+ jpaTester = new JpaTester(new SecurityPersistenceUnit());
+ jpaTester.start();
+ // Superclass setup will call createGroupSet so requires initialized JPA.
+ super.setUp();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ jpaTester.stop();
+ super.tearDown();
+ }
+
+ @Override
+ protected void checkGroupCount(int aSize) throws Exception {
+ super.checkGroupCount(aSize);
+ assertEquals(aSize, jpaTester.getDbUtils().getTableSize(GROUP_TABLE));
+ }
+
+ @Override
+ protected void checkGroupExists(String aGroup) throws Exception {
+ super.checkGroupExists(aGroup);
+ assertTrue(groupExists(aGroup));
+ }
+
+ private boolean groupExists(final String aGroup) throws Exception {
+ return jpaTester.getDbUtils().executeInTransaction(
+ new JdbcUnitOfWork<Boolean>() {
+ @Override
+ public Boolean execute(Connection aConnection) throws Exception {
+ ResultSet res = jpaTester.getDbUtils().executeQuery(
+ aConnection, GROUP_QUERY, aGroup);
+ return res.next();
+ }
+ });
+ }
+
+ @Override
+ protected void checkGroupNotExists(String aGroup) throws Exception {
+ super.checkGroupNotExists(aGroup);
+ assertFalse(groupExists(aGroup));
+ }
+
+ @Override
+ protected GroupSet createGroupSet() {
+ TransactionProxyFactory<GroupSet> factory = new TransactionProxyFactory<GroupSet>(
+ jpaTester.getJpaBuilder(), GroupSet.class);
+ GroupSet groupset = new JpaGroupSet(factory.getTransactionScopedEntityManager());
+ GroupSet proxy = factory.getProxy(groupset);
+ return proxy;
+ }
+
+}
--- /dev/null
+package org.wamblee.usermgt.jpa;
+
+import org.dbunit.dataset.DataSetException;
+import org.dbunit.dataset.filter.ITableFilterSimple;
+import org.wamblee.support.persistence.PersistenceUnitDescription;
+
+public class SecurityPersistenceUnit extends PersistenceUnitDescription {
+
+ public SecurityPersistenceUnit() {
+ super("jdbc/security", "securitytest", new ITableFilterSimple() {
+
+ @Override
+ public boolean accept(String aTableName) throws DataSetException {
+ return aTableName.startsWith("SEC_");
+ }
+ });
+ }
+}