(no commit message)
authorerik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Mon, 26 Apr 2010 20:15:57 +0000 (20:15 +0000)
committererik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Mon, 26 Apr 2010 20:15:57 +0000 (20:15 +0000)
security/jpatest/src/test/java/org/wamblee/usermgt/jpa/JpaGroupSetTest.java [new file with mode: 0644]
security/jpatest/src/test/java/org/wamblee/usermgt/jpa/SecurityPersistenceUnit.java [new file with mode: 0644]

diff --git a/security/jpatest/src/test/java/org/wamblee/usermgt/jpa/JpaGroupSetTest.java b/security/jpatest/src/test/java/org/wamblee/usermgt/jpa/JpaGroupSetTest.java
new file mode 100644 (file)
index 0000000..4d44124
--- /dev/null
@@ -0,0 +1,77 @@
+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;
+    }
+
+}
diff --git a/security/jpatest/src/test/java/org/wamblee/usermgt/jpa/SecurityPersistenceUnit.java b/security/jpatest/src/test/java/org/wamblee/usermgt/jpa/SecurityPersistenceUnit.java
new file mode 100644 (file)
index 0000000..8f3aeb8
--- /dev/null
@@ -0,0 +1,18 @@
+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_");
+            }
+        });
+    }
+}