Author: chris.laprun(a)jboss.com
Date: 2007-06-19 00:21:41 -0400 (Tue, 19 Jun 2007)
New Revision: 7462
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/consumer/ProducerInfoTestCase.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationInfo.java
Log:
- ProducerInfo.isRegistered now properly handles the case where registration properties
have changed since registration.
- deregister and modifyRegistration throw IllegalStateException when called when the
Consumer is not registered.
- RegistrationInfo now properly regenerates RegistrationData when needed and properly
marks registration properties as valid after modifyRegistration or register.
- RegistrationInfo.resetRegistration doesn't reset as much information, just the
information pertaining to the actual registration, not the producer metadata.
- Added tests for deregister and modifyRegistration.
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/consumer/ProducerInfoTestCase.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/consumer/ProducerInfoTestCase.java 2007-06-19
04:13:19 UTC (rev 7461)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/consumer/ProducerInfoTestCase.java 2007-06-19
04:21:41 UTC (rev 7462)
@@ -37,6 +37,7 @@
import org.jboss.portal.wsrp.consumer.EndpointConfigurationInfo;
import org.jboss.portal.wsrp.consumer.ProducerInfo;
import org.jboss.portal.wsrp.consumer.RegistrationInfo;
+import org.jboss.portal.wsrp.consumer.RegistrationProperty;
import org.jboss.portal.wsrp.core.AccessDeniedFault;
import org.jboss.portal.wsrp.core.GetPortletDescription;
import org.jboss.portal.wsrp.core.InconsistentParametersFault;
@@ -44,11 +45,13 @@
import org.jboss.portal.wsrp.core.InvalidRegistrationFault;
import org.jboss.portal.wsrp.core.InvalidUserCategoryFault;
import org.jboss.portal.wsrp.core.MissingParametersFault;
+import org.jboss.portal.wsrp.core.ModifyRegistration;
import org.jboss.portal.wsrp.core.OperationFailedFault;
import org.jboss.portal.wsrp.core.PortletDescriptionResponse;
import org.jboss.portal.wsrp.core.Property;
import org.jboss.portal.wsrp.core.RegistrationContext;
import org.jboss.portal.wsrp.core.RegistrationData;
+import org.jboss.portal.wsrp.core.RegistrationState;
import java.rmi.RemoteException;
@@ -190,7 +193,7 @@
}
RegistrationInfo regInfo = info.getRegistrationInfo();
- regInfo.setRegistrationPropertyValue("prop0", "value");
+ regInfo.setRegistrationPropertyValue(TestRegistrationBehavior.PROP_NAME,
TestRegistrationBehavior.ORIGINAL_VALUE);
info.register();
RegistrationContext registrationContext = info.getRegistrationContext();
@@ -201,6 +204,82 @@
assertTrue(info.isRegistrationRequired());
}
+ public void testDeregister() throws Exception
+ {
+ try
+ {
+ info.deregister();
+ fail("Shouldn't be able to deregister without being registered");
+ }
+ catch (IllegalStateException expected)
+ {
+ }
+
+ // setup registration
+ register();
+
+ info.deregister();
+ assertNull(info.getRegistrationContext());
+ assertFalse(info.isRegistered());
+ assertTrue(info.isRegistrationRequired());
+ assertTrue(info.isRegistrationChecked());
+ }
+
+ private void register() throws PortletInvokerException
+ {
+ ServiceDescriptionBehavior sd = new ServiceDescriptionBehavior();
+ sd.setServiceDescription(true, 1);
+ serviceFactory.getRegistry().setServiceDescriptionBehavior(sd);
+ RegistrationBehavior regBehavior = new TestRegistrationBehavior();
+ serviceFactory.getRegistry().setRegistrationBehavior(regBehavior);
+ info.refresh(false);
+ RegistrationInfo regInfo = info.getRegistrationInfo();
+ regInfo.setRegistrationPropertyValue(TestRegistrationBehavior.PROP_NAME,
TestRegistrationBehavior.ORIGINAL_VALUE);
+
+ info.register();
+ }
+
+ public void testModifyRegistration() throws Exception
+ {
+ try
+ {
+ info.modifyRegistration();
+ fail("Shouldn't be able to modify registration without being
registered");
+ }
+ catch (IllegalStateException expected)
+ {
+ }
+
+ register();
+
+ RegistrationInfo regInfo = info.getRegistrationInfo();
+ regInfo.setRegistrationPropertyValue(TestRegistrationBehavior.PROP_NAME,
"invalid");
+ assertTrue(info.isRefreshNeeded(false));
+ assertTrue(info.isRegistered());
+ RegistrationProperty prop =
regInfo.getRegistrationProperty(TestRegistrationBehavior.PROP_NAME);
+ assertNull(prop.isInvalid());
+
+ try
+ {
+ info.modifyRegistration();
+ fail("invalid value for property should fail to modify
registration");
+ }
+ catch (PortletInvokerException expected)
+ {
+ }
+
+ regInfo.setRegistrationPropertyValue(TestRegistrationBehavior.PROP_NAME,
TestRegistrationBehavior.MODIFIED_VALUE);
+ assertTrue(info.isRefreshNeeded(false));
+ assertNull(prop.isInvalid());
+
+ info.modifyRegistration();
+
+ assertFalse(info.isRefreshNeeded(false));
+ Boolean invalid = prop.isInvalid();
+ assertNotNull(invalid);
+ assertFalse(invalid.booleanValue());
+ }
+
private static class TestPortletManagementBehavior extends PortletManagementBehavior
{
public PortletDescriptionResponse getPortletDescription(GetPortletDescription
getPortletDescription)
@@ -214,8 +293,27 @@
private static class TestRegistrationBehavior extends RegistrationBehavior
{
+ private static final String PROP_NAME = "prop0";
+ private static final String MODIFIED_VALUE = "value2";
+ private static final String ORIGINAL_VALUE = "value";
+
public RegistrationContext register(RegistrationData register) throws
MissingParametersFault, OperationFailedFault, RemoteException
{
+ Property prop = checkRegistrationData(register);
+
+ String value = prop.getStringValue();
+ if (ORIGINAL_VALUE.equals(value) && PROP_NAME.equals(prop.getName()))
+ {
+ return super.register(register);
+ }
+
+ throw
WSRPExceptionFactory.throwSOAPFaultException(WSRPExceptionFactory.OPERATION_FAILED,
+ value + " is not a valid value for " + PROP_NAME, null);
+ }
+
+ private Property checkRegistrationData(RegistrationData register)
+ throws OperationFailedFault
+ {
WSRPExceptionFactory.throwOperationFailedFaultIfValueIsMissing(register,
"RegistrationData");
Property[] props = register.getRegistrationProperties();
@@ -223,15 +321,32 @@
Property prop = props[0];
WSRPExceptionFactory.throwOperationFailedFaultIfValueIsMissing(prop,
"Registration property");
+ return prop;
+ }
+ public RegistrationState modifyRegistration(ModifyRegistration modifyRegistration)
throws MissingParametersFault,
+ OperationFailedFault, InvalidRegistrationFault, RemoteException
+ {
+
WSRPExceptionFactory.throwOperationFailedFaultIfValueIsMissing(modifyRegistration,
"ModifyRegistration");
+
+ RegistrationContext context = modifyRegistration.getRegistrationContext();
+ WSRPExceptionFactory.throwMissingParametersFaultIfValueIsMissing(context,
"RegistrationContext", "ModifyRegistration");
+
+ if
(!RegistrationBehavior.REGISTRATION_HANDLE.equals(context.getRegistrationHandle()))
+ {
+
WSRPExceptionFactory.throwSOAPFaultException(WSRPExceptionFactory.INVALID_REGISTRATION,
"Invalid registration", null);
+ }
+
+ Property prop =
checkRegistrationData(modifyRegistration.getRegistrationData());
+
String value = prop.getStringValue();
- if ("value".equals(value) &&
"prop0".equals(prop.getName()))
+ if (MODIFIED_VALUE.equals(value) && PROP_NAME.equals(prop.getName()))
{
- return super.register(register);
+ return null;
}
- throw
WSRPExceptionFactory.throwSOAPFaultException(WSRPExceptionFactory.OPERATION_FAILED,
- value + " is not a valid value for 'prop0'", null);
+ throw
WSRPExceptionFactory.throwSOAPFaultException(WSRPExceptionFactory.OPERATION_FAILED, value
+ + " is not a valid value for " + PROP_NAME, null);
}
}
}
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java 2007-06-19
04:13:19 UTC (rev 7461)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java 2007-06-19
04:21:41 UTC (rev 7462)
@@ -166,7 +166,14 @@
if (persistentRegistrationInfo != null)
{
Boolean valid = persistentRegistrationInfo.isRegistrationValid();
- return valid != null && valid.booleanValue();
+ if (valid == null)
+ {
+ return persistentRegistrationInfo.getRegistrationHandle() != null;
+ }
+ else
+ {
+ return valid.booleanValue();
+ }
}
return false;
@@ -743,6 +750,10 @@
registry.updateProducerInfo(this);
}
}
+ else
+ {
+ throw new IllegalStateException("Cannot deregister producer '" +
persistentId + "' as it's not registered");
+ }
}
@@ -777,6 +788,11 @@
registry.updateProducerInfo(this);
}
}
+ else
+ {
+ throw new IllegalStateException("Cannot modify registration for producer
'" + persistentId
+ + "' as it's not registered");
+ }
}
public RefreshResult refreshRegistrationInfo(boolean mergeWithLocalInfo) throws
PortletInvokerException
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationInfo.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationInfo.java 2007-06-19
04:13:19 UTC (rev 7461)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationInfo.java 2007-06-19
04:21:41 UTC (rev 7462)
@@ -196,7 +196,7 @@
public RegistrationData getRegistrationData()
{
- if (registrationData == null)
+ if (dirty || registrationData == null)
{
registrationData = WSRPTypeFactory.createDefaultRegistrationData();
registrationData.setConsumerName(persistentConsumerName);
@@ -516,11 +516,8 @@
void resetRegistration()
{
- registrationData = null;
persistentRegistrationHandle = null;
persistentRegistrationState = null;
- requiresRegistration = null;
- consistentWithProducerExpectations = null;
}
public void setRegistrationContext(RegistrationContext registrationContext)
@@ -538,6 +535,16 @@
consistentWithProducerExpectations = Boolean.TRUE; // since we have a registration
context, we're consistent with the Producer
requiresRegistration = Boolean.TRUE; // we know we require registration
dirty = false; // our state is clean :)
+
+ // mark the registration properties as valid
+ if (persistentRegistrationProperties != null)
+ {
+ for (Iterator props = persistentRegistrationProperties.values().iterator();
props.hasNext();)
+ {
+ RegistrationProperty prop = (RegistrationProperty)props.next();
+ prop.setInvalid(Boolean.FALSE, null);
+ }
+ }
}
public RegistrationContext getRegistrationContext()