/**
* 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
*/
private static final Logger LOG = Logger
.getLogger(JpaUserAdministrationTest.class.getName());
- private UserAdministrationTester userAdminTester;
+ private UserAdministrationTester userAdminTester;
/*
* (non-Javadoc)
*/
@Override
protected void setUp() throws Exception {
- userAdminTester = new UserAdministrationTester();
+ userAdminTester = new UserAdministrationTester();
userAdminTester.start();
super.setUp();
clearUserCache();
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 {
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() +
* 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;
private EhCache<String, User> userCache;
- private JpaTester jpaTester;
+ private JpaTester jpaTester;
/*
* (non-Javadoc)
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;
}
}
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;
}
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;
}
*
*/
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());
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"));
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);
groupset, userValidator, groupValidator);
userAdmin = factory.getProxy(userAdminImpl);
}
-
+
public PersistenceUnitDescription getPersistenceUnit() {
return persistenceUnit;
}
-
+
public JpaTester getJpaTester() {
return jpaTester;
}
-
+
public Cache<String, User> getUserCache() {
return userCache;
}
public UserAdministration getUserAdministration() {
return userAdmin;
}
-
- public MessageDigester getPasswordEncoder() {
+
+ public MessageDigester getPasswordEncoder() {
return passwordDigester;
}