[gatein-commits] gatein SVN: r4447 - in components/wsrp/trunk/common/src: test/java/org/gatein/wsrp/other and 1 other directory.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu Sep 30 14:47:13 EDT 2010
Author: mwringe
Date: 2010-09-30 14:47:13 -0400 (Thu, 30 Sep 2010)
New Revision: 4447
Modified:
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPResourceURL.java
components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/other/WSRPPortletURLTestCase.java
Log:
GTNWSRP-81: fix issues with throwing exceptions about missing parameters which are not actually required. Updated tests to test for this.
Modified: components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPResourceURL.java
===================================================================
--- components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPResourceURL.java 2010-09-30 15:24:53 UTC (rev 4446)
+++ components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPResourceURL.java 2010-09-30 18:47:13 UTC (rev 4447)
@@ -111,11 +111,6 @@
requiresRewrite = Boolean.valueOf(requireRewrite);
params.remove(WSRPRewritingConstants.RESOURCE_REQUIRES_REWRITE);
}
- else
- {
- throw new IllegalArgumentException("The parsed parameters don't contain a value for the required "
- + WSRPRewritingConstants.RESOURCE_REQUIRES_REWRITE + " parameter in " + originalURL);
- }
String url = getRawParameterValueFor(params, WSRPRewritingConstants.RESOURCE_URL);
if (url != null)
@@ -138,6 +133,13 @@
{
resourceId = resourceIDParam;
}
+
+ // we either need a resource Id or (requiredRewrite and url)
+ if (resourceIDParam == null && (requireRewrite == null || url == null))
+ {
+ throw new IllegalArgumentException("The parsed parameters don't are not valid for a resource url. It must contain either a "
+ + WSRP2RewritingConstants.RESOURCE_ID + " or " + WSRPRewritingConstants.RESOURCE_URL + " and " + WSRPRewritingConstants.RESOURCE_REQUIRES_REWRITE + " parameter in " + originalURL);
+ }
String preferOperationParam = getRawParameterValueFor(params, WSRP2RewritingConstants.RESOURCE_PREFER_OPERATION);
if (preferOperationParam != null)
Modified: components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/other/WSRPPortletURLTestCase.java
===================================================================
--- components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/other/WSRPPortletURLTestCase.java 2010-09-30 15:24:53 UTC (rev 4446)
+++ components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/other/WSRPPortletURLTestCase.java 2010-09-30 18:47:13 UTC (rev 4447)
@@ -112,6 +112,45 @@
assertEquals("false",resourceMap.get(WSRP2RewritingConstants.RESOURCE_PREFER_OPERATION));
}
+ public void testResourcesNoRequiresRewrite()
+ {
+ String expected = "wsrp_rewrite?wsrp-urlType=resource&wsrp-resourceID=resource_123" +
+ "&wsrp-url=http%3A%2F%2Ftest.com%2Fimages%2Ftest.gif&/wsrp_rewrite";
+ WSRPPortletURL url = WSRPPortletURL.create(expected);
+
+ assertTrue(url instanceof WSRPResourceURL);
+ WSRPResourceURL resource = (WSRPResourceURL)url;
+ assertFalse(resource.requiresRewrite());
+ assertEquals("http://test.com/images/test.gif", resource.getResourceURL().toExternalForm());
+
+ //resource.getResourceId will not return the actual resource id, but an encoded resource map used to determine how to access the resource
+ Map<String, String> resourceMap = WSRPResourceURL.decodeResource(resource.getResourceId());
+ String resourceID = resourceMap.get(WSRP2RewritingConstants.RESOURCE_ID);
+ assertEquals("resource_123", resourceID);
+
+ String resourceURL = resourceMap.get(WSRPRewritingConstants.RESOURCE_URL);
+ assertEquals("http://test.com/images/test.gif", resourceURL);
+ assertEquals("false",resourceMap.get(WSRP2RewritingConstants.RESOURCE_PREFER_OPERATION));
+ }
+
+ public void testResourcesNoResourceURL()
+ {
+ String expected = "wsrp_rewrite?wsrp-urlType=resource&wsrp-resourceID=resource_123" +
+ "&wsrp-requiresRewrite=false/wsrp_rewrite";
+ WSRPPortletURL url = WSRPPortletURL.create(expected);
+
+ assertTrue(url instanceof WSRPResourceURL);
+ WSRPResourceURL resource = (WSRPResourceURL)url;
+ assertFalse(resource.requiresRewrite());
+
+ //resource.getResourceId will not return the actual resource id, but an encoded resource map used to determine how to access the resource
+ Map<String, String> resourceMap = WSRPResourceURL.decodeResource(resource.getResourceId());
+ String resourceID = resourceMap.get(WSRP2RewritingConstants.RESOURCE_ID);
+ assertEquals("resource_123", resourceID);
+
+ assertEquals("false",resourceMap.get(WSRP2RewritingConstants.RESOURCE_PREFER_OPERATION));
+ }
+
public void testPreferOperation()
{
String expected = "wsrp_rewrite?wsrp-urlType=resource&wsrp-resourceID=resource_123" +
More information about the gatein-commits
mailing list