Author: chris.laprun(a)jboss.com
Date: 2007-11-28 21:18:00 -0500 (Wed, 28 Nov 2007)
New Revision: 9177
Added:
branches/JBoss_Portal_Branch_2_6/registration/src/main/org/jboss/portal/registration/PropertyDescription.java
branches/JBoss_Portal_Branch_2_6/registration/src/main/org/jboss/portal/test/registration/DefaultRegistrationPolicyTestCase.java
Modified:
branches/JBoss_Portal_Branch_2_6/registration/build.xml
branches/JBoss_Portal_Branch_2_6/registration/src/main/org/jboss/portal/registration/RegistrationPolicy.java
branches/JBoss_Portal_Branch_2_6/registration/src/main/org/jboss/portal/registration/RegistrationPropertyChangeListener.java
branches/JBoss_Portal_Branch_2_6/registration/src/main/org/jboss/portal/registration/impl/RegistrationManagerImpl.java
branches/JBoss_Portal_Branch_2_6/registration/src/main/org/jboss/portal/registration/policies/DefaultRegistrationPolicy.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/config/TestRegistrationPolicy.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/config/impl/ProducerRegistrationRequirementsImpl.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/registration/RegistrationPropertyDescription.java
Log:
- JBPORTAL-1821:
+ Allow RegistrationPolicy to be aware of producer expectations to decide on
registration data.
+ Properly implement validateRegistrationDataFor to correctly analyze input
registration.
+ Updated RegistrationPropertyChangeListener to pass new registration property
descriptions.
+ Introduced PropertyDescription interface to access registration property information
in registration module.
+ Added DefaultRegistrationPolicyTestCase.
Modified: branches/JBoss_Portal_Branch_2_6/registration/build.xml
===================================================================
--- branches/JBoss_Portal_Branch_2_6/registration/build.xml 2007-11-29 00:52:01 UTC (rev
9176)
+++ branches/JBoss_Portal_Branch_2_6/registration/build.xml 2007-11-29 02:18:00 UTC (rev
9177)
@@ -150,7 +150,7 @@
</jar>
<jar jarfile="${build.lib}/portal-registration-test-lib.jar">
- <fileset dir="${build.classes}"
includes="org/jboss/portal/test/registration/**"/>
+ <fileset dir="${build.classes}"
includes="org/jboss/portal/test/registration/**"/>
</jar>
</target>
@@ -193,6 +193,7 @@
<test todir="${test.reports}"
name="org.jboss.portal.test.registration.ConsumerGroupTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.registration.RegistrationManagerTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.registration.RegistrationTestCase"/>
+ <test todir="${test.reports}"
name="org.jboss.portal.test.registration.DefaultRegistrationPolicyTestCase"/>
</x-test>
<x-sysproperty>
<!--<jvmarg value="-Xdebug"/>
@@ -225,7 +226,7 @@
<delete file="tests.log"/>
<delete file="output.log"/>
</target>
-
+
<target name="tests" depends="clean-test">
<antcall target="registration-test"/>
</target>
Added:
branches/JBoss_Portal_Branch_2_6/registration/src/main/org/jboss/portal/registration/PropertyDescription.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/registration/src/main/org/jboss/portal/registration/PropertyDescription.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_6/registration/src/main/org/jboss/portal/registration/PropertyDescription.java 2007-11-29
02:18:00 UTC (rev 9177)
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2007, Your Corporation. All Rights Reserved.
+ */
+
+package org.jboss.portal.registration;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ * @since 2.6.3
+ */
+public interface PropertyDescription
+{
+ QName getName();
+
+ QName getType();
+}
Property changes on:
branches/JBoss_Portal_Branch_2_6/registration/src/main/org/jboss/portal/registration/PropertyDescription.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified:
branches/JBoss_Portal_Branch_2_6/registration/src/main/org/jboss/portal/registration/RegistrationPolicy.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/registration/src/main/org/jboss/portal/registration/RegistrationPolicy.java 2007-11-29
00:52:01 UTC (rev 9176)
+++
branches/JBoss_Portal_Branch_2_6/registration/src/main/org/jboss/portal/registration/RegistrationPolicy.java 2007-11-29
02:18:00 UTC (rev 9177)
@@ -23,6 +23,7 @@
package org.jboss.portal.registration;
+import javax.xml.namespace.QName;
import java.util.Map;
/**
@@ -127,4 +128,13 @@
* @param manager the RegistrationManager with which this RegistrationPolicy should be
associated.
*/
void setManager(RegistrationManager manager);
+
+ /**
+ * Define what the expectations are as far as acceptable registration properties go.
+ *
+ * @param registrationPropertyDescriptions
+ * a map of containing the description of expected registrations
+ * @since 2.6.3
+ */
+ void setExpectations(Map<QName, ? extends PropertyDescription>
registrationPropertyDescriptions);
}
Modified:
branches/JBoss_Portal_Branch_2_6/registration/src/main/org/jboss/portal/registration/RegistrationPropertyChangeListener.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/registration/src/main/org/jboss/portal/registration/RegistrationPropertyChangeListener.java 2007-11-29
00:52:01 UTC (rev 9176)
+++
branches/JBoss_Portal_Branch_2_6/registration/src/main/org/jboss/portal/registration/RegistrationPropertyChangeListener.java 2007-11-29
02:18:00 UTC (rev 9177)
@@ -23,6 +23,9 @@
package org.jboss.portal.registration;
+import javax.xml.namespace.QName;
+import java.util.Map;
+
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
* @version $Revision$
@@ -30,5 +33,5 @@
*/
public interface RegistrationPropertyChangeListener
{
- void propertiesHaveChanged();
+ void propertiesHaveChanged(Map<QName, ? extends PropertyDescription>
newRegistrationProperties);
}
Modified:
branches/JBoss_Portal_Branch_2_6/registration/src/main/org/jboss/portal/registration/impl/RegistrationManagerImpl.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/registration/src/main/org/jboss/portal/registration/impl/RegistrationManagerImpl.java 2007-11-29
00:52:01 UTC (rev 9176)
+++
branches/JBoss_Portal_Branch_2_6/registration/src/main/org/jboss/portal/registration/impl/RegistrationManagerImpl.java 2007-11-29
02:18:00 UTC (rev 9177)
@@ -30,6 +30,7 @@
import org.jboss.portal.registration.ConsumerGroup;
import org.jboss.portal.registration.InvalidConsumerDataException;
import org.jboss.portal.registration.NoSuchRegistrationException;
+import org.jboss.portal.registration.PropertyDescription;
import org.jboss.portal.registration.Registration;
import org.jboss.portal.registration.RegistrationException;
import org.jboss.portal.registration.RegistrationManager;
@@ -37,6 +38,7 @@
import org.jboss.portal.registration.RegistrationPolicy;
import org.jboss.portal.registration.RegistrationStatus;
+import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -323,18 +325,24 @@
* We listen to registration property changes on the producer configuration so that we
can invalidate the current
* registrations. Consumers will need to call modifyRegistration since properties have
changed... which requires
* throwing an OperationFailedFault... not an InvalidRegistrationFault!
+ *
+ * @param registrationProperties
*/
- public void propertiesHaveChanged()
+ public void propertiesHaveChanged(Map<QName, ? extends PropertyDescription>
registrationProperties)
{
log.debug("Registration properties have changed, existing registrations will
be invalidated...");
- for (Iterator regs = persistenceManager.getRegistrations().iterator();
regs.hasNext();)
+ Collection registrations = persistenceManager.getRegistrations();
+ for (Object registration : registrations)
{
- Registration reg = (Registration)regs.next();
+ Registration reg = (Registration)registration;
// pending instead of invalid as technically, the registration is not yet
invalid
reg.setStatus(RegistrationStatus.PENDING);
// reg.clearAssociatedState(); //todo: do we need to clear the associated state?
If we do, should we wait until current operations are done?
}
+
+ // make policy aware of new registration properties
+ policy.setExpectations(registrationProperties);
}
/**
Modified:
branches/JBoss_Portal_Branch_2_6/registration/src/main/org/jboss/portal/registration/policies/DefaultRegistrationPolicy.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/registration/src/main/org/jboss/portal/registration/policies/DefaultRegistrationPolicy.java 2007-11-29
00:52:01 UTC (rev 9176)
+++
branches/JBoss_Portal_Branch_2_6/registration/src/main/org/jboss/portal/registration/policies/DefaultRegistrationPolicy.java 2007-11-29
02:18:00 UTC (rev 9177)
@@ -28,6 +28,7 @@
import org.jboss.portal.registration.Consumer;
import org.jboss.portal.registration.DuplicateRegistrationException;
import org.jboss.portal.registration.InvalidConsumerDataException;
+import org.jboss.portal.registration.PropertyDescription;
import org.jboss.portal.registration.Registration;
import org.jboss.portal.registration.RegistrationException;
import org.jboss.portal.registration.RegistrationManager;
@@ -35,8 +36,9 @@
import javax.xml.namespace.QName;
import java.util.Collections;
-import java.util.Iterator;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
/**
* Provides a default implementation of RegistrationPolicy which should be enough for
most user needs provided the
@@ -50,6 +52,7 @@
{
private RegistrationManager manager;
private RegistrationPropertyValidator validator;
+ private Map<QName, ? extends PropertyDescription> expectations;
public RegistrationManager getManager()
@@ -62,6 +65,11 @@
this.manager = manager;
}
+ public void setExpectations(Map<QName, ? extends PropertyDescription>
registrationPropertyDescriptions)
+ {
+ this.expectations = registrationPropertyDescriptions;
+ }
+
/**
* Only accepts the registration if no registration with identical values exists for
the Consumer identified by the
* specified identify and delegates the validation of properties to the configured
RegistrationPropertyValidator.
@@ -75,14 +83,59 @@
ParameterValidation.throwIllegalArgExceptionIfNull(registrationProperties,
"Registration properties");
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(consumerIdentity,
"Consumer identity", null);
+ StringBuilder message = new StringBuilder();
+
+ // check that values are consistent with expectations
+ if (expectations != null)
+ {
+ Set<QName> expectedNames = expectations.keySet();
+ boolean consistentWithExpectations = true;
+
+ // check for extra properties
+ Set<QName> unexpected = new
HashSet<QName>(registrationProperties.keySet());
+ unexpected.removeAll(expectedNames);
+ if (!unexpected.isEmpty())
+ {
+ consistentWithExpectations = false;
+ message.append("Consumer '").append(consumerIdentity)
+ .append("' provided values for unexpected registration
properties:\n");
+ for (QName name : unexpected)
+ {
+ message.append("\t- ").append(name).append("\n");
+ }
+ }
+
+ for (Map.Entry<QName, ? extends PropertyDescription> entry :
expectations.entrySet())
+ {
+ QName name = entry.getKey();
+ Object value = registrationProperties.get(name);
+ try
+ {
+ validator.validateValueFor(name, value);
+ }
+ catch (IllegalArgumentException e)
+ {
+ message.append("Missing value for expected
'").append(name.getLocalPart()).append("' property.\n");
+ consistentWithExpectations = false;
+ }
+ }
+
+ if (!consistentWithExpectations)
+ {
+ log.debug(message);
+ throw new InvalidConsumerDataException(message.toString());
+ }
+ }
+
+ // check that this is not a duplicate registration
Consumer consumer = manager.getConsumerByIdentity(consumerIdentity);
if (consumer != null)
{
// allow the new registration only if the registration properties are different
that existing registrations
// for this consumer...
- for (Iterator iterator = consumer.getRegistrations().iterator();
iterator.hasNext();)
+ for (Object o : consumer.getRegistrations())
{
- Registration registration = (Registration)iterator.next();
+ Registration registration = (Registration)o;
if (registration.hasEqualProperties(registrationProperties))
{
throw new DuplicateRegistrationException("Consumer named '"
+ consumer.getName()
@@ -90,12 +143,9 @@
}
}
}
-
- // check that values are consistent with ProducerRegistrationRequirement
- for (Iterator properties = registrationProperties.entrySet().iterator();
properties.hasNext();)
+ else
{
- Map.Entry property = (Map.Entry)properties.next();
- validator.validateValueFor((QName)property.getKey(), property.getValue());
+ throw new RegistrationException("'" + consumerIdentity +
"' is not a valid Consumer");
}
}
Added:
branches/JBoss_Portal_Branch_2_6/registration/src/main/org/jboss/portal/test/registration/DefaultRegistrationPolicyTestCase.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/registration/src/main/org/jboss/portal/test/registration/DefaultRegistrationPolicyTestCase.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_6/registration/src/main/org/jboss/portal/test/registration/DefaultRegistrationPolicyTestCase.java 2007-11-29
02:18:00 UTC (rev 9177)
@@ -0,0 +1,164 @@
+/*
+ * Copyright (c) 2007, Your Corporation. All Rights Reserved.
+ */
+
+package org.jboss.portal.test.registration;
+
+import junit.framework.TestCase;
+import org.jboss.portal.registration.PropertyDescription;
+import org.jboss.portal.registration.RegistrationException;
+import org.jboss.portal.registration.RegistrationManager;
+import org.jboss.portal.registration.impl.RegistrationManagerImpl;
+import org.jboss.portal.registration.impl.RegistrationPersistenceManagerImpl;
+import org.jboss.portal.registration.policies.DefaultRegistrationPolicy;
+import org.jboss.portal.registration.policies.DefaultRegistrationPropertyValidator;
+
+import javax.xml.namespace.QName;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ * @since 2.6.3
+ */
+public class DefaultRegistrationPolicyTestCase extends TestCase
+{
+ DefaultRegistrationPolicy policy;
+ Map registrationProperties;
+ HashMap<QName, PropertyDescription> expectations;
+ private static final String CONSUMER = "consumer";
+ private static final QName PROP1 = new QName("prop1");
+ private static final QName PROP2 = new QName("prop2");
+ private static final QName PROP3 = new QName("prop3");
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ policy = new DefaultRegistrationPolicy();
+
+ policy.setValidator(new DefaultRegistrationPropertyValidator());
+
+ RegistrationManager manager = new RegistrationManagerImpl();
+ manager.setPolicy(policy);
+ manager.setPersistenceManager(new RegistrationPersistenceManagerImpl());
+ manager.createConsumer(CONSUMER);
+
+ policy.setManager(manager);
+
+ registrationProperties = new HashMap();
+ registrationProperties.put(PROP1, "value1");
+ registrationProperties.put(PROP2, "value2");
+
+ expectations = new HashMap<QName, PropertyDescription>();
+ policy.setExpectations(expectations);
+ }
+
+ public void testValidateRegistrationDataForNull() throws RegistrationException
+ {
+ try
+ {
+ policy.validateRegistrationDataFor(null, "foo");
+ fail("null data cannot be validated");
+ }
+ catch (IllegalArgumentException e)
+ {
+ // expected
+ }
+
+ try
+ {
+ policy.validateRegistrationDataFor(Collections.EMPTY_MAP, null);
+ fail("null data cannot be validated");
+ }
+ catch (IllegalArgumentException e)
+ {
+ // expected
+ }
+ }
+
+ public void testValidateRegistrationDataForInexistentConsumer()
+ {
+ try
+ {
+ policy.validateRegistrationDataFor(Collections.EMPTY_MAP, "foo");
+ fail("shouldn't validate data for inexistent consumer");
+ }
+ catch (RegistrationException e)
+ {
+ // expected
+ }
+ }
+
+ public void testValidateRegistrationDataMissingProps()
+ {
+ expectations.put(PROP1, new TestPropertyDescription(PROP1));
+ expectations.put(PROP2, new TestPropertyDescription(PROP2));
+ expectations.put(PROP3, new TestPropertyDescription(PROP3));
+
+ try
+ {
+ policy.validateRegistrationDataFor(registrationProperties, CONSUMER);
+ fail("Missing prop3 should have been detected");
+ }
+ catch (RegistrationException e)
+ {
+ assertTrue(e.getLocalizedMessage().contains("prop3"));
+ }
+ }
+
+ public void testValidateRegistrationDataExtraProps()
+ {
+ expectations.put(PROP1, new TestPropertyDescription(PROP1));
+
+ try
+ {
+ policy.validateRegistrationDataFor(registrationProperties, CONSUMER);
+ fail("Extra prop2 should have been detected");
+ }
+ catch (RegistrationException e)
+ {
+ assertTrue(e.getLocalizedMessage().contains("prop2"));
+ }
+ }
+
+ public void testValidateRegistrationDataInvalidValue()
+ {
+ expectations.put(PROP1, new TestPropertyDescription(PROP1));
+
+ registrationProperties.remove(PROP2);
+ registrationProperties.put(PROP1, null);
+
+ try
+ {
+ policy.validateRegistrationDataFor(registrationProperties, CONSUMER);
+ fail("Should have detected null value for prop1");
+ }
+ catch (RegistrationException e)
+ {
+ assertTrue(e.getLocalizedMessage().contains("prop1"));
+ }
+ }
+
+ static class TestPropertyDescription implements PropertyDescription
+ {
+ private QName name;
+ private static final QName TYPE = new QName("type");
+
+ TestPropertyDescription(QName name)
+ {
+ this.name = name;
+ }
+
+ public QName getName()
+ {
+ return name;
+ }
+
+ public QName getType()
+ {
+ return TYPE;
+ }
+ }
+}
Property changes on:
branches/JBoss_Portal_Branch_2_6/registration/src/main/org/jboss/portal/test/registration/DefaultRegistrationPolicyTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/config/TestRegistrationPolicy.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/config/TestRegistrationPolicy.java 2007-11-29
00:52:01 UTC (rev 9176)
+++
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/config/TestRegistrationPolicy.java 2007-11-29
02:18:00 UTC (rev 9177)
@@ -24,10 +24,12 @@
package org.jboss.portal.test.wsrp.config;
import org.jboss.portal.registration.InvalidConsumerDataException;
+import org.jboss.portal.registration.PropertyDescription;
import org.jboss.portal.registration.RegistrationException;
import org.jboss.portal.registration.RegistrationManager;
import org.jboss.portal.registration.RegistrationPolicy;
+import javax.xml.namespace.QName;
import java.util.Map;
/**
@@ -72,4 +74,8 @@
public void setManager(RegistrationManager manager)
{
}
+
+ public void setExpectations(Map<QName, ? extends PropertyDescription>
registrationPropertyDescriptions)
+ {
+ }
}
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/config/impl/ProducerRegistrationRequirementsImpl.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/config/impl/ProducerRegistrationRequirementsImpl.java 2007-11-29
00:52:01 UTC (rev 9176)
+++
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/config/impl/ProducerRegistrationRequirementsImpl.java 2007-11-29
02:18:00 UTC (rev 9177)
@@ -177,7 +177,7 @@
{
for (RegistrationPropertyChangeListener listener : propertyChangeListeners)
{
- listener.propertiesHaveChanged();
+ listener.propertiesHaveChanged(registrationProperties);
}
}
@@ -241,6 +241,8 @@
DefaultRegistrationPolicy registrationPolicy =
(DefaultRegistrationPolicy)policy;
validatorClassName = registrationPolicy.getValidator().getClass().getName();
}
+
+ this.policy.setExpectations(registrationProperties);
}
notifyRegistrationPolicyChangeListeners();
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/registration/RegistrationPropertyDescription.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/registration/RegistrationPropertyDescription.java 2007-11-29
00:52:01 UTC (rev 9176)
+++
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/registration/RegistrationPropertyDescription.java 2007-11-29
02:18:00 UTC (rev 9177)
@@ -24,6 +24,7 @@
package org.jboss.portal.wsrp.registration;
import org.jboss.portal.common.util.ParameterValidation;
+import org.jboss.portal.registration.PropertyDescription;
import org.jboss.portal.wsrp.producer.config.ProducerRegistrationRequirements;
import javax.xml.namespace.QName;
@@ -37,7 +38,7 @@
* @version $Revision:5865 $
* @since 2.6
*/
-public class RegistrationPropertyDescription implements Cloneable
+public class RegistrationPropertyDescription implements Cloneable, PropertyDescription
{
private Long key;
private QName name;