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.wamblee.support.persistence.JpaTester;
10 import org.wamblee.support.persistence.TransactionProxyFactory;
11 import org.wamblee.support.persistence.DatabaseUtils.JdbcUnitOfWork;
12 import org.wamblee.usermgt.GroupSet;
13 import org.wamblee.usermgt.InMemoryGroupSetTest;
15 public class JpaGroupSetTest extends InMemoryGroupSetTest {
17 private static final String GROUP_TABLE = "SEC_GROUP";
19 private static final String GROUP_QUERY = "select * from " + GROUP_TABLE +
22 private JpaTester jpaTester;
25 public void setUp() throws Exception {
26 jpaTester = new JpaTester(new SecurityPersistenceUnit());
28 // Superclass setup will call createGroupSet so requires initialized JPA.
33 public void tearDown() throws Exception {
39 protected void checkGroupCount(int aSize) throws Exception {
40 super.checkGroupCount(aSize);
41 assertEquals(aSize, jpaTester.getDbUtils().getTableSize(GROUP_TABLE));
45 protected void checkGroupExists(String aGroup) throws Exception {
46 super.checkGroupExists(aGroup);
47 assertTrue(groupExists(aGroup));
50 private boolean groupExists(final String aGroup) throws Exception {
51 return jpaTester.getDbUtils().executeInTransaction(
52 new JdbcUnitOfWork<Boolean>() {
54 public Boolean execute(Connection aConnection) throws Exception {
55 ResultSet res = jpaTester.getDbUtils().executeQuery(
56 aConnection, GROUP_QUERY, aGroup);
63 protected void checkGroupNotExists(String aGroup) throws Exception {
64 super.checkGroupNotExists(aGroup);
65 assertFalse(groupExists(aGroup));
69 protected GroupSet createGroupSet() {
70 TransactionProxyFactory<GroupSet> factory = new TransactionProxyFactory<GroupSet>(
71 jpaTester.getJpaBuilder(), GroupSet.class);
72 GroupSet groupset = new JpaGroupSet(factory.getTransactionScopedEntityManager());
73 GroupSet proxy = factory.getProxy(groupset);