[portal-commits] JBoss Portal SVN: r5805 - in trunk: build/ide/intellij/idea60/modules/core core core/src/main/org/jboss/portal/core/impl/portlet/state core/src/main/org/jboss/portal/test/core/state core/src/resources/portal-core-sar/conf/hibernate/portlet core/src/resources/portal-core-test-jar/org/jboss/portal/test/core/state jems/src/main/org/jboss/portal/jems/hibernate tools/etc/buildfragments wsrp wsrp/src/main/org/jboss/portal/test/wsrp/registration wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl

portal-commits at lists.jboss.org portal-commits at lists.jboss.org
Mon Dec 11 20:25:11 EST 2006


Author: julien at jboss.com
Date: 2006-12-11 20:24:50 -0500 (Mon, 11 Dec 2006)
New Revision: 5805

Added:
   trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/RegistrationStatusUserType.java
   trunk/core/src/main/org/jboss/portal/test/core/state/RegistrationPersistenceManagerTestCase.java
   trunk/core/src/resources/portal-core-test-jar/org/jboss/portal/test/core/state/registration-persistence-manager-beans.xml
   trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/AbstractRegistrationPersistenceManagerTestCase.java
Modified:
   trunk/build/ide/intellij/idea60/modules/core/core.iml
   trunk/core/build.xml
   trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/PersistentConsumer.java
   trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/PersistentConsumerGroup.java
   trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/PersistentRegistration.java
   trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/PersistentStateStore.java
   trunk/core/src/main/org/jboss/portal/test/core/state/ProducerTestCase.java
   trunk/core/src/resources/portal-core-sar/conf/hibernate/portlet/domain.hbm.xml
   trunk/jems/src/main/org/jboss/portal/jems/hibernate/QNameUserType.java
   trunk/tools/etc/buildfragments/modules.ent
   trunk/wsrp/build.xml
   trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/RegistrationPersistenceManagerTestCase.java
   trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/RegistrationStatus.java
   trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/ConsumerGroupImpl.java
Log:
Fix and test the RegistrationPersistenceManager implemented with hibernate (without the portlet clone integration yet)

Modified: trunk/build/ide/intellij/idea60/modules/core/core.iml
===================================================================
--- trunk/build/ide/intellij/idea60/modules/core/core.iml	2006-12-11 21:32:57 UTC (rev 5804)
+++ trunk/build/ide/intellij/idea60/modules/core/core.iml	2006-12-12 01:24:50 UTC (rev 5805)
@@ -258,6 +258,15 @@
     </orderEntry>
     <orderEntry type="module" module-name="wsrp" />
     <orderEntry type="module" module-name="api" />
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MODULE_DIR$/../../../../../../thirdparty/jbossas/core-libs/lib/namespace.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
     <orderEntryProperties />
   </component>
   <component name="VcsManagerConfiguration">

Modified: trunk/core/build.xml
===================================================================
--- trunk/core/build.xml	2006-12-11 21:32:57 UTC (rev 5804)
+++ trunk/core/build.xml	2006-12-12 01:24:50 UTC (rev 5805)
@@ -603,6 +603,9 @@
             <zest todir="${test.reports}" name="org.jboss.portal.test.core.state.ProducerTestCase"
                   outfile="TEST-ProducerTestCase">
             </zest>
+            <zest todir="${test.reports}" name="org.jboss.portal.test.core.state.RegistrationPersistenceManagerTestCase"
+                  outfile="TEST-RegistrationPersistenceManagerTestCase">
+            </zest>
             <test todir="${test.reports}"
                   name="org.jboss.portal.test.core.deployment.JBossApplicationMetaDataFactoryTestCase"/>
             <test todir="${test.reports}"

Modified: trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/PersistentConsumer.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/PersistentConsumer.java	2006-12-11 21:32:57 UTC (rev 5804)
+++ trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/PersistentConsumer.java	2006-12-12 01:24:50 UTC (rev 5805)
@@ -30,7 +30,6 @@
 import org.jboss.portal.wsrp.producer.registration.api.DuplicateRegistrationException;
 
 import java.util.Collection;
-import java.util.Map;
 import java.util.Collections;
 import java.util.Set;
 import java.util.HashSet;
@@ -44,7 +43,8 @@
 
    // Persistent fields
 
-   private String key;
+   private Long key;
+   private String persistentId;
    private String persistentName;
    private RegistrationStatus persistentStatus;
    private String persistentAgent;
@@ -60,9 +60,10 @@
     * @param id
     * @param name
     */
-   PersistentConsumer(String id, String name)
+   public PersistentConsumer(String id, String name)
    {
-      this.key = id;
+      this.key = null;
+      this.persistentId = id;
       this.persistentName = name;
       this.persistentStatus = RegistrationStatus.PENDING;
       this.relatedRegistrations = new HashSet();
@@ -76,6 +77,7 @@
    PersistentConsumer()
    {
       this.key = null;
+      this.persistentId = null;
       this.persistentName = null;
       this.persistentStatus = null;
       this.relatedRegistrations = null;
@@ -85,16 +87,26 @@
 
    // Hibernate
 
-   public String getKey()
+   public Long getKey()
    {
       return key;
    }
 
-   public void setKey(String key)
+   public void setKey(Long key)
    {
       this.key = key;
    }
 
+   public String getPersistentId()
+   {
+      return persistentId;
+   }
+
+   public void setPersistentId(String persistentId)
+   {
+      this.persistentId = persistentId;
+   }
+
    public String getPersistentName()
    {
       return persistentName;
@@ -174,7 +186,7 @@
 
    public String getId()
    {
-      return key;
+      return persistentId;
    }
 
    public ConsumerCapabilities getCapabilities()

Modified: trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/PersistentConsumerGroup.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/PersistentConsumerGroup.java	2006-12-11 21:32:57 UTC (rev 5804)
+++ trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/PersistentConsumerGroup.java	2006-12-12 01:24:50 UTC (rev 5805)
@@ -26,6 +26,8 @@
 import org.jboss.portal.wsrp.producer.registration.api.RegistrationException;
 import org.jboss.portal.wsrp.producer.registration.api.Consumer;
 import org.jboss.portal.wsrp.producer.registration.api.RegistrationStatus;
+import org.jboss.portal.jems.hibernate.ContextObject;
+import org.hibernate.Session;
 
 import java.util.Collection;
 import java.util.Map;
@@ -36,11 +38,12 @@
  * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
  * @version $Revision: 1.1 $
  */
-public class PersistentConsumerGroup implements ConsumerGroup
+public class PersistentConsumerGroup implements ConsumerGroup, ContextObject
 {
 
    // Persistent fields
 
+   private Long key;
    private String persistentName;
    private RegistrationStatus persistentStatus;
 
@@ -48,19 +51,49 @@
 
    private Map relatedConsumers;
 
-   public PersistentConsumerGroup(String name)
+   // Context
+
+   private PersistentStateStore context;
+
+   public PersistentConsumerGroup(PersistentStateStore context, String name)
    {
+      this.key = null;
       this.persistentName = name;
       this.relatedConsumers = new HashMap();
       this.persistentStatus = RegistrationStatus.PENDING;
+      this.context = context;
    }
 
-   public PersistentConsumerGroup()
+   /**
+    * Hibernate constructor.
+    */
+   PersistentConsumerGroup()
    {
+      this.key = null;
+      this.persistentName = null;
+      this.persistentStatus = null;
+      this.relatedConsumers = null;
    }
 
+   // ContextObject
+
+   public void setContext(Object context)
+   {
+      this.context = (PersistentStateStore)context;
+   }
+
    // Hibernate
 
+   public Long getKey()
+   {
+      return key;
+   }
+
+   public void setKey(Long key)
+   {
+      this.key = key;
+   }
+
    public String getPersistentName()
    {
       return persistentName;
@@ -105,21 +138,33 @@
 
    public Consumer getConsumer(String consumerId) throws IllegalArgumentException, RegistrationException
    {
+      if (consumerId == null)
+      {
+         throw new IllegalArgumentException("No null consumer id accepted");
+      }
+
+      //
       return (Consumer)relatedConsumers.get(consumerId);
    }
 
    public void addConsumer(Consumer consumer) throws RegistrationException
    {
-      validateImplementation(consumer);
+      PersistentConsumer pconsumer = validateImplementation(consumer);
 
       //
       if (relatedConsumers.containsKey(consumer.getId()))
       {
-         throw new IllegalArgumentException();
+         throw new IllegalArgumentException("Consumer already attached " + consumer.getId());
       }
 
       //
-      relatedConsumers.put(consumer.getId(), consumer);
+      Session session = context.getCurrentSession();
+
+      // Create the relationship
+      relatedConsumers.put(consumer.getId(), pconsumer);
+      pconsumer.setRelatedGroup(this);
+      session.saveOrUpdate(this);
+      session.saveOrUpdate(consumer);
    }
 
    public void removeConsumer(Consumer consumer) throws RegistrationException

Modified: trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/PersistentRegistration.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/PersistentRegistration.java	2006-12-11 21:32:57 UTC (rev 5804)
+++ trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/PersistentRegistration.java	2006-12-12 01:24:50 UTC (rev 5805)
@@ -67,7 +67,7 @@
       this.properties = new Properties();
    }
 
-   PersistentRegistration(Map properties, RegistrationStatus status)
+   public PersistentRegistration(Map properties, RegistrationStatus status)
    {
       this.key = null;
       this.persistentHandle = null;

Modified: trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/PersistentStateStore.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/PersistentStateStore.java	2006-12-11 21:32:57 UTC (rev 5804)
+++ trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/PersistentStateStore.java	2006-12-12 01:24:50 UTC (rev 5805)
@@ -27,6 +27,7 @@
 import org.hibernate.SessionFactory;
 import org.jboss.portal.common.value.Value;
 import org.jboss.portal.jems.as.system.AbstractJBossService;
+import org.jboss.portal.jems.hibernate.ObjectContextualizer;
 import org.jboss.portal.portlet.state.InvalidStateIdException;
 import org.jboss.portal.portlet.state.NoSuchStateException;
 import org.jboss.portal.portlet.state.PropertyMap;
@@ -40,6 +41,7 @@
 import org.jboss.portal.wsrp.producer.registration.api.Registration;
 import org.jboss.portal.wsrp.producer.registration.api.NoSuchRegistrationException;
 import org.jboss.portal.wsrp.producer.registration.api.RegistrationStatus;
+import org.jboss.portal.wsrp.producer.registration.api.DuplicateRegistrationException;
 
 import javax.naming.InitialContext;
 import java.util.Iterator;
@@ -59,6 +61,9 @@
    /** . */
    protected String sessionFactoryJNDIName;
 
+   /** . */
+   protected ObjectContextualizer contextualizer;
+
    public String getSessionFactoryJNDIName()
    {
       return sessionFactoryJNDIName;
@@ -200,10 +205,13 @@
    protected void startService() throws Exception
    {
       sessionFactory = (SessionFactory)new InitialContext().lookup(sessionFactoryJNDIName);
+      contextualizer = new ObjectContextualizer(this);
+      contextualizer.attach(sessionFactory);
    }
 
    protected void stopService() throws Exception
    {
+      contextualizer = null;
       sessionFactory = null;
    }
 
@@ -282,10 +290,17 @@
 
       // Get hibernate session
       Session session = getCurrentSession();
+      PersistentConsumerGroup group = null;
 
+      // Detect duplicate
+      if (findGroupByName(session, name) != null)
+      {
+         throw new DuplicateRegistrationException("Group " + name + " already exists");
+      }
+
       // Create and persist
-      PersistentConsumerGroup group = new PersistentConsumerGroup(name);
-      session.persist(session);
+      group = new PersistentConsumerGroup(this, name);
+      session.persist(group);
 
       //
       return group;
@@ -337,6 +352,7 @@
 
       // Delete the registration
       session.delete(registration);
+      session.flush();
    }
 
    public Consumer getConsumerById(String consumerId) throws RegistrationException
@@ -350,19 +366,23 @@
 
    public Registration addRegistrationFor(String consumerId, Map registrationProperties) throws RegistrationException
    {
+      if (registrationProperties == null)
+      {
+         throw new IllegalArgumentException("No null registration properties accepted");
+      }
+
       // Get hibernate session
       Session session = getCurrentSession();
 
       // Perform lookup
       PersistentConsumer consumer = getConsumerById(session, consumerId);
 
-      // Create and persist registration
+      // Create and persist registration and build relationship
       PersistentRegistration registration = new PersistentRegistration(registrationProperties, RegistrationStatus.PENDING);
-      session.persist(registration);
-
-      // Build relationship
       registration.setRelatedConsumer(consumer);
       consumer.getRelatedRegistrations().add(registration);
+      session.persist(registration);
+      session.saveOrUpdate(consumer);
 
       //
       return registration;
@@ -460,7 +480,9 @@
       }
 
       //
-      return (PersistentConsumer)session.get(PersistentConsumer.class, consumerId);
+      Query query = session.createQuery("from PersistentConsumer where persistentId=:consumerId");
+      query.setString("consumerId", consumerId);
+      return (PersistentConsumer)query.uniqueResult();
    }
 
    private PersistentConsumerGroup getGroupByName(Session session, String groupName) throws IllegalArgumentException, NoSuchRegistrationException
@@ -485,6 +507,8 @@
       }
 
       //
-      return (PersistentConsumerGroup)session.get(PersistentConsumerGroup.class, groupName);
+      Query query = session.createQuery("from PersistentConsumerGroup where persistentName=:groupName");
+      query.setString("groupName", groupName);
+      return (PersistentConsumerGroup)query.uniqueResult();
    }
 }

Added: trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/RegistrationStatusUserType.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/RegistrationStatusUserType.java	2006-12-11 21:32:57 UTC (rev 5804)
+++ trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/RegistrationStatusUserType.java	2006-12-12 01:24:50 UTC (rev 5805)
@@ -0,0 +1,142 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat                                               *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.core.impl.portlet.state;
+
+import org.hibernate.usertype.UserType;
+import org.hibernate.HibernateException;
+import org.hibernate.Hibernate;
+import org.jboss.portal.wsrp.producer.registration.api.RegistrationStatus;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.PreparedStatement;
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class RegistrationStatusUserType implements UserType
+{
+
+   /** . */
+   private static final int[] SQL_TYPES = {Hibernate.INTEGER.sqlType()};
+
+   public int[] sqlTypes()
+   {
+      return SQL_TYPES;
+   }
+
+   public Class returnedClass()
+   {
+      return RegistrationStatus.class;
+   }
+
+   public boolean equals(Object x, Object y) throws HibernateException
+   {
+      if (x == y)
+      {
+         return true;
+      }
+      else if (x == null || y == null)
+      {
+         return false;
+      }
+      else
+      {
+         return x.equals(y);
+      }
+   }
+
+   public int hashCode(Object x) throws HibernateException
+   {
+      return x.hashCode();
+   }
+
+   public Object nullSafeGet(ResultSet resultSet, String[] names, Object owner) throws HibernateException, SQLException
+   {
+      int value = resultSet.getInt(names[0]);
+      if (resultSet.wasNull())
+      {
+         return null;
+      }
+
+      //
+      switch (value)
+      {
+         case 1:
+            return RegistrationStatus.VALID;
+         case 2:
+            return RegistrationStatus.INVALID;
+         default:
+            return RegistrationStatus.PENDING;
+      }
+   }
+
+   public void nullSafeSet(PreparedStatement statement, Object value, int index) throws HibernateException, SQLException
+   {
+      if (value == null)
+      {
+         statement.setNull(index, SQL_TYPES[0]);
+      }
+      else
+      {
+         RegistrationStatus status = (RegistrationStatus)value;
+         int i = 0;
+         if (status == RegistrationStatus.VALID)
+         {
+            i = 1;
+         }
+         else if (status == RegistrationStatus.INVALID)
+         {
+            i = 2;
+         }
+         statement.setInt(index, i);
+      }
+   }
+
+   public Object deepCopy(Object value) throws HibernateException
+   {
+      return value;
+   }
+
+   public boolean isMutable()
+   {
+      return false;
+   }
+
+   public Serializable disassemble(Object value) throws HibernateException
+   {
+      return (RegistrationStatus)value;
+   }
+
+   public Object assemble(Serializable cached, Object owner) throws HibernateException
+   {
+      return cached;
+   }
+
+   public Object replace(Object original, Object target, Object owner) throws HibernateException
+   {
+      return original;
+   }
+}

Modified: trunk/core/src/main/org/jboss/portal/test/core/state/ProducerTestCase.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/test/core/state/ProducerTestCase.java	2006-12-11 21:32:57 UTC (rev 5804)
+++ trunk/core/src/main/org/jboss/portal/test/core/state/ProducerTestCase.java	2006-12-12 01:24:50 UTC (rev 5805)
@@ -30,6 +30,7 @@
 import org.apache.log4j.Logger;
 import org.apache.log4j.SimpleLayout;
 import org.jboss.portal.Mode;
+import org.jboss.portal.wsrp.producer.registration.api.RegistrationStatus;
 import org.jboss.portal.common.junit.TransactionAssert;
 import org.jboss.portal.common.test.TestParametrization;
 import org.jboss.portal.common.test.junit.JUnitAdapter;
@@ -37,6 +38,8 @@
 import org.jboss.portal.common.value.StringValue;
 import org.jboss.portal.core.impl.portlet.state.PersistentStateStore;
 import org.jboss.portal.core.impl.portlet.state.ProducerPortletInvoker;
+import org.jboss.portal.core.impl.portlet.state.PersistentRegistration;
+import org.jboss.portal.core.impl.portlet.state.PersistentConsumer;
 import org.jboss.portal.portlet.NoSuchPortletException;
 import org.jboss.portal.portlet.Portlet;
 import org.jboss.portal.portlet.PortletContext;
@@ -61,10 +64,13 @@
 import org.jboss.portal.test.framework.TestRuntimeContext;
 import org.jboss.portal.test.framework.embedded.DataSourceSupport;
 import org.jboss.portal.test.framework.embedded.HibernateSupport;
+import org.hibernate.Session;
 
+import javax.xml.namespace.QName;
 import java.net.URL;
 import java.util.Collections;
 import java.util.List;
+import java.util.HashMap;
 
 /**
  * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
@@ -250,8 +256,32 @@
       runtimeContext.stop();
    }
 
-   public void testCloneNonExistingPortletWithinTx() throws Exception
+   public void testABC()
    {
+      TransactionAssert.beginTransaction();
+      Session session = hibernateSupport.getCurrentSession();
+      PersistentConsumer consumer = new PersistentConsumer("myconsumer", "myconsumer");
+      session.persist(consumer);
+      Long consumerPK = consumer.getKey();
+      TransactionAssert.commitTransaction();
+
+      TransactionAssert.beginTransaction();
+      session = hibernateSupport.getCurrentSession();
+      consumer = (PersistentConsumer)session.get(PersistentConsumer.class, consumerPK);
+      HashMap properties = new HashMap();
+      properties.put(new QName("a", "b"), "abc");
+      properties.put(new QName("b"), "def");
+      PersistentRegistration reg = new PersistentRegistration(properties, RegistrationStatus.PENDING);
+      reg.setPersistentHandle("handle");
+      reg.setRelatedConsumer(consumer);
+      consumer.getRelatedRegistrations().add(reg);
+      session.persist(reg);
+      session.flush();
+      TransactionAssert.commitTransaction();
+   }
+
+   public void _testCloneNonExistingPortletWithinTx() throws Exception
+   {
       try
       {
          TransactionAssert.beginTransaction();
@@ -279,7 +309,7 @@
       // todo check state
    }
 
-   public void testCloneNullPortletWithinTx() throws Exception
+   public void _testCloneNullPortletWithinTx() throws Exception
    {
       try
       {
@@ -293,7 +323,7 @@
       }
    }
 
-   public void testCloneExistingPortletWithinTx() throws Exception
+   public void _testCloneExistingPortletWithinTx() throws Exception
    {
       // Clone a POP
       TransactionAssert.beginTransaction();
@@ -341,7 +371,7 @@
       TransactionAssert.commitTransaction();
    }
 
-   public void testDestroyNonExistingPortletWithinTx() throws Exception
+   public void _testDestroyNonExistingPortletWithinTx() throws Exception
    {
       TransactionAssert.beginTransaction();
       List failures = producer.destroyClones(Collections.singletonList(PortletContext.createPortletContext("_1")));
@@ -349,7 +379,7 @@
       TransactionAssert.commitTransaction();
    }
 
-   public void testDestroyNullPortletWithinTx() throws Exception
+   public void _testDestroyNullPortletWithinTx() throws Exception
    {
       try
       {
@@ -364,7 +394,7 @@
    }
 
 /*
-   public void testDestroyInvalidPortletWithinTx() throws Exception
+   public void _testDestroyInvalidPortletWithinTx() throws Exception
    {
       try
       {
@@ -379,7 +409,7 @@
    }
 */
 
-   public void testDestroyPortletWithinTx() throws Exception
+   public void _testDestroyPortletWithinTx() throws Exception
    {
       // Clone a POP 2 times
       TransactionAssert.beginTransaction();
@@ -418,7 +448,7 @@
       TransactionAssert.commitTransaction();
    }
 
-   public void testInvokeCloneBeforeWritePOPWithinTx() throws Exception
+   public void _testInvokeCloneBeforeWritePOPWithinTx() throws Exception
    {
       TransactionAssert.beginTransaction();
       PortletInvocation action = new ActionInvocation(new ActionContextImpl(Mode.VIEW));
@@ -444,7 +474,7 @@
       TransactionAssert.commitTransaction();
    }
 
-   public void testInvokeReadWritePOPWithinTx() throws Exception
+   public void _testInvokeReadWritePOPWithinTx() throws Exception
    {
       TransactionAssert.beginTransaction();
       PortletInvocation action = new ActionInvocation(new ActionContextImpl(Mode.VIEW));
@@ -462,7 +492,7 @@
       TransactionAssert.commitTransaction();
    }
 
-   public void testInvokeReadOnlyPOPWithinTx() throws Exception
+   public void _testInvokeReadOnlyPOPWithinTx() throws Exception
    {
       TransactionAssert.beginTransaction();
       PortletInvocation action = new ActionInvocation(new ActionContextImpl(Mode.VIEW));
@@ -480,7 +510,7 @@
       TransactionAssert.commitTransaction();
    }
 
-   public void testInvokeCloneBeforeWriteCCPWithinTx() throws Exception
+   public void _testInvokeCloneBeforeWriteCCPWithinTx() throws Exception
    {
       TransactionAssert.beginTransaction();
       PortletContext cloningPortletId = producer.createClone(PortletContext.createPortletContext("CloningPortlet"));
@@ -519,7 +549,7 @@
       TransactionAssert.commitTransaction();
    }
 
-   public void testInvokeReadWriteCCPWithinTx() throws Exception
+   public void _testInvokeReadWriteCCPWithinTx() throws Exception
    {
       TransactionAssert.beginTransaction();
       PortletContext cloningPortletId = producer.createClone(PortletContext.createPortletContext("CloningPortlet"));
@@ -549,7 +579,7 @@
       TransactionAssert.commitTransaction();
    }
 
-   public void testInvokeReadOnlyCCPWithinTx() throws Exception
+   public void _testInvokeReadOnlyCCPWithinTx() throws Exception
    {
       TransactionAssert.beginTransaction();
       PortletContext cloneFailedCloningPortletId = producer.createClone(PortletContext.createPortletContext("CloneFailedCloningPortlet"));
@@ -571,7 +601,7 @@
       TransactionAssert.commitTransaction();
    }
 
-   public void testInvokeCloneBeforeWritePOPWithinTxThrowsException() throws Exception
+   public void _testInvokeCloneBeforeWritePOPWithinTxThrowsException() throws Exception
    {
       TransactionAssert.beginTransaction();
       PortletInvocation action = new ActionInvocation(new ActionContextImpl(Mode.VIEW));
@@ -597,18 +627,18 @@
       TransactionAssert.commitTransaction();
    }
 
-   public void testGetProperties()
+   public void _testGetProperties()
    {
 
    }
 
-   public void testSetProperties()
+   public void _testSetProperties()
    {
 
    }
 
    /** todo : should check the portlet metadata as well */
-   public void testGetPortlet() throws Exception
+   public void _testGetPortlet() throws Exception
    {
       // Clone a POP
       TransactionAssert.beginTransaction();

Added: trunk/core/src/main/org/jboss/portal/test/core/state/RegistrationPersistenceManagerTestCase.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/test/core/state/RegistrationPersistenceManagerTestCase.java	2006-12-11 21:32:57 UTC (rev 5804)
+++ trunk/core/src/main/org/jboss/portal/test/core/state/RegistrationPersistenceManagerTestCase.java	2006-12-12 01:24:50 UTC (rev 5805)
@@ -0,0 +1,155 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat                                               *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.core.state;
+
+import junit.framework.TestSuite;
+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 org.jboss.portal.common.test.TestParametrization;
+import org.jboss.portal.common.test.junit.JUnitAdapter;
+import org.jboss.portal.common.test.junit.POJOJUnitTest;
+import org.jboss.portal.common.junit.TransactionAssert;
+import org.jboss.portal.test.framework.embedded.DataSourceSupport;
+import org.jboss.portal.test.framework.embedded.HibernateSupport;
+import org.jboss.portal.test.framework.TestRuntimeContext;
+import org.jboss.portal.test.wsrp.registration.AbstractRegistrationPersistenceManagerTestCase;
+import org.jboss.portal.core.impl.portlet.state.PersistentStateStore;
+import org.jboss.portal.wsrp.producer.registration.api.RegistrationPersistenceManager;
+
+import java.net.URL;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @version $Revision: 5776 $
+ */
+public class RegistrationPersistenceManagerTestCase extends AbstractRegistrationPersistenceManagerTestCase
+{
+
+   static
+   {
+      Appender appender = new ConsoleAppender(new SimpleLayout());
+      Logger.getRoot().addAppender(appender);
+      Logger.getRoot().setLevel(Level.DEBUG);
+      Logger.getLogger("org.hibernate").setLevel(Level.ERROR);
+   }
+
+   public static TestSuite suite() throws Exception
+   {
+      TestParametrization parametrization = JUnitAdapter.getParametrization();
+      URL configsURL = Thread.currentThread().getContextClassLoader().getResource("datasources.xml");
+      parametrization.setParameterValue("DataSourceConfig", DataSourceSupport.Config.fromXML2(configsURL));
+      POJOJUnitTest abc = new POJOJUnitTest(RegistrationPersistenceManagerTestCase.class);
+      JUnitAdapter adapter = new JUnitAdapter(abc, parametrization);
+      TestSuite suite = new TestSuite();
+      suite.addTest(adapter);
+      return suite;
+   }
+
+   /** . */
+   private TestRuntimeContext runtimeContext;
+
+   /** . */
+   private DataSourceSupport.Config dataSourceConfigParameter;
+
+   /** . */
+   private HibernateSupport hibernateSupport;
+
+   /** . */
+   private PersistentStateStore persistenceManager;
+
+   public String getName()
+   {
+      return super.getName() + ",ds=" + dataSourceConfigParameter.getName();
+   }
+
+   public HibernateSupport getHibernateSupport()
+   {
+      return hibernateSupport;
+   }
+
+   public void setHibernateSupport(HibernateSupport hibernateSupport)
+   {
+      this.hibernateSupport = hibernateSupport;
+   }
+
+   public PersistentStateStore getPersistenceManager()
+   {
+      return persistenceManager;
+   }
+
+   public void setPersistenceManager(PersistentStateStore persistenceManager)
+   {
+      this.persistenceManager = persistenceManager;
+   }
+
+   public DataSourceSupport.Config getDataSourceConfigParameter()
+   {
+      return dataSourceConfigParameter;
+   }
+
+   public void setDataSourceConfigParameter(DataSourceSupport.Config dataSourceConfigParameter)
+   {
+      this.dataSourceConfigParameter = dataSourceConfigParameter;
+   }
+
+   public void setUp() throws Exception
+   {
+      runtimeContext = new TestRuntimeContext("org/jboss/portal/test/core/state/registration-persistence-manager-beans.xml");
+      runtimeContext.addBean("TestBean", this);
+      runtimeContext.addBean("DataSourceConfig", dataSourceConfigParameter);
+      runtimeContext.addBean("HibernateConfig", HibernateSupport.getConfig(dataSourceConfigParameter.getName()));
+      runtimeContext.start();
+
+      //
+      super.setUp();
+   }
+
+   public void tearDown() throws Exception
+   {
+      super.tearDown();
+
+      // Cleanup any pending transaction
+      TransactionAssert.endTransaction();
+
+      //
+      runtimeContext.stop();
+   }
+
+   public RegistrationPersistenceManager getManager()
+   {
+      return persistenceManager;
+   }
+
+   public void startInteraction()
+   {
+      TransactionAssert.beginTransaction();
+   }
+
+   public void stopInteraction()
+   {
+      TransactionAssert.commitTransaction();
+   }
+}

Modified: trunk/core/src/resources/portal-core-sar/conf/hibernate/portlet/domain.hbm.xml
===================================================================
--- trunk/core/src/resources/portal-core-sar/conf/hibernate/portlet/domain.hbm.xml	2006-12-11 21:32:57 UTC (rev 5804)
+++ trunk/core/src/resources/portal-core-sar/conf/hibernate/portlet/domain.hbm.xml	2006-12-12 01:24:50 UTC (rev 5805)
@@ -135,4 +135,122 @@
          not-null="true"
          unique="false"/>
    </class>
+
+   <class
+      name="org.jboss.portal.core.impl.portlet.state.PersistentConsumerGroup"
+      table="JBP_PORTLET_GROUP">
+      <cache usage="@portal.hibernate.cache.usage@"/>
+      <id
+         name="key"
+         column="PK"
+         type="java.lang.Long">
+         <generator class="native">
+            <param name="sequence">portlet_seq</param>
+         </generator>
+      </id>
+      <property
+         name="persistentName"
+         column="ID"
+         type="java.lang.String"
+         not-null="true"
+         unique="true"/>
+      <property
+         name="persistentStatus"
+         column="STATUS"
+         type="org.jboss.portal.core.impl.portlet.state.RegistrationStatusUserType"/>
+      <map
+         name="relatedConsumers"
+         inverse="true">
+         <cache usage="@portal.hibernate.cache.usage@"/>
+         <key column="GROUP_PK"/>
+         <map-key
+            type="string"
+            column="ID"/>
+         <one-to-many class="org.jboss.portal.core.impl.portlet.state.PersistentConsumer"/>
+      </map>
+   </class>
+   <class
+      name="org.jboss.portal.core.impl.portlet.state.PersistentConsumer"
+      table="JBP_PORTLET_CONSUMER">
+      <cache usage="@portal.hibernate.cache.usage@"/>
+      <id
+         name="key"
+         column="PK"
+         type="java.lang.Long">
+         <generator class="native">
+            <param name="sequence">portlet_seq</param>
+         </generator>
+      </id>
+      <property
+         name="persistentId"
+         column="ID"
+         type="java.lang.String"
+         not-null="true"
+         unique="true"/>
+      <property
+         name="persistentName"
+         column="NAME"
+         type="java.lang.String"/>
+      <property
+         name="persistentAgent"
+         column="AGENT"
+         type="java.lang.String"/>
+      <property
+         name="persistentStatus"
+         column="STATUS"
+         type="org.jboss.portal.core.impl.portlet.state.RegistrationStatusUserType"/>
+      <many-to-one
+         name="relatedGroup"
+         column="GROUP_PK"
+         class="org.jboss.portal.core.impl.portlet.state.PersistentConsumerGroup"/>
+      <set
+         name="relatedRegistrations"
+         inverse="true">
+         <cache usage="@portal.hibernate.cache.usage@"/>
+         <key column="CONSUMER_PK"/>
+         <one-to-many class="org.jboss.portal.core.impl.portlet.state.PersistentRegistration"/>
+      </set>
+   </class>
+   <class
+      name="org.jboss.portal.core.impl.portlet.state.PersistentRegistration"
+      table="JBP_PORTLET_REGISTRATION">
+      <cache usage="@portal.hibernate.cache.usage@"/>
+      <id
+         name="key"
+         column="PK"
+         type="java.lang.Long">
+         <generator class="native">
+            <param name="sequence">portlet_seq</param>
+         </generator>
+      </id>
+      <map
+         name="persistentProperties"
+         sort="unsorted"
+         inverse="false"
+         cascade="all-delete-orphan"
+         fetch="join">
+         <cache usage="@portal.hibernate.cache.usage@"/>
+         <key column="REGISTRATION_PK"/>
+         <map-key
+            type="org.jboss.portal.jems.hibernate.QNameUserType"
+            column="QNAME"/>
+         <element
+            type="string"
+            column="VALUE"/>
+      </map>
+      <property
+         name="persistentHandle"
+         column="HANDLE"
+         type="java.lang.String"/>
+      <property
+         name="persistentStatus"
+         column="STATUS"
+         type="org.jboss.portal.core.impl.portlet.state.RegistrationStatusUserType"/>
+      <many-to-one
+         name="relatedConsumer"
+         column="CONSUMER_PK"
+         class="org.jboss.portal.core.impl.portlet.state.PersistentConsumer"
+         not-null="true"
+         update="false"/>
+   </class>
 </hibernate-mapping>

Added: trunk/core/src/resources/portal-core-test-jar/org/jboss/portal/test/core/state/registration-persistence-manager-beans.xml
===================================================================
--- trunk/core/src/resources/portal-core-test-jar/org/jboss/portal/test/core/state/registration-persistence-manager-beans.xml	2006-12-11 21:32:57 UTC (rev 5804)
+++ trunk/core/src/resources/portal-core-test-jar/org/jboss/portal/test/core/state/registration-persistence-manager-beans.xml	2006-12-12 01:24:50 UTC (rev 5805)
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+  ~ JBoss, a division of Red Hat                                              ~
+  ~ Copyright 2006, Red Hat Middleware, LLC, 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.                  ~
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+
+<deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_1_0.xsd"
+            xmlns="urn:jboss:bean-deployer">
+
+   <bean name="DataSourceConfig" class="org.jboss.portal.test.framework.embedded.DataSourceSupport$Config">
+      <constructor factoryMethod="getBean">
+         <factory bean="BeanFactory"/>
+         <parameter>DataSourceConfig</parameter>
+      </constructor>
+   </bean>
+
+   <bean name="HibernateConfig" class="org.jboss.portal.test.framework.embedded.HibernateSupport$Config">
+      <constructor factoryMethod="getBean">
+         <factory bean="BeanFactory"/>
+         <parameter>HibernateConfig</parameter>
+      </constructor>
+   </bean>
+
+   <bean name="JNDISupport" class="org.jboss.portal.test.framework.embedded.JNDISupport">
+   </bean>
+
+   <bean name="TransactionManagerSupport" class="org.jboss.portal.test.framework.embedded.TransactionManagerSupport">
+   </bean>
+
+   <bean name="ConnectionManagerSupport" class="org.jboss.portal.test.framework.embedded.ConnectionManagerSupport">
+      <property name="transactionManager"><inject bean="TransactionManagerSupport" property="transactionManager"/></property>
+   </bean>
+
+   <bean name="DataSourceSupport" class="org.jboss.portal.test.framework.embedded.DataSourceSupport">
+      <property name="transactionManager"><inject bean="TransactionManagerSupport" property="transactionManager"/></property>
+      <property name="connectionManagerReference"><inject bean="ConnectionManagerSupport" property="connectionManagerReference"/></property>
+      <property name="config"><inject bean="DataSourceConfig"/></property>
+   </bean>
+
+   <bean name="HibernateSupport" class="org.jboss.portal.test.framework.embedded.HibernateSupport">
+      <property name="config"><inject bean="HibernateConfig"/></property>
+      <property name="mappings">
+         <list elementClass="java.lang.String">
+            <value>conf/hibernate/portlet/domain.hbm.xml</value>
+         </list>
+      </property>
+      <property name="jNDIName">java:/SessionFactory</property>
+   </bean>
+
+   <bean name="PersistenceManager" class="org.jboss.portal.core.impl.portlet.state.PersistentStateStore">
+      <property name="sessionFactoryJNDIName">java:/SessionFactory</property>
+   </bean>
+
+   <bean name="TestBean" class="org.jboss.portal.test.core.state.RegistrationPersistenceManagerTestCase">
+      <constructor factoryMethod="getBean">
+         <factory bean="BeanFactory"/>
+         <parameter>TestBean</parameter>
+      </constructor>
+      <property name="hibernateSupport"><inject bean="HibernateSupport"/></property>
+      <property name="persistenceManager"><inject bean="PersistenceManager"/></property>
+   </bean>
+</deployment>

Modified: trunk/jems/src/main/org/jboss/portal/jems/hibernate/QNameUserType.java
===================================================================
--- trunk/jems/src/main/org/jboss/portal/jems/hibernate/QNameUserType.java	2006-12-11 21:32:57 UTC (rev 5804)
+++ trunk/jems/src/main/org/jboss/portal/jems/hibernate/QNameUserType.java	2006-12-12 01:24:50 UTC (rev 5805)
@@ -43,7 +43,7 @@
 {
 
    /** . */
-   private static final int[] SQL_TYPES = {Hibernate.STRING.sqlType(),Hibernate.STRING.sqlType()};
+   private static final int[] SQL_TYPES = {Hibernate.STRING.sqlType()};
 
    public int[] sqlTypes()
    {
@@ -78,38 +78,37 @@
 
    public Object nullSafeGet(ResultSet resultSet, String[] names, Object owner) throws HibernateException, SQLException
    {
-      // Test nullity on local part
-      String localPart = resultSet.getString(names[1]);
+      // Test nullity
+      String value = resultSet.getString(names[0]);
       if (resultSet.wasNull())
       {
          return null;
       }
 
-      // The namespace URI
-      String namespaceURI = resultSet.getString(names[0]);
-
-      // Oracle considers that the empty string is null (very nice feature, clap clap), so we replace null by empty string
-      if (namespaceURI == null)
+      //
+      int pos = value.indexOf(':');
+      if (pos == -1)
       {
-         namespaceURI = "";
+         return new QName(value);
       }
-
-      //
-      return new QName(namespaceURI, localPart);
+      else
+      {
+         String namespaceURI = value.substring(0, pos);
+         String localPart = value.substring(pos + 1);
+         return new QName(namespaceURI, localPart);
+      }
    }
 
    public void nullSafeSet(PreparedStatement statement, Object value, int index) throws HibernateException, SQLException
    {
       if (value == null)
       {
-         statement.setNull(index, Types.VARCHAR);
-         statement.setNull(index + 1, Types.VARCHAR);
+         statement.setNull(index, SQL_TYPES[0]);
       }
       else
       {
          QName qname = (QName)value;
-         statement.setString(index, qname.getNamespaceURI());
-         statement.setString(index + 1, qname.getLocalPart());
+         statement.setString(index, qname.getNamespaceURI() + ":" + qname.getLocalPart());
       }
    }
 

Modified: trunk/tools/etc/buildfragments/modules.ent
===================================================================
--- trunk/tools/etc/buildfragments/modules.ent	2006-12-11 21:32:57 UTC (rev 5804)
+++ trunk/tools/etc/buildfragments/modules.ent	2006-12-12 01:24:50 UTC (rev 5805)
@@ -103,6 +103,7 @@
   <property name="jboss.portal-wsrp.lib" value="${jboss.portal-wsrp.root}/lib"/>
     <path id="jboss.portal-wsrp.classpath">
       <pathelement path="${jboss.portal-wsrp.lib}/portal-wsrp-lib.jar"/>
+      <pathelement path="${jboss.portal-wsrp.lib}/portal-wsrp-test-lib.jar"/>
    </path>
 
   <!-- security -->

Modified: trunk/wsrp/build.xml
===================================================================
--- trunk/wsrp/build.xml	2006-12-11 21:32:57 UTC (rev 5804)
+++ trunk/wsrp/build.xml	2006-12-12 01:24:50 UTC (rev 5805)
@@ -229,6 +229,11 @@
          </fileset>
          <!--<fileset dir="${build.resources}/portal-wsrp-lib-jar"/>-->
       </jar>
+      <jar jarfile="${build.lib}/portal-wsrp-test-lib.jar">
+         <fileset dir="${build.classes}">
+            <include name="org/jboss/portal/test/**"/>
+         </fileset>
+      </jar>
       <jar jarfile="${build.lib}/portal-wsrp.jse">
          <fileset dir="${build.resources}/portal-wsrp-war"/>
       </jar>

Added: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/AbstractRegistrationPersistenceManagerTestCase.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/AbstractRegistrationPersistenceManagerTestCase.java	2006-12-11 21:32:57 UTC (rev 5804)
+++ trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/AbstractRegistrationPersistenceManagerTestCase.java	2006-12-12 01:24:50 UTC (rev 5805)
@@ -0,0 +1,400 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat                                               *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.wsrp.registration;
+
+import junit.framework.TestCase;
+import org.jboss.portal.wsrp.producer.registration.api.RegistrationPersistenceManager;
+import org.jboss.portal.wsrp.producer.registration.api.ConsumerGroup;
+import org.jboss.portal.wsrp.producer.registration.api.DuplicateRegistrationException;
+import org.jboss.portal.wsrp.producer.registration.api.NoSuchRegistrationException;
+import org.jboss.portal.wsrp.producer.registration.api.Consumer;
+import org.jboss.portal.wsrp.producer.registration.api.Registration;
+
+import javax.xml.namespace.QName;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Collections;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+
+/**
+ * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
+ * @version $Revision: 5787 $
+ * @since 2.6
+ */
+public abstract class AbstractRegistrationPersistenceManagerTestCase extends TestCase
+{
+
+   /** . */
+   private Map registrationProperties;
+
+   public abstract RegistrationPersistenceManager getManager();
+
+   public void startInteraction()
+   {
+   }
+
+   public void stopInteraction()
+   {
+   }
+
+   public void setUp() throws Exception
+   {
+      registrationProperties = new HashMap();
+      registrationProperties.put(new QName("prop1"), "value1");
+      registrationProperties.put(new QName("prop2"), "value2");
+   }
+
+   protected void tearDown() throws Exception
+   {
+      registrationProperties = null;
+   }
+
+   public void testGetGroupThrowsIAE() throws Exception
+   {
+      startInteraction();
+      try
+      {
+         getManager().getConsumerGroup(null);
+         fail();
+      }
+      catch (IllegalArgumentException expected)
+      {
+      }
+      stopInteraction();
+   }
+
+   public void testAddGroup() throws Exception
+   {
+      startInteraction();
+      ConsumerGroup group = getManager().createConsumerGroup("Foo");
+      assertNotNull(group);
+      assertEquals("Foo", group.getName());
+      assertEquals(Collections.EMPTY_LIST, new ArrayList(group.getConsumers()));
+      stopInteraction();
+
+      // Test by retrieving the same consumer
+      startInteraction();
+      group = getManager().getConsumerGroup("Foo");
+      assertNotNull(group);
+      assertEquals("Foo", group.getName());
+      assertEquals(Collections.EMPTY_LIST, new ArrayList(group.getConsumers()));
+      stopInteraction();
+
+      // Test by retrieving the consumer list
+      startInteraction();
+      Collection groups = getManager().getConsumerGroups();
+      assertNotNull(groups);
+      assertEquals(1, groups.size());
+      group = (ConsumerGroup)groups.iterator().next();
+      assertNotNull(group);
+      assertEquals("Foo", group.getName());
+      assertEquals(Collections.EMPTY_LIST, new ArrayList(group.getConsumers()));
+      stopInteraction();
+   }
+
+   public void testAddDuplicateGroup() throws Exception
+   {
+      startInteraction();
+      getManager().createConsumerGroup("Foo");
+      try
+      {
+         getManager().createConsumerGroup("Foo");
+         fail();
+      }
+      catch (DuplicateRegistrationException expected)
+      {
+      }
+      stopInteraction();
+   }
+
+   public void testAddGroupThrowsIAE() throws Exception
+   {
+      startInteraction();
+      try
+      {
+         getManager().createConsumerGroup(null);
+      }
+      catch (IllegalArgumentException expected)
+      {
+         assertEquals(Collections.EMPTY_SET, new HashSet(getManager().getConsumerGroups()));
+      }
+      stopInteraction();
+   }
+
+   public void testRemoveGroup() throws Exception
+   {
+      startInteraction();
+      getManager().createConsumerGroup("Foo");
+      stopInteraction();
+
+      startInteraction();
+      getManager().removeConsumerGroup("Foo");
+      assertNull(getManager().getConsumerGroup("Foo"));
+      assertEquals(Collections.EMPTY_SET, new HashSet(getManager().getConsumerGroups()));
+      stopInteraction();
+   }
+
+   public void testRemoveGroupThrowsIAE() throws Exception
+   {
+      startInteraction();
+      try
+      {
+         getManager().removeConsumerGroup(null);
+      }
+      catch (IllegalArgumentException expected)
+      {
+      }
+      stopInteraction();
+   }
+
+   public void testRemoveNonExistingGroup() throws Exception
+   {
+      startInteraction();
+      try
+      {
+         getManager().removeConsumerGroup("Foo");
+      }
+      catch (NoSuchRegistrationException expected)
+      {
+      }
+      stopInteraction();
+   }
+
+   public void testGetConsumerThrowsIAE() throws Exception
+   {
+      startInteraction();
+      try
+      {
+         ConsumerGroup group = getManager().createConsumerGroup("Foo");
+         group.getConsumer(null);
+         fail();
+      }
+      catch (IllegalArgumentException expected)
+      {
+      }
+      stopInteraction();
+   }
+
+   public void testAddConsumer() throws Exception
+   {
+      startInteraction();
+      ConsumerGroup group = getManager().createConsumerGroup("Foo");
+      stopInteraction();
+
+      startInteraction();
+      Consumer consumer = getManager().createConsumer("Bar", "Bar");
+      group.addConsumer(consumer);
+      assertNotNull(consumer);
+      assertEquals("Bar", consumer.getName());
+      assertEquals(Collections.EMPTY_LIST, new ArrayList(consumer.getRegistrations()));
+      assertEquals("Foo", consumer.getGroup().getName());
+      stopInteraction();
+
+      // Test by retrieving the same consumer
+      startInteraction();
+      consumer = group.getConsumer("Bar");
+      assertNotNull(consumer);
+      assertEquals("Bar", consumer.getName());
+      assertEquals(Collections.EMPTY_LIST, new ArrayList(consumer.getRegistrations()));
+      assertEquals("Foo", consumer.getGroup().getName());
+      stopInteraction();
+
+      // Test by retrieving the consumer list
+      startInteraction();
+      Collection consumers = group.getConsumers();
+      assertNotNull(consumers);
+      assertEquals(1, consumers.size());
+      consumer = (Consumer)consumers.iterator().next();
+      assertNotNull(consumer);
+      assertEquals("Bar", consumer.getName());
+      assertEquals(Collections.EMPTY_LIST, new ArrayList(consumer.getRegistrations()));
+      assertEquals("Foo", consumer.getGroup().getName());
+      stopInteraction();
+   }
+
+   public void testAddDuplicateConsumer() throws Exception
+   {
+      startInteraction();
+      ConsumerGroup group = getManager().createConsumerGroup("Foo");
+      Consumer consumer = getManager().createConsumer("Bar", "Bar");
+      group.addConsumer(consumer);
+      stopInteraction();
+
+      startInteraction();
+      try
+      {
+         group.addConsumer(consumer);
+         fail();
+      }
+      catch (IllegalArgumentException expected)
+      {
+      }
+      stopInteraction();
+   }
+
+   public void testAddConsumerThrowsIAE() throws Exception
+   {
+      startInteraction();
+      ConsumerGroup group = getManager().createConsumerGroup("Foo");
+      try
+      {
+         group.addConsumer(null);
+      }
+      catch (IllegalArgumentException expected)
+      {
+         assertEquals(Collections.EMPTY_SET, new HashSet(group.getConsumers()));
+      }
+      stopInteraction();
+   }
+
+   public void testRemoveConsumer() throws Exception
+   {
+      startInteraction();
+      ConsumerGroup group = getManager().createConsumerGroup("Foo");
+      Consumer consumer = getManager().createConsumer("Bar", "Bar");
+      group.addConsumer(consumer);
+      group.removeConsumer(consumer);
+      assertNull(group.getConsumer("Bar"));
+      assertEquals(Collections.EMPTY_SET, new HashSet(group.getConsumers()));
+      stopInteraction();
+   }
+
+   public void testRemoveConsumerThrowsIAE() throws Exception
+   {
+      startInteraction();
+      ConsumerGroup group = getManager().createConsumerGroup("Foo");
+      try
+      {
+         group.removeConsumer(null);
+      }
+      catch (IllegalArgumentException expected)
+      {
+      }
+      stopInteraction();
+   }
+
+   public void testAddRegistration() throws Exception
+   {
+      startInteraction();
+      ConsumerGroup group = getManager().createConsumerGroup("Foo");
+      Consumer consumer = getManager().createConsumer("Bar", "Bar");
+      group.addConsumer(consumer);
+      stopInteraction();
+
+      startInteraction();
+      consumer = getManager().getConsumerById("Bar");
+      Registration reg1 = getManager().addRegistrationFor("Bar", registrationProperties);
+      assertNotNull(reg1);
+      String regId = reg1.getId();
+      assertNotNull(regId);
+      assertEquals(consumer, reg1.getConsumer());
+      Map expectedProps = new HashMap();
+      expectedProps.put(new QName("prop1"), "value1");
+      expectedProps.put(new QName("prop2"), "value2");
+      assertEquals(expectedProps, reg1.getProperties());
+      stopInteraction();
+
+      // Retrieve it from the list of consumer registrations
+      startInteraction();
+      consumer = getManager().getConsumerById("Bar");
+      Collection registrations = consumer.getRegistrations();
+      assertNotNull(registrations);
+      assertEquals(1, registrations.size());
+      Registration reg3 = (Registration)registrations.iterator().next();
+      assertEquals(regId, reg3.getId());
+      assertEquals(consumer, reg3.getConsumer());
+      assertEquals(expectedProps, reg3.getProperties());
+      stopInteraction();
+
+      // Retrieve the same registration from the registry
+      startInteraction();
+      Registration reg2 = getManager().getRegistration(regId);
+      consumer = getManager().getConsumerById("Bar");
+      assertNotNull(reg2);
+      assertEquals(regId, reg2.getId());
+      assertEquals(consumer, reg2.getConsumer());
+      assertEquals(expectedProps, reg2.getProperties());
+      stopInteraction();
+   }
+
+   public void testAddRegistrationThrowsIAE() throws Exception
+   {
+      startInteraction();
+      ConsumerGroup group = getManager().createConsumerGroup("Foo");
+      Consumer consumer = getManager().createConsumer("Bar", "Bar");
+      group.addConsumer(consumer);
+
+      try
+      {
+         getManager().addRegistrationFor(consumer.getId(), null);
+         fail();
+      }
+      catch (IllegalArgumentException expected)
+      {
+      }
+      stopInteraction();
+   }
+
+   public void testRemoveRegistrationThrowsIAE() throws Exception
+   {
+      startInteraction();
+      try
+      {
+         getManager().removeRegistration(null);
+         fail();
+      }
+      catch (IllegalArgumentException expected)
+      {
+      }
+      stopInteraction();
+   }
+
+   public void testRemoveRegistration() throws Exception
+   {
+      startInteraction();
+      ConsumerGroup group = getManager().createConsumerGroup("Foo");
+      Consumer consumer = getManager().createConsumer("Bar", "Bar");
+      group.addConsumer(consumer);
+      Registration reg = getManager().addRegistrationFor("Bar", registrationProperties);
+      String regId = reg.getId();
+      getManager().removeRegistration(regId);
+      stopInteraction();
+
+      // remove registration is the only method on RegistrationPersistenceManager that needs to "cascade"
+      // this is needed because there is no remove method on Consumer, hence the manager needs to remove the
+      // registration from its consumer since it's the only class that has access to the specific consumer impl
+      startInteraction();
+      consumer = getManager().getConsumerById("Bar");
+      Collection registrations = consumer.getRegistrations();
+      assertNotNull(registrations);
+      assertEquals(0, registrations.size());
+      stopInteraction();
+
+      //
+      startInteraction();
+      assertEquals(null, getManager().getRegistration(regId));
+      stopInteraction();
+   }
+}

Modified: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/RegistrationPersistenceManagerTestCase.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/RegistrationPersistenceManagerTestCase.java	2006-12-11 21:32:57 UTC (rev 5804)
+++ trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/RegistrationPersistenceManagerTestCase.java	2006-12-12 01:24:50 UTC (rev 5805)
@@ -23,309 +23,38 @@
 
 package org.jboss.portal.test.wsrp.registration;
 
-import junit.framework.TestCase;
-import org.jboss.portal.wsrp.producer.registration.api.Consumer;
-import org.jboss.portal.wsrp.producer.registration.api.ConsumerGroup;
-import org.jboss.portal.wsrp.producer.registration.api.DuplicateRegistrationException;
-import org.jboss.portal.wsrp.producer.registration.api.NoSuchRegistrationException;
-import org.jboss.portal.wsrp.producer.registration.api.Registration;
 import org.jboss.portal.wsrp.producer.registration.api.RegistrationPersistenceManager;
 import org.jboss.portal.wsrp.producer.registration.impl.RegistrationPersistenceManagerImpl;
 
-import javax.xml.namespace.QName;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-
 /**
  * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
  * @version $Revision$
  * @since 2.6
  */
-public class RegistrationPersistenceManagerTestCase extends TestCase
+public class RegistrationPersistenceManagerTestCase extends AbstractRegistrationPersistenceManagerTestCase
 {
+
+   /** . */
    private RegistrationPersistenceManager manager;
-   private Map registrationProperties;
 
-   public void setUp()
+   public void setUp() throws Exception
    {
       manager = new RegistrationPersistenceManagerImpl();
-      registrationProperties = new HashMap();
-      registrationProperties.put(new QName("prop1"), "value1");
-      registrationProperties.put(new QName("prop2"), "value2");
+
+      //
+      super.setUp();
    }
 
    protected void tearDown() throws Exception
    {
-      manager = null;
-      registrationProperties = null;
-   }
+      super.tearDown();
 
-   public void testGetGroupThrowsIAE() throws Exception
-   {
-      try
-      {
-         manager.getConsumerGroup(null);
-         fail();
-      }
-      catch (IllegalArgumentException expected)
-      {
-      }
-   }
-
-   public void testAddGroup() throws Exception
-   {
-      ConsumerGroup group = manager.createConsumerGroup("Foo");
-      assertNotNull(group);
-      assertEquals("Foo", group.getName());
-      assertEquals(Collections.EMPTY_LIST, new ArrayList(group.getConsumers()));
-
-      // Test by retrieving the same consumer
-      group = manager.getConsumerGroup("Foo");
-      assertNotNull(group);
-      assertEquals("Foo", group.getName());
-      assertEquals(Collections.EMPTY_LIST, new ArrayList(group.getConsumers()));
-
-      // Test by retrieving the consumer list
-      Collection groups = manager.getConsumerGroups();
-      assertNotNull(groups);
-      assertEquals(1, groups.size());
-      group = (ConsumerGroup)groups.iterator().next();
-      assertNotNull(group);
-      assertEquals("Foo", group.getName());
-      assertEquals(Collections.EMPTY_LIST, new ArrayList(group.getConsumers()));
-   }
-
-   public void testAddDuplicateGroup() throws Exception
-   {
-      manager.createConsumerGroup("Foo");
-      try
-      {
-         manager.createConsumerGroup("Foo");
-         fail();
-      }
-      catch (DuplicateRegistrationException expected)
-      {
-      }
-   }
-
-   public void testAddGroupThrowsIAE() throws Exception
-   {
-      try
-      {
-         manager.createConsumerGroup(null);
-      }
-      catch (IllegalArgumentException expected)
-      {
-         assertEquals(Collections.EMPTY_SET, new HashSet(manager.getConsumerGroups()));
-      }
-   }
-
-   public void testRemoveGroup() throws Exception
-   {
-      manager.createConsumerGroup("Foo");
-      manager.removeConsumerGroup("Foo");
-      assertNull(manager.getConsumerGroup("Foo"));
-      assertEquals(Collections.EMPTY_SET, new HashSet(manager.getConsumerGroups()));
-   }
-
-   public void testRemoveGroupThrowsIAE() throws Exception
-   {
-      try
-      {
-         manager.removeConsumerGroup(null);
-      }
-      catch (IllegalArgumentException expected)
-      {
-      }
-   }
-
-   public void testRemoveNonExistingGroup() throws Exception
-   {
-      try
-      {
-         manager.removeConsumerGroup("Foo");
-      }
-      catch (NoSuchRegistrationException expected)
-      {
-      }
-   }
-
-   public void testGetConsumerThrowsIAE() throws Exception
-   {
-      try
-      {
-         ConsumerGroup group = manager.createConsumerGroup("Foo");
-         group.getConsumer(null);
-         fail();
-      }
-      catch (IllegalArgumentException expected)
-      {
-      }
-   }
-
-   public void testAddConsumer() throws Exception
-   {
-      ConsumerGroup group = manager.createConsumerGroup("Foo");
-
-      Consumer consumer = manager.createConsumer("Bar", "Bar");
-      group.addConsumer(consumer);
-      assertNotNull(consumer);
-      assertEquals("Bar", consumer.getName());
-      assertEquals(Collections.EMPTY_LIST, new ArrayList(consumer.getRegistrations()));
-      assertEquals("Foo", consumer.getGroup().getName());
-
-      // Test by retrieving the same consumer
-      consumer = group.getConsumer("Bar");
-      assertNotNull(consumer);
-      assertEquals("Bar", consumer.getName());
-      assertEquals(Collections.EMPTY_LIST, new ArrayList(consumer.getRegistrations()));
-      assertEquals("Foo", consumer.getGroup().getName());
-
-      // Test by retrieving the consumer list
-      Collection consumers = group.getConsumers();
-      assertNotNull(consumers);
-      assertEquals(1, consumers.size());
-      consumer = (Consumer)consumers.iterator().next();
-      assertNotNull(consumer);
-      assertEquals("Bar", consumer.getName());
-      assertEquals(Collections.EMPTY_LIST, new ArrayList(consumer.getRegistrations()));
-      assertEquals("Foo", consumer.getGroup().getName());
-   }
-
-   public void testAddDuplicateConsumer() throws Exception
-   {
-      ConsumerGroup group = manager.createConsumerGroup("Foo");
-      Consumer consumer = manager.createConsumer("Bar", "Bar");
-      group.addConsumer(consumer);
-
-      try
-      {
-         group.addConsumer(consumer);
-         fail();
-      }
-      catch (DuplicateRegistrationException expected)
-      {
-      }
-   }
-
-   public void testAddConsumerThrowsIAE() throws Exception
-   {
-      ConsumerGroup group = manager.createConsumerGroup("Foo");
-      try
-      {
-         group.addConsumer(null);
-      }
-      catch (IllegalArgumentException expected)
-      {
-         assertEquals(Collections.EMPTY_SET, new HashSet(group.getConsumers()));
-      }
-   }
-
-   public void testRemoveConsumer() throws Exception
-   {
-      ConsumerGroup group = manager.createConsumerGroup("Foo");
-      Consumer consumer = manager.createConsumer("Bar", "Bar");
-      group.addConsumer(consumer);
-      group.removeConsumer(consumer);
-      assertNull(group.getConsumer("Bar"));
-      assertEquals(Collections.EMPTY_SET, new HashSet(group.getConsumers()));
-   }
-
-   public void testRemoveConsumerThrowsIAE() throws Exception
-   {
-      ConsumerGroup group = manager.createConsumerGroup("Foo");
-      try
-      {
-         group.removeConsumer(null);
-      }
-      catch (IllegalArgumentException expected)
-      {
-      }
-   }
-
-   public void testAddRegistration() throws Exception
-   {
-      ConsumerGroup group = manager.createConsumerGroup("Foo");
-      Consumer consumer = manager.createConsumer("Bar", "Bar");
-      group.addConsumer(consumer);
-
       //
-      Registration reg1 = manager.addRegistrationFor("Bar", registrationProperties);
-      assertNotNull(reg1);
-      String regId = reg1.getId();
-      assertNotNull(regId);
-      assertEquals(consumer, reg1.getConsumer());
-      Map expectedProps = new HashMap();
-      expectedProps.put(new QName("prop1"), "value1");
-      expectedProps.put(new QName("prop2"), "value2");
-      assertEquals(expectedProps, reg1.getProperties());
-
-      // Retrieve it from the list of consumer registrations
-      Collection registrations = consumer.getRegistrations();
-      assertNotNull(registrations);
-      assertEquals(1, registrations.size());
-      Registration reg3 = (Registration)registrations.iterator().next();
-      assertEquals(regId, reg3.getId());
-      assertEquals(consumer, reg3.getConsumer());
-      assertEquals(expectedProps, reg3.getProperties());
-
-      // Retrieve the same registration from the registry
-      Registration reg2 = manager.getRegistration(regId);
-      assertNotNull(reg2);
-      assertEquals(regId, reg2.getId());
-      assertEquals(consumer, reg2.getConsumer());
-      assertEquals(expectedProps, reg2.getProperties());
+      this.manager = null;
    }
 
-   public void testAddRegistrationThrowsIAE() throws Exception
+   public RegistrationPersistenceManager getManager()
    {
-      ConsumerGroup group = manager.createConsumerGroup("Foo");
-      Consumer consumer = manager.createConsumer("Bar", "Bar");
-      group.addConsumer(consumer);
-
-      try
-      {
-         manager.addRegistrationFor(consumer.getId(), null);
-         fail();
-      }
-      catch (IllegalArgumentException expected)
-      {
-      }
+      return manager;
    }
-
-   public void testRemoveRegistrationThrowsIAE() throws Exception
-   {
-      try
-      {
-         manager.removeRegistration(null);
-         fail();
-      }
-      catch (IllegalArgumentException expected)
-      {
-      }
-   }
-
-   public void testRemoveRegistration() throws Exception
-   {
-      ConsumerGroup group = manager.createConsumerGroup("Foo");
-      Consumer consumer = manager.createConsumer("Bar", "Bar");
-      group.addConsumer(consumer);
-      Registration reg = manager.addRegistrationFor("Bar", registrationProperties);
-      String regId = reg.getId();
-      manager.removeRegistration(regId);
-
-      // remove registration is the only method on RegistrationPersistenceManager that needs to "cascade"
-      // this is needed because there is no remove method on Consumer, hence the manager needs to remove the
-      // registration from its consumer since it's the only class that has access to the specific consumer impl
-      Collection registrations = consumer.getRegistrations();
-      assertNotNull(registrations);
-      assertEquals(0, registrations.size());
-
-      //
-      assertEquals(null, manager.getRegistration(regId));
-   }
 }

Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/RegistrationStatus.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/RegistrationStatus.java	2006-12-11 21:32:57 UTC (rev 5804)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/RegistrationStatus.java	2006-12-12 01:24:50 UTC (rev 5805)
@@ -22,13 +22,15 @@
  ******************************************************************************/
 package org.jboss.portal.wsrp.producer.registration.api;
 
+import java.io.Serializable;
+
 /**
  * Type safe enumeration that describes the status of a registration.
  *
  * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
  * @version $Revision:5641 $
  */
-public class RegistrationStatus
+public class RegistrationStatus implements Serializable
 {
    /** The registration is valid. */
    public static final RegistrationStatus VALID = new RegistrationStatus();

Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/ConsumerGroupImpl.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/ConsumerGroupImpl.java	2006-12-11 21:32:57 UTC (rev 5804)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/ConsumerGroupImpl.java	2006-12-12 01:24:50 UTC (rev 5805)
@@ -124,7 +124,7 @@
       String identity = consumer.getId();
       if (consumers.containsKey(identity))
       {
-         throw new DuplicateRegistrationException("ConsumerGroup named '" + name
+         throw new IllegalArgumentException("ConsumerGroup named '" + name
             + "' already contains a Consumer named '" + consumer.getName() + "' (identity: '" + identity + "')");
       }
 




More information about the portal-commits mailing list