Author: chris.laprun(a)jboss.com
Date: 2007-04-26 18:34:39 -0400 (Thu, 26 Apr 2007)
New Revision: 7091
Added:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/RegistrationInfoTestCase.java
Modified:
trunk/wsrp/build.xml
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationInfo.java
Log:
- Added refreshRegistrationRequirementsFor method to be able to manually refresh the
registration metadata from the producer.
- Fixed several issues.
- Added test case.
Modified: trunk/wsrp/build.xml
===================================================================
--- trunk/wsrp/build.xml 2007-04-26 21:42:53 UTC (rev 7090)
+++ trunk/wsrp/build.xml 2007-04-26 22:34:39 UTC (rev 7091)
@@ -755,6 +755,7 @@
<test todir="${test.reports}"
name="org.jboss.portal.test.wsrp.other.UserContextConverterTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.wsrp.other.EndpointConfigurationInfoTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.wsrp.other.ProducerInfoTestCase"/>
+ <test todir="${test.reports}"
name="org.jboss.portal.test.wsrp.other.RegistrationInfoTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.wsrp.handler.RequestHeaderClientHandlerTestCase"/>
</x-test>
<x-sysproperty>
Added: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/RegistrationInfoTestCase.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/RegistrationInfoTestCase.java
(rev 0)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/RegistrationInfoTestCase.java 2007-04-26
22:34:39 UTC (rev 7091)
@@ -0,0 +1,151 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2007, 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.other;
+
+import junit.framework.TestCase;
+import org.jboss.portal.wsrp.WSRPConstants;
+import org.jboss.portal.wsrp.WSRPTypeFactory;
+import org.jboss.portal.wsrp.consumer.RegistrationInfo;
+import org.jboss.portal.wsrp.consumer.RegistrationProperty;
+import org.jboss.portal.wsrp.core.PropertyDescription;
+import org.jboss.portal.wsrp.core.ServiceDescription;
+
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ * @since 2.6
+ */
+public class RegistrationInfoTestCase extends TestCase
+{
+ private RegistrationInfo info;
+ private static final String producerId = "test";
+
+ protected void setUp() throws Exception
+ {
+ info = new RegistrationInfo();
+ }
+
+ public void testInitialState()
+ {
+ assertTrue(info.getRegistrationProperties().isEmpty());
+ assertTrue(info.getRegistrationPropertyNames().isEmpty());
+ assertNull(info.getRegistrationContext());
+ assertNotNull(info.getRegistrationData());
+ assertNull(info.getRegistrationHandle());
+ assertNull(info.getRegistrationState());
+ }
+
+ public void testSetGetRegistrationProperty()
+ {
+ String key = "foo";
+ info.setRegistrationPropertyValue(key, "bar");
+ assertFalse(info.getRegistrationProperties().isEmpty());
+ assertFalse(info.getRegistrationPropertyNames().isEmpty());
+ assertTrue(info.getRegistrationProperties().containsKey(key));
+ assertTrue(info.getRegistrationPropertyNames().contains(key));
+ assertNotNull(info.getRegistrationProperties().get(key));
+ assertEquals(info.getRegistrationProperties().get(key),
info.getRegistrationProperty(key));
+ assertEquals("bar", info.getRegistrationProperty(key).getValue());
+ }
+
+ public void testRefreshNoRegistration()
+ {
+ ServiceDescription sd = createServiceDescription(false, 0);
+ RegistrationInfo.RegistrationRefreshResult result =
info.refreshRegistrationRequirementsFor(sd, producerId, true);
+ assertNotNull(result);
+ assertTrue(result.isValid());
+ assertFalse(info.isRequiresRegistration());
+ assertTrue(info.isRegistrationValid());
+
+ result = info.refreshRegistrationRequirementsFor(sd, producerId, false);
+ assertNotNull(result);
+ assertTrue(result.isValid());
+ assertFalse(info.isRequiresRegistration());
+ assertTrue(info.isRegistrationValid());
+ }
+
+ public void testRefreshRegistrationDefaultRegistrationNoLocalInfo()
+ {
+ RegistrationInfo.RegistrationRefreshResult result =
info.refreshRegistrationRequirementsFor(
+ createServiceDescription(true, 0), producerId, true);
+ assertNotNull(result);
+ assertTrue(result.isValid());
+ assertTrue(info.isRequiresRegistration());
+ assertFalse(info.isRegistrationValid());
+ }
+
+ public void testRefreshRegistrationDefaultRegistrationExtraLocalInfo()
+ {
+ // set a registration property
+ info.setRegistrationPropertyValue("foo", "bar");
+
+ RegistrationInfo.RegistrationRefreshResult result =
info.refreshRegistrationRequirementsFor(
+ createServiceDescription(true, 0), producerId, false);
+ assertNotNull(result);
+ assertFalse(result.isValid());
+ String status = result.getStatus();
+ assertNotNull(status);
+ assertTrue(status.contains("foo"));
+
+ Map regProps = result.getRegistrationProperties();
+ assertNotNull(regProps);
+
+ RegistrationProperty prop = (RegistrationProperty)regProps.get("foo");
+ assertNotNull(prop);
+ assertEquals("bar", prop.getValue());
+ assertTrue(prop.isInvalid());
+ }
+
+ public void testRefreshRegistrationRegistrationNoLocalInfo()
+ {
+ // producer requests 2 registration properties
+ ServiceDescription sd = createServiceDescription(true, 2);
+
+ RegistrationInfo.RegistrationRefreshResult result =
info.refreshRegistrationRequirementsFor(sd, producerId, false);
+ assertNotNull(result);
+ assertFalse(result.isValid());
+ String status = result.getStatus();
+ assertNotNull(status);
+ assertTrue(status.contains("prop0") &&
status.contains("prop1"));
+ }
+
+ private ServiceDescription createServiceDescription(boolean requiresRegistration, int
numberOfProperties)
+ {
+ ServiceDescription sd =
WSRPTypeFactory.createServiceDescription(requiresRegistration);
+
+ if (requiresRegistration)
+ {
+ PropertyDescription[] descriptions = new
PropertyDescription[numberOfProperties];
+ for (int i = 0; i < numberOfProperties; i++)
+ {
+ descriptions[i] = WSRPTypeFactory.createPropertyDescription("prop"
+ i, WSRPConstants.XSD_STRING);
+ }
+
sd.setRegistrationPropertyDescription(WSRPTypeFactory.createModelDescription(descriptions));
+ }
+
+ return sd;
+ }
+}
Property changes on:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/RegistrationInfoTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationInfo.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationInfo.java 2007-04-26
21:42:53 UTC (rev 7090)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationInfo.java 2007-04-26
22:34:39 UTC (rev 7091)
@@ -238,8 +238,22 @@
*/
boolean initialize(ServiceDescription serviceDescription, String producerId)
{
+ return refreshRegistrationRequirementsFor(serviceDescription, producerId,
true).isValid();
+ }
+
+
+ /**
+ * @param serviceDescription
+ * @param producerId
+ * @param discardLocalInfo
+ * @return
+ * @since 2.6
+ */
+ public RegistrationRefreshResult refreshRegistrationRequirementsFor(ServiceDescription
serviceDescription, String producerId, boolean discardLocalInfo)
+ {
log.debug("RegistrationInfo initialization requested");
- boolean configurationValid;
+ RegistrationRefreshResult result = new RegistrationRefreshResult();
+
if (serviceDescription.isRequiresRegistration())
{
requiresRegistration = true;
@@ -250,85 +264,118 @@
ModelDescription regPropDescs =
serviceDescription.getRegistrationPropertyDescription();
if (regPropDescs != null)
{
- configurationValid = true;
+ result.setValid(true);
PropertyDescription[] propertyDescriptions =
regPropDescs.getPropertyDescriptions();
if (propertyDescriptions != null && propertyDescriptions.length >
0)
{
Map descriptionsMap =
getRegistrationPropertyDescriptionsFromWSRP(propertyDescriptions);
- Map registrationProperties = getOrCreateRegistrationPropertiesMap(true);
+ if (discardLocalInfo)
+ {
+ registrationProperties = descriptionsMap;
+ result.setValid(false);
+ }
+ else
+ {
+ registrationProperties = getOrCreateRegistrationPropertiesMap(true);
- // check that we don't have unexpected registration properties and if
so, mark them as invalid
- Set unexpected = new HashSet(registrationProperties.keySet());
- Set expectedNames = descriptionsMap.keySet();
- unexpected.removeAll(expectedNames);
- if (!unexpected.isEmpty())
- {
- message = new StringBuffer("The registration for producer
'"
- + producerId + "' provided values for unexpected
registration properties: ");
- for (Iterator invalidProps = unexpected.iterator();
invalidProps.hasNext();)
+ // check that we don't have unexpected registration properties and
if so, mark them as invalid
+ Set expectedNames = descriptionsMap.keySet();
+ checkForExtraProperties(producerId, result, expectedNames,
registrationProperties);
+
+ // now check for missing properties, add the missing ones with a null
value
+ StringBuffer missingProps = new StringBuffer();
+ for (Iterator descriptionNames = expectedNames.iterator();
descriptionNames.hasNext();)
{
- String name = (String)invalidProps.next();
- message.append("\t-
").append(name).append("\n");
-
((RegistrationProperty)registrationProperties.get(name)).setInvalid(true);
+ String name = (String)descriptionNames.next();
+ RegistrationProperty prop =
(RegistrationProperty)registrationProperties.get(name);
+ if (prop == null)
+ {
+ Object missingProp = descriptionsMap.get(name);
+ registrationProperties.put(name, missingProp);
+ missingProps.append("Missing value for property
'").append(name).append("'\n");
+ }
}
- log.info(message);
- resetRegistration();
- configurationValid = false;
- }
- // now check for missing properties, add the missing ones with a null
value
- StringBuffer missingProps = new StringBuffer();
- for (Iterator descriptionNames = expectedNames.iterator();
descriptionNames.hasNext();)
- {
- String name = (String)descriptionNames.next();
- RegistrationProperty prop =
(RegistrationProperty)registrationProperties.get(name);
- if (prop == null)
+ if (missingProps.length() > 0)
{
- Object missingProp = descriptionsMap.get(name);
- registrationProperties.put(name, missingProp);
- missingProps.append("Missing value for
").append(missingProp).append("\n");
+ log.info(missingProps);
+ result.appendToStatus(missingProps.toString());
+ resetRegistration();
+ result.setValid(false);
}
}
-
- if (missingProps.length() > 0)
- {
- log.info(missingProps);
- resetRegistration();
- configurationValid = false;
- }
}
- }
- else
- {
- log.info("The producer didn't require any specific registration
properties.");
- if (!getRegistrationProperties().isEmpty())
- {
- resetRegistration();
- log.info("Registration data is available for producer '"
- + producerId + "' when none is expected by the
producer.");
- configurationValid = false;
- }
else
{
- log.info("Using default registration data for producer '" +
producerId + "'");
- registrationData = WSRPTypeFactory.createDefaultRegistrationData();
- configurationValid = true;
+ handleNoRequiredRegistrationProperties(producerId, result);
}
}
+ else
+ {
+ handleNoRequiredRegistrationProperties(producerId, result);
+ }
}
else
{
log.info("Producer '" + producerId + "' doesn't
require registration.");
requiresRegistration = false;
- configurationValid = true;
+ result.setValid(true);
}
- log.debug("Registration configuration is " + (configurationValid ?
"" : "NOT") + " valid");
- return configurationValid;
+ result.setRegistrationProperties(registrationProperties);
+ log.debug("Registration configuration is " + (result.isValid() ?
"" : "NOT") + " valid");
+ return result;
}
+ private void handleNoRequiredRegistrationProperties(String producerId,
RegistrationRefreshResult result)
+ {
+ log.info("The producer didn't require any specific registration
properties.");
+ Map properties = getRegistrationProperties();
+ if (!properties.isEmpty())
+ {
+ String msg = "Registration data is available for producer '"
+ + producerId + "' when none is expected by the producer.";
+ log.info(msg);
+ checkForExtraProperties(producerId, result, Collections.EMPTY_SET, properties);
+ }
+ else
+ {
+ log.info("Using default registration data for producer '" +
producerId + "'");
+ registrationData = WSRPTypeFactory.createDefaultRegistrationData();
+ result.setValid(true);
+ }
+ }
+
/**
+ * @param producerId
+ * @param result
+ * @param expectedNames
+ * @param properties
+ * @return a set of the property names expected by the producer
+ */
+ private void checkForExtraProperties(String producerId, RegistrationRefreshResult
result, Set expectedNames, Map properties)
+ {
+ Set unexpected = new HashSet(properties.keySet());
+ unexpected.removeAll(expectedNames);
+ if (!unexpected.isEmpty())
+ {
+ StringBuffer message = new StringBuffer("The registration for producer
'"
+ + producerId + "' provided values for unexpected registration
properties: ");
+ for (Iterator invalidProps = unexpected.iterator(); invalidProps.hasNext();)
+ {
+ String name = (String)invalidProps.next();
+ message.append("\t- ").append(name).append("\n");
+ ((RegistrationProperty)properties.get(name)).setInvalid(true);
+ }
+ log.info(message);
+ result.appendToStatus(message.toString());
+ resetRegistration();
+ result.setValid(false);
+ }
+ }
+
+ /**
* @param descriptions
* @return
* @since 2.6
@@ -391,4 +438,59 @@
return null;
}
}
+
+ public class RegistrationRefreshResult
+ {
+ private Map registrationProperties;
+ private StringBuffer status;
+ private boolean valid;
+
+ public String getStatus()
+ {
+ if (status == null)
+ {
+ return null;
+ }
+
+ return status.toString();
+ }
+
+ public Map getRegistrationProperties()
+ {
+ return registrationProperties;
+ }
+
+ public void setRegistrationProperties(Map registrationProperties)
+ {
+ this.registrationProperties = registrationProperties;
+ }
+
+ public boolean isValid()
+ {
+ return valid;
+ }
+
+ public void setValid(boolean valid)
+ {
+ this.valid = valid;
+ }
+
+ void appendToStatus(String message)
+ {
+ if (status == null)
+ {
+ status = new StringBuffer(message);
+ }
+ else
+ {
+ status.append(message);
+ }
+ }
+ }
+
+ class RegistrationPropertyHolder
+ {
+ RegistrationProperty property;
+ String status;
+ }
}