Author: chris.laprun(a)jboss.com
Date: 2006-11-28 01:43:48 -0500 (Tue, 28 Nov 2006)
New Revision: 5731
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/RegistrationTestCase.java
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/RegistrationTestCase.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPUtils.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/RegistrationHandler.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/Registration.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/ConsumerImpl.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/RegistrationImpl.java
Log:
- Can now modify consumer agent on Consumer. Dunno why I didn't allow it in the first
place...
- Added remove/get property and updateProperties(Map) on Registration and associated test
cases.
- Implemented modifyRegistration and activated test case. With this first implementation
of Registration is finished! ^_^
Modified:
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-28
05:41:09 UTC (rev 5730)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/registration/RegistrationTestCase.java 2006-11-28
06:43:48 UTC (rev 5731)
@@ -114,6 +114,34 @@
}
}
+ public void testProperties()
+ {
+ QName name = new QName("prop1");
+ assertEquals("value1", registration.getProperties().get(name));
+ assertEquals("value2", registration.getProperties().get(new
QName("prop2")));
+
+ String newValue = "new value";
+ registration.setPropertyValueFor("prop1", newValue);
+ assertEquals(newValue, registration.getProperties().get(name));
+
+ registration.removeProperty(name);
+ assertNull(registration.getPropertyValueFor(name));
+ }
+
+ public void testUpdateProperties()
+ {
+ registrationProperties.remove(new QName("prop1"));
+
+ registration.updateProperties(registrationProperties);
+ assertNull(registration.getPropertyValueFor("prop1"));
+
+ QName name = new QName("prop3");
+ String value = "value3";
+ registrationProperties.put(name, value);
+ registration.updateProperties(registrationProperties);
+ assertEquals(value, registration.getPropertyValueFor(name));
+ }
+
public void testHasEqualProperties()
{
assertTrue(registration.hasEqualProperties(registration));
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/RegistrationTestCase.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/RegistrationTestCase.java 2006-11-28
05:41:09 UTC (rev 5730)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/RegistrationTestCase.java 2006-11-28
06:43:48 UTC (rev 5731)
@@ -26,13 +26,19 @@
import org.jboss.portal.common.junit.ExtendedAssert;
import org.jboss.portal.wsrp.WSRPConstants;
import org.jboss.portal.wsrp.WSRPTypeFactory;
+import org.jboss.portal.wsrp.WSRPUtils;
import org.jboss.portal.wsrp.core.GetMarkup;
import org.jboss.portal.wsrp.core.GetServiceDescription;
import org.jboss.portal.wsrp.core.InvalidRegistrationFault;
+import org.jboss.portal.wsrp.core.ModifyRegistration;
import org.jboss.portal.wsrp.core.OperationFailedFault;
+import org.jboss.portal.wsrp.core.PropertyDescription;
import org.jboss.portal.wsrp.core.RegistrationContext;
import org.jboss.portal.wsrp.core.RegistrationData;
+import org.jboss.portal.wsrp.producer.registration.api.RegistrationPropertyDescription;
+import javax.xml.namespace.QName;
+
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
* @version $Revision$
@@ -109,25 +115,57 @@
// expected
}
- // Get description should still work?
+ // Get description with old registration context should fail
GetServiceDescription gs = getNoRegistrationServiceDescriptionRequest();
gs.setRegistrationContext(rc);
+ try
+ {
+ serviceDescriptionService.getServiceDescription(gs);
+ ExtendedAssert.fail("Required registration info has been modified:
operations should fail until registration is modified.");
+ }
+ catch (InvalidRegistrationFault invalidRegistrationFault)
+ {
+ // expected
+ }
+
+ // Get description should still work without registration context
+ gs = getNoRegistrationServiceDescriptionRequest();
+
ExtendedAssert.assertNotNull(serviceDescriptionService.getServiceDescription(gs));
}
- /*public void testModifyRegistration() throws Exception
+ public void testModifyRegistration() throws Exception
{
// initiate registration
configureRegistrationSettings(false);
RegistrationContext rc = registerConsumer();
// now modify Producer's set of required registration info
- RegistrationPropertyDescription regProp = new
RegistrationPropertyDescription("new prop", new QName("xsd:string"));
+ String newPropName = "New Prop";
+ RegistrationPropertyDescription regProp = new
RegistrationPropertyDescription(newPropName,
+ new QName("urn:oasis:names:tc:wsrp:v1:types",
"LocalizedString", "ns1"));
regProp.setDefaultLabel("New Registration Property");
producer.getProducerRegistrationRequirements().addRegistrationProperty(regProp);
- // Try to get service description
+ // try to get markup, portlet handle doesn't matter since it should fail before
trying to retrieve the portlet
+ GetMarkup getMarkup = WSRPTypeFactory.createDefaultMarkupRequest("foo");
+ getMarkup.getMarkupParams().setMarkupCharacterSets(new
String[]{WSRPConstants.DEFAULT_CHARACTER_SET});
+ getMarkup.setRegistrationContext(rc);
+
+ try
+ {
+ markupService.getMarkup(getMarkup);
+ ExtendedAssert.fail("Required registration info has been modified:
operations should fail until registration is modified.");
+ }
+ catch (InvalidRegistrationFault expected)
+ {
+ // expected
+ // WSRP primer recommends returning OperationFailedFault and NOT
InvalidRegistrationFault
+ // kinda weird... will be replaced by ModifyRegistrationRequiredFault in WSRP
2.0
+ }
+
+ // Get description should return information just as if consumer wasn't
registered
GetServiceDescription gs = getNoRegistrationServiceDescriptionRequest();
gs.setRegistrationContext(rc);
@@ -136,7 +174,7 @@
serviceDescriptionService.getServiceDescription(gs);
ExtendedAssert.fail("Required registration info has been modified:
operations should fail until registration is modified.");
}
- catch (OperationFailedFault operationFailedFault)
+ catch (InvalidRegistrationFault expected)
{
// expected
// WSRP primer recommends returning OperationFailedFault and NOT
InvalidRegistrationFault
@@ -155,13 +193,13 @@
org.jboss.portal.wsrp.core.Property[] props = regData.getRegistrationProperties();
org.jboss.portal.wsrp.core.Property[] newProps = new
org.jboss.portal.wsrp.core.Property[props.length + 1];
System.arraycopy(props, 0, newProps, 0, props.length);
- newProps[props.length] = new org.jboss.portal.wsrp.core.Property("new
prop", "en", "blah", null);
+ newProps[props.length] = new org.jboss.portal.wsrp.core.Property(newPropName,
"en", "blah", null);
// Modify registration and get service description
registrationService.modifyRegistration(new ModifyRegistration(rc, regData));
gs.setRegistrationContext(rc);
checkServiceDescriptionWithOnlyBasicPortlet(gs);
- }*/
+ }
public void testRegister() throws Exception
{
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPUtils.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPUtils.java 2006-11-28 05:41:09 UTC (rev
5730)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPUtils.java 2006-11-28 06:43:48 UTC (rev
5731)
@@ -339,6 +339,7 @@
public static void validateConsumerAgent(String consumerAgent) throws
IllegalArgumentException
{
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(consumerAgent,
"consumer agent", null);
char periodChar = '.';
int period = consumerAgent.indexOf(periodChar);
if (period != -1)
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/RegistrationHandler.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/RegistrationHandler.java 2006-11-28
05:41:09 UTC (rev 5730)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/RegistrationHandler.java 2006-11-28
06:43:48 UTC (rev 5731)
@@ -86,15 +86,7 @@
WSRPUtils.validateConsumerAgent(consumerAgent);
registration = producer.getRegistrationManager().addRegistrationTo(consumerName,
createRegistrationProperties(registrationData), true);
- registration.setStatus(RegistrationStatus.VALID);
- Consumer consumer = registration.getConsumer();
- consumer.setConsumerAgent(consumerAgent);
- ConsumerCapabilities capabilities = consumer.getCapabilities();
-
capabilities.setSupportedModes(getListFromArray(registrationData.getConsumerModes(),
false));
-
capabilities.setSupportedWindowStates(getListFromArray(registrationData.getConsumerWindowStates(),
false));
-
capabilities.setSupportedUserProfileData(getListFromArray(registrationData.getCustomUserProfileData(),
false));
-
capabilities.setSupportedUserScopes(getListFromArray(registrationData.getConsumerUserScopes(),
false));
- capabilities.setSupportsGetMethod(registrationData.isMethodGetSupported());
+ updateRegistrationInformation(registration, registrationData);
}
catch (Exception e)
{
@@ -107,6 +99,19 @@
return registrationContext;
}
+ private void updateRegistrationInformation(Registration registration, RegistrationData
registrationData)
+ {
+ registration.setStatus(RegistrationStatus.VALID);
+ Consumer consumer = registration.getConsumer();
+ consumer.setConsumerAgent(registrationData.getConsumerAgent());
+ ConsumerCapabilities capabilities = consumer.getCapabilities();
+
capabilities.setSupportedModes(getListFromArray(registrationData.getConsumerModes(),
false));
+
capabilities.setSupportedWindowStates(getListFromArray(registrationData.getConsumerWindowStates(),
false));
+
capabilities.setSupportedUserProfileData(getListFromArray(registrationData.getCustomUserProfileData(),
false));
+
capabilities.setSupportedUserScopes(getListFromArray(registrationData.getConsumerUserScopes(),
false));
+ capabilities.setSupportsGetMethod(registrationData.isMethodGetSupported());
+ }
+
public ReturnAny deregister(RegistrationContext deregister) throws
OperationFailedFault, InvalidRegistrationFault,
RemoteException
{
@@ -141,7 +146,45 @@
public RegistrationState modifyRegistration(ModifyRegistration modifyRegistration)
throws MissingParametersFault,
OperationFailedFault, InvalidRegistrationFault, RemoteException
{
- return null; // todo: implement
+ WSRPUtils.throwOperationFailedFaultIfValueIsMissing(modifyRegistration,
"ModifyRegistration");
+
+ RegistrationContext registrationContext =
modifyRegistration.getRegistrationContext();
+ WSRPUtils.throwMissingParametersFaultIfValueIsMissing(registrationContext,
"RegistrationContext", "ModifyRegistration");
+ String registrationHandle = registrationContext.getRegistrationHandle();
+ if (ParameterValidation.isNullOrEmpty(registrationHandle))
+ {
+ throwInvalidRegistrationFault("Null or empty registration handle");
+ }
+
+ RegistrationData registrationData = modifyRegistration.getRegistrationData();
+ WSRPUtils.throwMissingParametersFaultIfValueIsMissing(registrationData,
"RegistrationData", "ModifyRegistration");
+
+ String consumerName = registrationData.getConsumerName();
+ WSRPUtils.throwMissingParametersFaultIfValueIsMissing(consumerName, "consumer
name", "RegistrationData");
+
+ String consumerAgent = registrationData.getConsumerAgent();
+ WSRPUtils.throwMissingParametersFaultIfValueIsMissing(consumerAgent, "consumer
agent", "RegistrationData");
+
+ log.debug("Attempting to modify registration with handle '" +
registrationHandle + "'");
+ try
+ {
+ Registration registration =
producer.getRegistrationManager().getRegistration(registrationHandle);
+ registration.updateProperties(createRegistrationProperties(registrationData));
+ updateRegistrationInformation(registration, registrationData);
+ }
+ catch (NoSuchRegistrationException e)
+ {
+ log.debug(e);
+ throwInvalidRegistrationFault(e.getLocalizedMessage());
+ }
+ catch (RegistrationException e)
+ {
+ log.debug(e);
+ throw WSRPUtils.createOperationFailedFault(e);
+ }
+
+
+ return null;
}
public boolean isRegistrationValid(RegistrationContext registrationContext) throws
InvalidRegistrationFault, OperationFailedFault
Modified:
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/Registration.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/Registration.java 2006-11-28
05:41:09 UTC (rev 5730)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/api/Registration.java 2006-11-28
06:43:48 UTC (rev 5731)
@@ -96,4 +96,14 @@
/** Clears any state (cloned portlet information, session, etc) associated with this
Registration */
void clearAssociatedState();
+
+ void updateProperties(Map registrationProperties);
+
+ void removeProperty(QName propertyName);
+
+ void removeProperty(String propertyName);
+
+ Object getPropertyValueFor(QName propertyName);
+
+ Object getPropertyValueFor(String propertyName);
}
Modified:
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/ConsumerImpl.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/ConsumerImpl.java 2006-11-28
05:41:09 UTC (rev 5730)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/ConsumerImpl.java 2006-11-28
06:43:48 UTC (rev 5731)
@@ -52,7 +52,6 @@
private RegistrationStatus status;
private ConsumerGroup group;
private ConsumerCapabilities capabilities;
- private boolean agentSet = false;
private ConsumerImpl()
@@ -117,14 +116,11 @@
public void setConsumerAgent(String consumerAgent) throws IllegalArgumentException,
IllegalStateException
{
- if (agentSet)
+ if (consumerAgent != null && !consumerAgent.equals(this.consumerAgent))
{
- throw new IllegalStateException("Cannot modify the agent of a
Consumer!");
+ WSRPUtils.validateConsumerAgent(consumerAgent);
+ this.consumerAgent = consumerAgent;
}
-
- WSRPUtils.validateConsumerAgent(consumerAgent);
- this.consumerAgent = consumerAgent;
- agentSet = true;
}
public ConsumerCapabilities getCapabilities()
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-28
05:41:09 UTC (rev 5730)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/registration/impl/RegistrationImpl.java 2006-11-28
06:43:48 UTC (rev 5731)
@@ -86,14 +86,46 @@
{
ParameterValidation.throwIllegalArgExceptionIfNull(propertyName, "Property
name");
ParameterValidation.throwIllegalArgExceptionIfNull(value, "Property
value");
- properties.put(propertyName, value);
+
+ // avoid modifying the properties if new value is the same as old one
+ Object oldValue = properties.get(propertyName);
+ if (!value.equals(oldValue))
+ {
+ properties.put(propertyName, value);
+ }
}
public void setPropertyValueFor(String propertyName, Object value)
{
+ ParameterValidation.throwIllegalArgExceptionIfNull(propertyName, "Property
name");
setPropertyValueFor(new QName(propertyName), value);
}
+ public Object getPropertyValueFor(QName propertyName)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(propertyName, "Property
name");
+ return properties.get(propertyName);
+ }
+
+ public Object getPropertyValueFor(String propertyName)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(propertyName, "Property
name");
+ return getPropertyValueFor(new QName(propertyName));
+ }
+
+
+ public void removeProperty(QName propertyName)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(propertyName, "Property
name");
+ properties.remove(propertyName);
+ }
+
+ public void removeProperty(String propertyName)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(propertyName, "Property
name");
+ removeProperty(new QName(propertyName));
+ }
+
public boolean hasEqualProperties(Registration registration)
{
if (registration == null)
@@ -154,4 +186,9 @@
//todo: implement
}
+ public void updateProperties(Map registrationProperties)
+ {
+ properties = new HashMap(registrationProperties);
+ }
+
}