(no commit message)
[utils] / security / jpatest / src / test / java / org / wamblee / security / authentication / jpa / JpaUserAdministrationTest.java
index 2e95c823f096ad17e2116c3d01a42d5924c1d0d9..f165b53160524d685b99942671d6a97d13c12628 100644 (file)
@@ -17,45 +17,27 @@ package org.wamblee.security.authentication.jpa;
 
 import java.lang.reflect.Method;
 import java.sql.Connection;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.junit.Ignore;
-import org.wamblee.cache.EhCache;
-import org.wamblee.io.ClassPathResource;
-import org.wamblee.security.authentication.GroupSet;
-import org.wamblee.security.authentication.NameValidator;
-import org.wamblee.security.authentication.RegexpNameValidator;
-import org.wamblee.security.authentication.User;
 import org.wamblee.security.authentication.UserAdministration;
-import org.wamblee.security.authentication.UserAdministrationImpl;
 import org.wamblee.security.authentication.UserAdministrationImplTest;
-import org.wamblee.security.authentication.UserSet;
-import org.wamblee.security.authentication.jpa.JpaGroupSet;
-import org.wamblee.security.authentication.jpa.JpaUserSet;
-import org.wamblee.security.encryption.Md5HexMessageDigester;
-import org.wamblee.security.encryption.MessageDigester;
-import org.wamblee.support.persistence.JpaTester;
-import org.wamblee.support.persistence.TransactionProxyFactory;
-import org.wamblee.support.persistence.DatabaseUtils.JdbcUnitOfWork;
+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
  */
 public class JpaUserAdministrationTest extends UserAdministrationImplTest {
-    private static final Log LOG = LogFactory
-        .getLog(JpaUserAdministrationTest.class);
+    private static final Logger LOG = Logger
+        .getLogger(JpaUserAdministrationTest.class.getName());
 
-    private JpaTester jpaTester;
-
-    private EhCache<String, User> userCache;
-
-    private UserAdministration userAdmin;
+    private UserAdministrationTester userAdminTester;
 
     /*
      * (non-Javadoc)
@@ -64,38 +46,15 @@ public class JpaUserAdministrationTest extends UserAdministrationImplTest {
      */
     @Override
     protected void setUp() throws Exception {
-        jpaTester = new JpaTester(new SecurityPersistenceUnit());
-        jpaTester.start();
-
-        userCache = new EhCache<String, User>(new ClassPathResource(
-            "properties/org.wamblee.security.ehcache.xml"), "users");
-
-        TransactionProxyFactory<UserAdministration> factory = new TransactionProxyFactory<UserAdministration>(
-            jpaTester.getJpaBuilder(), UserAdministration.class);
-
-        NameValidator passwordValidator = new RegexpNameValidator(".{5,}",
-            "INVALID_PASSWORD", "Password must have at least 5 characters");
-        MessageDigester passwordDigester = new Md5HexMessageDigester();
-        UserSet userset = new JpaUserSet(userCache, passwordValidator,
-            passwordDigester, factory.getTransactionScopedEntityManager());
-        GroupSet groupset = new JpaGroupSet(factory
-            .getTransactionScopedEntityManager());
-
-        NameValidator userValidator = new RegexpNameValidator(
-            "[a-zA-Z]+[a-zA-Z0-9]*", "INVALID_USERNAME", "");
-        NameValidator groupValidator = new RegexpNameValidator(
-            "[a-zA-Z]+[a-zA-Z0-9]*", "INVALID_GROUPNAME", "");
-        UserAdministration userAdminImpl = new UserAdministrationImpl(userset,
-            groupset, userValidator, groupValidator);
-        userAdmin = factory.getProxy(userAdminImpl);
-
+        userAdminTester = new UserAdministrationTester();
+        userAdminTester.start();
         super.setUp();
         clearUserCache();
     }
 
     @Override
     protected void tearDown() throws Exception {
-        jpaTester.stop();
+        userAdminTester.stop();
         super.tearDown();
     }
 
@@ -106,18 +65,19 @@ public class JpaUserAdministrationTest extends UserAdministrationImplTest {
      */
     @Override
     protected UserAdministration createAdmin() {
-        return userAdmin;
+        return userAdminTester.getUserAdministration();
     }
-    
+
     public void testAllTestsInASeparateTransaction() throws Exception {
         Method[] methods = UserAdministrationImplTest.class.getMethods();
 
         for (final Method method : methods) {
             if (method.getName().startsWith("test")) {
-                jpaTester.getDbUtils().cleanDatabase();
+                userAdminTester.getJpaTester().getDbUtils().cleanDatabase(
+                    new SecurityTables());
                 clearUserCache();
-                jpaTester.getDbUtils().executeInTransaction(
-                    new JdbcUnitOfWork<Void>() {
+                userAdminTester.getJpaTester().getDbUtils()
+                    .executeInTransaction(new JdbcUnitOfWork<Void>() {
                         @Override
                         public Void execute(Connection aConnection)
                             throws Exception {
@@ -126,8 +86,8 @@ public class JpaUserAdministrationTest extends UserAdministrationImplTest {
                             try {
                                 method.invoke(JpaUserAdministrationTest.this);
                             } catch (Throwable t) {
-                                LOG.error("Test " + method.getName() +
-                                    " failed");
+                                LOG.log(Level.WARNING, "Test " +
+                                    method.getName() + " failed", t);
                                 throw new RuntimeException(t.getMessage(), t);
                             } finally {
                                 LOG.info("Test " + method.getName() +
@@ -141,6 +101,6 @@ public class JpaUserAdministrationTest extends UserAdministrationImplTest {
     }
 
     private void clearUserCache() {
-        userCache.clear();
+        userAdminTester.getUserCache().clear();
     }
 }