Author: chris.laprun(a)jboss.com
Date: 2006-11-27 16:36:52 -0500 (Mon, 27 Nov 2006)
New Revision: 5728
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/RegistrationManagerTestCase.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/ConsumerImpl.java
Log:
- Added more tests to cover removal of Registrations.
- Consumer now become pending when they don't own any registrations.
Modified:
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-27
21:33:14 UTC (rev 5727)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/RegistrationManagerTestCase.java 2006-11-27
21:36:52 UTC (rev 5728)
@@ -32,6 +32,7 @@
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.api.RegistrationStatus;
import org.jboss.portal.wsrp.producer.registration.impl.RegistrationManagerImpl;
import
org.jboss.portal.wsrp.producer.registration.impl.RegistrationPersistenceManagerImpl;
import org.jboss.portal.wsrp.producer.registration.policies.DefaultRegistrationPolicy;
@@ -55,10 +56,13 @@
protected void setUp() throws Exception
{
manager = new RegistrationManagerImpl();
+ // todo: policy will need access to registration configuration information to
validate properties
RegistrationPolicy policy = new DefaultRegistrationPolicy();
manager.setPolicy(policy);
manager.setPersistenceManager(new RegistrationPersistenceManagerImpl());
policy.setManager(manager);
+
+ //todo: registration properties setup will need to be updated when property
validation is implemented
registrationProperties = new HashMap();
registrationProperties.put(new QName("prop1"), "value1");
registrationProperties.put(new QName("prop2"), "value2");
@@ -315,7 +319,7 @@
assertNull(manager.getRegistration(handle));
}
- public void testRemoveRegistration() throws Exception
+ public void testRemoveSingleRegistration() throws Exception
{
String consumerName = "consumer";
Consumer consumer = manager.createConsumer(consumerName);
@@ -325,11 +329,51 @@
assertTrue(consumer.getRegistrations().contains(reg));
+ // set the consumer status to valid
+ consumer.setStatus(RegistrationStatus.VALID);
+
manager.removeRegistration(handle);
assertTrue(!consumer.getRegistrations().contains(reg));
assertNull(manager.getRegistration(handle));
+
+ // since the consumer doesn't have any registration anymore, its status should
become pending
+ assertEquals(RegistrationStatus.PENDING, consumer.getStatus());
+
+ // shouldn't be possible anymore to retrieve the consumer from the registration
handle
+ assertNull(manager.getConsumerFor(handle));
}
+ public void testRemoveRegistrationOnConsumerWithOtherRegistrations() throws Exception
+ {
+ String consumerName = "consumer";
+ Consumer consumer = manager.createConsumer(consumerName);
+
+ Registration reg = manager.addRegistrationTo(consumerName, registrationProperties,
false);
+ String handle = reg.getRegistrationHandle();
+
+ // todo: this won't work anymore when properties validation is implemented
+ registrationProperties.put(new QName("prop3"), "value3");
+ Registration r2 = manager.addRegistrationTo(consumerName, registrationProperties,
false);
+
+ RegistrationStatus status = consumer.getStatus();
+
+ manager.removeRegistration(handle);
+
+ // consumer status shouldn't have changed
+ assertEquals(status, consumer.getStatus());
+
+ // should still be able to retrieve consumer from r2 handle
+ assertEquals(consumer, manager.getConsumerFor(r2.getRegistrationHandle()));
+
+ // ... but not from handle
+ assertNull(manager.getConsumerFor(handle));
+ }
+
+ public void testAddRegistrationWithInvalidRegistrationProperties() throws Exception
+ {
+ // todo: implement
+ }
+
public void testRemoveInexistentRegistration() throws RegistrationException
{
try
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-27
21:33:14 UTC (rev 5727)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/ConsumerImpl.java 2006-11-27
21:36:52 UTC (rev 5728)
@@ -170,6 +170,12 @@
ParameterValidation.throwIllegalArgExceptionIfNull(registration,
"Registration");
registrations.remove(registration);
+
+ // status should become pending if there are no registrations
+ if (registrations.isEmpty())
+ {
+ setStatus(RegistrationStatus.PENDING);
+ }
}
public void setGroup(ConsumerGroup group) throws RegistrationException