1 package org.wamblee.usermgt.jpa;
3 import java.sql.Connection;
4 import java.sql.ResultSet;
5 import java.sql.SQLException;
7 import org.junit.After;
8 import org.junit.Before;
9 import org.junit.Ignore;
10 import org.wamblee.support.persistence.JpaTester;
11 import org.wamblee.support.persistence.TransactionProxyFactory;
12 import org.wamblee.support.persistence.DatabaseUtils.JdbcUnitOfWork;
13 import org.wamblee.usermgt.GroupSet;
14 import org.wamblee.usermgt.InMemoryGroupSetTest;
17 public class JpaGroupSetTest extends InMemoryGroupSetTest {
19 private static final String GROUP_TABLE = "SEC_GROUP";
21 private static final String GROUP_QUERY = "select * from " + GROUP_TABLE +
24 private JpaTester jpaTester;
27 public void setUp() throws Exception {
28 jpaTester = new JpaTester(new SecurityPersistenceUnit());
31 // Superclass setup will call createGroupSet so requires initialized JPA.
36 public void tearDown() throws Exception {
42 protected void checkGroupCount(int aSize) throws Exception {
43 super.checkGroupCount(aSize);
44 assertEquals(aSize, jpaTester.getDbUtils().getTableSize(GROUP_TABLE));
48 protected void checkGroupExists(String aGroup) throws Exception {
49 super.checkGroupExists(aGroup);
50 assertTrue(groupExists(aGroup));
53 private boolean groupExists(final String aGroup) throws Exception {
54 return jpaTester.getDbUtils().executeInTransaction(
55 new JdbcUnitOfWork<Boolean>() {
57 public Boolean execute(Connection aConnection) throws Exception {
58 ResultSet res = jpaTester.getDbUtils().executeQuery(
59 aConnection, GROUP_QUERY, aGroup);
66 protected void checkGroupNotExists(String aGroup) throws Exception {
67 super.checkGroupNotExists(aGroup);
68 assertFalse(groupExists(aGroup));
72 protected GroupSet createGroupSet() {
73 TransactionProxyFactory<GroupSet> factory = new TransactionProxyFactory<GroupSet>(
74 jpaTester.getJpaBuilder(), GroupSet.class);
75 GroupSet groupset = new JpaGroupSet(factory.getTransactionScopedEntityManager());
76 GroupSet proxy = factory.getProxy(groupset);