Author: chris.laprun(a)jboss.com
Date: 2010-08-27 08:49:41 -0400 (Fri, 27 Aug 2010)
New Revision: 3951
Modified:
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v1/V1ToV2Converter.java
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v1/V2ToV1Converter.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v1/PortletManagementTestCase.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/PortletManagementTestCase.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v1/behaviors/BasicPortletManagementBehavior.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/behaviors/BasicPortletManagementBehavior.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/PortletManagementHandler.java
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/PortletManagementTestCase.java
Log:
- GTNWSRP-63: PortletManagementHandler now properly produces an InconsistentParameters
exception when needed & added test case.
- Fixed BasicPortletManagementBehavior to be more useful in checking errors instead of
magically producing expected output.
- Reactivated commented-out tests in PortletManagementTestCase (v1 & v2) on the
consumer side and added test for proper handling of case when we try to set/reset a
property in the same call.
- Fixed converters which weren't properly dealing with ResetProperties.
- WSRPConsumerImpl.getProperties should now behave more precisely in case of producer
error.
Modified:
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v1/V1ToV2Converter.java
===================================================================
---
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v1/V1ToV2Converter.java 2010-08-27
06:38:36 UTC (rev 3950)
+++
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v1/V1ToV2Converter.java 2010-08-27
12:49:41 UTC (rev 3951)
@@ -684,6 +684,12 @@
result.getProperties().addAll(properties);
}
+ List<ResetProperty> resetProperties =
WSRPUtils.transform(v1PropertyList.getResetProperties(), RESETPROPERTY);
+ if (resetProperties != null)
+ {
+ result.getResetProperties().addAll(resetProperties);
+ }
+
List<Extension> extensions =
WSRPUtils.transform(v1PropertyList.getExtensions(), EXTENSION);
if (extensions != null)
{
Modified:
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v1/V2ToV1Converter.java
===================================================================
---
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v1/V2ToV1Converter.java 2010-08-27
06:38:36 UTC (rev 3950)
+++
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v1/V2ToV1Converter.java 2010-08-27
12:49:41 UTC (rev 3951)
@@ -809,6 +809,12 @@
result.getProperties().addAll(properties);
}
+ List<V1ResetProperty> resetProperties =
WSRPUtils.transform(propertyList.getResetProperties(), RESETPROPERTY);
+ if (resetProperties != null)
+ {
+ result.getResetProperties().addAll(resetProperties);
+ }
+
List<V1Extension> extensions =
WSRPUtils.transform(propertyList.getExtensions(), EXTENSION);
if (extensions != null)
{
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java 2010-08-27
06:38:36 UTC (rev 3950)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java 2010-08-27
12:49:41 UTC (rev 3951)
@@ -25,6 +25,7 @@
import org.gatein.common.NotYetImplemented;
import org.gatein.common.util.ParameterValidation;
+import org.gatein.pc.api.InvalidPortletIdException;
import org.gatein.pc.api.InvokerUnavailableException;
import org.gatein.pc.api.NoSuchPortletException;
import org.gatein.pc.api.Portlet;
@@ -57,7 +58,10 @@
import org.gatein.wsrp.servlet.UserAccess;
import org.oasis.wsrp.v2.Extension;
import org.oasis.wsrp.v2.FailedPortlets;
+import org.oasis.wsrp.v2.InconsistentParameters;
+import org.oasis.wsrp.v2.InvalidHandle;
import org.oasis.wsrp.v2.Lifetime;
+import org.oasis.wsrp.v2.OperationNotSupported;
import org.oasis.wsrp.v2.Property;
import org.oasis.wsrp.v2.PropertyList;
import org.oasis.wsrp.v2.RegistrationContext;
@@ -318,11 +322,44 @@
return new SimplePropertyMap();
}
}
+ catch (OperationNotSupported operationNotSupported)
+ {
+ throw new UnsupportedOperationException(operationNotSupported);
+ }
+ catch (InvalidHandle invalidHandle)
+ {
+ throw new InvalidPortletIdException(invalidHandle, portletContext.getId());
+ }
+ catch (InconsistentParameters inconsistentParameters)
+ {
+ throw new IllegalArgumentException(inconsistentParameters);
+ }
+ /*
+ // GTNWSRP-62
+ catch (InvalidRegistration invalidRegistration)
+ {
+ }
+ catch (MissingParameters missingParameters)
+ {
+ }
+ catch (ResourceSuspended resourceSuspended)
+ {
+ }
+ catch (OperationFailed operationFailed)
+ {
+ }
+ catch (AccessDenied accessDenied)
+ {
+ }
+ catch (InvalidUserCategory invalidUserCategory)
+ {
+ }
+ catch (ModifyRegistrationRequired modifyRegistrationRequired)
+ {
+ }*/
catch (Exception e)
{
- // something went wrong but support for getPortletProperties is optional so
return an empty PropertyMap
- log.debug("Couldn't get properties for portlet '" +
portletContext.getId() + "'", e);
- return new SimplePropertyMap();
+ throw new PortletInvokerException(e);
}
}
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v1/PortletManagementTestCase.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v1/PortletManagementTestCase.java 2010-08-27
06:38:36 UTC (rev 3950)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v1/PortletManagementTestCase.java 2010-08-27
12:49:41 UTC (rev 3951)
@@ -27,7 +27,10 @@
import org.gatein.pc.api.PortletContext;
import org.gatein.pc.api.PortletInvokerException;
import org.gatein.pc.api.PortletStateType;
+import org.gatein.pc.api.info.MetaInfo;
import org.gatein.pc.api.state.DestroyCloneFailure;
+import org.gatein.pc.api.state.PropertyChange;
+import org.gatein.pc.api.state.PropertyMap;
import org.gatein.wsrp.test.ExtendedAssert;
import org.gatein.wsrp.test.protocol.v1.BehaviorRegistry;
import org.gatein.wsrp.test.protocol.v1.behaviors.BasicMarkupBehavior;
@@ -48,10 +51,10 @@
{
}
- /*public void testClone() throws Exception
+ public void testClone() throws Exception
{
PortletContext original =
PortletContext.createPortletContext(BasicMarkupBehavior.PORTLET_HANDLE);
- PortletContext clone = consumer.createClone(original);
+ PortletContext clone = consumer.createClone(PortletStateType.OPAQUE, original);
ExtendedAssert.assertNotNull(clone);
ExtendedAssert.assertFalse(original.equals(clone));
ExtendedAssert.assertEquals(BasicPortletManagementBehavior.CLONED_HANDLE,
clone.getId());
@@ -74,14 +77,14 @@
PropertyMap props = consumer.getProperties(original);
checkProperties(props, BasicPortletManagementBehavior.PROPERTY_VALUE);
- PortletContext clone = consumer.createClone(original);
+ PortletContext clone = consumer.createClone(PortletStateType.OPAQUE, original);
props = consumer.getProperties(clone);
checkProperties(props, BasicPortletManagementBehavior.PROPERTY_VALUE);
consumer.setProperties(clone, new PropertyChange[]
{
PropertyChange.newUpdate(BasicPortletManagementBehavior.PROPERTY_NAME,
- new StringValue(BasicPortletManagementBehavior.PROPERTY_NEW_VALUE))
+ BasicPortletManagementBehavior.PROPERTY_NEW_VALUE)
});
checkProperties(consumer.getProperties(clone),
BasicPortletManagementBehavior.PROPERTY_NEW_VALUE);
@@ -92,13 +95,34 @@
checkProperties(consumer.getProperties(clone),
BasicPortletManagementBehavior.PROPERTY_VALUE);
}
+ public void testSetResetSameProperty() throws PortletInvokerException
+ {
+ PortletContext original =
PortletContext.createPortletContext(BasicMarkupBehavior.PORTLET_HANDLE);
+ PortletContext clone = consumer.createClone(PortletStateType.OPAQUE, original);
+
+ try
+ {
+ consumer.setProperties(clone, new PropertyChange[]
+ {
+ PropertyChange.newUpdate(BasicPortletManagementBehavior.PROPERTY_NAME,
+ BasicPortletManagementBehavior.PROPERTY_NEW_VALUE),
+ PropertyChange.newReset(BasicPortletManagementBehavior.PROPERTY_NAME)
+ });
+ fail("Shouldn't be possible to set and reset the same property in the
same call");
+ }
+ catch (Exception e)
+ {
+
assertTrue(e.getCause().getLocalizedMessage().contains(BasicPortletManagementBehavior.CANNOT_BOTH_SET_AND_RESET_A_PROPERTY_AT_THE_SAME_TIME));
+ }
+ }
+
private void checkProperties(PropertyMap props, String expectedValue)
{
ExtendedAssert.assertNotNull(props);
ExtendedAssert.assertEquals(1, props.size());
ExtendedAssert.assertEquals(expectedValue,
- props.getProperty(BasicPortletManagementBehavior.PROPERTY_NAME).asString());
- }*/
+ props.getProperty(BasicPortletManagementBehavior.PROPERTY_NAME).get(0));
+ }
public void testDestroyClones() throws Exception
{
@@ -144,7 +168,7 @@
}
}
- /*public void testInvalidSetProperties() throws Exception
+ public void testInvalidSetProperties() throws Exception
{
PortletContext original =
PortletContext.createPortletContext(BasicMarkupBehavior.PORTLET_HANDLE);
try
@@ -156,5 +180,5 @@
{
//expected
}
- }*/
+ }
}
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/PortletManagementTestCase.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/PortletManagementTestCase.java 2010-08-27
06:38:36 UTC (rev 3950)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/PortletManagementTestCase.java 2010-08-27
12:49:41 UTC (rev 3951)
@@ -27,7 +27,10 @@
import org.gatein.pc.api.PortletContext;
import org.gatein.pc.api.PortletInvokerException;
import org.gatein.pc.api.PortletStateType;
+import org.gatein.pc.api.info.MetaInfo;
import org.gatein.pc.api.state.DestroyCloneFailure;
+import org.gatein.pc.api.state.PropertyChange;
+import org.gatein.pc.api.state.PropertyMap;
import org.gatein.wsrp.test.ExtendedAssert;
import org.gatein.wsrp.test.protocol.v2.BehaviorRegistry;
import org.gatein.wsrp.test.protocol.v2.behaviors.BasicMarkupBehavior;
@@ -48,10 +51,10 @@
{
}
- /*public void testClone() throws Exception
+ public void testClone() throws Exception
{
PortletContext original =
PortletContext.createPortletContext(BasicMarkupBehavior.PORTLET_HANDLE);
- PortletContext clone = consumer.createClone(original);
+ PortletContext clone = consumer.createClone(PortletStateType.OPAQUE, original);
ExtendedAssert.assertNotNull(clone);
ExtendedAssert.assertFalse(original.equals(clone));
ExtendedAssert.assertEquals(BasicPortletManagementBehavior.CLONED_HANDLE,
clone.getId());
@@ -74,14 +77,14 @@
PropertyMap props = consumer.getProperties(original);
checkProperties(props, BasicPortletManagementBehavior.PROPERTY_VALUE);
- PortletContext clone = consumer.createClone(original);
+ PortletContext clone = consumer.createClone(PortletStateType.OPAQUE, original);
props = consumer.getProperties(clone);
checkProperties(props, BasicPortletManagementBehavior.PROPERTY_VALUE);
consumer.setProperties(clone, new PropertyChange[]
{
PropertyChange.newUpdate(BasicPortletManagementBehavior.PROPERTY_NAME,
- new StringValue(BasicPortletManagementBehavior.PROPERTY_NEW_VALUE))
+ BasicPortletManagementBehavior.PROPERTY_NEW_VALUE)
});
checkProperties(consumer.getProperties(clone),
BasicPortletManagementBehavior.PROPERTY_NEW_VALUE);
@@ -92,13 +95,33 @@
checkProperties(consumer.getProperties(clone),
BasicPortletManagementBehavior.PROPERTY_VALUE);
}
+ public void testSetResetSameProperty() throws PortletInvokerException
+ {
+ PortletContext original =
PortletContext.createPortletContext(BasicMarkupBehavior.PORTLET_HANDLE);
+ PortletContext clone = consumer.createClone(PortletStateType.OPAQUE, original);
+
+ try
+ {
+ consumer.setProperties(clone, new PropertyChange[]
+ {
+ PropertyChange.newUpdate(BasicPortletManagementBehavior.PROPERTY_NAME,
+ BasicPortletManagementBehavior.PROPERTY_NEW_VALUE),
+ PropertyChange.newReset(BasicPortletManagementBehavior.PROPERTY_NAME)
+ });
+ fail("Shouldn't be possible to set and reset the same property in the
same call");
+ }
+ catch (Exception e)
+ {
+
assertTrue(e.getCause().getLocalizedMessage().contains(BasicPortletManagementBehavior.CANNOT_BOTH_SET_AND_RESET_A_PROPERTY_AT_THE_SAME_TIME));
+ }
+ }
+
private void checkProperties(PropertyMap props, String expectedValue)
{
ExtendedAssert.assertNotNull(props);
ExtendedAssert.assertEquals(1, props.size());
- ExtendedAssert.assertEquals(expectedValue,
- props.getProperty(BasicPortletManagementBehavior.PROPERTY_NAME).asString());
- }*/
+ ExtendedAssert.assertEquals(expectedValue,
props.getProperty(BasicPortletManagementBehavior.PROPERTY_NAME).get(0));
+ }
public void testDestroyClones() throws Exception
{
@@ -144,7 +167,7 @@
}
}
- /*public void testInvalidSetProperties() throws Exception
+ public void testInvalidSetProperties() throws Exception
{
PortletContext original =
PortletContext.createPortletContext(BasicMarkupBehavior.PORTLET_HANDLE);
try
@@ -156,5 +179,5 @@
{
//expected
}
- }*/
+ }
}
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v1/behaviors/BasicPortletManagementBehavior.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v1/behaviors/BasicPortletManagementBehavior.java 2010-08-27
06:38:36 UTC (rev 3950)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v1/behaviors/BasicPortletManagementBehavior.java 2010-08-27
12:49:41 UTC (rev 3951)
@@ -23,6 +23,7 @@
package org.gatein.wsrp.test.protocol.v1.behaviors;
+import org.gatein.common.util.ParameterValidation;
import org.gatein.wsrp.spec.v1.WSRP1ExceptionFactory;
import org.gatein.wsrp.spec.v1.WSRP1TypeFactory;
import org.gatein.wsrp.test.protocol.v1.BehaviorRegistry;
@@ -63,7 +64,9 @@
public static final String PROPERTY_VALUE = "value1";
public static final String PROPERTY_NEW_VALUE = "value2";
public static final String CLONED_HANDLE = BasicMarkupBehavior.PORTLET_HANDLE +
CLONE_SUFFIX;
+ public static final String CANNOT_BOTH_SET_AND_RESET_A_PROPERTY_AT_THE_SAME_TIME =
"Cannot both set and reset a property at the same time!";
private BehaviorRegistry registry;
+ private String propValue = PROPERTY_VALUE;
public BasicPortletManagementBehavior(BehaviorRegistry registry)
{
@@ -125,18 +128,18 @@
}
else if (CLONED_HANDLE.equals(handle))
{
- if (callCount != 2)
+ if (propValue != null)
{
- propertyList.add(WSRP1TypeFactory.createProperty(PROPERTY_NAME,
"en", PROPERTY_VALUE));
+ propertyList.add(WSRP1TypeFactory.createProperty(PROPERTY_NAME,
"en", propValue));
}
- else
+ if (callCount > 4)
{
- propertyList.add(WSRP1TypeFactory.createProperty(PROPERTY_NAME,
"en", PROPERTY_NEW_VALUE));
+ throw new IllegalStateException("Shouldn't have been called more
than four times!");
}
}
else
{
- WSRP1ExceptionFactory.throwWSException(V1OperationFailed.class, "Cannot
modify portlet '" + handle + "'", null);
+ WSRP1ExceptionFactory.throwWSException(V1InvalidHandle.class, "Unknown
handle '" + handle + "'", null);
}
incrementCallCount();
@@ -153,6 +156,64 @@
throw WSRP1ExceptionFactory.throwWSException(V1OperationFailed.class,
"Cannot modify portlet '" + handle + "'", null);
}
+ List<V1Property> properties = propertyList.getProperties();
+ List<V1ResetProperty> resetProperties = propertyList.getResetProperties();
+
+ // check that we don't try to set and reset the same property
+ if (ParameterValidation.existsAndIsNotEmpty(properties) &&
ParameterValidation.existsAndIsNotEmpty(resetProperties))
+ {
+ if (properties.size() != 1 && resetProperties.size() != 1)
+ {
+ WSRP1ExceptionFactory.throwWSException(V1InconsistentParameters.class,
"Invalid number of properties!", null);
+ }
+
+ if (properties.get(0).getName().equals(resetProperties.get(0).getName()))
+ {
+ WSRP1ExceptionFactory.throwWSException(V1InconsistentParameters.class,
CANNOT_BOTH_SET_AND_RESET_A_PROPERTY_AT_THE_SAME_TIME, null);
+ }
+ }
+
+ // if we have the expected property name, update the value
+ if (ParameterValidation.existsAndIsNotEmpty(properties))
+ {
+ if (properties.size() != 1)
+ {
+ WSRP1ExceptionFactory.throwWSException(V1InconsistentParameters.class,
"Invalid number of properties!", null);
+ }
+
+ V1Property property = properties.get(0);
+ String name = property.getName();
+ if (name.equals(PROPERTY_NAME))
+ {
+ propValue = property.getStringValue();
+ }
+ else
+ {
+ WSRP1ExceptionFactory.throwWSException(V1InconsistentParameters.class,
"Unknown property '" + name + "'", null);
+ }
+ }
+
+ // if we have the proper reset property, reset it
+ if (ParameterValidation.existsAndIsNotEmpty(resetProperties))
+ {
+ if (resetProperties.size() != 1)
+ {
+ WSRP1ExceptionFactory.throwWSException(V1InconsistentParameters.class,
"Invalid number of reset properties!", null);
+ }
+
+ V1ResetProperty resetProperty = resetProperties.get(0);
+ String name = resetProperty.getName();
+ if (name.equals(PROPERTY_NAME))
+ {
+ propValue = PROPERTY_VALUE;
+ }
+ else
+ {
+ WSRP1ExceptionFactory.throwWSException(V1InconsistentParameters.class,
"Unknown property '" + name + "'", null);
+ }
+ }
+
+
portletHandle.value = handle;
}
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/behaviors/BasicPortletManagementBehavior.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/behaviors/BasicPortletManagementBehavior.java 2010-08-27
06:38:36 UTC (rev 3950)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/behaviors/BasicPortletManagementBehavior.java 2010-08-27
12:49:41 UTC (rev 3951)
@@ -24,6 +24,7 @@
package org.gatein.wsrp.test.protocol.v2.behaviors;
import org.gatein.common.NotYetImplemented;
+import org.gatein.common.util.ParameterValidation;
import org.gatein.wsrp.WSRPTypeFactory;
import org.gatein.wsrp.spec.v2.ErrorCodes;
import org.gatein.wsrp.spec.v2.WSRP2ExceptionFactory;
@@ -63,6 +64,7 @@
import org.oasis.wsrp.v2.UserContext;
import javax.jws.WebParam;
+import javax.xml.namespace.QName;
import javax.xml.ws.Holder;
import java.util.ArrayList;
import java.util.List;
@@ -79,7 +81,9 @@
public static final String PROPERTY_VALUE = "value1";
public static final String PROPERTY_NEW_VALUE = "value2";
public static final String CLONED_HANDLE = BasicMarkupBehavior.PORTLET_HANDLE +
CLONE_SUFFIX;
+ public static final String CANNOT_BOTH_SET_AND_RESET_A_PROPERTY_AT_THE_SAME_TIME =
"Cannot both set and reset a property at the same time!";
private BehaviorRegistry registry;
+ private String propValue = PROPERTY_VALUE;
public BasicPortletManagementBehavior(BehaviorRegistry registry)
{
@@ -213,6 +217,64 @@
throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class, "Cannot
modify portlet '" + handle + "'", null);
}
+ List<Property> properties = propertyList.getProperties();
+ List<ResetProperty> resetProperties = propertyList.getResetProperties();
+
+ // check that we don't try to set and reset the same property
+ if (ParameterValidation.existsAndIsNotEmpty(properties) &&
ParameterValidation.existsAndIsNotEmpty(resetProperties))
+ {
+ if (properties.size() != 1 && resetProperties.size() != 1)
+ {
+ WSRP2ExceptionFactory.throwWSException(InconsistentParameters.class,
"Invalid number of properties!", null);
+ }
+
+ if (properties.get(0).getName().equals(resetProperties.get(0).getName()))
+ {
+ WSRP2ExceptionFactory.throwWSException(InconsistentParameters.class,
CANNOT_BOTH_SET_AND_RESET_A_PROPERTY_AT_THE_SAME_TIME, null);
+ }
+ }
+
+ // if we have the expected property name, update the value
+ if (ParameterValidation.existsAndIsNotEmpty(properties))
+ {
+ if (properties.size() != 1)
+ {
+ WSRP2ExceptionFactory.throwWSException(InconsistentParameters.class,
"Invalid number of properties!", null);
+ }
+
+ Property property = properties.get(0);
+ QName name = property.getName();
+ if (name.getLocalPart().equals(PROPERTY_NAME))
+ {
+ propValue = property.getStringValue();
+ }
+ else
+ {
+ WSRP2ExceptionFactory.throwWSException(InconsistentParameters.class,
"Unknown property '" + name + "'", null);
+ }
+ }
+
+ // if we have the proper reset property, reset it
+ if (ParameterValidation.existsAndIsNotEmpty(resetProperties))
+ {
+ if (resetProperties.size() != 1)
+ {
+ WSRP2ExceptionFactory.throwWSException(InconsistentParameters.class,
"Invalid number of reset properties!", null);
+ }
+
+ ResetProperty resetProperty = resetProperties.get(0);
+ QName name = resetProperty.getName();
+ if (name.getLocalPart().equals(PROPERTY_NAME))
+ {
+ propValue = PROPERTY_VALUE;
+ }
+ else
+ {
+ WSRP2ExceptionFactory.throwWSException(InconsistentParameters.class,
"Unknown property '" + name + "'", null);
+ }
+ }
+
+
portletHandle.value = handle;
}
@@ -229,13 +291,13 @@
}
else if (CLONED_HANDLE.equals(handle))
{
- if (callCount != 2)
+ if (propValue != null)
{
- propertyList.add(WSRPTypeFactory.createProperty(PROPERTY_NAME,
"en", PROPERTY_VALUE));
+ propertyList.add(WSRPTypeFactory.createProperty(PROPERTY_NAME,
"en", propValue));
}
- else
+ if (callCount > 4)
{
- propertyList.add(WSRPTypeFactory.createProperty(PROPERTY_NAME,
"en", PROPERTY_NEW_VALUE));
+ throw new IllegalStateException("Shouldn't have been called more
than four times!");
}
}
else
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/PortletManagementHandler.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/PortletManagementHandler.java 2010-08-27
06:38:36 UTC (rev 3950)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/PortletManagementHandler.java 2010-08-27
12:49:41 UTC (rev 3951)
@@ -23,12 +23,14 @@
package org.gatein.wsrp.producer.handlers;
+import com.google.common.base.Function;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import org.gatein.common.NotYetImplemented;
import org.gatein.common.i18n.LocalizedString;
import org.gatein.common.logging.Logger;
import org.gatein.common.logging.LoggerFactory;
+import org.gatein.common.util.ParameterValidation;
import org.gatein.exports.data.ExportContext;
import org.gatein.exports.data.ExportPortletData;
import org.gatein.pc.api.InvalidPortletIdException;
@@ -103,6 +105,7 @@
import org.oasis.wsrp.v2.SetPortletsLifetimeResponse;
import org.oasis.wsrp.v2.UserContext;
+import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -329,11 +332,36 @@
List<Property> properties = propertyList.getProperties();
List<ResetProperty> resetProperties = propertyList.getResetProperties();
int changesCount = 0;
- if (properties != null)
+ if (ParameterValidation.existsAndIsNotEmpty(properties))
{
changesCount += properties.size();
+
+ // check that we don't set and reset the same property
+ if (ParameterValidation.existsAndIsNotEmpty(resetProperties))
+ {
+ List<QName> names = new
ArrayList<QName>(WSRPUtils.transform(properties, new Function<Property,
QName>()
+ {
+ public QName apply(Property from)
+ {
+ return from.getName();
+ }
+ }));
+ names.retainAll(WSRPUtils.transform(resetProperties, new
Function<ResetProperty, QName>()
+ {
+ public QName apply(ResetProperty from)
+ {
+ return from.getName();
+ }
+ }));
+
+ if (!names.isEmpty())
+ {
+ WSRP2ExceptionFactory.throwWSException(InconsistentParameters.class,
+ "Attempted to set and reset at the same time the following
properties: " + names, null);
+ }
+ }
}
- if (resetProperties != null)
+ if (ParameterValidation.existsAndIsNotEmpty(resetProperties))
{
changesCount += resetProperties.size();
}
@@ -595,7 +623,7 @@
ResourceList resourceList = null;
byte[] exportContextBytes =
producer.getExportManager().encodeExportContextData(exportContext);
-
+
return WSRPTypeFactory.createExportPortletsResponse(exportContextBytes,
exportedPortlets, new ArrayList<FailedPortlets>(failedPortletsMap.values()),
exportContext.getLifeTime(), resourceList);
}
catch (Exception e)
@@ -747,7 +775,7 @@
{
WSRP2ExceptionFactory.throwWSException(OperationNotSupported.class, "This
producer does not support export by reference.", null);
}
-
+
WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(setExportLifetime,
"setExportLifetimePortlets");
byte[] exportContextBytes = setExportLifetime.getExportContext();
Modified:
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/PortletManagementTestCase.java
===================================================================
---
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/PortletManagementTestCase.java 2010-08-27
06:38:36 UTC (rev 3950)
+++
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/PortletManagementTestCase.java 2010-08-27
12:49:41 UTC (rev 3951)
@@ -90,27 +90,27 @@
jar.addClass(WSRPProducerBaseTest.class);
return jar;
}
-
+
@Before
public void setUp() throws Exception
{
if (System.getProperty("test.deployables.dir") != null)
{
- super.setUp();
- //hack to get around having to have a httpservletrequest when accessing the
producer services
- //I don't know why its really needed, seems to be a dependency where wsrp
connects with the pc module
-
ServletAccess.setRequestAndResponse(MockHttpServletRequest.createMockRequest(null),
MockHttpServletResponse.createMockResponse());
+ super.setUp();
+ //hack to get around having to have a httpservletrequest when accessing the
producer services
+ //I don't know why its really needed, seems to be a dependency where wsrp
connects with the pc module
+
ServletAccess.setRequestAndResponse(MockHttpServletRequest.createMockRequest(null),
MockHttpServletResponse.createMockResponse());
}
}
-
-
+
+
@After
public void tearDown() throws Exception
{
- if (System.getProperty("test.deployables.dir") != null)
- {
- super.tearDown();
- }
+ if (System.getProperty("test.deployables.dir") != null)
+ {
+ super.tearDown();
+ }
}
@Test
@@ -180,7 +180,7 @@
response = producer.destroyPortlets(destroyPortlets);
ExtendedAssert.assertNotNull(response);
failures = response.getDestroyFailed();
-
+
ExtendedAssert.assertTrue("Got back failures when none expected :" +
failures, (failures == null || failures.isEmpty()));
}
@@ -350,6 +350,28 @@
}
@Test
+ public void testSetResetSamePortletProperty() throws Exception
+ {
+ String handle = getDefaultHandle();
+
+ V1PortletContext portletContext = clonePortlet(handle);
+ V1PropertyList propertyList = WSRP1TypeFactory.createPropertyList();
+
propertyList.getProperties().add(WSRP1TypeFactory.createProperty("prefName1",
"en", "newPrefValue1"));
+
propertyList.getResetProperties().add(WSRP1TypeFactory.createResetProperty("prefName1"));
+ V1SetPortletProperties setPortletProperties =
WSRP1TypeFactory.createSetPortletProperties(null, portletContext, propertyList);
+
+ try
+ {
+ producer.setPortletProperties(setPortletProperties);
+ fail("Shouldn't be possible to set and reset a property in the same
call");
+ }
+ catch (V1InconsistentParameters v1InconsistentParameters)
+ {
+ // expected
+ }
+ }
+
+ @Test
public void testSetPortletPropertiesNoRegistrationWhenRequired()
{
producer.getConfigurationService().getConfiguration().getRegistrationRequirements().setRegistrationRequired(true);