Author: chris.laprun(a)jboss.com
Date: 2006-12-28 17:58:58 -0500 (Thu, 28 Dec 2006)
New Revision: 5939
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestWSRPProducerImpl.java
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/PortletManagementTestCase.java
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/behaviors/BasicPortletManagementBehavior.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java
Log:
- Added more PortletManagement tests for Consumer. One test doesn't pass since I need
to hook in clone detection on the Consumer.
- Temporary fix for language when creating Properties in WSRPConsumerImpl. Need a better
solution.
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestWSRPProducerImpl.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestWSRPProducerImpl.java 2006-12-28
02:59:43 UTC (rev 5938)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestWSRPProducerImpl.java 2006-12-28
22:58:58 UTC (rev 5939)
@@ -125,6 +125,8 @@
/** The current order in the sequence (number of times the methods have been called)
*/
private int sequenceOrder;
+ private PortletManagementBehavior portletManagementBehavior;
+
public static final String USER_COOKIE = "cookie";
public TestWSRPProducerImpl()
@@ -154,6 +156,7 @@
sequence = new SingleBehaviorSequence(new TestBehaviorSequence.TestBehaviorSet(new
BasicServiceDescriptionBehavior()));
sequenceOrder = 0;
+ portletManagementBehavior = new BasicPortletManagementBehavior();
}
// Behavior management
**********************************************************************************************
@@ -305,38 +308,44 @@
throws AccessDeniedFault, InvalidHandleFault, InvalidUserCategoryFault,
InconsistentParametersFault,
MissingParametersFault, InvalidRegistrationFault, OperationFailedFault,
RemoteException
{
+ PortletDescriptionResponse response =
portletManagementBehavior.getPortletDescription(getPortletDescription);
incrementBehaviorCallCount();
- return new
BasicPortletManagementBehavior().getPortletDescription(getPortletDescription);
+ return response;
}
public PortletContext clonePortlet(ClonePortlet clonePortlet) throws
InvalidUserCategoryFault, AccessDeniedFault, OperationFailedFault, InvalidHandleFault,
InvalidRegistrationFault, InconsistentParametersFault, MissingParametersFault,
RemoteException
{
+ PortletContext portletContext =
portletManagementBehavior.clonePortlet(clonePortlet);
incrementBehaviorCallCount();
- return new BasicPortletManagementBehavior().clonePortlet(clonePortlet);
+ return portletContext;
}
public DestroyPortletsResponse destroyPortlets(DestroyPortlets destroyPortlets) throws
InconsistentParametersFault, MissingParametersFault, InvalidRegistrationFault,
OperationFailedFault, RemoteException
{
+ DestroyPortletsResponse response =
portletManagementBehavior.destroyPortlets(destroyPortlets);
incrementBehaviorCallCount();
- return null;
+ return response;
}
public PortletContext setPortletProperties(SetPortletProperties setPortletProperties)
throws OperationFailedFault, InvalidHandleFault, MissingParametersFault,
InconsistentParametersFault, InvalidUserCategoryFault, AccessDeniedFault,
InvalidRegistrationFault, RemoteException
{
+ PortletContext portletContext =
portletManagementBehavior.setPortletProperties(setPortletProperties);
incrementBehaviorCallCount();
- return null;
+ return portletContext;
}
public PropertyList getPortletProperties(GetPortletProperties getPortletProperties)
throws InvalidHandleFault, MissingParametersFault, InvalidRegistrationFault,
AccessDeniedFault, OperationFailedFault, InconsistentParametersFault,
InvalidUserCategoryFault, RemoteException
{
+ PropertyList list =
portletManagementBehavior.getPortletProperties(getPortletProperties);
incrementBehaviorCallCount();
- return null;
+ return list;
}
public PortletPropertyDescriptionResponse
getPortletPropertyDescription(GetPortletPropertyDescription getPortletPropertyDescription)
throws MissingParametersFault, InconsistentParametersFault, InvalidUserCategoryFault,
InvalidRegistrationFault, AccessDeniedFault, InvalidHandleFault, OperationFailedFault,
RemoteException
{
+ PortletPropertyDescriptionResponse descriptionResponse =
portletManagementBehavior.getPortletPropertyDescription(getPortletPropertyDescription);
incrementBehaviorCallCount();
- return null;
+ return descriptionResponse;
}
// Producer implementation
******************************************************************************************
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/PortletManagementTestCase.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/PortletManagementTestCase.java 2006-12-28
02:59:43 UTC (rev 5938)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/PortletManagementTestCase.java 2006-12-28
22:58:58 UTC (rev 5939)
@@ -24,10 +24,15 @@
package org.jboss.portal.test.wsrp.v1.consumer;
import org.jboss.portal.common.junit.ExtendedAssert;
+import org.jboss.portal.common.value.StringValue;
import org.jboss.portal.portlet.Portlet;
import org.jboss.portal.portlet.PortletContext;
+import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.portlet.info.MetaInfo;
+import org.jboss.portal.portlet.state.PropertyChange;
+import org.jboss.portal.portlet.state.PropertyMap;
import org.jboss.portal.test.wsrp.v1.consumer.behaviors.BasicMarkupBehavior;
+import org.jboss.portal.test.wsrp.v1.consumer.behaviors.BasicPortletManagementBehavior;
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
@@ -46,6 +51,7 @@
PortletContext clone = consumer.createClone(original);
ExtendedAssert.assertNotNull(clone);
ExtendedAssert.assertFalse(original.equals(clone));
+ ExtendedAssert.assertEquals(BasicPortletManagementBehavior.CLONED_HANDLE,
clone.getId());
Portlet originalPortlet = consumer.getPortlet(original);
Portlet clonePortlet = consumer.getPortlet(clone);
@@ -61,16 +67,52 @@
public void testGetProperties() throws Exception
{
+ PortletContext original =
PortletContext.createPortletContext(BasicMarkupBehavior.PORTLET_HANDLE);
+ PropertyMap props = consumer.getProperties(original);
+ checkProperties(props, BasicPortletManagementBehavior.PROPERTY_VALUE);
+ PortletContext clone = consumer.createClone(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))
+ });
+ checkProperties(consumer.getProperties(clone),
BasicPortletManagementBehavior.PROPERTY_NEW_VALUE);
+
+ consumer.setProperties(clone, new PropertyChange[]
+ {
+ PropertyChange.newReset(BasicPortletManagementBehavior.PROPERTY_NAME)
+ });
+ checkProperties(consumer.getProperties(clone),
BasicPortletManagementBehavior.PROPERTY_VALUE);
}
+ private void checkProperties(PropertyMap props, String expectedValue)
+ {
+ ExtendedAssert.assertNotNull(props);
+ ExtendedAssert.assertEquals(1, props.size());
+ ExtendedAssert.assertEquals(expectedValue,
+ props.getProperty(BasicPortletManagementBehavior.PROPERTY_NAME).asString());
+ }
+
public void testDestroyClones() throws Exception
{
}
- public void testSetProperties() throws Exception
+ public void testInvalidSetProperties() throws Exception
{
-
+ PortletContext original =
PortletContext.createPortletContext(BasicMarkupBehavior.PORTLET_HANDLE);
+ try
+ {
+ consumer.setProperties(original, null);
+ ExtendedAssert.fail("Shouldn't be possible to set properties on
non-cloned portlet");
+ }
+ catch (PortletInvokerException expected)
+ {
+ //expected
+ }
}
}
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/behaviors/BasicPortletManagementBehavior.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/behaviors/BasicPortletManagementBehavior.java 2006-12-28
02:59:43 UTC (rev 5938)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/behaviors/BasicPortletManagementBehavior.java 2006-12-28
22:58:58 UTC (rev 5939)
@@ -29,6 +29,7 @@
import org.jboss.portal.wsrp.core.AccessDeniedFault;
import org.jboss.portal.wsrp.core.ClonePortlet;
import org.jboss.portal.wsrp.core.GetPortletDescription;
+import org.jboss.portal.wsrp.core.GetPortletProperties;
import org.jboss.portal.wsrp.core.InconsistentParametersFault;
import org.jboss.portal.wsrp.core.InvalidHandleFault;
import org.jboss.portal.wsrp.core.InvalidRegistrationFault;
@@ -37,6 +38,9 @@
import org.jboss.portal.wsrp.core.OperationFailedFault;
import org.jboss.portal.wsrp.core.PortletContext;
import org.jboss.portal.wsrp.core.PortletDescriptionResponse;
+import org.jboss.portal.wsrp.core.Property;
+import org.jboss.portal.wsrp.core.PropertyList;
+import org.jboss.portal.wsrp.core.SetPortletProperties;
import java.rmi.RemoteException;
@@ -47,22 +51,25 @@
*/
public class BasicPortletManagementBehavior extends PortletManagementBehavior
{
- public static final String CLONE_SUFFIX = "_clone";
+ private static final String CLONE_SUFFIX = "_clone";
+ public static final String PROPERTY_NAME = "prop1";
+ 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 PortletContext clonePortlet(ClonePortlet clonePortlet) throws
InvalidUserCategoryFault, AccessDeniedFault,
OperationFailedFault, InvalidHandleFault, InvalidRegistrationFault,
InconsistentParametersFault,
MissingParametersFault, RemoteException
{
WSRPUtils.throwOperationFailedFaultIfValueIsMissing(clonePortlet,
"ClonePortlet");
- PortletContext portletContext = clonePortlet.getPortletContext();
- WSRPUtils.throwMissingParametersFaultIfValueIsMissing(portletContext, "portlet
context", "ClonePortlet");
- String handle = portletContext.getPortletHandle();
- if (handle == null || handle.length() == 0 ||
!BasicMarkupBehavior.PORTLET_HANDLE.equals(handle))
+ String handle = getHandleFrom(clonePortlet.getPortletContext(),
"ClonePortlet");
+
+ if (!BasicMarkupBehavior.PORTLET_HANDLE.equals(handle))
{
throw (InvalidHandleFault)WSRPUtils.createFaultFrom(InvalidHandleFault.class,
null);
}
- return WSRPTypeFactory.createPortletContext(handle + CLONE_SUFFIX);
+ return WSRPTypeFactory.createPortletContext(CLONED_HANDLE);
}
@@ -71,10 +78,7 @@
MissingParametersFault, InvalidRegistrationFault, OperationFailedFault,
RemoteException
{
WSRPUtils.throwOperationFailedFaultIfValueIsMissing(getPortletDescription,
"GetPortletDescription");
- PortletContext portletContext = getPortletDescription.getPortletContext();
- WSRPUtils.throwMissingParametersFaultIfValueIsMissing(portletContext, "portlet
context", "GetPortletDescription");
- String handle = portletContext.getPortletHandle();
- WSRPUtils.throwMissingParametersFaultIfValueIsMissing(handle, "portlet
handle", "PortletContext");
+ String handle = getHandleFrom(getPortletDescription.getPortletContext(),
"GetPortletDescription");
String suffix;
if (handle.startsWith(BasicMarkupBehavior.PORTLET_HANDLE))
@@ -92,4 +96,63 @@
}
return
WSRPTypeFactory.createPortletDescriptionResponse(createPortletDescription(handle,
suffix));
}
+
+ public PropertyList getPortletProperties(GetPortletProperties getPortletProperties)
throws InvalidHandleFault, MissingParametersFault, InvalidRegistrationFault,
AccessDeniedFault, OperationFailedFault, InconsistentParametersFault,
InvalidUserCategoryFault, RemoteException
+ {
+ WSRPUtils.throwOperationFailedFaultIfValueIsMissing(getPortletProperties,
"GetPortletProperties");
+ String handle = getHandleFrom(getPortletProperties.getPortletContext(),
"GetPortletProperties");
+ PropertyList result = WSRPTypeFactory.createPropertyList();
+ if (BasicMarkupBehavior.PORTLET_HANDLE.equals(handle))
+ {
+ result.setProperties(new
Property[]{WSRPTypeFactory.createProperty(PROPERTY_NAME, "en",
PROPERTY_VALUE)});
+ }
+ else if (CLONED_HANDLE.equals(handle))
+ {
+ if (callCount != 2)
+ {
+ result.setProperties(new
Property[]{WSRPTypeFactory.createProperty(PROPERTY_NAME, "en",
PROPERTY_VALUE)});
+ }
+ else
+ {
+ result.setProperties(new
Property[]{WSRPTypeFactory.createProperty(PROPERTY_NAME, "en",
PROPERTY_NEW_VALUE)});
+ }
+ }
+ else
+ {
+ throw (InvalidHandleFault)WSRPUtils.createFaultFrom(InvalidHandleFault.class,
+ new IllegalArgumentException("Unknown handle '" + handle +
"'"));
+ }
+
+ incrementCallCount();
+ return result;
+ }
+
+
+ public PortletContext setPortletProperties(SetPortletProperties setPortletProperties)
throws OperationFailedFault,
+ InvalidHandleFault, MissingParametersFault, InconsistentParametersFault,
InvalidUserCategoryFault,
+ AccessDeniedFault, InvalidRegistrationFault, RemoteException
+ {
+ WSRPUtils.throwOperationFailedFaultIfValueIsMissing(setPortletProperties,
"SetPortletProperties");
+ String handle = getHandleFrom(setPortletProperties.getPortletContext(),
"SetPortletProperties");
+
+ if (!(CLONED_HANDLE).equals(handle))
+ {
+ throw WSRPUtils.createOperationFailedFault(new
IllegalArgumentException("Cannot modify portlet '" + handle +
"'"));
+ }
+
+ return setPortletProperties.getPortletContext();
+ }
+
+ private String getHandleFrom(PortletContext portletContext, String context) throws
MissingParametersFault, InvalidHandleFault
+ {
+ WSRPUtils.throwMissingParametersFaultIfValueIsMissing(portletContext, "portlet
context", context);
+ String handle = portletContext.getPortletHandle();
+ WSRPUtils.throwMissingParametersFaultIfValueIsMissing(handle, "portlet
handle", "PortletContext");
+ if (handle.length() == 0)
+ {
+ throw (InvalidHandleFault)WSRPUtils.createFaultFrom(InvalidHandleFault.class,
null);
+ }
+
+ return handle;
+ }
}
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java 2006-12-28
02:59:43 UTC (rev 5938)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java 2006-12-28
22:58:58 UTC (rev 5939)
@@ -23,6 +23,7 @@
package org.jboss.portal.wsrp.consumer;
import org.jboss.portal.common.invocation.InvocationException;
+import org.jboss.portal.common.util.LocaleInfo;
import org.jboss.portal.common.util.ParameterValidation;
import org.jboss.portal.common.value.StringValue;
import org.jboss.portal.jems.as.system.AbstractJBossService;
@@ -85,6 +86,7 @@
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.Set;
@@ -387,7 +389,9 @@
break;
case PropertyChange.PREF_UPDATE:
- updates.add(WSRPTypeFactory.createProperty(change.getKey(), null,
change.getValue().asString())); // todo: deal with language
+ // todo: deal with language more appropriately
+ updates.add(WSRPTypeFactory.createProperty(change.getKey(),
+ LocaleInfo.getRFC3066LanguageTagFor(Locale.getDefault()),
change.getValue().asString()));
break;
default: