[jboss-svn-commits] JBoss Portal SVN: r5698 - in trunk/wsrp: . src/main/org/jboss/portal/test/wsrp src/main/org/jboss/portal/test/wsrp/registration src/main/org/jboss/portal/wsrp/producer/registration src/main/org/jboss/portal/wsrp/producer/registration/api src/main/org/jboss/portal/wsrp/producer/registration/impl src/main/org/jboss/portal/wsrp/producer/registration/policies
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Nov 21 02:07:29 EST 2006
Author: chris.laprun at jboss.com
Date: 2006-11-21 02:07:20 -0500 (Tue, 21 Nov 2006)
New Revision: 5698
Added:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/ConsumerTestCase.java
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/RegistrationManagerTestCase.java
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/RegistrationPersistenceManagerTestCase.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/PersistentRegistrationObject.java
Removed:
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/spi/
Modified:
trunk/wsrp/build.xml
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/Consumer.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/ConsumerCapabilities.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/ConsumerGroup.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/InvalidConsumerDataException.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/LocalizedString.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/ProducerRegistrationRequirements.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/Registration.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/RegistrationManager.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/RegistrationPersistenceManager.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/RegistrationPolicy.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/RegistrationPropertyDescription.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/ConsumerGroupImpl.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/ConsumerImpl.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/ProducerRegistrationRequirementsImpl.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/RegistrationImpl.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/RegistrationPersistenceManagerImpl.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/policies/DefaultRegistrationPolicy.java
Log:
Second pass at implementing registration entities:
- RegistrationManager is the gateway to registration operations
- RegistrationPersistenceManager does not cascade operations
- Business objects should behave properly
- Added test cases
- Producer tests still broken: fixing them is the next step.
Modified: trunk/wsrp/build.xml
===================================================================
--- trunk/wsrp/build.xml 2006-11-21 07:00:09 UTC (rev 5697)
+++ trunk/wsrp/build.xml 2006-11-21 07:07:20 UTC (rev 5698)
@@ -349,6 +349,13 @@
</jar>
</target>
+ <target name="package-registration-test" description="Generates the registration test artifacts" depends="compile">
+ <jar jarfile="${build.lib.test}/test-registration-lib.jar">
+ <fileset dir="${build.classes}/">
+ <include name="org/jboss/portal/test/wsrp/registration/*.class"/>
+ </fileset>
+ </jar>
+ </target>
<target name="package-consumer-test" description="Generates the consumer test artifacts"
depends="compile">
@@ -527,6 +534,7 @@
<antcall target="consumer-test"/>
<antcall target="deployment-test"/>
<antcall target="other-test"/>
+ <antcall target="registration-test"/>
<antcall target="agent-undeploy"/>
<server:stop name="default"/>
<antcall target="reports"/>
@@ -537,6 +545,7 @@
<antcall target="consumer-test"/>
<antcall target="deployment-test"/>
<antcall target="other-test"/>
+ <antcall target="registration-test"/>
</target>
<!-- WSRP Producer tests -->
@@ -604,10 +613,10 @@
<test todir="${test.reports}" name="org.jboss.portal.test.wsrp.deployment.DeploymentTestCase"/>
</x-test>
<x-sysproperty>
- <jvmarg value="-Xdebug"/>
+ <!--<jvmarg value="-Xdebug"/>
<jvmarg value="-Xnoagent"/>
<jvmarg value="-Djava.compiler=NONE"/>
- <jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8787"/>
+ <jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8787"/>-->
<sysproperty key="test.root" value="${build.lib}/tests"/>
</x-sysproperty>
<x-classpath>
@@ -625,16 +634,16 @@
<target name="other-test" depends="package-other-test">
<execute-tests>
<x-test>
- <!--<test todir="${test.reports}" name="org.jboss.portal.test.wsrp.other.RegistrationPersistenceManagerTestCase"/>-->
+ <!--<test todir="${test.reports}" name="org.jboss.portal.test.wsrp.registration.RegistrationPersistenceManagerTestCase"/>-->
<test todir="${test.reports}" name="org.jboss.portal.test.wsrp.other.ProducerSessionInformationTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.wsrp.other.WSRPPortletURLTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.wsrp.handler.RequestHeaderClientHandlerTestCase"/>
</x-test>
<x-sysproperty>
- <jvmarg value="-Xdebug"/>
+ <!--<jvmarg value="-Xdebug"/>
<jvmarg value="-Xnoagent"/>
<jvmarg value="-Djava.compiler=NONE"/>
- <jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8787"/>
+ <jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8787"/>-->
<sysproperty key="test.root" value="${build.lib}/tests"/>
</x-sysproperty>
<x-classpath>
@@ -648,6 +657,33 @@
</execute-tests>
</target>
+ <!-- Registration tests -->
+ <target name="registration-test" depends="package-registration-test">
+ <execute-tests>
+ <x-test>
+ <test todir="${test.reports}"
+ name="org.jboss.portal.test.wsrp.registration.RegistrationPersistenceManagerTestCase"/>
+ <test todir="${test.reports}" name="org.jboss.portal.test.wsrp.registration.ConsumerTestCase"/>
+ <test todir="${test.reports}" name="org.jboss.portal.test.wsrp.registration.RegistrationManagerTestCase"/>
+ </x-test>
+ <x-sysproperty>
+ <!--<jvmarg value="-Xdebug"/>
+ <jvmarg value="-Xnoagent"/>
+ <jvmarg value="-Djava.compiler=NONE"/>
+ <jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8787"/>-->
+ <sysproperty key="test.root" value="${build.lib}/tests"/>
+ </x-sysproperty>
+ <x-classpath>
+ <fileset dir="${build.lib}" includes="portal-wsrp-lib.jar"/>
+ <fileset dir="${build.lib.test}" includes="test-registration-lib.jar"/>
+ <path refid="jboss.microcontainer.classpath"/>
+ <path refid="library.classpath"/>
+ <path refid="dependentmodule.classpath"/>
+ <path refid="ws.classpath"/>
+ </x-classpath>
+ </execute-tests>
+ </target>
+
<target name="reports">
<junitreport todir="${reports.dir}">
<fileset dir="${test.reports}">
Added: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/ConsumerTestCase.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/ConsumerTestCase.java 2006-11-21 07:00:09 UTC (rev 5697)
+++ trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/ConsumerTestCase.java 2006-11-21 07:07:20 UTC (rev 5698)
@@ -0,0 +1,103 @@
+/******************************************************************************
+ * 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.Consumer;
+import org.jboss.portal.wsrp.producer.registration.api.ConsumerGroup;
+import org.jboss.portal.wsrp.producer.registration.api.RegistrationManager;
+import org.jboss.portal.wsrp.producer.registration.api.RegistrationStatus;
+import org.jboss.portal.wsrp.producer.registration.impl.RegistrationPersistenceManagerImpl;
+import org.jboss.portal.wsrp.producer.registration.policies.DefaultRegistrationPolicy;
+
+import javax.xml.namespace.QName;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
+ * @version $Revision$
+ * @since 2.6
+ */
+public class ConsumerTestCase extends TestCase
+{
+ private Consumer consumer;
+ private RegistrationManager manager;
+ private Map registrationProperties;
+
+ protected void setUp() throws Exception
+ {
+ manager = new RegistrationManager();
+ manager.setPolicy(new DefaultRegistrationPolicy());
+ manager.setPersistenceManager(new RegistrationPersistenceManagerImpl());
+ consumer = manager.createConsumer("name");
+ registrationProperties = new HashMap();
+ registrationProperties.put(new QName("prop1"), "value1");
+ registrationProperties.put(new QName("prop2"), "value2");
+ }
+
+ public void testGetName()
+ {
+ assertEquals("name", consumer.getName());
+ }
+
+ public void testStatus()
+ {
+ assertEquals(RegistrationStatus.PENDING, consumer.getStatus());
+
+ consumer.setStatus(RegistrationStatus.VALID);
+ assertEquals(RegistrationStatus.VALID, consumer.getStatus());
+ }
+
+ public void testIllegalStatus()
+ {
+ try
+ {
+ consumer.setStatus(null);
+ fail("Was expecting an IllegalArgumentException to be thrown on setStatus(null)");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ }
+
+ public void testSetGroup() throws Exception
+ {
+ ConsumerGroup group = manager.createConsumerGroup("group");
+ assertTrue(!group.getConsumers().contains(consumer));
+
+ consumer.setGroup(group);
+ assertEquals(group, consumer.getGroup());
+ assertTrue(group.getConsumers().contains(consumer));
+
+ consumer.setGroup(null);
+ assertNull(consumer.getGroup());
+ assertTrue(!group.getConsumers().contains(consumer));
+ }
+
+ public void testGetIdentity() throws Exception
+ {
+ assertNotNull(consumer.getIdentity());
+ }
+}
Property changes on: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/ConsumerTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/RegistrationManagerTestCase.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/RegistrationManagerTestCase.java 2006-11-21 07:00:09 UTC (rev 5697)
+++ trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/RegistrationManagerTestCase.java 2006-11-21 07:07:20 UTC (rev 5698)
@@ -0,0 +1,367 @@
+/******************************************************************************
+ * 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.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.RegistrationException;
+import org.jboss.portal.wsrp.producer.registration.api.RegistrationManager;
+import org.jboss.portal.wsrp.producer.registration.api.RegistrationPolicy;
+import org.jboss.portal.wsrp.producer.registration.impl.RegistrationPersistenceManagerImpl;
+import org.jboss.portal.wsrp.producer.registration.policies.DefaultRegistrationPolicy;
+
+import javax.xml.namespace.QName;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
+ * @version $Revision$
+ * @since 2.6
+ */
+public class RegistrationManagerTestCase extends TestCase
+{
+
+ private RegistrationManager manager;
+ private Map registrationProperties;
+
+ protected void setUp() throws Exception
+ {
+ manager = new RegistrationManager();
+ manager.setPolicy(new DefaultRegistrationPolicy());
+ manager.setPersistenceManager(new RegistrationPersistenceManagerImpl());
+ registrationProperties = new HashMap();
+ registrationProperties.put(new QName("prop1"), "value1");
+ registrationProperties.put(new QName("prop2"), "value2");
+ }
+
+ public void testPolicy()
+ {
+ RegistrationPolicy policy = manager.getPolicy();
+ assertNotNull(policy);
+ assertEquals(manager, policy.getManager());
+ }
+
+ public void testAddRegistrationTo() throws Exception
+ {
+ Registration registration = manager.addRegistrationTo("consumerName", registrationProperties, true);
+ assertNotNull(registration);
+ assertNotNull(registration.getId());
+
+ Consumer consumer = manager.getConsumerByIdentity("consumerName");
+ assertNotNull(consumer); // default policy: name == identity
+ assertEquals(consumer, registration.getConsumer());
+
+ String registrationHandle = registration.getRegistrationHandle();
+ assertNotNull(registrationHandle);
+ assertEquals(consumer, manager.getConsumerFor(registrationHandle));
+ }
+
+ public void testAddRegistrationToInexistentConsumer() throws RegistrationException
+ {
+ try
+ {
+ manager.addRegistrationTo("consumerName", registrationProperties, false);
+ fail("Should have failed: consumer does not exist");
+ }
+ catch (NoSuchRegistrationException expected)
+ {
+ }
+
+ assertNull(manager.getConsumerByIdentity("consumerName")); // default policy: name == identity
+ }
+
+ public void testGetConsumerForNullRegistrationHandle() throws Exception
+ {
+ try
+ {
+ manager.getConsumerFor(null);
+ fail("Should have failed: cannot find a consumer for a null registration handle");
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ }
+
+ public void testCreateConsumer() throws Exception
+ {
+ String name = "consumerName";
+ Consumer consumer = manager.createConsumer(name);
+ assertNotNull(consumer);
+ assertEquals(name, consumer.getName());
+ assertNotNull(consumer.getIdentity());
+ assertNull(consumer.getGroup());
+
+ Collection consumers = manager.getConsumers();
+ assertEquals(1, consumers.size());
+ assertTrue(consumers.contains(consumer));
+ assertEquals(consumer, manager.getConsumerByIdentity(name)); // default policy: name == identity
+
+ try
+ {
+ consumers.add(consumer);
+ fail("Shouldn't be possible to directly modify consumer collection");
+ }
+ catch (UnsupportedOperationException expected)
+ {
+ }
+ }
+
+ public void testCreateConsumerWithGroupFromPolicy() throws RegistrationException
+ {
+ // use a different policy: now specifies that when creating a consumer, it should be added to a group with the same name
+ manager.setPolicy(new DefaultRegistrationPolicy()
+ {
+ public String getGroupNameFor(String consumerName)
+ {
+ return consumerName;
+ }
+ });
+
+ String name = "name";
+ Consumer consumer = manager.createConsumer(name);
+ assertNotNull(consumer);
+
+ ConsumerGroup group = manager.getConsumerGroup(name);
+ assertNotNull(group);
+ assertEquals(group, consumer.getGroup());
+ assertTrue(group.getConsumers().contains(consumer));
+ }
+
+ public void testCreateDuplicateConsumer() throws RegistrationException
+ {
+ String name = "name";
+ assertNotNull(manager.createConsumer(name));
+
+ try
+ {
+ manager.createConsumer(name);
+ fail("Should have failed when trying to create a consumer with an existing name");
+ }
+ catch (DuplicateRegistrationException expected)
+ {
+ }
+ }
+
+ public void testAddAutomaticallyCreatedConsumerToInexistentGroup() throws RegistrationException
+ {
+ try
+ {
+ manager.addConsumerToGroupNamed("foo", "bar", false, true);
+ fail("Shouldn't be possible to add a consumer to an inexistent group without first creating it");
+ }
+ catch (NoSuchRegistrationException expected)
+ {
+ }
+
+ assertNull(manager.getConsumerByIdentity("foo"));
+ assertNull(manager.getConsumerGroup("bar"));
+ }
+
+ public void testAddInexistentConsumerToAutomaticallyCreatedGroup() throws RegistrationException
+ {
+ try
+ {
+ manager.addConsumerToGroupNamed("foo", "bar", true, false);
+ fail("Shouldn't be possible to add an inexistent consumer to a group without first creating it");
+ }
+ catch (NoSuchRegistrationException expected)
+ {
+ }
+
+ assertNull(manager.getConsumerByIdentity("foo"));
+ assertNull(manager.getConsumerGroup("bar"));
+ }
+
+ public void testAddInexistentConsumerToGroup() throws RegistrationException
+ {
+ manager.createConsumerGroup("bar");
+ try
+ {
+ manager.addConsumerToGroupNamed("foo", "bar", false, false);
+ fail("Shouldn't be possible to add an inexistent consumer to a group without first creating it");
+ }
+ catch (NoSuchRegistrationException expected)
+ {
+ }
+
+ assertNull(manager.getConsumerByIdentity("foo"));
+ assertNotNull(manager.getConsumerGroup("bar"));
+ }
+
+ public void testAddInexistentConsumerToInexistentGroup() throws RegistrationException
+ {
+ try
+ {
+ manager.addConsumerToGroupNamed("foo", "bar", false, false);
+ fail("Shouldn't be possible to add a consumer to an inexistent group without first creating it");
+ }
+ catch (NoSuchRegistrationException expected)
+ {
+ }
+
+ assertNull(manager.getConsumerByIdentity("foo"));
+ assertNull(manager.getConsumerGroup("bar"));
+ }
+
+ public void testAddConsumerToGroup() throws Exception
+ {
+ String groupName = "group";
+ String consumerName = "consumer";
+ Consumer consumer = manager.addConsumerToGroupNamed(consumerName, groupName, true, true);
+
+ Consumer consumer1 = manager.getConsumerByIdentity(consumerName);
+ assertNotNull(consumer1);
+ assertEquals(consumer1, consumer); // default policy: identity == name
+
+ ConsumerGroup group = manager.getConsumerGroup(groupName);
+ assertNotNull(group);
+ assertEquals(group, consumer.getGroup());
+ }
+
+ public void testCreateConsumerGroup() throws Exception
+ {
+ String groupName = "name";
+ ConsumerGroup group = manager.createConsumerGroup(groupName);
+ assertNotNull(group);
+ assertEquals(groupName, group.getName());
+
+ Collection groups = manager.getConsumerGroups();
+ assertEquals(1, groups.size());
+ assertTrue(groups.contains(group));
+ assertEquals(group, manager.getConsumerGroup(groupName));
+
+ try
+ {
+ groups.add(group);
+ fail("Shouldn't be possible to directly modify group collection");
+ }
+ catch (UnsupportedOperationException expected)
+ {
+ }
+ }
+
+ public void testRemoveConsumerGroup() throws RegistrationException
+ {
+ String groupName = "name";
+ ConsumerGroup group = manager.createConsumerGroup(groupName);
+ manager.removeConsumerGroup(group);
+ assertNull(manager.getConsumerGroup(groupName));
+
+ manager.createConsumerGroup(groupName);
+ manager.removeConsumerGroup(groupName);
+ assertNull(manager.getConsumerGroup(groupName));
+ }
+
+ public void testCascadeRemovalOnConsumerGroupRemoval() throws Exception
+ {
+ String groupName = "group";
+ String consumerName = "consumer";
+ Consumer consumer = manager.addConsumerToGroupNamed(consumerName, groupName, true, true);
+ String consumerIdentity = consumer.getIdentity();
+
+ Registration reg = manager.addRegistrationTo(consumerName, registrationProperties, false);
+ String handle = reg.getRegistrationHandle();
+
+ ConsumerGroup group = manager.getConsumerGroup(groupName);
+
+ manager.removeConsumerGroup(group);
+ assertNull(manager.getConsumerByIdentity(consumerIdentity));
+ assertNull(manager.getRegistration(handle));
+ }
+
+ public void testCascadeRemovalOnConsumerRemoval() throws Exception
+ {
+ String consumerName = "consumer";
+ Consumer consumer = manager.createConsumer(consumerName);
+ String consumerIdentity = consumer.getIdentity();
+
+ Registration reg = manager.addRegistrationTo(consumerName, registrationProperties, false);
+ String handle = reg.getRegistrationHandle();
+
+ manager.removeConsumer(consumer);
+ assertNull(manager.getConsumerByIdentity(consumerIdentity));
+ assertNull(manager.getRegistration(handle));
+ }
+
+ public void testRemoveRegistration() throws Exception
+ {
+ String consumerName = "consumer";
+ Consumer consumer = manager.createConsumer(consumerName);
+ String consumerIdentity = consumer.getIdentity();
+
+ Registration reg = manager.addRegistrationTo(consumerName, registrationProperties, false);
+ String handle = reg.getRegistrationHandle();
+
+ assertTrue(consumer.getRegistrations().contains(reg));
+
+ manager.removeRegistration(handle);
+ assertTrue(!consumer.getRegistrations().contains(reg));
+ assertNull(manager.getRegistration(handle));
+ }
+
+ public void testRemoveInexistentRegistration() throws RegistrationException
+ {
+ try
+ {
+ manager.removeRegistration((Registration)null);
+ fail("Should be possible to remove a null registration");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ try
+ {
+ manager.removeRegistration((String)null);
+ fail("Should be possible to remove a registration with a null handle");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ try
+ {
+ manager.removeRegistration("");
+ fail("Should be possible to remove a registration with an empty handle");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ try
+ {
+ manager.removeRegistration("doesn't exist");
+ fail("Should be possible to remove a registration with an invalid handle");
+ }
+ catch (NoSuchRegistrationException expected)
+ {
+ }
+ }
+}
Property changes on: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/RegistrationManagerTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/RegistrationPersistenceManagerTestCase.java (from rev 5685, trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/RegistrationPersistenceManagerTestCase.java)
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/RegistrationPersistenceManagerTestCase.java 2006-11-20 15:42:02 UTC (rev 5685)
+++ trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/RegistrationPersistenceManagerTestCase.java 2006-11-21 07:07:20 UTC (rev 5698)
@@ -0,0 +1,331 @@
+/******************************************************************************
+ * 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.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 org.jboss.portal.wsrp.producer.registration.spi.ConsumerGroupSPI;
+import org.jboss.portal.wsrp.producer.registration.spi.ConsumerSPI;
+
+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
+{
+ private RegistrationPersistenceManager manager;
+ private Map registrationProperties;
+
+ public void setUp()
+ {
+ manager = new RegistrationPersistenceManagerImpl();
+ registrationProperties = new HashMap();
+ registrationProperties.put(new QName("prop1"), "value1");
+ registrationProperties.put(new QName("prop2"), "value2");
+ }
+
+ protected void tearDown() throws Exception
+ {
+ manager = null;
+ registrationProperties = null;
+ }
+
+ 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());
+ }
+
+ public void testAddRegistrationThrowsIAE() throws Exception
+ {
+ ConsumerGroup group = manager.createConsumerGroup("Foo");
+ Consumer consumer = manager.createConsumer("Bar", "Bar");
+ group.addConsumer(consumer);
+
+ try
+ {
+ manager.addRegistrationFor(consumer.getIdentity(), null);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ }
+
+ 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);
+
+ //
+ Collection registrations = consumer.getRegistrations();
+ assertNotNull(registrations);
+ assertEquals(0, registrations.size());
+
+ //
+ assertEquals(null, manager.getRegistration(regId));
+ }
+}
Property changes on: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/RegistrationPersistenceManagerTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/Consumer.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/Consumer.java 2006-11-21 07:00:09 UTC (rev 5697)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/Consumer.java 2006-11-21 07:07:20 UTC (rev 5698)
@@ -65,6 +65,12 @@
*/
Collection getRegistrations() throws RegistrationException;
+/*
+ Registration addRegistration(Map registrationProperties) throws RegistrationException;
+
+ void removeRegistration(Registration registration) throws RegistrationException;
+*/
+
/**
* Returns the group that this consumer belongs to.
*
@@ -84,4 +90,6 @@
ConsumerCapabilities getCapabilities();
void setCapabilities(ConsumerCapabilities capabilities);
+
+ void setGroup(ConsumerGroup group) throws RegistrationException, DuplicateRegistrationException;
}
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/ConsumerCapabilities.java
===================================================================
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/ConsumerGroup.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/ConsumerGroup.java 2006-11-21 07:00:09 UTC (rev 5697)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/ConsumerGroup.java 2006-11-21 07:07:20 UTC (rev 5698)
@@ -61,6 +61,12 @@
*/
Consumer getConsumer(String consumerIdentity) throws IllegalArgumentException, RegistrationException;
+ void addConsumer(Consumer consumer) throws RegistrationException;
+
+ void removeConsumer(Consumer consumer) throws RegistrationException;
+
+ boolean contains(Consumer consumer);
+
boolean isEmpty();
RegistrationStatus getStatus();
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/InvalidConsumerDataException.java
===================================================================
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/LocalizedString.java
===================================================================
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/ProducerRegistrationRequirements.java
===================================================================
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/Registration.java
===================================================================
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/RegistrationManager.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/RegistrationManager.java 2006-11-21 07:00:09 UTC (rev 5697)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/RegistrationManager.java 2006-11-21 07:07:20 UTC (rev 5698)
@@ -25,10 +25,10 @@
import EDU.oswego.cs.dl.util.concurrent.ConcurrentHashMap;
import org.jboss.portal.common.util.ParameterValidation;
-import org.jboss.portal.wsrp.producer.registration.spi.ConsumerGroupSPI;
-import org.jboss.portal.wsrp.producer.registration.spi.ConsumerSPI;
+import org.jboss.portal.wsrp.producer.registration.impl.ConsumerImpl;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
@@ -57,7 +57,9 @@
public void setPolicy(RegistrationPolicy policy)
{
+ ParameterValidation.throwIllegalArgExceptionIfNull(policy, "RegistrationPolicy");
this.policy = policy;
+ policy.setManager(this);
}
public RegistrationPersistenceManager getPersistenceManager()
@@ -104,7 +106,6 @@
String identity = policy.getConsumerIdentityFrom(name, Collections.EMPTY_MAP);
Consumer consumer = persistenceManager.createConsumer(identity, name);
- consumer.setStatus(RegistrationStatus.PENDING);
// deal with group if needed
// let the policy decide if there should be a group associated with the Consumer and if yes, with which id
@@ -119,18 +120,26 @@
public Consumer addConsumerToGroupNamed(String consumerName, String groupName, boolean createGroupIfNeeded, boolean createConsumerIfNeeded) throws RegistrationException
{
- // check with the policy if we allow the group
- policy.validateConsumerGroupName(groupName);
+ // check with the policy if we allow the group name in case we need to create it
+ if (createGroupIfNeeded)
+ {
+ policy.validateConsumerGroupName(groupName);
+ }
- // check with policy if we allow the consumer
- policy.validateConsumerName(consumerName);
+ // check with policy if we allow the consumer name in case we need to create it
+ if (createConsumerIfNeeded)
+ {
+ policy.validateConsumerName(consumerName);
+ }
- ConsumerGroupSPI group = (ConsumerGroupSPI)getConsumerGroup(groupName);
+ ConsumerGroup group = getConsumerGroup(groupName);
+ boolean justCreatedGroup = false;
if (group == null)
{
if (createGroupIfNeeded)
{
- group = (ConsumerGroupSPI)createConsumerGroup(groupName);
+ createConsumerGroup(groupName);
+ justCreatedGroup = true;
}
else
{
@@ -139,13 +148,19 @@
}
String identity = policy.getConsumerIdentityFrom(consumerName, Collections.EMPTY_MAP);
- ConsumerSPI consumer = getOrCreateConsumer(identity, createConsumerIfNeeded, consumerName);
+ try
+ {
+ getOrCreateConsumer(identity, createConsumerIfNeeded, consumerName);
+ }
+ catch (NoSuchRegistrationException e)
+ {
+ if (justCreatedGroup)
+ {
+ removeConsumerGroup(groupName);
+ }
+ }
- group.addConsumer(consumer);
- consumer.setGroup(group);
-
- persistenceManager.save(group);
- return persistenceManager.save(consumer);
+ return persistenceManager.addConsumerToGroupNamed(identity, groupName);
}
public ConsumerGroup createConsumerGroup(String groupName) throws RegistrationException
@@ -158,22 +173,13 @@
public void removeConsumer(String identity) throws RegistrationException, NoSuchRegistrationException
{
- ConsumerSPI consumer = getOrCreateConsumer(identity, false, null);
+ Consumer consumer = getOrCreateConsumer(identity, false, null);
- ConsumerGroupSPI group = (ConsumerGroupSPI)getConsumerGroup(consumer.getGroup().getName());
+ ConsumerGroup group = consumer.getGroup();
if (group != null)
{
group.removeConsumer(consumer);
-
- // if the group is now empty, destroy it
- if (group.isEmpty())
- {
- persistenceManager.removeConsumerGroup(group.getName());
- }
- else
- {
- persistenceManager.save(group);
- }
+ persistenceManager.save(group);
}
// cascade delete the registrations
@@ -223,7 +229,7 @@
{
ParameterValidation.throwIllegalArgExceptionIfNull(registration, "Registration");
String handle = registration.getRegistrationHandle();
- ConsumerSPI consumer = (ConsumerSPI)getConsumerFor(handle);
+ ConsumerImpl consumer = (ConsumerImpl)getConsumerFor(handle);
if (consumer == null)
{
@@ -231,9 +237,8 @@
+ "' (id: '" + registration.getId() + "')");
}
- consumer.removeRegistration(registration);
+ persistenceManager.removeRegistration(registration.getId());
registrations.remove(registration.getRegistrationHandle());
- persistenceManager.removeRegistration(registration.getId());
persistenceManager.save(consumer);
}
@@ -243,15 +248,15 @@
return persistenceManager.getConsumerGroup(groupName);
}
- private ConsumerSPI getOrCreateConsumer(String identity, boolean createConsumerIfNeeded, String consumerName)
+ private Consumer getOrCreateConsumer(String identity, boolean createConsumerIfNeeded, String consumerName)
throws RegistrationException
{
- ConsumerSPI consumer = (ConsumerSPI)getConsumerByIdentity(identity);
+ Consumer consumer = getConsumerByIdentity(identity);
if (consumer == null)
{
if (createConsumerIfNeeded)
{
- consumer = (ConsumerSPI)createConsumer(consumerName);
+ consumer = createConsumer(consumerName);
}
else
{
@@ -277,6 +282,34 @@
}
}
+ public Collection getConsumerGroups()
+ {
+ return persistenceManager.getConsumerGroups();
+ }
+
+ public void removeConsumerGroup(ConsumerGroup group) throws RegistrationException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(group, "ConsumerGroup");
+
+ for (Iterator consumers = group.getConsumers().iterator(); consumers.hasNext();)
+ {
+ removeConsumer((Consumer)consumers.next());
+ }
+
+ persistenceManager.removeConsumerGroup(group.getName());
+ }
+
+ public void removeConsumerGroup(String name) throws RegistrationException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(name, "ConsumerGroup name");
+ removeConsumerGroup(getConsumerGroup(name));
+ }
+
+ public Collection getConsumers()
+ {
+ return persistenceManager.getConsumers();
+ }
+
private static class ConsumerRegistration
{
private Registration registration;
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/RegistrationPersistenceManager.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/RegistrationPersistenceManager.java 2006-11-21 07:00:09 UTC (rev 5697)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/RegistrationPersistenceManager.java 2006-11-21 07:07:20 UTC (rev 5698)
@@ -80,4 +80,8 @@
Collection getConsumerGroups();
Registration getRegistration(String registrationId);
+
+ Consumer addConsumerToGroupNamed(String consumerIdentity, String groupName) throws RegistrationException;
+
+ Collection getConsumers();
}
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/RegistrationPolicy.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/RegistrationPolicy.java 2006-11-21 07:00:09 UTC (rev 5697)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/RegistrationPolicy.java 2006-11-21 07:07:20 UTC (rev 5698)
@@ -46,4 +46,8 @@
throws IllegalArgumentException, RegistrationException;
void validateConsumerGroupName(String groupName) throws IllegalArgumentException, RegistrationException;
+
+ RegistrationManager getManager();
+
+ void setManager(RegistrationManager manager);
}
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/RegistrationPropertyDescription.java
===================================================================
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-11-21 07:00:09 UTC (rev 5697)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/ConsumerGroupImpl.java 2006-11-21 07:07:20 UTC (rev 5698)
@@ -24,6 +24,7 @@
import org.jboss.portal.common.util.ParameterValidation;
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.RegistrationException;
@@ -38,17 +39,24 @@
/**
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
+ * @version $Revision:5672 $
*/
-public class ConsumerGroupImpl implements ConsumerGroupSPI
+public class ConsumerGroupImpl extends PersistentRegistrationObject implements ConsumerGroup
{
private String name;
private Map consumers;
private RegistrationStatus status;
- public ConsumerGroupImpl(String name)
+
+ public ConsumerGroupImpl()
{
+ this.consumers = new HashMap();
+ }
+
+ public ConsumerGroupImpl(String name, RegistrationPersistenceManagerImpl manager)
+ {
+ super(manager);
this.name = name;
this.consumers = new HashMap();
}
@@ -59,6 +67,27 @@
}
+ public boolean equals(Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
+
+ ConsumerGroupImpl that = (ConsumerGroupImpl)o;
+
+ return name.equals(that.name);
+ }
+
+ public int hashCode()
+ {
+ return name.hashCode();
+ }
+
public RegistrationStatus getStatus()
{
return status;
@@ -85,21 +114,38 @@
return consumers.isEmpty();
}
- public void addConsumer(ConsumerSPI consumer) throws DuplicateRegistrationException
+ public void addConsumer(Consumer consumer) throws RegistrationException
{
ParameterValidation.throwIllegalArgExceptionIfNull(consumer, "Consumer");
- if (consumers.containsKey(consumer.getName()))
+ String identity = consumer.getIdentity();
+ if (consumers.containsKey(identity))
{
- throw new DuplicateRegistrationException();
+ throw new DuplicateRegistrationException("ConsumerGroup named '" + name
+ + "' already contains a Consumer named '" + consumer.getName() + "' (identity: '" + identity + "')");
}
+
+ consumers.put(identity, consumer);
+ consumer.setGroup(this);
}
- public void removeConsumer(ConsumerSPI consumer) throws NoSuchRegistrationException
+ public void removeConsumer(Consumer consumer) throws RegistrationException
{
ParameterValidation.throwIllegalArgExceptionIfNull(consumer, "Consumer");
- if (consumers.remove(consumer.getName()) == null)
+
+ if (consumers.remove(consumer.getIdentity()) == null)
{
- throw new NoSuchRegistrationException();
+ throw new NoSuchRegistrationException("ConsumerGroup named '" + name
+ + "' does not contain a Consumer named '" + consumer.getName() + "' (identity: '" + consumer.getIdentity()
+ + "')");
}
+
+ consumer.setGroup(null);
}
+
+ public boolean contains(Consumer consumer)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(consumer, "Consumer");
+
+ return consumers.containsKey(consumer.getIdentity());
+ }
}
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/ConsumerImpl.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/ConsumerImpl.java 2006-11-21 07:00:09 UTC (rev 5697)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/ConsumerImpl.java 2006-11-21 07:07:20 UTC (rev 5698)
@@ -24,13 +24,12 @@
package org.jboss.portal.wsrp.producer.registration.impl;
import org.jboss.portal.common.util.ParameterValidation;
+import org.jboss.portal.wsrp.producer.registration.api.Consumer;
import org.jboss.portal.wsrp.producer.registration.api.ConsumerCapabilities;
import org.jboss.portal.wsrp.producer.registration.api.ConsumerGroup;
import org.jboss.portal.wsrp.producer.registration.api.Registration;
import org.jboss.portal.wsrp.producer.registration.api.RegistrationException;
import org.jboss.portal.wsrp.producer.registration.api.RegistrationStatus;
-import org.jboss.portal.wsrp.producer.registration.spi.ConsumerGroupSPI;
-import org.jboss.portal.wsrp.producer.registration.spi.ConsumerSPI;
import java.util.Collection;
import java.util.Collections;
@@ -42,7 +41,7 @@
* @version $Revision$
* @since 2.6
*/
-public class ConsumerImpl implements ConsumerSPI
+public class ConsumerImpl extends PersistentRegistrationObject implements Consumer
{
private String name;
@@ -52,14 +51,22 @@
private ConsumerGroup group;
private ConsumerCapabilities capabilities;
- public ConsumerImpl(String identity, String name)
+
+ private ConsumerImpl()
{
+ super();
+ }
+
+ ConsumerImpl(String identity, String name, RegistrationPersistenceManagerImpl manager)
+ {
+ super(manager);
+
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(name, "name", "Consumer");
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(name, "identity", "Consumer");
this.name = name;
this.identity = identity;
- registrations = new HashSet();
+ registrations = new HashSet(7);
}
public String getName()
@@ -103,18 +110,41 @@
return group;
}
- public void addRegistration(Registration registration)
+ void addRegistration(Registration registration)
{
+ ParameterValidation.throwIllegalArgExceptionIfNull(registration, "Registration");
+
registrations.add(registration);
}
- public void removeRegistration(Registration registration)
+ void removeRegistration(Registration registration) throws RegistrationException
{
- registrations.remove(registrations);
+ ParameterValidation.throwIllegalArgExceptionIfNull(registration, "Registration");
+
+ registrations.remove(registration);
}
- public void setGroup(ConsumerGroupSPI group)
+ public void setGroup(ConsumerGroup group) throws RegistrationException
{
+ if (this.group != null)
+ {
+ // if we're trying to set the same group, just return
+ if (this.group.equals(group))
+ {
+ return;
+ }
+
+ if (this.group.contains(this))
+ {
+ this.group.removeConsumer(this);
+ }
+ }
+
this.group = group;
+
+ if (group != null && !this.group.contains(this))
+ {
+ group.addConsumer(this);
+ }
}
}
Added: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/PersistentRegistrationObject.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/PersistentRegistrationObject.java 2006-11-21 07:00:09 UTC (rev 5697)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/PersistentRegistrationObject.java 2006-11-21 07:07:20 UTC (rev 5698)
@@ -0,0 +1,55 @@
+/******************************************************************************
+ * 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.wsrp.producer.registration.impl;
+
+/**
+ * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
+ * @version $Revision$
+ * @since 2.6
+ */
+public class PersistentRegistrationObject
+{
+ protected RegistrationPersistenceManagerImpl manager;
+
+
+ public PersistentRegistrationObject()
+ {
+ }
+
+ protected PersistentRegistrationObject(RegistrationPersistenceManagerImpl manager)
+ {
+ this.manager = manager;
+ }
+
+
+ public RegistrationPersistenceManagerImpl getManager()
+ {
+ return manager;
+ }
+
+ public void setManager(RegistrationPersistenceManagerImpl manager)
+ {
+ this.manager = manager;
+ }
+}
Property changes on: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/PersistentRegistrationObject.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/ProducerRegistrationRequirementsImpl.java
===================================================================
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/RegistrationImpl.java
===================================================================
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/RegistrationPersistenceManagerImpl.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/RegistrationPersistenceManagerImpl.java 2006-11-21 07:00:09 UTC (rev 5697)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/RegistrationPersistenceManagerImpl.java 2006-11-21 07:07:20 UTC (rev 5698)
@@ -26,6 +26,7 @@
import org.jboss.portal.common.util.ParameterValidation;
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.RegistrationException;
@@ -54,7 +55,8 @@
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(identity, "Consumer identity", null);
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(name, "Consumer name", null);
- ConsumerImpl consumer = new ConsumerImpl(identity, name);
+ ConsumerImpl consumer = new ConsumerImpl(identity, name, this);
+ consumer.setStatus(RegistrationStatus.PENDING);
consumers.put(identity, consumer);
return consumer;
@@ -62,48 +64,57 @@
public ConsumerGroup getConsumerGroup(String name) throws RegistrationException
{
- ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(name, "Group name", null);
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(name, "ConsumerGroup name", null);
return (ConsumerGroup)groups.get(name);
}
public ConsumerGroup createConsumerGroup(String name) throws RegistrationException
{
- ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(name, "Group name", null);
-
- ConsumerGroupImpl group = new ConsumerGroupImpl(name);
- groups.put(name, group);
-
- return group;
+ ConsumerGroup group = getConsumerGroup(name);
+ if (group != null)
+ {
+ throw new DuplicateRegistrationException("A ConsumerGroup named '" + name + "' has already been registered.");
+ }
+ else
+ {
+ group = new ConsumerGroupImpl(name, this);
+ groups.put(name, group);
+ return group;
+ }
}
public void removeConsumerGroup(String name) throws RegistrationException
{
- ConsumerGroup group = getConsumerGroup(name);
-
- if (group == null)
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(name, "ConsumerGroup name", null);
+ if (groups.remove(name) == null)
{
- throw new RegistrationException("There is no ConsumerGroup named '" + name + "'.");
+ throw new NoSuchRegistrationException("There is no ConsumerGroup named '" + name + "'.");
}
-
- groups.remove(name);
}
public void removeConsumer(String identity) throws RegistrationException
{
- Consumer consumer = getConsumerByIdentity(identity);
-
- if (consumer == null)
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(identity, "Consumer identity", null);
+ if (consumers.remove(identity) == null)
{
throw new RegistrationException("There is no Consumer with identity '" + identity + "'.");
}
-
- consumers.remove(identity);
}
public void removeRegistration(String id) throws RegistrationException
{
- //To change body of implemented methods use File | Settings | File Templates.
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(id, "Registration identity", null);
+
+ RegistrationImpl registration = (RegistrationImpl)registrations.get(id);
+ if (registration == null)
+ {
+ throw new NoSuchRegistrationException("There is no Registration with id '" + id + "'");
+ }
+
+ ConsumerImpl consumer = (ConsumerImpl)registration.getConsumer();
+ consumer.removeRegistration(registration);
+ registrations.remove(id);
}
public Consumer getConsumerByIdentity(String identity) throws RegistrationException
@@ -122,7 +133,7 @@
if (consumer == null)
{
throw new NoSuchRegistrationException("There is no Consumer with identity '" + consumerIdentity
- + "' to a Registration to...");
+ + "' to add a Registration to...");
}
RegistrationImpl registration = new RegistrationImpl("" + lastRegistrationId++, consumer,
@@ -131,22 +142,59 @@
registrations.put(registration.getId(), registration);
+ // is this needed?
+ save(registration);
+ save(consumer);
+
return registration;
}
+ public Consumer addConsumerToGroupNamed(String consumerIdentity, String groupName) throws RegistrationException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(consumerIdentity, "Consumer identity", null);
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(groupName, "ConsumerGroup name", null);
+
+ ConsumerGroupImpl group = (ConsumerGroupImpl)getConsumerGroup(groupName);
+ if (group == null)
+ {
+ throw new NoSuchRegistrationException("There is no ConsumerGroup named '" + groupName
+ + "' to add a Consumer to...");
+ }
+
+ ConsumerImpl consumer = (ConsumerImpl)getConsumerByIdentity(consumerIdentity);
+ if (consumer == null)
+ {
+ throw new NoSuchRegistrationException("There is no Consumer with identity '" + consumerIdentity
+ + "' to add to ConsumerGroup named '" + groupName + "'. Did you create it?");
+ }
+
+ group.addConsumer(consumer);
+
+ // is this needed?
+ save(group);
+ save(consumer);
+
+ return consumer;
+ }
+
+ public Collection getConsumers()
+ {
+ return Collections.unmodifiableCollection(consumers.values());
+ }
+
public ConsumerGroup save(ConsumerGroup group)
{
- return null; //todo: implement
+ return group; //todo: implement
}
public Registration save(Registration registration)
{
- return null; //todo: implement
+ return registration; //todo: implement
}
public Consumer save(Consumer consumer)
{
- return null; //todo: implement
+ return consumer; //todo: implement
}
public Collection getConsumerGroups()
@@ -156,6 +204,8 @@
public Registration getRegistration(String registrationId)
{
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(registrationId, "Registration id", null);
+
return (Registration)registrations.get(registrationId);
}
}
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/policies/DefaultRegistrationPolicy.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/policies/DefaultRegistrationPolicy.java 2006-11-21 07:00:09 UTC (rev 5697)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/policies/DefaultRegistrationPolicy.java 2006-11-21 07:07:20 UTC (rev 5698)
@@ -26,7 +26,6 @@
import org.jboss.portal.common.util.ParameterValidation;
import org.jboss.portal.jems.as.system.AbstractJBossService;
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.InvalidConsumerDataException;
import org.jboss.portal.wsrp.producer.registration.api.Registration;
@@ -128,12 +127,6 @@
/** Rejects name if a ConsumerGroup with the specified name already exists. */
public void validateConsumerGroupName(String groupName) throws IllegalArgumentException, RegistrationException
{
- ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(groupName, "ConsumerGroup name", null);
-
- ConsumerGroup group = manager.getConsumerGroup(groupName);
- if (group != null)
- {
- throw new DuplicateRegistrationException("A ConsumerGroup named '" + groupName + "' has already been registered.");
- }
+ // this is already the behavior in the RegistrationPersistenceManager so no need to do anything
}
}
More information about the jboss-svn-commits
mailing list