From: erik Date: Mon, 26 Apr 2010 20:15:57 +0000 (+0000) Subject: (no commit message) X-Git-Tag: wamblee-utils-0.2.2^2~40 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=da0e2f53e8060979b191b66d8f392ea0a0241a5f;p=utils --- 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 index 00000000..4d44124e --- /dev/null +++ b/security/jpatest/src/test/java/org/wamblee/usermgt/jpa/JpaGroupSetTest.java @@ -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() { + @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 factory = new TransactionProxyFactory( + 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 index 00000000..8f3aeb8a --- /dev/null +++ b/security/jpatest/src/test/java/org/wamblee/usermgt/jpa/SecurityPersistenceUnit.java @@ -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_"); + } + }); + } +}