Author: chris.laprun(a)jboss.com
Date: 2006-11-27 16:33:14 -0500 (Mon, 27 Nov 2006)
New Revision: 5727
Added:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/RegistrationTestCase.java
Modified:
trunk/wsrp/build.xml
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/RegistrationImpl.java
Log:
- Fixed a problem with Registration where the given registration properties where
"live" (i.e. it was possible to modify outside of the registration).
- Added RegistrationTestCase to cover Registration.
- Added ConsumerGroupTestCase and RegistrationTestCase to test suite.
Modified: trunk/wsrp/build.xml
===================================================================
--- trunk/wsrp/build.xml 2006-11-27 20:33:29 UTC (rev 5726)
+++ trunk/wsrp/build.xml 2006-11-27 21:33:14 UTC (rev 5727)
@@ -700,7 +700,9 @@
<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.ConsumerGroupTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.wsrp.registration.RegistrationManagerTestCase"/>
+ <test todir="${test.reports}"
name="org.jboss.portal.test.wsrp.registration.RegistrationTestCase"/>
</x-test>
<x-sysproperty>
<!--<jvmarg value="-Xdebug"/>
Added:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/RegistrationTestCase.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/RegistrationTestCase.java 2006-11-27
20:33:29 UTC (rev 5726)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/RegistrationTestCase.java 2006-11-27
21:33:14 UTC (rev 5727)
@@ -0,0 +1,132 @@
+/******************************************************************************
+ * 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.DuplicateRegistrationException;
+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.RegistrationManagerImpl;
+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$
+ * @since 2.6
+ */
+public class RegistrationTestCase extends TestCase
+{
+ private Registration registration;
+ private Map registrationProperties;
+
+ protected void setUp() throws Exception
+ {
+ RegistrationManager manager = new RegistrationManagerImpl();
+ RegistrationPolicy policy = new DefaultRegistrationPolicy()
+ {
+ public void validateRegistrationDataFor(Map registrationProperties, String
consumerIdentity) throws IllegalArgumentException, RegistrationException,
DuplicateRegistrationException
+ {
+ // accept any registration data here
+ }
+ };
+ manager.setPolicy(policy);
+ manager.setPersistenceManager(new RegistrationPersistenceManagerImpl());
+ policy.setManager(manager);
+
+ registrationProperties = new HashMap();
+ registrationProperties.put(new QName("prop1"), "value1");
+ registrationProperties.put(new QName("prop2"), "value2");
+
+ registration = manager.addRegistrationTo("name", registrationProperties,
true);
+ }
+
+ public void testGetPropertiesIsUnmodifiable()
+ {
+ Map properties = registration.getProperties();
+
+ try
+ {
+ properties.remove("foo");
+ fail("Properties shouldn't be directly modifiable");
+ }
+ catch (Exception expected)
+ {
+ }
+ }
+
+ public void testPropertiesAreClonedNotLive()
+ {
+ QName prop = new QName("prop3");
+ registrationProperties.put(prop, "value3");
+
+ assertNull(registration.getProperties().get(prop));
+ }
+
+ public void testSetNullPropertyValueThrowsIAE()
+ {
+ try
+ {
+ registration.setPropertyValueFor("foo", null);
+ fail("Shouldn't accept null values for properties");
+ }
+ catch (Exception expected)
+ {
+ }
+ }
+
+ public void testSetNullPropertyNameThrowsIAE()
+ {
+ try
+ {
+ registration.setPropertyValueFor((QName)null, null);
+ fail("Shouldn't accept null names for properties");
+ }
+ catch (Exception expected)
+ {
+ }
+ }
+
+ public void testHasEqualProperties()
+ {
+ assertTrue(registration.hasEqualProperties(registration));
+
+ assertTrue(registration.hasEqualProperties(registrationProperties));
+
+ registrationProperties.put(new QName("prop3"), "value3");
+ assertTrue(!registration.hasEqualProperties(registrationProperties));
+ }
+
+ public void testClearAssociatedState()
+ {
+ //todo: implement
+ }
+
+}
Modified:
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/RegistrationImpl.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/RegistrationImpl.java 2006-11-27
20:33:29 UTC (rev 5726)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/RegistrationImpl.java 2006-11-27
21:33:14 UTC (rev 5727)
@@ -30,6 +30,7 @@
import javax.xml.namespace.QName;
import java.util.Collections;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -53,7 +54,7 @@
this.id = id;
this.consumer = consumer;
this.status = status;
- this.properties = properties;
+ this.properties = new HashMap(properties);
}
public String getId()