1 package org.wamblee.security.authentication.jpa;
3 import java.sql.Connection;
4 import java.sql.ResultSet;
6 import org.junit.After;
7 import org.junit.Before;
8 import org.wamblee.security.authentication.GroupSet;
9 import org.wamblee.security.authentication.InMemoryGroupSetTest;
10 import org.wamblee.security.authentication.jpa.JpaGroupSet;
11 import org.wamblee.support.persistence.JpaTester;
12 import org.wamblee.support.persistence.TransactionProxyFactory;
13 import org.wamblee.support.persistence.DatabaseUtils.JdbcUnitOfWork;
16 public class JpaGroupSetTest extends InMemoryGroupSetTest {
18 private static final String GROUP_TABLE = "SEC_GROUP";
20 private static final String GROUP_QUERY = "select * from " + GROUP_TABLE +
23 private JpaTester jpaTester;
26 public void setUp() throws Exception {
27 jpaTester = new JpaTester(new SecurityPersistenceUnit());
30 // Superclass setup will call createGroupSet so requires initialized JPA.
35 public void tearDown() throws Exception {
41 protected void checkGroupCount(int aSize) throws Exception {
42 super.checkGroupCount(aSize);
43 assertEquals(aSize, jpaTester.getDbUtils().getTableSize(GROUP_TABLE));
47 protected void checkGroupExists(String aGroup) throws Exception {
48 super.checkGroupExists(aGroup);
49 assertTrue(groupExists(aGroup));
52 private boolean groupExists(final String aGroup) throws Exception {
53 return jpaTester.getDbUtils().executeInTransaction(
54 new JdbcUnitOfWork<Boolean>() {
56 public Boolean execute(Connection aConnection) throws Exception {
57 ResultSet res = jpaTester.getDbUtils().executeQuery(
58 aConnection, GROUP_QUERY, aGroup);
65 protected void checkGroupNotExists(String aGroup) throws Exception {
66 super.checkGroupNotExists(aGroup);
67 assertFalse(groupExists(aGroup));
71 protected GroupSet createGroupSet() {
72 TransactionProxyFactory<GroupSet> factory = new TransactionProxyFactory<GroupSet>(
73 jpaTester.getJpaBuilder(), GroupSet.class);
74 GroupSet groupset = new JpaGroupSet(factory.getTransactionScopedEntityManager());
75 GroupSet proxy = factory.getProxy(groupset);