Author: chris.laprun(a)jboss.com
Date: 2006-12-13 17:47:58 -0500 (Wed, 13 Dec 2006)
New Revision: 5852
Modified:
trunk/common/src/main/org/jboss/portal/common/junit/ExtendedAssert.java
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/WSRPBaseTest.java
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/MarkupTestCase.java
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/PortletManagementTestCase.java
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/V1ProducerBaseTest.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPTypeFactory.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/PortletManagementHandler.java
Log:
- Moved assert methods and support classes from WSRPBaseTest to ExtendedAssert.
- Added test for getPortletPropertyDescription and fixed a bug in implementation.
- Added creation methods to WSRPTypeFactory.
- Minor other code improvements.
Modified: trunk/common/src/main/org/jboss/portal/common/junit/ExtendedAssert.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/junit/ExtendedAssert.java 2006-12-13
22:16:24 UTC (rev 5851)
+++ trunk/common/src/main/org/jboss/portal/common/junit/ExtendedAssert.java 2006-12-13
22:47:58 UTC (rev 5852)
@@ -25,6 +25,7 @@
import junit.framework.Assert;
import java.util.Arrays;
+import java.util.List;
/**
* Add more assert methods.
@@ -35,17 +36,13 @@
public class ExtendedAssert extends Assert
{
- /**
- * @see #assertEquals(Object[], Object[])
- */
+ /** @see #assertEquals(Object[],Object[]) */
public static void assertEquals(Object[] expected, Object[] actual)
{
assertEquals(null, (Object[])expected, (Object[])actual);
}
- /**
- * Test equality as defined by java.util.Array#equals(Object[], Object[]).
- */
+ /** Test equality as defined by java.util.Array#equals(Object[], Object[]). */
public static void assertEquals(String message, Object[] expected, Object[] actual)
{
if (Arrays.equals(expected, actual))
@@ -55,17 +52,13 @@
fail(format(message, expected, actual));
}
- /**
- * @see #assertEquals(byte[], byte[])
- */
+ /** @see #assertEquals(byte[],byte[]) */
public static void assertEquals(byte[] expected, byte[] actual)
{
assertEquals(null, expected, actual);
}
- /**
- * Test equality as defined by java.util.Array#equals(Object[], Object[]).
- */
+ /** Test equality as defined by java.util.Array#equals(Object[], Object[]). */
public static void assertEquals(String message, byte[] expected, byte[] actual)
{
if (Arrays.equals(expected, actual))
@@ -75,8 +68,9 @@
fail(format(message, expected, actual));
}
- private static String format(String message, Object expected, Object actual) {
- String formatted= "";
+ private static String format(String message, Object expected, Object actual)
+ {
+ String formatted = "";
if (message != null)
{
formatted = message + " ";
@@ -103,4 +97,109 @@
}
}
+ public static void assertEquals(Object[] expected, Object[] tested, boolean
isOrderRelevant, String failMessage)
+ {
+ if (isOrderRelevant)
+ {
+ if (!Arrays.equals(expected, tested))
+ {
+ fail(failMessage);
+ }
+ }
+ else
+ {
+ boolean equals = (expected == tested);
+
+ if (!equals)
+ {
+ if (expected == null || tested == null)
+ {
+ fail(failMessage + " Not both null.");
+ }
+
+ if (expected.getClass().getComponentType() !=
tested.getClass().getComponentType())
+ {
+ fail(failMessage + " Different classes.");
+ }
+
+ if (expected.length != tested.length)
+ {
+ fail(failMessage + " Different sizes (tested: " + tested.length
+ ", expected: " + expected.length + ").");
+ }
+
+ List expectedList = Arrays.asList(expected);
+ List testedList = Arrays.asList(tested);
+ if (!expectedList.containsAll(testedList))
+ {
+ fail(failMessage);
+ }
+ }
+ }
+ }
+
+ public static void assertEquals(Object[] expected, Object[] tested, boolean
isOrderRelevant, String failMessage, Decorator decorator)
+ {
+ Object[] decoratedExpected = null, decoratedTested = null;
+ if (decorator != null)
+ {
+ decoratedExpected = decorate(expected, decorator);
+ decoratedTested = decorate(tested, decorator);
+ }
+
+ assertEquals(decoratedExpected, decoratedTested, isOrderRelevant, failMessage);
+ }
+
+ public static Object[] decorate(Object[] toBeDecorated, Decorator decorator)
+ {
+ if (toBeDecorated != null)
+ {
+ DecoratedObject[] decorated = new DecoratedObject[toBeDecorated.length];
+ for (int i = 0; i < decorated.length; i++)
+ {
+ decorated[i] = new DecoratedObject(toBeDecorated[i], decorator);
+ }
+ return decorated;
+ }
+ return null;
+
+ }
+
+ public static void assertString1ContainsString2(String string1, String string2)
+ {
+ assertTrue("<" + string1 + "> does not contain <" +
string2 + ">", string1.indexOf(string2) >= 0);
+ }
+
+ public static interface Decorator
+ {
+ void decorate(Object decorated);
+ }
+
+ public static class DecoratedObject
+ {
+ private Decorator decorator;
+ private Object decorated;
+
+ public Object getDecorated()
+ {
+ return decorated;
+ }
+
+ public DecoratedObject(Object decorated, Decorator decorator)
+ {
+ this.decorator = decorator;
+ this.decorated = decorated;
+ }
+
+ public boolean equals(Object obj)
+ {
+ decorator.decorate(decorated);
+ return decorator.equals(obj);
+ }
+
+ public String toString()
+ {
+ decorator.decorate(decorated);
+ return decorator.toString();
+ }
+ }
}
Modified: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/WSRPBaseTest.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/test/wsrp/WSRPBaseTest.java 2006-12-13 22:16:24
UTC (rev 5851)
+++ trunk/wsrp/src/main/org/jboss/portal/test/wsrp/WSRPBaseTest.java 2006-12-13 22:47:58
UTC (rev 5852)
@@ -30,20 +30,16 @@
package org.jboss.portal.test.wsrp;
import org.jboss.logging.Logger;
-import org.jboss.portal.test.framework.driver.http.HttpTestContext;
-import org.jboss.portal.test.framework.driver.http.HttpTestDriverServer;
-import org.jboss.portal.test.framework.server.driver.HttpTestDriverRegistry;
-import org.jboss.portal.jems.as.system.AbstractJBossService;
-import org.jboss.portal.common.test.driver.DriverResponse;
import org.jboss.portal.common.test.driver.DriverCommand;
+import org.jboss.portal.common.test.driver.DriverResponse;
import org.jboss.portal.common.test.driver.TestDriverException;
import org.jboss.portal.common.test.info.TestItemInfo;
import org.jboss.portal.common.test.junit.POJOJUnitTest;
-import org.jboss.portal.common.junit.ExtendedAssert;
+import org.jboss.portal.jems.as.system.AbstractJBossService;
+import org.jboss.portal.test.framework.driver.http.HttpTestContext;
+import org.jboss.portal.test.framework.driver.http.HttpTestDriverServer;
+import org.jboss.portal.test.framework.server.driver.HttpTestDriverRegistry;
-import java.util.Arrays;
-import java.util.List;
-
/**
* Base Class for all WSRP Test Cases
*
@@ -112,112 +108,6 @@
{
}
- public static void assertEquals(Object[] expected, Object[] tested, boolean
isOrderRelevant, String failMessage)
- {
- if (isOrderRelevant)
- {
- if (!Arrays.equals(expected, tested))
- {
- ExtendedAssert.fail(failMessage);
- }
- }
- else
- {
- boolean equals = (expected == tested);
-
- if (!equals)
- {
- if (expected == null || tested == null)
- {
- ExtendedAssert.fail(failMessage + " Not both null.");
- }
-
- if (expected.getClass().getComponentType() !=
tested.getClass().getComponentType())
- {
- ExtendedAssert.fail(failMessage + " Different classes.");
- }
-
- if (expected.length != tested.length)
- {
- ExtendedAssert.fail(failMessage + " Different sizes (tested: " +
tested.length + ", expected: " + expected.length + ").");
- }
-
- List expectedList = Arrays.asList(expected);
- List testedList = Arrays.asList(tested);
- if (!expectedList.containsAll(testedList))
- {
- ExtendedAssert.fail(failMessage);
- }
- }
- }
- }
-
- public static void assertEquals(Object[] expected, Object[] tested, boolean
isOrderRelevant, String failMessage, Decorator decorator)
- {
- Object[] decoratedExpected = null, decoratedTested = null;
- if (decorator != null)
- {
- decoratedExpected = decorate(expected, decorator);
- decoratedTested = decorate(tested, decorator);
- }
-
- assertEquals(decoratedExpected, decoratedTested, isOrderRelevant, failMessage);
- }
-
- private static Object[] decorate(Object[] toBeDecorated, Decorator decorator)
- {
- if (toBeDecorated != null)
- {
- DecoratedObject[] decorated = new DecoratedObject[toBeDecorated.length];
- for (int i = 0; i < decorated.length; i++)
- {
- decorated[i] = new DecoratedObject(toBeDecorated[i], decorator);
- }
- return decorated;
- }
- return null;
-
- }
-
- public static interface Decorator
- {
- void decorate(Object decorated);
- }
-
- public static class DecoratedObject
- {
- private Decorator decorator;
- private Object decorated;
-
- public Object getDecorated()
- {
- return decorated;
- }
-
- public DecoratedObject(Object decorated, Decorator decorator)
- {
- this.decorator = decorator;
- this.decorated = decorated;
- }
-
- public boolean equals(Object obj)
- {
- decorator.decorate(decorated);
- return decorator.equals(obj);
- }
-
- public String toString()
- {
- decorator.decorate(decorated);
- return decorator.toString();
- }
- }
-
- public static void assertString1ContainsString2(String string1, String string2)
- {
- ExtendedAssert.assertTrue("<" + string1 + "> does not contain
<" + string2 + ">", string1.indexOf(string2) >= 0);
- }
-
protected void deploy(String archiveId) throws Exception
{
context.deploy(archiveId);
Modified: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/MarkupTestCase.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/MarkupTestCase.java 2006-12-13
22:16:24 UTC (rev 5851)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/MarkupTestCase.java 2006-12-13
22:47:58 UTC (rev 5852)
@@ -114,8 +114,8 @@
String julienLink = extractLink(markupString, 0);
WSRPPortletURL julienURL = WSRPPortletURL.create(julienLink);
- assertString1ContainsString2(markupString, "Hello, Anonymous!");
- assertString1ContainsString2(markupString, "Counter: 0");
+ ExtendedAssert.assertString1ContainsString2(markupString, "Hello,
Anonymous!");
+ ExtendedAssert.assertString1ContainsString2(markupString, "Counter: 0");
ExtendedAssert.assertTrue(julienURL instanceof WSRPRenderURL);
WSRPRenderURL julienRender = (WSRPRenderURL)julienURL;
@@ -124,7 +124,7 @@
gm.getMarkupParams().setNavigationalState(julienRender.getNavigationalState().getStringValue());
res = markupService.getMarkup(gm);
markupString = res.getMarkupContext().getMarkupString();
- assertString1ContainsString2(markupString, "Hello, Julien!");
+ ExtendedAssert.assertString1ContainsString2(markupString, "Hello,
Julien!");
// julien.length() * 2 to bypass second link
WSRPPortletURL incrementURL = WSRPPortletURL.create(extractLink(markupString,
julienLink.length() * 2));
@@ -139,7 +139,7 @@
markupService.performBlockingInteraction(performBlockingInteraction);
res = markupService.getMarkup(gm);
markupString = res.getMarkupContext().getMarkupString();
- assertString1ContainsString2(markupString, "Counter: 1");
+ ExtendedAssert.assertString1ContainsString2(markupString, "Counter: 1");
undeploy(archiveName);
}
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/PortletManagementTestCase.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/PortletManagementTestCase.java 2006-12-13
22:16:24 UTC (rev 5851)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/PortletManagementTestCase.java 2006-12-13
22:47:58 UTC (rev 5852)
@@ -24,11 +24,16 @@
package org.jboss.portal.test.wsrp.v1.producer;
import org.jboss.portal.common.junit.ExtendedAssert;
+import org.jboss.portal.wsrp.WSRPConstants;
import org.jboss.portal.wsrp.WSRPTypeFactory;
import org.jboss.portal.wsrp.core.GetPortletDescription;
import org.jboss.portal.wsrp.core.GetPortletProperties;
+import org.jboss.portal.wsrp.core.GetPortletPropertyDescription;
+import org.jboss.portal.wsrp.core.ModelDescription;
import org.jboss.portal.wsrp.core.PortletDescriptionResponse;
+import org.jboss.portal.wsrp.core.PortletPropertyDescriptionResponse;
import org.jboss.portal.wsrp.core.Property;
+import org.jboss.portal.wsrp.core.PropertyDescription;
import org.jboss.portal.wsrp.core.PropertyList;
import javax.xml.soap.SOAPElement;
@@ -78,8 +83,8 @@
PropertyList response =
portletManagementService.getPortletProperties(getPortletProperties);
Property[] expected = new Property[]{
- new Property("prefName1", "en", "prefValue1",
null),
- new Property("prefName2", "en", "prefValue2",
null)
+ WSRPTypeFactory.createProperty("prefName1", "en",
"prefValue1"),
+ WSRPTypeFactory.createProperty("prefName2", "en",
"prefValue2")
};
checkGetPropertiesResponse(response, expected);
@@ -89,7 +94,7 @@
getPortletProperties.setNames(new String[]{"prefName2"});
response = portletManagementService.getPortletProperties(getPortletProperties);
- expected = new Property[]{new Property("prefName2", "en",
"prefValue2", null)};
+ expected = new Property[]{WSRPTypeFactory.createProperty("prefName2",
"en", "prefValue2")};
checkGetPropertiesResponse(response, expected);
}
@@ -97,13 +102,48 @@
{
ExtendedAssert.assertNotNull(response);
Property[] properties = response.getProperties();
- assertEquals(expected, properties, false, "Didn't receive expected
properties!", new PropertyDecorator());
+ ExtendedAssert.assertEquals(expected, properties, false, "Didn't receive
expected properties!", new PropertyDecorator());
return properties;
}
- public void testGetPortletPropertyDescription()
+ public void testGetPortletPropertyDescription() throws Exception
{
- // todo: implement
+ String handle = getDefaultHandle();
+ GetPortletPropertyDescription getPortletPropertyDescription =
WSRPTypeFactory.createSimpleGetPortletPropertyDescription(handle);
+
+ PortletPropertyDescriptionResponse response =
portletManagementService.getPortletPropertyDescription(getPortletPropertyDescription);
+
+ ModelDescription desc = response.getModelDescription();
+ ExtendedAssert.assertNotNull(desc);
+ PropertyDescription[] propertyDescriptions = desc.getPropertyDescriptions();
+ ExtendedAssert.assertNotNull(propertyDescriptions);
+
+ PropertyDescription[] expected = new PropertyDescription[2];
+ expected[0] = WSRPTypeFactory.createPropertyDescription("prefName1",
WSRPConstants.XSD_STRING);
+ expected[0].setHint(WSRPTypeFactory.createLocalizedString("prefName1"));
+
expected[0].setLabel(WSRPTypeFactory.createLocalizedString("prefName1"));
+ expected[1] = WSRPTypeFactory.createPropertyDescription("prefName2",
WSRPConstants.XSD_STRING);
+ expected[1].setHint(WSRPTypeFactory.createLocalizedString("prefName2"));
+
expected[1].setLabel(WSRPTypeFactory.createLocalizedString("prefName2"));
+
+ ExtendedAssert.assertEquals(2, propertyDescriptions.length);
+ PropertyDescription propDesc = propertyDescriptions[0];
+ ExtendedAssert.assertNotNull(propDesc);
+ String name = propDesc.getName();
+ if ("prefName1".equals(name))
+ {
+ assertEquals(expected[0], propDesc);
+ assertEquals(expected[1], propertyDescriptions[1]);
+ }
+ else if ("prefName2".equals(name))
+ {
+ assertEquals(expected[1], propDesc);
+ assertEquals(expected[0], propertyDescriptions[1]);
+ }
+ else
+ {
+ ExtendedAssert.fail("Unexpected PropertyDescription named '" +
name + "'");
+ }
}
public void testSetPortletProperties()
@@ -116,7 +156,7 @@
return TEST_BASIC_PORTLET_WAR;
}
- private static class PropertyDecorator implements Decorator
+ private static class PropertyDecorator implements ExtendedAssert.Decorator
{
private Property prop;
@@ -127,9 +167,9 @@
public boolean equals(Object o)
{
- if (o instanceof DecoratedObject)
+ if (o instanceof ExtendedAssert.DecoratedObject)
{
- DecoratedObject decoratedObject = (DecoratedObject)o;
+ ExtendedAssert.DecoratedObject decoratedObject =
(ExtendedAssert.DecoratedObject)o;
Property that = (Property)decoratedObject.getDecorated();
String name = prop.getName();
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/V1ProducerBaseTest.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/V1ProducerBaseTest.java 2006-12-13
22:16:24 UTC (rev 5851)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/V1ProducerBaseTest.java 2006-12-13
22:47:58 UTC (rev 5852)
@@ -195,10 +195,10 @@
}
- assertEquals(expected.getExtensions(), tested.getExtensions(), false, message +
"Extensions");
- assertEquals(expected.getLocales(), tested.getLocales(), false, message +
"Locales");
- assertEquals(expected.getModes(), tested.getModes(), false, message +
"Modes");
- assertEquals(expected.getWindowStates(), tested.getWindowStates(), false,
message + "Window states");
+ ExtendedAssert.assertEquals(expected.getExtensions(), tested.getExtensions(),
false, message + "Extensions");
+ ExtendedAssert.assertEquals(expected.getLocales(), tested.getLocales(), false,
message + "Locales");
+ ExtendedAssert.assertEquals(expected.getModes(), tested.getModes(), false,
message + "Modes");
+ ExtendedAssert.assertEquals(expected.getWindowStates(),
tested.getWindowStates(), false, message + "Window states");
}
}
@@ -213,7 +213,7 @@
ExtendedAssert.fail(message + "Different classes or not both
null.");
}
- assertEquals(expected.getExtensions(), tested.getExtensions(), false, message +
"Extensions");
+ ExtendedAssert.assertEquals(expected.getExtensions(), tested.getExtensions(),
false, message + "Extensions");
assertEquals(message + "Hint", expected.getHint(), tested.getHint());
assertEquals(message + "Label", expected.getLabel(),
tested.getLabel());
ExtendedAssert.assertEquals(message + "Name", expected.getName(),
tested.getName());
@@ -227,7 +227,7 @@
{
if (expected == null || tested == null)
{
- ExtendedAssert.fail(message + "Different classes or not both
null.");
+ ExtendedAssert.fail(message + ": Different classes or not both
null.");
}
ExtendedAssert.assertEquals(expected.getLang(), tested.getLang());
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPTypeFactory.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPTypeFactory.java 2006-12-13 22:16:24 UTC
(rev 5851)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPTypeFactory.java 2006-12-13 22:47:58 UTC
(rev 5852)
@@ -38,6 +38,7 @@
import org.jboss.portal.wsrp.core.GetMarkup;
import org.jboss.portal.wsrp.core.GetPortletDescription;
import org.jboss.portal.wsrp.core.GetPortletProperties;
+import org.jboss.portal.wsrp.core.GetPortletPropertyDescription;
import org.jboss.portal.wsrp.core.GetServiceDescription;
import org.jboss.portal.wsrp.core.InitCookie;
import org.jboss.portal.wsrp.core.InteractionParams;
@@ -694,6 +695,7 @@
*/
public static PortletDescriptionResponse
createPortletDescriptionResponse(PortletDescription portletDescription)
{
+ ParameterValidation.throwIllegalArgExceptionIfNull(portletDescription,
"PortletDescription");
return new PortletDescriptionResponse(portletDescription, null, null);
}
@@ -706,6 +708,34 @@
*/
public static PortletPropertyDescriptionResponse
createPortletPropertyDescriptionResponse(PropertyDescription[] propertyDescriptions)
{
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(propertyDescriptions,
"PropertyDescriptions");
return new
PortletPropertyDescriptionResponse(createModelDescription(propertyDescriptions), null,
null);
}
+
+ /**
+ * registrationContext(RegistrationContext)?, portletContext(PortletContext),
userContext(UserContext)?,
+ * desiredLocales(xsd:string)*
+ *
+ * @return
+ * @since 2.6
+ */
+ public static GetPortletPropertyDescription
createGetPortletPropertyDescription(RegistrationContext registrationContext,
+
PortletContext portletContext,
+
UserContext userContext, String[] desiredLocales)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(portletContext,
"PortletContext");
+ return new GetPortletPropertyDescription(registrationContext, portletContext,
userContext, desiredLocales);
+ }
+
+ /**
+ * Same as createGetPortletPropertyDescription(null,
createPortletContext(portletHandle), null, null)
+ *
+ * @param portletHandle
+ * @return
+ * @since 2.6
+ */
+ public static GetPortletPropertyDescription
createSimpleGetPortletPropertyDescription(String portletHandle)
+ {
+ return createGetPortletPropertyDescription(null,
createPortletContext(portletHandle), null, null);
+ }
}
Modified:
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/PortletManagementHandler.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/PortletManagementHandler.java 2006-12-13
22:16:24 UTC (rev 5851)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/PortletManagementHandler.java 2006-12-13
22:47:58 UTC (rev 5852)
@@ -130,9 +130,9 @@
int index = 0;
for (Iterator keys = keySey.iterator(); keys.hasNext();)
{
- PreferenceInfo prefInfo = (PreferenceInfo)keys.next();
+ PreferenceInfo prefInfo = prefsInfo.getPreference((String)keys.next());
- // WSRP Spec 8.7: return only the portion of the Portlet's persistent
state is allowed to modify
+ // WSRP Spec 8.7: return only the portion of the Portlet's persistent
state the user is allowed to modify
if (!prefInfo.isReadOnly().booleanValue())
{
//todo: check what we should use key