[jboss-svn-commits] JBoss Portal SVN: r5219 - in trunk: cms/src/resources/portal-cms-jar/org/jboss/portal/cms core/src/resources/portal-core-sar/META-INF identity identity/src/main/org/jboss/portal/identity/db identity/src/main/org/jboss/portal/test/identity identity/src/resources/portal-identity-test-jar/org/jboss/portal/test/identity

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Sep 18 03:27:24 EDT 2006


Author: bdaw
Date: 2006-09-18 03:27:07 -0400 (Mon, 18 Sep 2006)
New Revision: 5219

Added:
   trunk/identity/src/main/org/jboss/portal/identity/db/DBRoleModuleImpl.java
   trunk/identity/src/main/org/jboss/portal/identity/db/DBUserModuleImpl.java
   trunk/identity/src/main/org/jboss/portal/test/identity/DBUserTestCase.java
Removed:
   trunk/identity/src/main/org/jboss/portal/identity/db/RoleModuleImpl.java
   trunk/identity/src/main/org/jboss/portal/identity/db/UserModuleImpl.java
   trunk/identity/src/main/org/jboss/portal/test/identity/UserTestCase.java
Modified:
   trunk/cms/src/resources/portal-cms-jar/org/jboss/portal/cms/jboss-beans.xml
   trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml
   trunk/identity/build.xml
   trunk/identity/src/resources/portal-identity-test-jar/org/jboss/portal/test/identity/jboss-beans.xml
Log:
making space for ldap identity implementation

Modified: trunk/cms/src/resources/portal-cms-jar/org/jboss/portal/cms/jboss-beans.xml
===================================================================
--- trunk/cms/src/resources/portal-cms-jar/org/jboss/portal/cms/jboss-beans.xml	2006-09-18 06:37:43 UTC (rev 5218)
+++ trunk/cms/src/resources/portal-cms-jar/org/jboss/portal/cms/jboss-beans.xml	2006-09-18 07:27:07 UTC (rev 5219)
@@ -40,7 +40,7 @@
    </bean>
 
 <!--
-   <bean name="TestBean" class="org.jboss.portal.test.identity.UserTestCase">
+   <bean name="TestBean" class="org.jboss.portal.test.identity.DBUserTestCase">
       <constructor factoryMethod="getBean">
          <factory bean="BeanFactory"/>
          <parameter>TestBean</parameter>

Modified: trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml
===================================================================
--- trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml	2006-09-18 06:37:43 UTC (rev 5218)
+++ trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml	2006-09-18 07:27:07 UTC (rev 5219)
@@ -398,7 +398,7 @@
 
    <!-- Modules -->
    <mbean
-      code="org.jboss.portal.identity.db.UserModuleImpl"
+      code="org.jboss.portal.identity.db.DBUserModuleImpl"
       name="portal:service=Module,type=User"
       xmbean-dd=""
       xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
@@ -408,7 +408,7 @@
       <attribute name="SessionFactoryJNDIName">java:/portal/UserSessionFactory</attribute>
    </mbean>
    <mbean
-      code="org.jboss.portal.identity.db.RoleModuleImpl"
+      code="org.jboss.portal.identity.db.DBRoleModuleImpl"
       name="portal:service=Module,type=Role"
       xmbean-dd=""
       xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">

Modified: trunk/identity/build.xml
===================================================================
--- trunk/identity/build.xml	2006-09-18 06:37:43 UTC (rev 5218)
+++ trunk/identity/build.xml	2006-09-18 07:27:07 UTC (rev 5219)
@@ -191,7 +191,7 @@
    <target name="tests" depends="init">
       <execute-tests>
          <x-test>
-            <test todir="${test.reports}"  name="org.jboss.portal.test.identity.UserTestCase"/>
+            <test todir="${test.reports}"  name="org.jboss.portal.test.identity.DBUserTestCase"/>
          </x-test>
          <x-classpath>
             <pathelement location="${build.lib}/portal-identity-lib.jar"/>

Copied: trunk/identity/src/main/org/jboss/portal/identity/db/DBRoleModuleImpl.java (from rev 5217, trunk/identity/src/main/org/jboss/portal/identity/db/RoleModuleImpl.java)
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity/db/RoleModuleImpl.java	2006-09-18 04:21:11 UTC (rev 5217)
+++ trunk/identity/src/main/org/jboss/portal/identity/db/DBRoleModuleImpl.java	2006-09-18 07:27:07 UTC (rev 5219)
@@ -0,0 +1,418 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.portal.identity.db;
+
+import org.apache.log4j.Logger;
+import org.hibernate.Criteria;
+import org.hibernate.HibernateException;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.criterion.Restrictions;
+import org.jboss.portal.common.util.JNDI;
+import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.Role;
+import org.jboss.portal.identity.RoleModule;
+import org.jboss.portal.identity.User;
+import org.jboss.portal.jems.as.system.AbstractJBossService;
+
+import javax.naming.InitialContext;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet </a>
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute </a>
+ * @author Roy Russo : roy at jboss dot org
+ * @version $Revision$
+ * @portal.core
+ */
+public class DBRoleModuleImpl
+   extends AbstractJBossService
+   implements RoleModule
+{
+
+   /** . */
+   private final Logger log = Logger.getLogger(getClass());
+
+   /** . */
+   protected String sessionFactoryJNDIName;
+
+   /** . */
+   protected SessionFactory sessionFactory;
+
+   /** . */
+   protected String jndiName;
+
+   /** . */
+   protected JNDI.Binding jndiBinding;
+
+   public String getSessionFactoryJNDIName()
+   {
+      return sessionFactoryJNDIName;
+   }
+
+   public void setSessionFactoryJNDIName(String sessionFactoryJNDIName)
+   {
+      this.sessionFactoryJNDIName = sessionFactoryJNDIName;
+   }
+
+   public SessionFactory getSessionFactory()
+   {
+      return sessionFactory;
+   }
+
+   public String getJNDIName()
+   {
+      return jndiName;
+   }
+
+   public void setJNDIName(String jndiName)
+   {
+      this.jndiName = jndiName;
+   }
+
+   protected void startService() throws Exception
+   {
+      //
+      sessionFactory = (SessionFactory)new InitialContext().lookup(sessionFactoryJNDIName);
+
+      //
+      if (jndiName != null)
+      {
+         jndiBinding = new JNDI.Binding(jndiName, this);
+         jndiBinding.bind();
+      }
+   }
+
+   protected void stopService() throws Exception
+   {
+      if (jndiBinding != null)
+      {
+         jndiBinding.unbind();
+         jndiBinding = null;
+      }
+
+      //
+      sessionFactory = null;
+   }
+
+   public Role findRoleByName(String name) throws IdentityException
+   {
+      if (name != null)
+      {
+         try
+         {
+            Session session = getCurrentSession();
+            Criteria criteria = session.createCriteria(RoleImpl.class);
+            criteria.add(Restrictions.naturalId().set("name", name));
+            criteria.setCacheable(true);
+            RoleImpl role = (RoleImpl)criteria.uniqueResult();
+            if (role == null)
+            {
+               throw new IdentityException("No such role " + name);
+            }
+            return role;
+         }
+         catch (HibernateException e)
+         {
+            String message = "Cannot find role by name " + name;
+            log.error(message, e);
+            throw new IdentityException(message, e);
+         }
+      }
+      else
+      {
+         throw new IllegalArgumentException("name cannot be null");
+      }
+   }
+
+   public Set findRolesByNames(String[] names) throws IdentityException
+   {
+      if (names != null)
+      {
+         try
+         {
+            Session session = getCurrentSession();
+            StringBuffer queryString = new StringBuffer("from RoleImpl as g where g.name=?");
+            for (int i = 1; i < names.length; i++)
+            {
+               queryString.append(" or g.name=?");
+            }
+            Query query = session.createQuery(queryString.toString());
+            for (int i = 0; i < names.length; i++)
+            {
+               query.setString(i, names[i]);
+            }
+            Iterator iterator = query.iterate();
+            return Tools.toSet(iterator);
+         }
+         catch (HibernateException e)
+         {
+            String message = "Cannot find roles";
+            log.error(message, e);
+            throw new IdentityException(message, e);
+         }
+      }
+      else
+      {
+         throw new IllegalArgumentException("name cannot be null");
+      }
+   }
+
+   public Role findRoleById(String id) throws IllegalArgumentException, IdentityException
+   {
+      if (id == null)
+      {
+         throw new IllegalArgumentException("The id is null");
+      }
+      try
+      {
+         return findRoleById(new Long(id));
+      }
+      catch (NumberFormatException e)
+      {
+         throw new IllegalArgumentException("Cannot parse id into an long " + id);
+      }
+   }
+
+   public Role findRoleById(Object id) throws IdentityException
+   {
+      if (id instanceof Long)
+      {
+         try
+         {
+            Session session = getCurrentSession();
+            RoleImpl role = (RoleImpl)session.get(RoleImpl.class, (Long)id);
+            if (role == null)
+            {
+               throw new IdentityException("No role found for " + id);
+            }
+            return role;
+         }
+         catch (HibernateException e)
+         {
+            String message = "Cannot find role by id " + id;
+            log.error(message, e);
+            throw new IdentityException(message, e);
+         }
+      }
+      else
+      {
+         throw new IllegalArgumentException("The id is not an long : " + id);
+      }
+   }
+
+   public Role createRole(String name, String displayName) throws IdentityException
+   {
+      if (name != null)
+      {
+         try
+         {
+            RoleImpl role = new RoleImpl(name, displayName);
+            Session session = getCurrentSession();
+            session.save(role);
+            return role;
+         }
+         catch (HibernateException e)
+         {
+            String message = "Cannot create role " + name;
+            log.error(message, e);
+            throw new IdentityException(message, e);
+         }
+      }
+      else
+      {
+         throw new IllegalArgumentException("name cannot be null");
+      }
+   }
+
+   public void removeRole(Object id) throws IdentityException
+   {
+      if (id instanceof Long)
+      {
+         try
+         {
+            Session session = getCurrentSession();
+            RoleImpl role = (RoleImpl)session.load(RoleImpl.class, (Long)id);
+            Iterator users = role.getUsers().iterator();
+            while (users.hasNext())
+            {
+               UserImpl user = (UserImpl)users.next();
+               user.getRoles().remove(role);
+            }
+            session.delete(role);
+            session.flush();
+         }
+         catch (HibernateException e)
+         {
+            String message = "Cannot remove role  " + id;
+            log.error(message, e);
+            throw new IdentityException(message, e);
+         }
+      }
+      else
+      {
+         throw new IllegalArgumentException("The id is not an long : " + id);
+      }
+   }
+
+   public int getRolesCount() throws IdentityException
+   {
+      try
+      {
+         Session session = getCurrentSession();
+         Query query = session.createQuery("select count(g.id) from RoleImpl as g");
+         return ((Number)query.uniqueResult()).intValue();
+      }
+      catch (HibernateException e)
+      {
+         String message = "Cannot count roles";
+         log.error(message, e);
+         throw new IdentityException(message, e);
+      }
+   }
+
+   public Set findRoles() throws IdentityException
+   {
+      try
+      {
+         Session session = getCurrentSession();
+         Query query = session.createQuery("from RoleImpl");
+         Iterator iterator = query.iterate();
+         return Tools.toSet(iterator);
+      }
+      catch (HibernateException e)
+      {
+         String message = "Cannot find roles";
+         log.error(message, e);
+         throw new IdentityException(message, e);
+      }
+   }
+
+   public Set findRoleMembers(String roleName, int offset, int limit, String userNameFilter) throws IdentityException
+   {
+      if (roleName != null)
+      {
+         try
+         {
+            Session session = getCurrentSession();
+
+            UserImpl userimpl = new UserImpl();
+            userimpl.setEnabled(true);
+
+            Query query;
+            if (userNameFilter.trim().length() != 0)
+            {
+               //
+               userNameFilter = "%" + userNameFilter.replaceAll("%", "") + "%";
+
+               //
+               query = session.createQuery("from UserImpl as user left join user.roles role where role.name=:name" + " AND user.userName LIKE :filter");
+               query.setString("filter", userNameFilter);
+            }
+            else
+            {
+               query = session.createQuery("from UserImpl as user left join user.roles role where role.name=:name");
+            }
+            query.setString("name", roleName);
+            query.setFirstResult(offset);
+            query.setMaxResults(limit);
+
+            Iterator iterator = query.iterate();
+            Set result = Tools.toSet(iterator);
+
+            Set newResult = new HashSet();
+            Iterator cleaner = result.iterator();
+            while (cleaner.hasNext())
+            {
+               Object[] oArr = (Object[])cleaner.next();
+               newResult.add(oArr[0]);
+            }
+
+            return newResult;
+         }
+         catch (HibernateException e)
+         {
+            String message = "Cannot find role  " + roleName;
+            log.error(message, e);
+            throw new IdentityException(message, e);
+         }
+      }
+      else
+      {
+         throw new IllegalArgumentException("id cannot be null");
+      }
+   }
+
+   public void setRoles(User user, Set roles) throws IdentityException
+   {
+      if (!(user instanceof UserImpl))
+      {
+         throw new IllegalArgumentException("User is not a db user");
+      }
+
+      // We make a defensive copy and update with a new set
+      Set copy = new HashSet();
+      for (Iterator i = roles.iterator(); i.hasNext();)
+      {
+         Object o = i.next();
+         if (o instanceof RoleImpl)
+         {
+            copy.add(o);
+         }
+         else
+         {
+            throw new IllegalArgumentException("Only db roles can be accepted");
+         }
+      }
+
+      // Assign new roles
+      UserImpl ui = (UserImpl)user;
+      ui.setRoles(copy);
+   }
+
+   public Set getRoles(User user) throws IdentityException
+   {
+      if (!(user instanceof UserImpl))
+      {
+         throw new IllegalArgumentException("User is not a db user");
+      }
+
+      // We return an immutable set to avoid modifications
+      UserImpl ui = (UserImpl)user;
+      return Collections.unmodifiableSet(ui.getRoles());
+   }
+
+   /** Can be subclasses to provide testing in a non JTA environement. */
+   protected Session getCurrentSession()
+   {
+      if (sessionFactory == null)
+      {
+         throw new IllegalStateException("No session factory");
+      }
+      return sessionFactory.getCurrentSession();
+   }
+}


Property changes on: trunk/identity/src/main/org/jboss/portal/identity/db/DBRoleModuleImpl.java
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Copied: trunk/identity/src/main/org/jboss/portal/identity/db/DBUserModuleImpl.java (from rev 5217, trunk/identity/src/main/org/jboss/portal/identity/db/UserModuleImpl.java)
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity/db/UserModuleImpl.java	2006-09-18 04:21:11 UTC (rev 5217)
+++ trunk/identity/src/main/org/jboss/portal/identity/db/DBUserModuleImpl.java	2006-09-18 07:27:07 UTC (rev 5219)
@@ -0,0 +1,329 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.portal.identity.db;
+
+import java.io.Serializable;
+import java.util.Iterator;
+import java.util.Set;
+import javax.naming.InitialContext;
+import org.apache.log4j.Logger;
+import org.hibernate.HibernateException;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.jboss.portal.common.util.JNDI;
+import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.NoSuchUserException;
+import org.jboss.portal.identity.User;
+import org.jboss.portal.identity.UserModule;
+import org.jboss.portal.jems.as.system.AbstractJBossService;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet </a>
+ * @version $Revision$
+ * @portal.core
+ */
+public class DBUserModuleImpl
+   extends AbstractJBossService
+   implements UserModule
+{
+
+   /**
+    * .
+    */
+   private final Logger log = Logger.getLogger(getClass());
+
+   /**
+    * .
+    */
+   protected SessionFactory sessionFactory;
+
+   /**
+    * .
+    */
+   protected String sessionFactoryJNDIName;
+
+   /**
+    * .
+    */
+   protected String jndiName;
+
+   /**
+    * .
+    */
+   protected JNDI.Binding jndiBinding;
+
+   public DBUserModuleImpl()
+   {
+   }
+
+   protected void startService() throws Exception
+   {
+      //
+      sessionFactory = (SessionFactory)new InitialContext().lookup(sessionFactoryJNDIName);
+
+      //
+      if (jndiName != null)
+      {
+         jndiBinding = new JNDI.Binding(jndiName, this);
+         jndiBinding.bind();
+      }
+   }
+
+   protected void stopService() throws Exception
+   {
+      if (jndiBinding != null)
+      {
+         jndiBinding.unbind();
+         jndiBinding = null;
+      }
+
+      //
+      sessionFactory = null;
+   }
+
+   public SessionFactory getSessionFactory()
+   {
+      return sessionFactory;
+   }
+
+   public String getSessionFactoryJNDIName()
+   {
+      return sessionFactoryJNDIName;
+   }
+
+   public void setSessionFactoryJNDIName(String sessionFactoryJNDIName)
+   {
+      this.sessionFactoryJNDIName = sessionFactoryJNDIName;
+   }
+
+   public String getJNDIName()
+   {
+      return jndiName;
+   }
+
+   public void setJNDIName(String jndiName)
+   {
+      this.jndiName = jndiName;
+   }
+
+   public User findUserByUserName(String userName) throws IdentityException
+   {
+      if(userName != null)
+      {
+         try
+         {
+            Session session = getCurrentSession();
+            Query query = session.createQuery("from UserImpl where userName=:userName");
+            query.setParameter("userName", userName);
+            query.setCacheable(true);
+            UserImpl user = (UserImpl) query.uniqueResult();
+            if(user == null)
+            {
+               throw new NoSuchUserException("No such user " + userName);
+            }
+            return user;
+         }
+         catch(HibernateException e)
+         {
+            String message = "Cannot find user by name " + userName;
+            log.error(message, e);
+            throw new IdentityException(message, e);
+         }
+      }
+      else
+      {
+         throw new IllegalArgumentException("user name cannot be null");
+      }
+   }
+
+   public User findUserById(String id) throws IllegalArgumentException, IdentityException, NoSuchUserException
+   {
+      if(id == null)
+      {
+         throw new IllegalArgumentException("The id is null");
+      }
+      try
+      {
+         return findUserById(new Long(id));
+      }
+      catch(NumberFormatException e)
+      {
+         throw new IllegalArgumentException("Cannot parse id into an long " + id);
+      }
+   }
+
+   public User findUserById(Object id) throws IllegalArgumentException, IdentityException, NoSuchUserException
+   {
+      if(id instanceof Long)
+      {
+         try
+         {
+            Session session = getCurrentSession();
+            UserImpl user = (UserImpl) session.get(UserImpl.class, (Long) id);
+            if(user == null)
+            {
+               throw new NoSuchUserException("No user found for " + id);
+            }
+            return user;
+         }
+         catch(HibernateException e)
+         {
+            String message = "Cannot find user by id " + id;
+            log.error(message, e);
+            throw new IdentityException(message, e);
+         }
+      }
+      else
+      {
+         throw new IllegalArgumentException("The id is not an long : " + id);
+      }
+   }
+
+   public User createUser(String userName, String password, String realEmail) throws IdentityException
+   {
+      if(userName != null)
+      {
+         try
+         {
+            UserImpl user = new UserImpl(userName);
+            user.updatePassword(password);
+            user.setRealEmail(realEmail);
+            Session session = getCurrentSession();
+            session.save(user);
+            return user;
+         }
+         catch(HibernateException e)
+         {
+            String message = "Cannot create user " + userName;
+            log.error(message, e);
+            throw new IdentityException(message, e);
+         }
+      }
+      else
+      {
+         throw new IllegalArgumentException("name cannot be null");
+      }
+   }
+
+   public void removeUser(Object id) throws IdentityException
+   {
+      if(id instanceof Long)
+      {
+         try
+         {
+            Session session = getCurrentSession();
+            UserImpl user = (UserImpl) session.load(UserImpl.class, (Serializable) id);
+            if(user == null)
+            {
+               throw new NoSuchUserException("No such user " + id);
+            }
+            session.delete(user);
+            session.flush();
+         }
+         catch(HibernateException e)
+         {
+            String message = "Cannot remove user " + id;
+            log.error(message, e);
+            throw new IdentityException(message, e);
+         }
+      }
+      else
+      {
+         throw new IllegalArgumentException("The id is not an long : " + id);
+      }
+   }
+
+   public Set findUsers(int offset, int limit) throws IdentityException
+   {
+      try
+      {
+         Session session = getCurrentSession();
+         Query query = session.createQuery("from UserImpl");
+         query.setFirstResult(offset);
+         query.setMaxResults(limit);
+         Iterator iterator = query.iterate();
+         return Tools.toSet(iterator);
+      }
+      catch(HibernateException e)
+      {
+         String message = "Cannot find user range [" + offset + "," + limit + "]";
+         log.error(message, e);
+         throw new IdentityException(message, e);
+      }
+   }
+
+   public Set findUsersFilteredByUserName(String filter, int offset, int limit) throws IdentityException
+   {
+      try
+      {
+         // Remove all occurences of % and add ours
+         filter = "%" + filter.replaceAll("%", "") + "%";
+
+         //
+         Session session = getCurrentSession();
+         Query query = session.createQuery("from UserImpl as u where u.userName like :filter");
+         query.setString("filter", filter);
+         query.setFirstResult(offset);
+         query.setMaxResults(limit);
+         Iterator iterator = query.iterate();
+         return Tools.toSet(iterator);
+      }
+      catch(HibernateException e)
+      {
+         String message = "Cannot find user range [" + offset + "," + limit + "]";
+         log.error(message, e);
+         throw new IdentityException(message, e);
+      }
+   }
+
+   public int getUserCount() throws IdentityException
+   {
+      try
+      {
+         Session session = getCurrentSession();
+         Query query = session.createQuery("select count(u.key) from UserImpl as u");
+         return ((Number) query.uniqueResult()).intValue();
+      }
+      catch(HibernateException e)
+      {
+         String message = "Cannot count users";
+         log.error(message, e);
+         throw new IdentityException(message, e);
+      }
+   }
+
+   /**
+    * Can be subclasses to provide testing in a non JTA environement.
+    *
+    * @throws IllegalStateException if no session factory is present
+    */
+   protected Session getCurrentSession() throws IllegalStateException
+   {
+      if (sessionFactory == null)
+      {
+         throw new IllegalStateException("No session factory");
+      }
+      return sessionFactory.getCurrentSession();
+   }
+}


Property changes on: trunk/identity/src/main/org/jboss/portal/identity/db/DBUserModuleImpl.java
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Deleted: trunk/identity/src/main/org/jboss/portal/identity/db/RoleModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity/db/RoleModuleImpl.java	2006-09-18 06:37:43 UTC (rev 5218)
+++ trunk/identity/src/main/org/jboss/portal/identity/db/RoleModuleImpl.java	2006-09-18 07:27:07 UTC (rev 5219)
@@ -1,418 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.portal.identity.db;
-
-import org.apache.log4j.Logger;
-import org.hibernate.Criteria;
-import org.hibernate.HibernateException;
-import org.hibernate.Query;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.criterion.Restrictions;
-import org.jboss.portal.common.util.JNDI;
-import org.jboss.portal.common.util.Tools;
-import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity.Role;
-import org.jboss.portal.identity.RoleModule;
-import org.jboss.portal.identity.User;
-import org.jboss.portal.jems.as.system.AbstractJBossService;
-
-import javax.naming.InitialContext;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-/**
- * @author <a href="mailto:julien at jboss.org">Julien Viet </a>
- * @author <a href="mailto:theute at jboss.org">Thomas Heute </a>
- * @author Roy Russo : roy at jboss dot org
- * @version $Revision$
- * @portal.core
- */
-public class RoleModuleImpl
-   extends AbstractJBossService
-   implements RoleModule
-{
-
-   /** . */
-   private final Logger log = Logger.getLogger(getClass());
-
-   /** . */
-   protected String sessionFactoryJNDIName;
-
-   /** . */
-   protected SessionFactory sessionFactory;
-
-   /** . */
-   protected String jndiName;
-
-   /** . */
-   protected JNDI.Binding jndiBinding;
-
-   public String getSessionFactoryJNDIName()
-   {
-      return sessionFactoryJNDIName;
-   }
-
-   public void setSessionFactoryJNDIName(String sessionFactoryJNDIName)
-   {
-      this.sessionFactoryJNDIName = sessionFactoryJNDIName;
-   }
-
-   public SessionFactory getSessionFactory()
-   {
-      return sessionFactory;
-   }
-
-   public String getJNDIName()
-   {
-      return jndiName;
-   }
-
-   public void setJNDIName(String jndiName)
-   {
-      this.jndiName = jndiName;
-   }
-
-   protected void startService() throws Exception
-   {
-      //
-      sessionFactory = (SessionFactory)new InitialContext().lookup(sessionFactoryJNDIName);
-
-      //
-      if (jndiName != null)
-      {
-         jndiBinding = new JNDI.Binding(jndiName, this);
-         jndiBinding.bind();
-      }
-   }
-
-   protected void stopService() throws Exception
-   {
-      if (jndiBinding != null)
-      {
-         jndiBinding.unbind();
-         jndiBinding = null;
-      }
-
-      //
-      sessionFactory = null;
-   }
-
-   public Role findRoleByName(String name) throws IdentityException
-   {
-      if (name != null)
-      {
-         try
-         {
-            Session session = getCurrentSession();
-            Criteria criteria = session.createCriteria(RoleImpl.class);
-            criteria.add(Restrictions.naturalId().set("name", name));
-            criteria.setCacheable(true);
-            RoleImpl role = (RoleImpl)criteria.uniqueResult();
-            if (role == null)
-            {
-               throw new IdentityException("No such role " + name);
-            }
-            return role;
-         }
-         catch (HibernateException e)
-         {
-            String message = "Cannot find role by name " + name;
-            log.error(message, e);
-            throw new IdentityException(message, e);
-         }
-      }
-      else
-      {
-         throw new IllegalArgumentException("name cannot be null");
-      }
-   }
-
-   public Set findRolesByNames(String[] names) throws IdentityException
-   {
-      if (names != null)
-      {
-         try
-         {
-            Session session = getCurrentSession();
-            StringBuffer queryString = new StringBuffer("from RoleImpl as g where g.name=?");
-            for (int i = 1; i < names.length; i++)
-            {
-               queryString.append(" or g.name=?");
-            }
-            Query query = session.createQuery(queryString.toString());
-            for (int i = 0; i < names.length; i++)
-            {
-               query.setString(i, names[i]);
-            }
-            Iterator iterator = query.iterate();
-            return Tools.toSet(iterator);
-         }
-         catch (HibernateException e)
-         {
-            String message = "Cannot find roles";
-            log.error(message, e);
-            throw new IdentityException(message, e);
-         }
-      }
-      else
-      {
-         throw new IllegalArgumentException("name cannot be null");
-      }
-   }
-
-   public Role findRoleById(String id) throws IllegalArgumentException, IdentityException
-   {
-      if (id == null)
-      {
-         throw new IllegalArgumentException("The id is null");
-      }
-      try
-      {
-         return findRoleById(new Long(id));
-      }
-      catch (NumberFormatException e)
-      {
-         throw new IllegalArgumentException("Cannot parse id into an long " + id);
-      }
-   }
-
-   public Role findRoleById(Object id) throws IdentityException
-   {
-      if (id instanceof Long)
-      {
-         try
-         {
-            Session session = getCurrentSession();
-            RoleImpl role = (RoleImpl)session.get(RoleImpl.class, (Long)id);
-            if (role == null)
-            {
-               throw new IdentityException("No role found for " + id);
-            }
-            return role;
-         }
-         catch (HibernateException e)
-         {
-            String message = "Cannot find role by id " + id;
-            log.error(message, e);
-            throw new IdentityException(message, e);
-         }
-      }
-      else
-      {
-         throw new IllegalArgumentException("The id is not an long : " + id);
-      }
-   }
-
-   public Role createRole(String name, String displayName) throws IdentityException
-   {
-      if (name != null)
-      {
-         try
-         {
-            RoleImpl role = new RoleImpl(name, displayName);
-            Session session = getCurrentSession();
-            session.save(role);
-            return role;
-         }
-         catch (HibernateException e)
-         {
-            String message = "Cannot create role " + name;
-            log.error(message, e);
-            throw new IdentityException(message, e);
-         }
-      }
-      else
-      {
-         throw new IllegalArgumentException("name cannot be null");
-      }
-   }
-
-   public void removeRole(Object id) throws IdentityException
-   {
-      if (id instanceof Long)
-      {
-         try
-         {
-            Session session = getCurrentSession();
-            RoleImpl role = (RoleImpl)session.load(RoleImpl.class, (Long)id);
-            Iterator users = role.getUsers().iterator();
-            while (users.hasNext())
-            {
-               UserImpl user = (UserImpl)users.next();
-               user.getRoles().remove(role);
-            }
-            session.delete(role);
-            session.flush();
-         }
-         catch (HibernateException e)
-         {
-            String message = "Cannot remove role  " + id;
-            log.error(message, e);
-            throw new IdentityException(message, e);
-         }
-      }
-      else
-      {
-         throw new IllegalArgumentException("The id is not an long : " + id);
-      }
-   }
-
-   public int getRolesCount() throws IdentityException
-   {
-      try
-      {
-         Session session = getCurrentSession();
-         Query query = session.createQuery("select count(g.id) from RoleImpl as g");
-         return ((Number)query.uniqueResult()).intValue();
-      }
-      catch (HibernateException e)
-      {
-         String message = "Cannot count roles";
-         log.error(message, e);
-         throw new IdentityException(message, e);
-      }
-   }
-
-   public Set findRoles() throws IdentityException
-   {
-      try
-      {
-         Session session = getCurrentSession();
-         Query query = session.createQuery("from RoleImpl");
-         Iterator iterator = query.iterate();
-         return Tools.toSet(iterator);
-      }
-      catch (HibernateException e)
-      {
-         String message = "Cannot find roles";
-         log.error(message, e);
-         throw new IdentityException(message, e);
-      }
-   }
-
-   public Set findRoleMembers(String roleName, int offset, int limit, String userNameFilter) throws IdentityException
-   {
-      if (roleName != null)
-      {
-         try
-         {
-            Session session = getCurrentSession();
-
-            UserImpl userimpl = new UserImpl();
-            userimpl.setEnabled(true);
-
-            Query query;
-            if (userNameFilter.trim().length() != 0)
-            {
-               //
-               userNameFilter = "%" + userNameFilter.replaceAll("%", "") + "%";
-
-               //
-               query = session.createQuery("from UserImpl as user left join user.roles role where role.name=:name" + " AND user.userName LIKE :filter");
-               query.setString("filter", userNameFilter);
-            }
-            else
-            {
-               query = session.createQuery("from UserImpl as user left join user.roles role where role.name=:name");
-            }
-            query.setString("name", roleName);
-            query.setFirstResult(offset);
-            query.setMaxResults(limit);
-
-            Iterator iterator = query.iterate();
-            Set result = Tools.toSet(iterator);
-
-            Set newResult = new HashSet();
-            Iterator cleaner = result.iterator();
-            while (cleaner.hasNext())
-            {
-               Object[] oArr = (Object[])cleaner.next();
-               newResult.add(oArr[0]);
-            }
-
-            return newResult;
-         }
-         catch (HibernateException e)
-         {
-            String message = "Cannot find role  " + roleName;
-            log.error(message, e);
-            throw new IdentityException(message, e);
-         }
-      }
-      else
-      {
-         throw new IllegalArgumentException("id cannot be null");
-      }
-   }
-
-   public void setRoles(User user, Set roles) throws IdentityException
-   {
-      if (!(user instanceof UserImpl))
-      {
-         throw new IllegalArgumentException("User is not a db user");
-      }
-
-      // We make a defensive copy and update with a new set
-      Set copy = new HashSet();
-      for (Iterator i = roles.iterator(); i.hasNext();)
-      {
-         Object o = i.next();
-         if (o instanceof RoleImpl)
-         {
-            copy.add(o);
-         }
-         else
-         {
-            throw new IllegalArgumentException("Only db roles can be accepted");
-         }
-      }
-
-      // Assign new roles
-      UserImpl ui = (UserImpl)user;
-      ui.setRoles(copy);
-   }
-
-   public Set getRoles(User user) throws IdentityException
-   {
-      if (!(user instanceof UserImpl))
-      {
-         throw new IllegalArgumentException("User is not a db user");
-      }
-
-      // We return an immutable set to avoid modifications
-      UserImpl ui = (UserImpl)user;
-      return Collections.unmodifiableSet(ui.getRoles());
-   }
-
-   /** Can be subclasses to provide testing in a non JTA environement. */
-   protected Session getCurrentSession()
-   {
-      if (sessionFactory == null)
-      {
-         throw new IllegalStateException("No session factory");
-      }
-      return sessionFactory.getCurrentSession();
-   }
-}

Deleted: trunk/identity/src/main/org/jboss/portal/identity/db/UserModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity/db/UserModuleImpl.java	2006-09-18 06:37:43 UTC (rev 5218)
+++ trunk/identity/src/main/org/jboss/portal/identity/db/UserModuleImpl.java	2006-09-18 07:27:07 UTC (rev 5219)
@@ -1,329 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.portal.identity.db;
-
-import java.io.Serializable;
-import java.util.Iterator;
-import java.util.Set;
-import javax.naming.InitialContext;
-import org.apache.log4j.Logger;
-import org.hibernate.HibernateException;
-import org.hibernate.Query;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.jboss.portal.common.util.JNDI;
-import org.jboss.portal.common.util.Tools;
-import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity.NoSuchUserException;
-import org.jboss.portal.identity.User;
-import org.jboss.portal.identity.UserModule;
-import org.jboss.portal.jems.as.system.AbstractJBossService;
-
-/**
- * @author <a href="mailto:julien at jboss.org">Julien Viet </a>
- * @version $Revision$
- * @portal.core
- */
-public class UserModuleImpl
-   extends AbstractJBossService
-   implements UserModule
-{
-
-   /**
-    * .
-    */
-   private final Logger log = Logger.getLogger(getClass());
-
-   /**
-    * .
-    */
-   protected SessionFactory sessionFactory;
-
-   /**
-    * .
-    */
-   protected String sessionFactoryJNDIName;
-
-   /**
-    * .
-    */
-   protected String jndiName;
-
-   /**
-    * .
-    */
-   protected JNDI.Binding jndiBinding;
-
-   public UserModuleImpl()
-   {
-   }
-
-   protected void startService() throws Exception
-   {
-      //
-      sessionFactory = (SessionFactory)new InitialContext().lookup(sessionFactoryJNDIName);
-
-      //
-      if (jndiName != null)
-      {
-         jndiBinding = new JNDI.Binding(jndiName, this);
-         jndiBinding.bind();
-      }
-   }
-
-   protected void stopService() throws Exception
-   {
-      if (jndiBinding != null)
-      {
-         jndiBinding.unbind();
-         jndiBinding = null;
-      }
-
-      //
-      sessionFactory = null;
-   }
-
-   public SessionFactory getSessionFactory()
-   {
-      return sessionFactory;
-   }
-
-   public String getSessionFactoryJNDIName()
-   {
-      return sessionFactoryJNDIName;
-   }
-
-   public void setSessionFactoryJNDIName(String sessionFactoryJNDIName)
-   {
-      this.sessionFactoryJNDIName = sessionFactoryJNDIName;
-   }
-
-   public String getJNDIName()
-   {
-      return jndiName;
-   }
-
-   public void setJNDIName(String jndiName)
-   {
-      this.jndiName = jndiName;
-   }
-
-   public User findUserByUserName(String userName) throws IdentityException
-   {
-      if(userName != null)
-      {
-         try
-         {
-            Session session = getCurrentSession();
-            Query query = session.createQuery("from UserImpl where userName=:userName");
-            query.setParameter("userName", userName);
-            query.setCacheable(true);
-            UserImpl user = (UserImpl) query.uniqueResult();
-            if(user == null)
-            {
-               throw new NoSuchUserException("No such user " + userName);
-            }
-            return user;
-         }
-         catch(HibernateException e)
-         {
-            String message = "Cannot find user by name " + userName;
-            log.error(message, e);
-            throw new IdentityException(message, e);
-         }
-      }
-      else
-      {
-         throw new IllegalArgumentException("user name cannot be null");
-      }
-   }
-
-   public User findUserById(String id) throws IllegalArgumentException, IdentityException, NoSuchUserException
-   {
-      if(id == null)
-      {
-         throw new IllegalArgumentException("The id is null");
-      }
-      try
-      {
-         return findUserById(new Long(id));
-      }
-      catch(NumberFormatException e)
-      {
-         throw new IllegalArgumentException("Cannot parse id into an long " + id);
-      }
-   }
-
-   public User findUserById(Object id) throws IllegalArgumentException, IdentityException, NoSuchUserException
-   {
-      if(id instanceof Long)
-      {
-         try
-         {
-            Session session = getCurrentSession();
-            UserImpl user = (UserImpl) session.get(UserImpl.class, (Long) id);
-            if(user == null)
-            {
-               throw new NoSuchUserException("No user found for " + id);
-            }
-            return user;
-         }
-         catch(HibernateException e)
-         {
-            String message = "Cannot find user by id " + id;
-            log.error(message, e);
-            throw new IdentityException(message, e);
-         }
-      }
-      else
-      {
-         throw new IllegalArgumentException("The id is not an long : " + id);
-      }
-   }
-
-   public User createUser(String userName, String password, String realEmail) throws IdentityException
-   {
-      if(userName != null)
-      {
-         try
-         {
-            UserImpl user = new UserImpl(userName);
-            user.updatePassword(password);
-            user.setRealEmail(realEmail);
-            Session session = getCurrentSession();
-            session.save(user);
-            return user;
-         }
-         catch(HibernateException e)
-         {
-            String message = "Cannot create user " + userName;
-            log.error(message, e);
-            throw new IdentityException(message, e);
-         }
-      }
-      else
-      {
-         throw new IllegalArgumentException("name cannot be null");
-      }
-   }
-
-   public void removeUser(Object id) throws IdentityException
-   {
-      if(id instanceof Long)
-      {
-         try
-         {
-            Session session = getCurrentSession();
-            UserImpl user = (UserImpl) session.load(UserImpl.class, (Serializable) id);
-            if(user == null)
-            {
-               throw new NoSuchUserException("No such user " + id);
-            }
-            session.delete(user);
-            session.flush();
-         }
-         catch(HibernateException e)
-         {
-            String message = "Cannot remove user " + id;
-            log.error(message, e);
-            throw new IdentityException(message, e);
-         }
-      }
-      else
-      {
-         throw new IllegalArgumentException("The id is not an long : " + id);
-      }
-   }
-
-   public Set findUsers(int offset, int limit) throws IdentityException
-   {
-      try
-      {
-         Session session = getCurrentSession();
-         Query query = session.createQuery("from UserImpl");
-         query.setFirstResult(offset);
-         query.setMaxResults(limit);
-         Iterator iterator = query.iterate();
-         return Tools.toSet(iterator);
-      }
-      catch(HibernateException e)
-      {
-         String message = "Cannot find user range [" + offset + "," + limit + "]";
-         log.error(message, e);
-         throw new IdentityException(message, e);
-      }
-   }
-
-   public Set findUsersFilteredByUserName(String filter, int offset, int limit) throws IdentityException
-   {
-      try
-      {
-         // Remove all occurences of % and add ours
-         filter = "%" + filter.replaceAll("%", "") + "%";
-
-         //
-         Session session = getCurrentSession();
-         Query query = session.createQuery("from UserImpl as u where u.userName like :filter");
-         query.setString("filter", filter);
-         query.setFirstResult(offset);
-         query.setMaxResults(limit);
-         Iterator iterator = query.iterate();
-         return Tools.toSet(iterator);
-      }
-      catch(HibernateException e)
-      {
-         String message = "Cannot find user range [" + offset + "," + limit + "]";
-         log.error(message, e);
-         throw new IdentityException(message, e);
-      }
-   }
-
-   public int getUserCount() throws IdentityException
-   {
-      try
-      {
-         Session session = getCurrentSession();
-         Query query = session.createQuery("select count(u.key) from UserImpl as u");
-         return ((Number) query.uniqueResult()).intValue();
-      }
-      catch(HibernateException e)
-      {
-         String message = "Cannot count users";
-         log.error(message, e);
-         throw new IdentityException(message, e);
-      }
-   }
-
-   /**
-    * Can be subclasses to provide testing in a non JTA environement.
-    *
-    * @throws IllegalStateException if no session factory is present
-    */
-   protected Session getCurrentSession() throws IllegalStateException
-   {
-      if (sessionFactory == null)
-      {
-         throw new IllegalStateException("No session factory");
-      }
-      return sessionFactory.getCurrentSession();
-   }
-}

Copied: trunk/identity/src/main/org/jboss/portal/test/identity/DBUserTestCase.java (from rev 5217, trunk/identity/src/main/org/jboss/portal/test/identity/UserTestCase.java)
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/UserTestCase.java	2006-09-18 04:21:11 UTC (rev 5217)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/DBUserTestCase.java	2006-09-18 07:27:07 UTC (rev 5219)
@@ -0,0 +1,313 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.portal.test.identity;
+
+import org.jboss.portal.test.framework.TestRuntimeContext;
+import org.jboss.portal.test.framework.junit.DatabaseTestSuite;
+import org.jboss.portal.test.framework.embedded.HibernateSupport;
+import org.jboss.portal.test.framework.embedded.DataSourceSupport;
+import org.jboss.portal.identity.db.DBUserModuleImpl;
+import org.jboss.portal.identity.db.DBRoleModuleImpl;
+import org.jboss.portal.identity.User;
+import org.jboss.portal.identity.ProfileMap;
+import org.jboss.portal.common.p3p.P3PConstants;
+import org.apache.log4j.Appender;
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.SimpleLayout;
+import org.apache.log4j.Logger;
+import org.apache.log4j.Level;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.net.URL;
+
+import junit.framework.TestSuite;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @version $Revision$
+ */
+public class DBUserTestCase extends junit.framework.TestCase implements UserTest.Context
+{
+
+   public static TestSuite suite() throws Exception
+   {
+      URL configsURL = Thread.currentThread().getContextClassLoader().getResource("datasources.xml");
+      DataSourceSupport.Config[] configs = DataSourceSupport.Config.fromXML(configsURL);
+      DatabaseTestSuite suite = new DatabaseTestSuite(configs);
+      suite.addTestCase(DBUserTestCase.class);
+      return suite;
+   }
+
+   static
+   {
+      Appender appender = new ConsoleAppender(new SimpleLayout());
+      Logger.getRoot().addAppender(appender);
+      Logger.getRoot().setLevel(Level.DEBUG);
+      Logger.getLogger("org.hibernate").setLevel(Level.ERROR);
+   }
+
+   /** . */
+   private TestRuntimeContext runtimeContext;
+
+   /** . */
+   private HibernateSupport hibernate;
+
+   /** . */
+   private UserTest utc;
+
+   /** . */
+   private DBUserModuleImpl userModule;
+
+   /** . */
+   private DBRoleModuleImpl roleModule;
+
+   /** . */
+   private DataSourceSupport.Config dsCfg;
+
+   public DBUserTestCase(DataSourceSupport.Config dsCfg)
+   {
+      this.dsCfg = dsCfg;
+   }
+
+   public HibernateSupport getHibernate()
+   {
+      return hibernate;
+   }
+
+   public void setHibernate(HibernateSupport hibernate)
+   {
+      this.hibernate = hibernate;
+   }
+
+   public String getName()
+   {
+      return super.getName() + "_" + dsCfg.getDriverClass().replaceAll("\\.", "_");
+   }
+
+   protected void setUp() throws Exception
+   {
+      runtimeContext = new TestRuntimeContext("org/jboss/portal/test/identity/jboss-beans.xml");
+      runtimeContext.addBean("TestBean", this);
+      runtimeContext.addBean("DataSourceConfig", dsCfg);
+      runtimeContext.start();
+
+      //
+      utc = new UserTest();
+      userModule = new DBUserModuleImpl();
+      userModule.setSessionFactoryJNDIName("java:/SessionFactory");
+      userModule.start();
+
+      //
+      roleModule = new DBRoleModuleImpl();
+      roleModule.setSessionFactoryJNDIName("java:/SessionFactory");
+      roleModule.start();
+
+      //
+      utc.setUserModule(userModule);
+      utc.setRoleModule(roleModule);
+      utc.setContext(this);
+      utc.populate();
+   }
+
+   protected void tearDown() throws Exception
+   {
+      utc.setUserModule(null);
+      utc.setRoleModule(null);
+      utc.setContext(null);
+      utc = null;
+
+      //
+      roleModule.destroy();
+      userModule.destroy();
+      roleModule = null;
+      userModule = null;
+
+      //
+      runtimeContext.stop();
+   }
+
+
+   public void begin()
+   {
+      hibernate.openSession();
+   }
+
+   public void commit()
+   {
+      assertTrue(hibernate.commitTransaction());
+   }
+
+   //
+
+   public void testFindUsersUsingFilter() throws Exception
+   {
+      utc.testFindUsersUsingFilter();
+   }
+
+   public void testFindUser1() throws Exception
+   {
+      utc.testFindUser1();
+   }
+
+   public void testFindUser2() throws Exception
+   {
+      utc.testFindUser2();
+   }
+
+   public void testFindUsers() throws Exception
+   {
+      utc.testFindUsers();
+   }
+
+   public void testCreateUser() throws Exception
+   {
+      utc.testCreateUser();
+   }
+
+   public void testCreateRole() throws Exception
+   {
+      utc.testCreateRole();
+   }
+
+   public void testCountUser() throws Exception
+   {
+      utc.testCountUser();
+   }
+
+   public void testRemoveNonExistingRole() throws Exception
+   {
+      utc.testRemoveNonExistingRole();
+   }
+
+   public void testRemoveRole() throws Exception
+   {
+      utc.testRemoveRole();
+   }
+
+   public void testRemoveUser() throws Exception
+   {
+      utc.testRemoveUser();
+   }
+
+   public void testFindRoles() throws Exception
+   {
+      utc.testFindRoles();
+   }
+
+   public void testFindRoleMembers() throws Exception
+   {
+      utc.testFindRoleMembers();
+   }
+
+   public void testDynamicProperty() throws Exception
+   {
+      begin();
+      User user = userModule.createUser("testname", "testpassword", "testemail");
+      ProfileMap map = user.getProfile();
+      assertNull(map.get("foo"));
+      assertFalse(map.isReadOnly("foo"));
+      map.put("foo", "value");
+      assertEquals("value", map.get("foo"));
+      assertFalse(map.isReadOnly("foo"));
+      commit();
+
+      begin();
+      user = userModule.findUserByUserName("testname");
+      map = user.getProfile();
+      assertEquals("value", map.get("foo"));
+      assertFalse(map.isReadOnly("foo"));
+      commit();
+   }
+
+   public void testStaticProperty() throws Exception
+   {
+      begin();
+
+      //
+      User user = userModule.createUser("testname", "testpassword", "testemail");
+      ProfileMap map = user.getProfile();
+      assertEquals("testname", map.get(P3PConstants.INFO_USER_NAME_NICKNAME));
+
+      // Test cannot remove a static property
+      try
+      {
+         map.remove(P3PConstants.INFO_USER_NAME_GIVEN);
+         fail("Should not be capable to remove static property");
+      }
+      catch (IllegalArgumentException expected)
+      {
+      }
+
+      // Test read only property
+      assertTrue(map.isReadOnly(P3PConstants.INFO_USER_NAME_NICKNAME));
+      try
+      {
+         map.put(P3PConstants.INFO_USER_NAME_NICKNAME, "anothername");
+         fail("Should not be capable to modify a read only static property");
+      }
+      catch (IllegalArgumentException expected)
+      {
+      }
+
+      // Test non nullable and writable property
+      try
+      {
+         map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, null);
+         fail("Should not be capable to nullify a non nullable static property");
+      }
+      catch (NullPointerException expected)
+      {
+      }
+      map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "true");
+      assertEquals(true, user.getViewRealEmail());
+
+      // Test boolean property
+      map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "false");
+      assertEquals("false", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+      assertEquals(false, user.getViewRealEmail());
+      map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "true");
+      assertEquals("true", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+      assertEquals(true, user.getViewRealEmail());
+      user.setViewRealEmail(false);
+      assertEquals("false", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+      assertEquals(false, user.getViewRealEmail());
+      user.setViewRealEmail(true);
+      assertEquals("true", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+      assertEquals(true, user.getViewRealEmail());
+      try
+      {
+         map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "truee");
+         fail("Should not be capable to set a bad value to boolean property");
+      }
+      catch (IllegalArgumentException expected)
+      {
+      }
+
+      // Test date
+      Date date = user.getRegistrationDate();
+      SimpleDateFormat sdf = new SimpleDateFormat();
+      assertEquals(sdf.format(date), map.get(User.INFO_USER_REGISTRATION_DATE));
+
+      commit();
+   }
+}


Property changes on: trunk/identity/src/main/org/jboss/portal/test/identity/DBUserTestCase.java
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Deleted: trunk/identity/src/main/org/jboss/portal/test/identity/UserTestCase.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/UserTestCase.java	2006-09-18 06:37:43 UTC (rev 5218)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/UserTestCase.java	2006-09-18 07:27:07 UTC (rev 5219)
@@ -1,313 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.portal.test.identity;
-
-import org.jboss.portal.test.framework.TestRuntimeContext;
-import org.jboss.portal.test.framework.junit.DatabaseTestSuite;
-import org.jboss.portal.test.framework.embedded.HibernateSupport;
-import org.jboss.portal.test.framework.embedded.DataSourceSupport;
-import org.jboss.portal.identity.db.UserModuleImpl;
-import org.jboss.portal.identity.db.RoleModuleImpl;
-import org.jboss.portal.identity.User;
-import org.jboss.portal.identity.ProfileMap;
-import org.jboss.portal.common.p3p.P3PConstants;
-import org.apache.log4j.Appender;
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.SimpleLayout;
-import org.apache.log4j.Logger;
-import org.apache.log4j.Level;
-
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.net.URL;
-
-import junit.framework.TestSuite;
-
-/**
- * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
- * @version $Revision$
- */
-public class UserTestCase extends junit.framework.TestCase implements UserTest.Context
-{
-
-   public static TestSuite suite() throws Exception
-   {
-      URL configsURL = Thread.currentThread().getContextClassLoader().getResource("datasources.xml");
-      DataSourceSupport.Config[] configs = DataSourceSupport.Config.fromXML(configsURL);
-      DatabaseTestSuite suite = new DatabaseTestSuite(configs);
-      suite.addTestCase(UserTestCase.class);
-      return suite;
-   }
-
-   static
-   {
-      Appender appender = new ConsoleAppender(new SimpleLayout());
-      Logger.getRoot().addAppender(appender);
-      Logger.getRoot().setLevel(Level.DEBUG);
-      Logger.getLogger("org.hibernate").setLevel(Level.ERROR);
-   }
-
-   /** . */
-   private TestRuntimeContext runtimeContext;
-
-   /** . */
-   private HibernateSupport hibernate;
-
-   /** . */
-   private UserTest utc;
-
-   /** . */
-   private UserModuleImpl userModule;
-
-   /** . */
-   private RoleModuleImpl roleModule;
-
-   /** . */
-   private DataSourceSupport.Config dsCfg;
-
-   public UserTestCase(DataSourceSupport.Config dsCfg)
-   {
-      this.dsCfg = dsCfg;
-   }
-
-   public HibernateSupport getHibernate()
-   {
-      return hibernate;
-   }
-
-   public void setHibernate(HibernateSupport hibernate)
-   {
-      this.hibernate = hibernate;
-   }
-
-   public String getName()
-   {
-      return super.getName() + "_" + dsCfg.getDriverClass().replaceAll("\\.", "_");
-   }
-
-   protected void setUp() throws Exception
-   {
-      runtimeContext = new TestRuntimeContext("org/jboss/portal/test/identity/jboss-beans.xml");
-      runtimeContext.addBean("TestBean", this);
-      runtimeContext.addBean("DataSourceConfig", dsCfg);
-      runtimeContext.start();
-
-      //
-      utc = new UserTest();
-      userModule = new UserModuleImpl();
-      userModule.setSessionFactoryJNDIName("java:/SessionFactory");
-      userModule.start();
-
-      //
-      roleModule = new RoleModuleImpl();
-      roleModule.setSessionFactoryJNDIName("java:/SessionFactory");
-      roleModule.start();
-
-      //
-      utc.setUserModule(userModule);
-      utc.setRoleModule(roleModule);
-      utc.setContext(this);
-      utc.populate();
-   }
-
-   protected void tearDown() throws Exception
-   {
-      utc.setUserModule(null);
-      utc.setRoleModule(null);
-      utc.setContext(null);
-      utc = null;
-
-      //
-      roleModule.destroy();
-      userModule.destroy();
-      roleModule = null;
-      userModule = null;
-
-      //
-      runtimeContext.stop();
-   }
-
-
-   public void begin()
-   {
-      hibernate.openSession();
-   }
-
-   public void commit()
-   {
-      assertTrue(hibernate.commitTransaction());
-   }
-
-   //
-
-   public void testFindUsersUsingFilter() throws Exception
-   {
-      utc.testFindUsersUsingFilter();
-   }
-
-   public void testFindUser1() throws Exception
-   {
-      utc.testFindUser1();
-   }
-
-   public void testFindUser2() throws Exception
-   {
-      utc.testFindUser2();
-   }
-
-   public void testFindUsers() throws Exception
-   {
-      utc.testFindUsers();
-   }
-
-   public void testCreateUser() throws Exception
-   {
-      utc.testCreateUser();
-   }
-
-   public void testCreateRole() throws Exception
-   {
-      utc.testCreateRole();
-   }
-
-   public void testCountUser() throws Exception
-   {
-      utc.testCountUser();
-   }
-
-   public void testRemoveNonExistingRole() throws Exception
-   {
-      utc.testRemoveNonExistingRole();
-   }
-
-   public void testRemoveRole() throws Exception
-   {
-      utc.testRemoveRole();
-   }
-
-   public void testRemoveUser() throws Exception
-   {
-      utc.testRemoveUser();
-   }
-
-   public void testFindRoles() throws Exception
-   {
-      utc.testFindRoles();
-   }
-
-   public void testFindRoleMembers() throws Exception
-   {
-      utc.testFindRoleMembers();
-   }
-
-   public void testDynamicProperty() throws Exception
-   {
-      begin();
-      User user = userModule.createUser("testname", "testpassword", "testemail");
-      ProfileMap map = user.getProfile();
-      assertNull(map.get("foo"));
-      assertFalse(map.isReadOnly("foo"));
-      map.put("foo", "value");
-      assertEquals("value", map.get("foo"));
-      assertFalse(map.isReadOnly("foo"));
-      commit();
-
-      begin();
-      user = userModule.findUserByUserName("testname");
-      map = user.getProfile();
-      assertEquals("value", map.get("foo"));
-      assertFalse(map.isReadOnly("foo"));
-      commit();
-   }
-
-   public void testStaticProperty() throws Exception
-   {
-      begin();
-
-      //
-      User user = userModule.createUser("testname", "testpassword", "testemail");
-      ProfileMap map = user.getProfile();
-      assertEquals("testname", map.get(P3PConstants.INFO_USER_NAME_NICKNAME));
-
-      // Test cannot remove a static property
-      try
-      {
-         map.remove(P3PConstants.INFO_USER_NAME_GIVEN);
-         fail("Should not be capable to remove static property");
-      }
-      catch (IllegalArgumentException expected)
-      {
-      }
-
-      // Test read only property
-      assertTrue(map.isReadOnly(P3PConstants.INFO_USER_NAME_NICKNAME));
-      try
-      {
-         map.put(P3PConstants.INFO_USER_NAME_NICKNAME, "anothername");
-         fail("Should not be capable to modify a read only static property");
-      }
-      catch (IllegalArgumentException expected)
-      {
-      }
-
-      // Test non nullable and writable property
-      try
-      {
-         map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, null);
-         fail("Should not be capable to nullify a non nullable static property");
-      }
-      catch (NullPointerException expected)
-      {
-      }
-      map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "true");
-      assertEquals(true, user.getViewRealEmail());
-
-      // Test boolean property
-      map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "false");
-      assertEquals("false", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
-      assertEquals(false, user.getViewRealEmail());
-      map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "true");
-      assertEquals("true", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
-      assertEquals(true, user.getViewRealEmail());
-      user.setViewRealEmail(false);
-      assertEquals("false", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
-      assertEquals(false, user.getViewRealEmail());
-      user.setViewRealEmail(true);
-      assertEquals("true", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
-      assertEquals(true, user.getViewRealEmail());
-      try
-      {
-         map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "truee");
-         fail("Should not be capable to set a bad value to boolean property");
-      }
-      catch (IllegalArgumentException expected)
-      {
-      }
-
-      // Test date
-      Date date = user.getRegistrationDate();
-      SimpleDateFormat sdf = new SimpleDateFormat();
-      assertEquals(sdf.format(date), map.get(User.INFO_USER_REGISTRATION_DATE));
-
-      commit();
-   }
-}

Modified: trunk/identity/src/resources/portal-identity-test-jar/org/jboss/portal/test/identity/jboss-beans.xml
===================================================================
--- trunk/identity/src/resources/portal-identity-test-jar/org/jboss/portal/test/identity/jboss-beans.xml	2006-09-18 06:37:43 UTC (rev 5218)
+++ trunk/identity/src/resources/portal-identity-test-jar/org/jboss/portal/test/identity/jboss-beans.xml	2006-09-18 07:27:07 UTC (rev 5219)
@@ -39,7 +39,7 @@
       </property>
    </bean>
 
-   <bean name="TestBean" class="org.jboss.portal.test.identity.UserTestCase">
+   <bean name="TestBean" class="org.jboss.portal.test.identity.DBUserTestCase">
       <constructor factoryMethod="getBean">
          <factory bean="BeanFactory"/>
          <parameter>TestBean</parameter>




More information about the jboss-svn-commits mailing list