Author: chris.laprun(a)jboss.com
Date: 2011-02-02 16:59:34 -0500 (Wed, 02 Feb 2011)
New Revision: 5849
Added:
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/policies/
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/policies/DefaultRegistrationPolicyTestCase.java
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/policies/RegistrationPolicyWrapperTestCase.java
Removed:
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/DefaultRegistrationPolicyTestCase.java
Modified:
components/wsrp/trunk/admin-gui/src/main/java/org/gatein/wsrp/admin/ui/ProducerBean.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/config/mapping/RegistrationRequirementsMapping.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationPolicy.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/policies/DefaultRegistrationPolicy.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/policies/DefaultRegistrationPropertyValidator.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/policies/RegistrationPolicyWrapper.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/ProducerRegistrationRequirements.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/impl/ProducerRegistrationRequirementsImpl.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/impl/xml/ProducerConfigurationProvider.java
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/ProducerConfigurationTestCase.java
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/ProducerRegistrationRequirementsTestCase.java
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/TestRegistrationPolicy.java
Log:
- GTNWSRP-198: Fixed improper persistence of custom RegistrationPolicy implementations.
Made clearer the fact that RegistrationPolicy instances are wrapped using a
RegistrationPolicyWrapper.
Modified:
components/wsrp/trunk/admin-gui/src/main/java/org/gatein/wsrp/admin/ui/ProducerBean.java
===================================================================
---
components/wsrp/trunk/admin-gui/src/main/java/org/gatein/wsrp/admin/ui/ProducerBean.java 2011-02-02
20:31:12 UTC (rev 5848)
+++
components/wsrp/trunk/admin-gui/src/main/java/org/gatein/wsrp/admin/ui/ProducerBean.java 2011-02-02
21:59:34 UTC (rev 5849)
@@ -1,6 +1,6 @@
/*
* JBoss, a division of Red Hat
- * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * Copyright 2011, 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.
@@ -25,6 +25,7 @@
import org.gatein.registration.RegistrationPolicy;
import org.gatein.registration.policies.DefaultRegistrationPolicy;
+import org.gatein.registration.policies.RegistrationPolicyWrapper;
import org.gatein.wsrp.producer.config.ProducerConfiguration;
import org.gatein.wsrp.producer.config.ProducerConfigurationService;
import org.gatein.wsrp.producer.config.ProducerRegistrationRequirements;
@@ -95,7 +96,7 @@
RegistrationPolicy policy = getRegRequirements().getPolicy();
if (policy != null)
{
- return policy.getClass().getName();
+ return policy.getClassName();
}
else
{
@@ -117,7 +118,8 @@
{
if (isDefaultRegistrationPolicy())
{
- return
((DefaultRegistrationPolicy)getRegRequirements().getPolicy()).getValidator().getClass().getName();
+ DefaultRegistrationPolicy policy =
(DefaultRegistrationPolicy)RegistrationPolicyWrapper.unwrap(getRegRequirements().getPolicy());
+ return policy.getValidator().getClass().getName();
}
throw new IllegalStateException("getValidatorClassName shouldn't be called
if we're not using the default registration");
}
@@ -163,14 +165,15 @@
registrationRequirements.setRegistrationRequiredForFullDescription(configuration.isRegistrationRequiredForFullDescription());
registrationRequirements.setRegistrationRequired(configuration.isRegistrationRequired());
- if
(!ProducerRegistrationRequirements.DEFAULT_POLICY_CLASS_NAME.equals(policyClassName))
- {
- registrationRequirements.reloadPolicyFrom(policyClassName,
validatorClassName);
- }
+ registrationRequirements.reloadPolicyFrom(policyClassName, validatorClassName);
registrationRequirements.setRegistrationProperties(configuration.getRegistrationRequirements().getRegistrationProperties());
getConfigurationService().saveConfiguration();
+
+ // force a reload local state
+ registrationConfiguration = null;
+
beanContext.createInfoMessage("bean_producer_save_success");
}
catch (Exception e)
Modified:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/config/mapping/RegistrationRequirementsMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/config/mapping/RegistrationRequirementsMapping.java 2011-02-02
20:31:12 UTC (rev 5848)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/config/mapping/RegistrationRequirementsMapping.java 2011-02-02
21:59:34 UTC (rev 5849)
@@ -30,6 +30,7 @@
import org.chromattic.api.annotations.Property;
import org.gatein.registration.RegistrationPolicy;
import org.gatein.registration.policies.DefaultRegistrationPolicy;
+import org.gatein.registration.policies.RegistrationPolicyWrapper;
import org.gatein.wsrp.producer.config.ProducerRegistrationRequirements;
import org.gatein.wsrp.producer.config.impl.ProducerRegistrationRequirementsImpl;
import org.gatein.wsrp.registration.RegistrationPropertyDescription;
@@ -80,10 +81,12 @@
setRegistrationRequired(registrationRequirements.isRegistrationRequired());
setRegistrationRequiredForFullDescription(registrationRequirements.isRegistrationRequiredForFullDescription());
RegistrationPolicy policy = registrationRequirements.getPolicy();
- setPolicyClassName(policy.getClass().getName());
- if (policy instanceof DefaultRegistrationPolicy)
+ setPolicyClassName(policy.getClassName());
+
+ RegistrationPolicy unwrap = RegistrationPolicyWrapper.unwrap(policy);
+ if (unwrap instanceof DefaultRegistrationPolicy)
{
- DefaultRegistrationPolicy drp = (DefaultRegistrationPolicy)policy;
+ DefaultRegistrationPolicy drp = (DefaultRegistrationPolicy)unwrap;
setValidatorClassName(drp.getValidator().getClass().getName());
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationPolicy.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationPolicy.java 2011-02-02
20:31:12 UTC (rev 5848)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationPolicy.java 2011-02-02
21:59:34 UTC (rev 5849)
@@ -33,6 +33,13 @@
* An interface allowing users of the Registration service to customize different aspects
of how Consumers are handled.
* Methods of this interface are used by RegistrationManager to make appropriate
decisions. Implementations of this
* interface <strong>MUST</strong> provide a no-argument constructor for
instantiation from the class name.
+ * <p/>
+ * <strong>IMPORTANT</strong>: RegistrationPolicy instances are wrapped using
a {@link
+ * org.gatein.registration.policies.RegistrationPolicyWrapper}. As a result, using
<code>instanceof</code> on a
+ * RegistrationPolicy will probably result in unexpected result. To retrieve the actual
class of the RegistrationPolicy
+ * instance in use, use {@link #getRealClass()} (or {@link #getClassName()} to retrieve
the class name). If, for some
+ * reason, the actual RegistrationPolicy instance is needed, use {@link
org.gatein.registration.policies.RegistrationPolicyWrapper#unwrap(RegistrationPolicy)},
+ * though it is not recommended to manipulate actual RegistrationPolicy instances
directly.
*
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
* @version $Revision: 11406 $
@@ -122,5 +129,34 @@
*/
void validateConsumerGroupName(String groupName, RegistrationManager manager) throws
IllegalArgumentException, RegistrationException;
+ /**
+ * TODO
+ *
+ * @param portletContext
+ * @param registration
+ * @param operation
+ * @return
+ */
boolean allowAccessTo(PortletContext portletContext, Registration registration, String
operation);
+
+ /**
+ * TODO
+ *
+ * @return
+ */
+ boolean isWrapped();
+
+ /**
+ * TODO
+ *
+ * @return
+ */
+ String getClassName();
+
+ /**
+ * TODO
+ *
+ * @return
+ */
+ Class<? extends RegistrationPolicy> getRealClass();
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/policies/DefaultRegistrationPolicy.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/policies/DefaultRegistrationPolicy.java 2011-02-02
20:31:12 UTC (rev 5848)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/policies/DefaultRegistrationPolicy.java 2011-02-02
21:59:34 UTC (rev 5849)
@@ -56,6 +56,11 @@
private RegistrationPropertyValidator validator;
private static final Logger log =
LoggerFactory.getLogger(DefaultRegistrationPolicy.class);
+ public DefaultRegistrationPolicy()
+ {
+ validator = DefaultRegistrationPropertyValidator.DEFAULT;
+ }
+
@Override
public boolean equals(Object o)
{
@@ -163,28 +168,24 @@
/** Simply returns the given registration id. */
public String createRegistrationHandleFor(String registrationId)
{
- ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(registrationId,
"Registration id", null);
return registrationId;
}
/** Doesn't support automatic ConsumerGroups so always return
<code>null</code>. */
public String getAutomaticGroupNameFor(String consumerName)
{
- ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(consumerName,
"Consumer name", null);
return null;
}
/** Compute a simple, safe id based on the provided consumer name trusted (!) to be
unique. */
public String getConsumerIdFrom(String consumerName, Map<QName, Object>
registrationProperties) throws IllegalArgumentException, InvalidConsumerDataException
{
- return RegistrationPolicyWrapper.sanitizeConsumerName(consumerName);
+ return consumerName;
}
/** Rejects registration if a Consumer with the specified name already exists. */
public void validateConsumerName(String consumerName, final RegistrationManager
manager) throws IllegalArgumentException, RegistrationException
{
- ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(consumerName,
"Consumer name", null);
-
Consumer consumer = manager.getConsumerByIdentity(getConsumerIdFrom(consumerName,
Collections.<QName, Object>emptyMap()));
if (consumer != null)
{
@@ -203,6 +204,21 @@
return true;
}
+ public boolean isWrapped()
+ {
+ return false;
+ }
+
+ public String getClassName()
+ {
+ return getClass().getName();
+ }
+
+ public Class<? extends RegistrationPolicy> getRealClass()
+ {
+ return getClass();
+ }
+
/**
* Instructs this policy to use the specified RegistrationPropertyValidator. There
shouldn't be any need to call this
* method manually, as the validator is configured via the WSRP Producer xml
configuration file.
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/policies/DefaultRegistrationPropertyValidator.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/policies/DefaultRegistrationPropertyValidator.java 2011-02-02
20:31:12 UTC (rev 5848)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/policies/DefaultRegistrationPropertyValidator.java 2011-02-02
21:59:34 UTC (rev 5849)
@@ -1,6 +1,6 @@
/*
* JBoss, a division of Red Hat
- * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * Copyright 2011, 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.
@@ -41,4 +41,6 @@
"'. DefaultRegistrationPropertyValidator only accepts non-null,
non-empty Strings.");
}
}
+
+ public static final RegistrationPropertyValidator DEFAULT = new
DefaultRegistrationPropertyValidator();
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/policies/RegistrationPolicyWrapper.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/policies/RegistrationPolicyWrapper.java 2011-02-02
20:31:12 UTC (rev 5848)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/policies/RegistrationPolicyWrapper.java 2011-02-02
21:59:34 UTC (rev 5849)
@@ -43,13 +43,40 @@
{
private final RegistrationPolicy delegate;
- public RegistrationPolicyWrapper(RegistrationPolicy delegate)
+ public static RegistrationPolicy wrap(RegistrationPolicy policy)
{
- ParameterValidation.throwIllegalArgExceptionIfNull(delegate,
"Delegate");
+ ParameterValidation.throwIllegalArgExceptionIfNull(policy, "RegistrationPolicy
to wrap");
+
+ if (!policy.isWrapped())
+ {
+ return new RegistrationPolicyWrapper(policy);
+ }
+ else
+ {
+ return policy;
+ }
+ }
+
+ public static RegistrationPolicy unwrap(RegistrationPolicy policy)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(policy, "RegistrationPolicy
to unwrap");
+
+ if (policy.isWrapped())
+ {
+ return ((RegistrationPolicyWrapper)policy).getDelegate();
+ }
+ else
+ {
+ return policy;
+ }
+ }
+
+ private RegistrationPolicyWrapper(RegistrationPolicy delegate)
+ {
this.delegate = delegate;
}
- public RegistrationPolicy getDelegate()
+ private RegistrationPolicy getDelegate()
{
return delegate;
}
@@ -63,13 +90,14 @@
public String createRegistrationHandleFor(String registrationId)
throws IllegalArgumentException
{
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(registrationId,
"Registration id", null);
return delegate.createRegistrationHandleFor(registrationId);
}
public String getAutomaticGroupNameFor(String consumerName)
throws IllegalArgumentException
{
- return delegate.getAutomaticGroupNameFor(consumerName);
+ return delegate.getAutomaticGroupNameFor(sanitizeConsumerName(consumerName));
}
public String getConsumerIdFrom(String consumerName, Map<QName, Object>
registrationProperties)
@@ -81,7 +109,7 @@
public void validateConsumerName(String consumerName, final RegistrationManager
manager)
throws IllegalArgumentException, RegistrationException
{
- delegate.validateConsumerName(consumerName, manager);
+ delegate.validateConsumerName(sanitizeConsumerName(consumerName), manager);
}
public void validateConsumerGroupName(String groupName, RegistrationManager manager)
@@ -90,6 +118,26 @@
delegate.validateConsumerGroupName(groupName, manager);
}
+ public boolean allowAccessTo(PortletContext portletContext, Registration registration,
String operation)
+ {
+ return delegate.allowAccessTo(portletContext, registration, operation);
+ }
+
+ public boolean isWrapped()
+ {
+ return true;
+ }
+
+ public String getClassName()
+ {
+ return delegate.getClassName();
+ }
+
+ public Class<? extends RegistrationPolicy> getRealClass()
+ {
+ return delegate.getClass();
+ }
+
static String sanitizeConsumerName(String consumerName)
{
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(consumerName,
"Consumer name", null);
@@ -100,9 +148,4 @@
return consumerName;
}
-
- public boolean allowAccessTo(PortletContext portletContext, Registration registration,
String operation)
- {
- return delegate.allowAccessTo(portletContext, registration, operation);
- }
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/ProducerRegistrationRequirements.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/ProducerRegistrationRequirements.java 2011-02-02
20:31:12 UTC (rev 5848)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/ProducerRegistrationRequirements.java 2011-02-02
21:59:34 UTC (rev 5849)
@@ -1,6 +1,6 @@
/*
* JBoss, a division of Red Hat
- * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * Copyright 2011, 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.
@@ -118,4 +118,6 @@
long getLastModified();
void setRegistrationProperties(Map<QName, RegistrationPropertyDescription>
registrationProperties);
+
+ String getPolicyClassName();
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/impl/ProducerRegistrationRequirementsImpl.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/impl/ProducerRegistrationRequirementsImpl.java 2011-02-02
20:31:12 UTC (rev 5848)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/impl/ProducerRegistrationRequirementsImpl.java 2011-02-02
21:59:34 UTC (rev 5849)
@@ -326,18 +326,25 @@
{
if (ParameterValidation.isOldAndNewDifferent(this.policy, policy))
{
- this.policy = policy;
-
if (policy != null)
{
- policyClassName = policy.getClass().getName();
+ this.policy = RegistrationPolicyWrapper.wrap(policy);
+ policyClassName = policy.getClassName();
- if (policy instanceof DefaultRegistrationPolicy)
+ if (DEFAULT_POLICY_CLASS_NAME.equals(policyClassName))
{
- DefaultRegistrationPolicy registrationPolicy =
(DefaultRegistrationPolicy)policy;
+ DefaultRegistrationPolicy registrationPolicy =
(DefaultRegistrationPolicy)RegistrationPolicyWrapper.unwrap(policy);
validatorClassName =
registrationPolicy.getValidator().getClass().getName();
}
+ else
+ {
+ validatorClassName = null;
+ }
}
+ else
+ {
+ this.policy = null;
+ }
modifyNow();
notifyRegistrationPolicyChangeListeners();
@@ -375,10 +382,7 @@
}
RegistrationPolicy policy =
(RegistrationPolicy)policyClass.newInstance();
- // wrap policy so that we can perform minimal sanitization of values
- RegistrationPolicyWrapper wrapper = new
RegistrationPolicyWrapper(policy);
-
- setPolicy(wrapper);
+ setPolicy(policy);
}
catch (ClassNotFoundException e)
{
@@ -422,9 +426,9 @@
}
- DefaultRegistrationPolicy policy = new DefaultRegistrationPolicy();
- policy.setValidator(validator);
- setPolicy(policy);
+ DefaultRegistrationPolicy delegate = new DefaultRegistrationPolicy();
+ delegate.setValidator(validator);
+ setPolicy(delegate);
}
}
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/impl/xml/ProducerConfigurationProvider.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/impl/xml/ProducerConfigurationProvider.java 2011-02-02
20:31:12 UTC (rev 5848)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/config/impl/xml/ProducerConfigurationProvider.java 2011-02-02
21:59:34 UTC (rev 5849)
@@ -1,6 +1,6 @@
/*
* JBoss, a division of Red Hat
- * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * Copyright 2011, 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.
@@ -25,6 +25,7 @@
import org.gatein.registration.RegistrationPolicy;
import org.gatein.registration.policies.DefaultRegistrationPolicy;
+import org.gatein.registration.policies.RegistrationPolicyWrapper;
import org.gatein.wsrp.WSRPUtils;
import org.gatein.wsrp.producer.config.ProducerRegistrationRequirements;
import org.gatein.wsrp.producer.config.impl.ProducerConfigurationImpl;
@@ -104,12 +105,12 @@
RegistrationPolicy policy = regReq.getPolicy();
if (policy != null)
{
- value = policy.getClass().getName();
+ value = policy.getClassName();
}
}
else if ("registration-property-validator".equals(localName))
{
- RegistrationPolicy policy = regReq.getPolicy();
+ RegistrationPolicy policy =
RegistrationPolicyWrapper.unwrap(regReq.getPolicy());
if (policy instanceof DefaultRegistrationPolicy)
{
DefaultRegistrationPolicy defaultRegistrationPolicy =
(DefaultRegistrationPolicy)policy;
Deleted:
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/DefaultRegistrationPolicyTestCase.java
===================================================================
---
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/DefaultRegistrationPolicyTestCase.java 2011-02-02
20:31:12 UTC (rev 5848)
+++
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/DefaultRegistrationPolicyTestCase.java 2011-02-02
21:59:34 UTC (rev 5849)
@@ -1,183 +0,0 @@
-/*
- * JBoss, a division of Red Hat
- * Copyright 2010, 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.gatein.registration;
-
-import junit.framework.TestCase;
-import org.gatein.registration.impl.RegistrationManagerImpl;
-import org.gatein.registration.impl.RegistrationPersistenceManagerImpl;
-import org.gatein.registration.policies.DefaultRegistrationPolicy;
-import org.gatein.registration.policies.DefaultRegistrationPropertyValidator;
-import org.gatein.wsrp.registration.PropertyDescription;
-
-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: 9180 $
- * @since 2.6.3
- */
-public class DefaultRegistrationPolicyTestCase extends TestCase
-{
- DefaultRegistrationPolicy policy;
- Map<QName, Object> registrationProperties;
- Map<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");
- private RegistrationManager manager;
-
- @Override
- protected void setUp() throws Exception
- {
- policy = new DefaultRegistrationPolicy();
-
- policy.setValidator(new DefaultRegistrationPropertyValidator());
-
- manager = new RegistrationManagerImpl();
- manager.setPolicy(policy);
- manager.setPersistenceManager(new RegistrationPersistenceManagerImpl());
- manager.createConsumer(CONSUMER);
-
- registrationProperties = new HashMap<QName, Object>();
- registrationProperties.put(PROP1, "value1");
- registrationProperties.put(PROP2, "value2");
-
- expectations = new HashMap<QName, PropertyDescription>();
- }
-
- public void testValidateRegistrationDataForNull() throws RegistrationException
- {
- try
- {
- policy.validateRegistrationDataFor(null, "foo", expectations,
manager);
- fail("null data cannot be validated");
- }
- catch (IllegalArgumentException e)
- {
- // expected
- }
-
- try
- {
- policy.validateRegistrationDataFor(Collections.<QName, Object>emptyMap(),
null, expectations, manager);
- fail("null data cannot be validated");
- }
- catch (IllegalArgumentException e)
- {
- // expected
- }
- }
-
- public void testValidateRegistrationDataForInexistentConsumer()
- {
- try
- {
- policy.validateRegistrationDataFor(Collections.<QName, Object>emptyMap(),
"foo", expectations, manager);
- }
- catch (RegistrationException e)
- {
- fail("Should be possible to validate information for inexistent consumer
(otherwise, how would we register!)");
- }
- }
-
- 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,
expectations, manager);
- 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,
expectations, manager);
- 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,
expectations, manager);
- 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;
- }
-
- public int compareTo(PropertyDescription o)
- {
- return name.toString().compareTo(o.getName().toString());
- }
- }
-}
Copied:
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/policies/DefaultRegistrationPolicyTestCase.java
(from rev 5829,
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/DefaultRegistrationPolicyTestCase.java)
===================================================================
---
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/policies/DefaultRegistrationPolicyTestCase.java
(rev 0)
+++
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/policies/DefaultRegistrationPolicyTestCase.java 2011-02-02
21:59:34 UTC (rev 5849)
@@ -0,0 +1,189 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2011, 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.gatein.registration.policies;
+
+import junit.framework.TestCase;
+import org.gatein.registration.RegistrationException;
+import org.gatein.registration.RegistrationManager;
+import org.gatein.registration.impl.RegistrationManagerImpl;
+import org.gatein.registration.impl.RegistrationPersistenceManagerImpl;
+import org.gatein.wsrp.registration.PropertyDescription;
+
+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: 9180 $
+ * @since 2.6.3
+ */
+public class DefaultRegistrationPolicyTestCase extends TestCase
+{
+ DefaultRegistrationPolicy policy;
+ Map<QName, Object> registrationProperties;
+ Map<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");
+ private RegistrationManager manager;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ policy = new DefaultRegistrationPolicy();
+
+ policy.setValidator(new DefaultRegistrationPropertyValidator());
+
+ manager = new RegistrationManagerImpl();
+ manager.setPolicy(policy);
+ manager.setPersistenceManager(new RegistrationPersistenceManagerImpl());
+ manager.createConsumer(CONSUMER);
+
+ registrationProperties = new HashMap<QName, Object>();
+ registrationProperties.put(PROP1, "value1");
+ registrationProperties.put(PROP2, "value2");
+
+ expectations = new HashMap<QName, PropertyDescription>();
+ }
+
+ public void testInitialState()
+ {
+ DefaultRegistrationPolicy registrationPolicy = new DefaultRegistrationPolicy();
+ assertEquals(DefaultRegistrationPropertyValidator.DEFAULT,
registrationPolicy.getValidator());
+ }
+
+ public void testValidateRegistrationDataForNull() throws RegistrationException
+ {
+ try
+ {
+ policy.validateRegistrationDataFor(null, "foo", expectations,
manager);
+ fail("null data cannot be validated");
+ }
+ catch (IllegalArgumentException e)
+ {
+ // expected
+ }
+
+ try
+ {
+ policy.validateRegistrationDataFor(Collections.<QName, Object>emptyMap(),
null, expectations, manager);
+ fail("null data cannot be validated");
+ }
+ catch (IllegalArgumentException e)
+ {
+ // expected
+ }
+ }
+
+ public void testValidateRegistrationDataForInexistentConsumer()
+ {
+ try
+ {
+ policy.validateRegistrationDataFor(Collections.<QName, Object>emptyMap(),
"foo", expectations, manager);
+ }
+ catch (RegistrationException e)
+ {
+ fail("Should be possible to validate information for inexistent consumer
(otherwise, how would we register!)");
+ }
+ }
+
+ 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,
expectations, manager);
+ 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,
expectations, manager);
+ 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,
expectations, manager);
+ 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;
+ }
+
+ public int compareTo(PropertyDescription o)
+ {
+ return name.toString().compareTo(o.getName().toString());
+ }
+ }
+}
Property changes on:
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/policies/DefaultRegistrationPolicyTestCase.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/policies/RegistrationPolicyWrapperTestCase.java
===================================================================
---
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/policies/RegistrationPolicyWrapperTestCase.java
(rev 0)
+++
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/policies/RegistrationPolicyWrapperTestCase.java 2011-02-02
21:59:34 UTC (rev 5849)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2011, 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.gatein.registration.policies;
+
+import junit.framework.TestCase;
+import org.gatein.registration.RegistrationPolicy;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class RegistrationPolicyWrapperTestCase extends TestCase
+{
+ public void testWrap()
+ {
+ RegistrationPolicy policy = new DefaultRegistrationPolicy();
+
+ RegistrationPolicy wrapper = RegistrationPolicyWrapper.wrap(policy);
+ assertEquals(policy.getClass(), wrapper.getRealClass());
+ assertEquals(policy.getClassName(), wrapper.getClassName());
+ assertEquals(policy.getClass().getName(), wrapper.getClassName());
+
+ assertEquals(wrapper, RegistrationPolicyWrapper.wrap(wrapper));
+ assertTrue(wrapper instanceof RegistrationPolicyWrapper);
+
+ assertEquals(policy, RegistrationPolicyWrapper.unwrap(wrapper));
+ assertEquals(policy, RegistrationPolicyWrapper.unwrap(policy));
+ }
+}
Modified:
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/ProducerConfigurationTestCase.java
===================================================================
---
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/ProducerConfigurationTestCase.java 2011-02-02
20:31:12 UTC (rev 5848)
+++
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/ProducerConfigurationTestCase.java 2011-02-02
21:59:34 UTC (rev 5849)
@@ -1,6 +1,6 @@
/*
* JBoss, a division of Red Hat
- * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * Copyright 2011, 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.
@@ -96,11 +96,13 @@
RegistrationPolicy policy = requirements.getPolicy();
// check that the policy is properly wrapped
- assertTrue(policy instanceof RegistrationPolicyWrapper);
+ assertTrue(policy.isWrapped());
+ // policy is wrapped so instanceof won't work!
+ assertFalse(policy instanceof TestRegistrationPolicy);
+
// and that the delegate is indeed the expected policy
- RegistrationPolicyWrapper wrapper = (RegistrationPolicyWrapper)policy;
- assertTrue(wrapper.getDelegate() instanceof TestRegistrationPolicy);
+ assertEquals(TestRegistrationPolicy.class,
RegistrationPolicyWrapper.unwrap(policy).getClass());
}
public void testExtendedUnmarshalling() throws Exception
@@ -110,7 +112,7 @@
ProducerRegistrationRequirements requirements =
producerConfiguration.getRegistrationRequirements();
assertNotNull(requirements);
- RegistrationPolicy policy = requirements.getPolicy();
+ RegistrationPolicy policy =
RegistrationPolicyWrapper.unwrap(requirements.getPolicy());
assertTrue(policy instanceof DefaultRegistrationPolicy);
RegistrationPropertyValidator propertyValidator =
((DefaultRegistrationPolicy)policy).getValidator();
assertNotNull(propertyValidator);
Modified:
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/ProducerRegistrationRequirementsTestCase.java
===================================================================
---
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/ProducerRegistrationRequirementsTestCase.java 2011-02-02
20:31:12 UTC (rev 5848)
+++
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/ProducerRegistrationRequirementsTestCase.java 2011-02-02
21:59:34 UTC (rev 5849)
@@ -28,7 +28,6 @@
import org.gatein.registration.RegistrationPolicyChangeListener;
import org.gatein.registration.RegistrationPropertyChangeListener;
import org.gatein.registration.policies.DefaultRegistrationPolicy;
-import org.gatein.registration.policies.RegistrationPolicyWrapper;
import org.gatein.wsrp.WSRPConstants;
import org.gatein.wsrp.producer.config.impl.ProducerRegistrationRequirementsImpl;
import org.gatein.wsrp.registration.PropertyDescription;
@@ -72,16 +71,22 @@
public void testChangeRegistrationPolicy()
{
- ProducerRegistrationRequirements requirements = new
ProducerRegistrationRequirementsImpl();
+ ProducerRegistrationRequirementsImpl requirements = new
ProducerRegistrationRequirementsImpl();
requirements.setRegistrationRequired(true); // so that we load the policy
- assertTrue(requirements.getPolicy() instanceof DefaultRegistrationPolicy);
+ RegistrationPolicy policy = requirements.getPolicy();
+ assertTrue(policy.isWrapped());
+ assertFalse(policy instanceof DefaultRegistrationPolicy); // cannot use instanceof
since policy is wrapped
+ assertEquals(ProducerRegistrationRequirements.DEFAULT_POLICY_CLASS_NAME,
policy.getClassName());
+
requirements.reloadPolicyFrom("org.gatein.wsrp.producer.config.TestRegistrationPolicy",
ProducerRegistrationRequirements.DEFAULT_VALIDATOR_CLASS_NAME);
- RegistrationPolicy policy = requirements.getPolicy();
- assertTrue(policy instanceof RegistrationPolicyWrapper);
- RegistrationPolicyWrapper wrapper = (RegistrationPolicyWrapper)policy;
- assertTrue(wrapper.getDelegate() instanceof TestRegistrationPolicy);
+ policy = requirements.getPolicy();
+ assertTrue(policy.isWrapped());
+ assertFalse(policy instanceof TestRegistrationPolicy); // cannot use instanceof
since policy is wrapped
+ assertEquals("org.gatein.wsrp.producer.config.TestRegistrationPolicy",
requirements.getPolicyClassName());
+ assertEquals("org.gatein.wsrp.producer.config.TestRegistrationPolicy",
policy.getClassName());
+ assertNull(requirements.getValidatorClassName());
}
public void testSetUnchangedRegistrationProperties()
Modified:
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/TestRegistrationPolicy.java
===================================================================
---
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/TestRegistrationPolicy.java 2011-02-02
20:31:12 UTC (rev 5848)
+++
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/TestRegistrationPolicy.java 2011-02-02
21:59:34 UTC (rev 5849)
@@ -72,4 +72,19 @@
{
return true;
}
+
+ public boolean isWrapped()
+ {
+ return false;
+ }
+
+ public String getClassName()
+ {
+ return getClass().getName();
+ }
+
+ public Class<? extends RegistrationPolicy> getRealClass()
+ {
+ return getClass();
+ }
}