Author: chris.laprun(a)jboss.com
Date: 2011-03-03 15:48:36 -0500 (Thu, 03 Mar 2011)
New Revision: 5966
Added:
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/TestRegistrationPropertyValidator.java
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/policies/DefaultRegistrationPolicy.java
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/policies/DefaultRegistrationPolicyTestCase.java
Log:
- GTNWSRP-203: Fixed improper error reporting. Added test case.
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-03-03
20:15:38 UTC (rev 5965)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/policies/DefaultRegistrationPolicy.java 2011-03-03
20:48:36 UTC (rev 5966)
@@ -53,8 +53,10 @@
*/
public class DefaultRegistrationPolicy implements RegistrationPolicy
{
+ static final String MISSING_VALUE_ERROR_MSG_BEGIN = "Missing value for expected
'";
private RegistrationPropertyValidator validator;
private static final Logger log =
LoggerFactory.getLogger(DefaultRegistrationPolicy.class);
+ static final String INVALID_VALUE_ERROR_MSG_BEGIN = "Invalid value for property
'";
public DefaultRegistrationPolicy()
{
@@ -129,14 +131,23 @@
{
QName name = entry.getKey();
Object value = registrationProperties.get(name);
- try
+
+ if (value == null || (value instanceof String &&
((String)value).isEmpty()))
{
- validator.validateValueFor(name, value);
+
message.append(MISSING_VALUE_ERROR_MSG_BEGIN).append(name.getLocalPart()).append("'
property.\n");
+ consistentWithExpectations = false;
}
- catch (IllegalArgumentException e)
+ else
{
- message.append("Missing value for expected
'").append(name.getLocalPart()).append("' property.\n");
- consistentWithExpectations = false;
+ try
+ {
+ validator.validateValueFor(name, value);
+ }
+ catch (IllegalArgumentException e)
+ {
+
message.append(INVALID_VALUE_ERROR_MSG_BEGIN).append(name.getLocalPart()).append("'
property.\n").append(e.getLocalizedMessage()).append("\n");
+ consistentWithExpectations = false;
+ }
}
}
Modified:
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/policies/DefaultRegistrationPolicyTestCase.java
===================================================================
---
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/policies/DefaultRegistrationPolicyTestCase.java 2011-03-03
20:15:38 UTC (rev 5965)
+++
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/policies/DefaultRegistrationPolicyTestCase.java 2011-03-03
20:48:36 UTC (rev 5966)
@@ -28,6 +28,7 @@
import org.gatein.registration.RegistrationManager;
import org.gatein.registration.impl.RegistrationManagerImpl;
import org.gatein.registration.impl.RegistrationPersistenceManagerImpl;
+import org.gatein.wsrp.producer.config.TestRegistrationPropertyValidator;
import org.gatein.wsrp.registration.PropertyDescription;
import javax.xml.namespace.QName;
@@ -124,10 +125,34 @@
}
catch (RegistrationException e)
{
- assertTrue(e.getLocalizedMessage().contains("prop3"));
+ String message = e.getLocalizedMessage();
+
assertTrue(message.startsWith(DefaultRegistrationPolicy.MISSING_VALUE_ERROR_MSG_BEGIN));
+ assertTrue(message.contains("prop3"));
}
}
+ public void testValidateRegistrationDataFailedValidation()
+ {
+ expectations.put(PROP1, new TestPropertyDescription(PROP1));
+ expectations.put(PROP2, new TestPropertyDescription(PROP2));
+
+ // set validator for test
+ policy.setValidator(new TestRegistrationPropertyValidator());
+
+ try
+ {
+ policy.validateRegistrationDataFor(registrationProperties, CONSUMER,
expectations, manager);
+ fail("Should have rejected properties based on values");
+ }
+ catch (RegistrationException e)
+ {
+ String message = e.getLocalizedMessage();
+
assertTrue(message.startsWith(DefaultRegistrationPolicy.INVALID_VALUE_ERROR_MSG_BEGIN));
+ assertTrue(message.contains("prop1"));
+ assertTrue(message.contains("prop2"));
+ }
+ }
+
public void testValidateRegistrationDataExtraProps()
{
expectations.put(PROP1, new TestPropertyDescription(PROP1));
Added:
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/TestRegistrationPropertyValidator.java
===================================================================
---
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/TestRegistrationPropertyValidator.java
(rev 0)
+++
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/TestRegistrationPropertyValidator.java 2011-03-03
20:48:36 UTC (rev 5966)
@@ -0,0 +1,44 @@
+/*
+ * 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.wsrp.producer.config;
+
+import org.gatein.registration.policies.RegistrationPropertyValidator;
+
+import javax.xml.namespace.QName;
+
+/** @author mvanco */
+public class TestRegistrationPropertyValidator implements RegistrationPropertyValidator
+{
+ public void validateValueFor(QName propertyName, Object value) throws
IllegalArgumentException
+ {
+ System.out.println("TEST validator is called for " + propertyName +
" with value " + value);
+ // accepts only non-null, String values containing: 'test'
+ if (!(value instanceof String) || !((String)value).contains("test"))
+ {
+ throw new IllegalArgumentException(value + " is not a valid value for
property '" + propertyName
+ + "'. TestRegistrationPropertyValidator only accepts non-null String
value containing 'test'.");
+ }
+ }
+
+}
\ No newline at end of file