(no commit message)
authorerik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Sat, 31 Jul 2010 17:31:57 +0000 (17:31 +0000)
committererik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Sat, 31 Jul 2010 17:31:57 +0000 (17:31 +0000)
security/jpatest/src/test/java/org/wamblee/security/authentication/jpa/JpaGroupSetTest.java
security/jpatest/src/test/java/org/wamblee/security/authentication/jpa/JpaUserAdministrationTest.java
security/jpatest/src/test/java/org/wamblee/security/authentication/jpa/JpaUserSetTest.java
security/jpatest/src/test/java/org/wamblee/security/authentication/jpa/SecurityPersistenceUnit.java
security/jpatest/src/test/java/org/wamblee/security/authentication/jpa/UserAdministrationTester.java

index 6f791cdd76777124a6d90bb2524012cce780ad23..0c645ff668533b3caa8f0fce0ab4961cba8dac76 100644 (file)
@@ -11,7 +11,6 @@ import org.wamblee.test.persistence.JpaTester;
 import org.wamblee.test.persistence.DatabaseUtils.JdbcUnitOfWork;
 import org.wamblee.test.transactions.TransactionProxyFactory;
 
-
 public class JpaGroupSetTest extends InMemoryGroupSetTest {
 
     private static final String GROUP_TABLE = "SEC_GROUP";
@@ -25,8 +24,9 @@ public class JpaGroupSetTest extends InMemoryGroupSetTest {
     public void setUp() throws Exception {
         jpaTester = new JpaTester(new SecurityPersistenceUnit());
         jpaTester.start();
-   
-        // Superclass setup will call createGroupSet so requires initialized JPA. 
+
+        // Superclass setup will call createGroupSet so requires initialized
+        // JPA.
         super.setUp();
     }
 
@@ -70,7 +70,8 @@ public class JpaGroupSetTest extends InMemoryGroupSetTest {
     protected GroupSet createGroupSet() {
         TransactionProxyFactory<GroupSet> factory = new TransactionProxyFactory<GroupSet>(
             jpaTester.getJpaBuilder(), GroupSet.class);
-        GroupSet groupset = new JpaGroupSet(factory.getTransactionScopedEntityManager());
+        GroupSet groupset = new JpaGroupSet(factory
+            .getTransactionScopedEntityManager());
         GroupSet proxy = factory.getProxy(groupset);
         return proxy;
     }
index 548c83b3ce179ccd71be9e4f1a916983e6abf0bf..f165b53160524d685b99942671d6a97d13c12628 100644 (file)
@@ -26,9 +26,10 @@ import org.wamblee.test.persistence.DatabaseUtils.JdbcUnitOfWork;
 
 /**
  * User administration tests with persistence based on Hibernate. This executes
- * the same test cases as {@link org.wamblee.security.authentication.UserAdministrationImplTest}
- * with in addition, one test case that executes all Hibernate test cases
- * separately with each test case in its own transaction.
+ * the same test cases as
+ * {@link org.wamblee.security.authentication.UserAdministrationImplTest} with
+ * in addition, one test case that executes all Hibernate test cases separately
+ * with each test case in its own transaction.
  * 
  * @author Erik Brakkee
  */
@@ -36,7 +37,7 @@ public class JpaUserAdministrationTest extends UserAdministrationImplTest {
     private static final Logger LOG = Logger
         .getLogger(JpaUserAdministrationTest.class.getName());
 
-    private UserAdministrationTester userAdminTester; 
+    private UserAdministrationTester userAdminTester;
 
     /*
      * (non-Javadoc)
@@ -45,7 +46,7 @@ public class JpaUserAdministrationTest extends UserAdministrationImplTest {
      */
     @Override
     protected void setUp() throws Exception {
-        userAdminTester = new UserAdministrationTester(); 
+        userAdminTester = new UserAdministrationTester();
         userAdminTester.start();
         super.setUp();
         clearUserCache();
@@ -66,16 +67,17 @@ public class JpaUserAdministrationTest extends UserAdministrationImplTest {
     protected UserAdministration createAdmin() {
         return userAdminTester.getUserAdministration();
     }
-    
+
     public void testAllTestsInASeparateTransaction() throws Exception {
         Method[] methods = UserAdministrationImplTest.class.getMethods();
 
         for (final Method method : methods) {
             if (method.getName().startsWith("test")) {
-                userAdminTester.getJpaTester().getDbUtils().cleanDatabase(new SecurityTables());
+                userAdminTester.getJpaTester().getDbUtils().cleanDatabase(
+                    new SecurityTables());
                 clearUserCache();
-                userAdminTester.getJpaTester().getDbUtils().executeInTransaction(
-                    new JdbcUnitOfWork<Void>() {
+                userAdminTester.getJpaTester().getDbUtils()
+                    .executeInTransaction(new JdbcUnitOfWork<Void>() {
                         @Override
                         public Void execute(Connection aConnection)
                             throws Exception {
@@ -84,8 +86,8 @@ public class JpaUserAdministrationTest extends UserAdministrationImplTest {
                             try {
                                 method.invoke(JpaUserAdministrationTest.this);
                             } catch (Throwable t) {
-                                LOG.log(Level.WARNING, "Test " + method.getName() +
-                                    " failed", t);
+                                LOG.log(Level.WARNING, "Test " +
+                                    method.getName() + " failed", t);
                                 throw new RuntimeException(t.getMessage(), t);
                             } finally {
                                 LOG.info("Test " + method.getName() +
index 7c5274ddadba550466454b9352ea8d63f0b68164..99b618653256bdc99876d663d50c264c4a53c9e0 100644 (file)
@@ -12,7 +12,7 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- */ 
+ */
 package org.wamblee.security.authentication.jpa;
 
 import java.sql.Connection;
@@ -56,7 +56,7 @@ public class JpaUserSetTest extends InMemoryUserSetTest {
 
     private EhCache<String, User> userCache;
 
-    private JpaTester jpaTester; 
+    private JpaTester jpaTester;
 
     /*
      * (non-Javadoc)
@@ -68,33 +68,34 @@ public class JpaUserSetTest extends InMemoryUserSetTest {
         jpaTester = new JpaTester(new SecurityPersistenceUnit());
         jpaTester.start();
 
-        userCache = new EhCache<String, User>(
-            new ClassPathResource("properties/org.wamblee.security.ehcache.xml"), "users");
-     
+        userCache = new EhCache<String, User>(new ClassPathResource(
+            "properties/org.wamblee.security.ehcache.xml"), "users");
+
         userset = createUserSetImpl();
         groupset = createGroupSetImpl();
-        
+
         clearUserCache();
 
         super.setUp();
     }
-    
+
     private UserSet createUserSetImpl() {
-        NameValidator passwordValidator = new RegexpNameValidator(
-            ".{5,}", "INVALID_PASSWORD", "Password must have at least 5 characters");
-        
+        NameValidator passwordValidator = new RegexpNameValidator(".{5,}",
+            "INVALID_PASSWORD", "Password must have at least 5 characters");
+
         MessageDigester passwordDigester = new Md5HexMessageDigester();
         TransactionProxyFactory<UserSet> factory = new TransactionProxyFactory<UserSet>(
             jpaTester.getJpaBuilder(), UserSet.class);
-        UserSet jpaUserset = new JpaUserSet(userCache, passwordValidator, passwordDigester,
-            factory.getTransactionScopedEntityManager());
+        UserSet jpaUserset = new JpaUserSet(userCache, passwordValidator,
+            passwordDigester, factory.getTransactionScopedEntityManager());
         return factory.getProxy(jpaUserset);
     }
-    
+
     private GroupSet createGroupSetImpl() {
         TransactionProxyFactory<GroupSet> factory = new TransactionProxyFactory<GroupSet>(
             jpaTester.getJpaBuilder(), GroupSet.class);
-        GroupSet groups = new JpaGroupSet(factory.getTransactionScopedEntityManager());
+        GroupSet groups = new JpaGroupSet(factory
+            .getTransactionScopedEntityManager());
         GroupSet proxy = factory.getProxy(groups);
         return proxy;
     }
@@ -136,13 +137,15 @@ public class JpaUserSetTest extends InMemoryUserSetTest {
     }
 
     private int countUser(final String aUser) throws Exception {
-        int count = jpaTester.getDbUtils().executeInTransaction(new JdbcUnitOfWork<Integer>() {
-            @Override
-            public Integer execute(Connection aConnection) throws Exception {
-                ResultSet res = jpaTester.getDbUtils().executeQuery(aConnection, USER_QUERY, aUser);
-                return jpaTester.getDbUtils().countResultSet(res);
-            }
-        });
+        int count = jpaTester.getDbUtils().executeInTransaction(
+            new JdbcUnitOfWork<Integer>() {
+                @Override
+                public Integer execute(Connection aConnection) throws Exception {
+                    ResultSet res = jpaTester.getDbUtils().executeQuery(
+                        aConnection, USER_QUERY, aUser);
+                    return jpaTester.getDbUtils().countResultSet(res);
+                }
+            });
         return count;
     }
 
@@ -167,15 +170,17 @@ public class JpaUserSetTest extends InMemoryUserSetTest {
     protected void checkGroupCount(int aSize) throws Exception {
         assertEquals(aSize, jpaTester.getDbUtils().getTableSize(GROUP_TABLE));
     }
-    
+
     private int countGroup(final String aGroup) throws Exception {
-        int count = jpaTester.getDbUtils().executeInTransaction(new JdbcUnitOfWork<Integer>() {
-            @Override
-            public Integer execute(Connection aConnection) throws Exception {
-                ResultSet res = jpaTester.getDbUtils().executeQuery(aConnection, GROUP_QUERY, aGroup);
-                return jpaTester.getDbUtils().countResultSet(res);
-            }
-        });
+        int count = jpaTester.getDbUtils().executeInTransaction(
+            new JdbcUnitOfWork<Integer>() {
+                @Override
+                public Integer execute(Connection aConnection) throws Exception {
+                    ResultSet res = jpaTester.getDbUtils().executeQuery(
+                        aConnection, GROUP_QUERY, aGroup);
+                    return jpaTester.getDbUtils().countResultSet(res);
+                }
+            });
         return count;
     }
 
@@ -230,8 +235,14 @@ public class JpaUserSetTest extends InMemoryUserSetTest {
      * 
      */
     public void testVerifyAddRemove() throws Exception {
-        jpaTester.getDbUtils().cleanDatabase(new SecurityTables()); // super class setup always creates one group. 
-        
+        jpaTester.getDbUtils().cleanDatabase(new SecurityTables()); // super
+                                                                    // class
+                                                                    // setup
+                                                                    // always
+                                                                    // creates
+                                                                    // one
+                                                                    // group.
+
         GroupSet groups = getGroups();
         assertEquals(0, groups.size());
 
@@ -249,9 +260,9 @@ public class JpaUserSetTest extends InMemoryUserSetTest {
         addUserToGroup(user, group2);
         getUsers().userModified(user);
         clearUserCache();
-        
+
         User user2 = getUsers().find("user");
-        
+
         Set<Group> userGroups = user2.getGroups();
         assertTrue(user2.isInGroup("group1"));
         assertTrue(user2.isInGroup("group2"));
index cf6d423522c88be94d6b9990fc6495bd67d4d147..5ce850bd862a5cff04adf7691045080a77916519 100644 (file)
@@ -4,7 +4,7 @@ import org.wamblee.test.persistence.PersistenceUnitDescription;
 
 public class SecurityPersistenceUnit extends PersistenceUnitDescription {
 
-    public SecurityPersistenceUnit() { 
+    public SecurityPersistenceUnit() {
         super("jdbc/security", "securitytest");
     }
 }
index e11c97cf67cffe771c018b1f0b32617a574bafea..c90afc8e94741afc89a65243f215087119590717 100644 (file)
@@ -32,29 +32,28 @@ import org.wamblee.test.persistence.PersistenceUnitDescription;
 import org.wamblee.test.transactions.TransactionProxyFactory;
 
 /**
- * Setup of a security repository for unit test. This provides all the necessary wiring
- * and JPA setup.
+ * Setup of a security repository for unit test. This provides all the necessary
+ * wiring and JPA setup.
  * 
  * @author Erik Brakkee
  */
 public class UserAdministrationTester {
 
-    private PersistenceUnitDescription persistenceUnit; 
+    private PersistenceUnitDescription persistenceUnit;
     private JpaTester jpaTester;
     private Cache<String, User> userCache;
-    private UserAdministration userAdmin; 
+    private UserAdministration userAdmin;
     private MessageDigester passwordDigester;
 
     public UserAdministrationTester() {
-        persistenceUnit = new SecurityPersistenceUnit(); 
+        persistenceUnit = new SecurityPersistenceUnit();
         jpaTester = new JpaTester(persistenceUnit);
     }
 
     public void start() throws Exception {
         jpaTester.start();
-        userCache = new EhCache<String, User>(
-            new ClassPathResource("properties/org.wamblee.security.ehcache.xml"),
-            "users");
+        userCache = new EhCache<String, User>(new ClassPathResource(
+            "properties/org.wamblee.security.ehcache.xml"), "users");
 
         TransactionProxyFactory<UserAdministration> factory = new TransactionProxyFactory<UserAdministration>(
             jpaTester.getJpaBuilder(), UserAdministration.class);
@@ -75,15 +74,15 @@ public class UserAdministrationTester {
             groupset, userValidator, groupValidator);
         userAdmin = factory.getProxy(userAdminImpl);
     }
-   
+
     public PersistenceUnitDescription getPersistenceUnit() {
         return persistenceUnit;
     }
-    
+
     public JpaTester getJpaTester() {
         return jpaTester;
     }
-    
+
     public Cache<String, User> getUserCache() {
         return userCache;
     }
@@ -91,8 +90,8 @@ public class UserAdministrationTester {
     public UserAdministration getUserAdministration() {
         return userAdmin;
     }
-    
-    public MessageDigester getPasswordEncoder() { 
+
+    public MessageDigester getPasswordEncoder() {
         return passwordDigester;
     }