Author: chris.laprun(a)jboss.com
Date: 2006-11-21 13:05:04 -0500 (Tue, 21 Nov 2006)
New Revision: 5704
Added:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/ConsumerGroupTestCase.java
Removed:
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/PersistentRegistrationObject.java
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/ConsumerTestCase.java
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/RegistrationPersistenceManagerTestCase.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/RegistrationManager.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/RegistrationPersistenceManagerImpl.java
Log:
- Removed unused PersistentRegistrationObject.
- Added ConsumerGroupTestCase.
- Cleaned up code.
Added:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/ConsumerGroupTestCase.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/ConsumerGroupTestCase.java 2006-11-21
17:38:29 UTC (rev 5703)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/ConsumerGroupTestCase.java 2006-11-21
18:05:04 UTC (rev 5704)
@@ -0,0 +1,116 @@
+/******************************************************************************
+ * 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.RegistrationException;
+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;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ * @since 2.6
+ */
+public class ConsumerGroupTestCase extends TestCase
+{
+ private RegistrationManager manager;
+ private ConsumerGroup group;
+ private static final String NAME = "name";
+
+
+ protected void setUp() throws Exception
+ {
+ manager = new RegistrationManager();
+ manager.setPolicy(new DefaultRegistrationPolicy());
+ manager.setPersistenceManager(new RegistrationPersistenceManagerImpl());
+ group = manager.createConsumerGroup(NAME);
+ }
+
+ public void testGetName()
+ {
+ assertEquals(NAME, group.getName());
+ }
+
+ public void testConsumersManagement() throws RegistrationException
+ {
+ assertTrue(group.isEmpty());
+ assertEquals(0, group.getConsumers().size());
+
+ Consumer c1 = manager.createConsumer("c1");
+ group.addConsumer(c1);
+ assertTrue(!group.isEmpty());
+ assertEquals(1, group.getConsumers().size());
+ assertTrue(group.contains(c1));
+ assertEquals(group, c1.getGroup());
+ assertEquals(c1, group.getConsumer(c1.getIdentity()));
+
+ Consumer c2 = manager.createConsumer("c2");
+ group.addConsumer(c2);
+ assertEquals(2, group.getConsumers().size());
+ assertTrue(group.contains(c2));
+ assertEquals(group, c2.getGroup());
+
+ group.removeConsumer(c1);
+ assertEquals(1, group.getConsumers().size());
+ assertTrue(!group.contains(c1));
+ assertTrue(group.contains(c2));
+ assertEquals(null, c1.getGroup());
+ }
+
+ public void testAddNullConsumer() throws RegistrationException
+ {
+ try
+ {
+ group.addConsumer(null);
+ fail("Shouldn't be possible to add null consumer");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ }
+
+ public void testStatus()
+ {
+ assertEquals(RegistrationStatus.PENDING, group.getStatus());
+ group.setStatus(RegistrationStatus.VALID);
+ assertEquals(RegistrationStatus.VALID, group.getStatus());
+ }
+
+ public void testIllegalStatus()
+ {
+ try
+ {
+ group.setStatus(null);
+ fail("Shouldn't be possible to set the status to null");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ }
+}
Modified:
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
17:38:29 UTC (rev 5703)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/ConsumerTestCase.java 2006-11-21
18:05:04 UTC (rev 5704)
@@ -31,10 +31,6 @@
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@jboss.com">Chris
Laprun</a>
* @version $Revision$
@@ -44,7 +40,6 @@
{
private Consumer consumer;
private RegistrationManager manager;
- private Map registrationProperties;
protected void setUp() throws Exception
{
@@ -52,9 +47,6 @@
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()
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-11-21
17:38:29 UTC (rev 5703)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/RegistrationPersistenceManagerTestCase.java 2006-11-21
18:05:04 UTC (rev 5704)
@@ -318,7 +318,9 @@
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());
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
17:38:29 UTC (rev 5703)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/RegistrationManager.java 2006-11-21
18:05:04 UTC (rev 5704)
@@ -25,7 +25,6 @@
import EDU.oswego.cs.dl.util.concurrent.ConcurrentHashMap;
import org.jboss.portal.common.util.ParameterValidation;
-import org.jboss.portal.wsrp.producer.registration.impl.ConsumerImpl;
import java.util.ArrayList;
import java.util.Collection;
@@ -226,7 +225,7 @@
{
ParameterValidation.throwIllegalArgExceptionIfNull(registration,
"Registration");
String handle = registration.getRegistrationHandle();
- ConsumerImpl consumer = (ConsumerImpl)getConsumerFor(handle);
+ Consumer consumer = getConsumerFor(handle);
if (consumer == null)
{
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
17:38:29 UTC (rev 5703)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/ConsumerGroupImpl.java 2006-11-21
18:05:04 UTC (rev 5704)
@@ -39,7 +39,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision:5672 $
*/
-public class ConsumerGroupImpl extends PersistentRegistrationObject implements
ConsumerGroup
+public class ConsumerGroupImpl implements ConsumerGroup
{
private String name;
@@ -47,16 +47,21 @@
private RegistrationStatus status;
- public ConsumerGroupImpl()
+ private ConsumerGroupImpl()
{
- this.consumers = new HashMap();
+ init();
}
- public ConsumerGroupImpl(String name, RegistrationPersistenceManagerImpl manager)
+ ConsumerGroupImpl(String name)
{
- super(manager);
this.name = name;
+ init();
+ }
+
+ private void init()
+ {
this.consumers = new HashMap();
+ status = RegistrationStatus.PENDING;
}
public String getName()
@@ -93,6 +98,7 @@
public void setStatus(RegistrationStatus status)
{
+ ParameterValidation.throwIllegalArgExceptionIfNull(status,
"RegistrationStatus");
this.status = status;
}
@@ -101,10 +107,10 @@
return Collections.unmodifiableCollection(consumers.values());
}
- public Consumer getConsumer(String consumerName) throws IllegalArgumentException,
RegistrationException
+ public Consumer getConsumer(String consumerIdentity) throws IllegalArgumentException,
RegistrationException
{
- ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(consumerName,
"Consumer name", null);
- return (Consumer)consumers.get(consumerName);
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(consumerIdentity,
"Consumer name", null);
+ return (Consumer)consumers.get(consumerIdentity);
}
public boolean isEmpty()
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
17:38:29 UTC (rev 5703)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/ConsumerImpl.java 2006-11-21
18:05:04 UTC (rev 5704)
@@ -41,7 +41,7 @@
* @version $Revision$
* @since 2.6
*/
-public class ConsumerImpl extends PersistentRegistrationObject implements Consumer
+public class ConsumerImpl implements Consumer
{
private String name;
@@ -54,21 +54,47 @@
private ConsumerImpl()
{
- super();
+ init();
}
- ConsumerImpl(String identity, String name, RegistrationPersistenceManagerImpl
manager)
+ ConsumerImpl(String identity, String name)
{
- super(manager);
-
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(name, "name",
"Consumer");
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(name,
"identity", "Consumer");
this.name = name;
this.identity = identity;
+ init();
+ }
+
+ private void init()
+ {
registrations = new HashSet(7);
+ status = RegistrationStatus.PENDING;
}
+
+ public boolean equals(Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
+
+ ConsumerImpl consumer = (ConsumerImpl)o;
+
+ return identity.equals(consumer.identity);
+ }
+
+ public int hashCode()
+ {
+ return identity.hashCode();
+ }
+
public String getName()
{
return name;
Deleted:
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
17:38:29 UTC (rev 5703)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/PersistentRegistrationObject.java 2006-11-21
18:05:04 UTC (rev 5704)
@@ -1,55 +0,0 @@
-/******************************************************************************
- * 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@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;
- }
-}
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
17:38:29 UTC (rev 5703)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/RegistrationPersistenceManagerImpl.java 2006-11-21
18:05:04 UTC (rev 5704)
@@ -55,7 +55,7 @@
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(identity, "Consumer
identity", null);
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(name, "Consumer
name", null);
- ConsumerImpl consumer = new ConsumerImpl(identity, name, this);
+ ConsumerImpl consumer = new ConsumerImpl(identity, name);
consumer.setStatus(RegistrationStatus.PENDING);
consumers.put(identity, consumer);
@@ -78,7 +78,7 @@
}
else
{
- group = new ConsumerGroupImpl(name, this);
+ group = new ConsumerGroupImpl(name);
groups.put(name, group);
return group;
}