Author: chris.laprun(a)jboss.com
Date: 2009-02-10 07:45:05 -0500 (Tue, 10 Feb 2009)
New Revision: 12804
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/other/WSRPPortletURLTestCase.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPPortletURL.java
Log:
- JBPORTAL-2306: Fixed WSRPPortletURL.toString() method to properly add WSRP end rewriting
token.
- Added test case.
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/other/WSRPPortletURLTestCase.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/other/WSRPPortletURLTestCase.java 2009-02-10
12:39:07 UTC (rev 12803)
+++
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/other/WSRPPortletURLTestCase.java 2009-02-10
12:45:05 UTC (rev 12804)
@@ -51,7 +51,7 @@
public void testResource()
{
String expected =
"wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http%3A%2F%2Ftest.com%2Fimages%2Ftest.gif"
+
- "&wsrp-requiresRewrite=true/wsrp_rewrite";
+ "&wsrp-requiresRewrite=true/wsrp_rewrite";
WSRPPortletURL url = WSRPPortletURL.create(expected);
assertEquals("http://test.com/images/test.gif", url.toString());
@@ -61,7 +61,7 @@
public void testSecureInteraction()
{
String expected =
"wsrp_rewrite?wsrp-urlType=blockingAction&wsrp-secureURL=true" +
-
"&wsrp-navigationalState=a8h4K5JD9&wsrp-interactionState=fg4h923mdk/wsrp_rewrite";
+
"&wsrp-navigationalState=a8h4K5JD9&wsrp-interactionState=fg4h923mdk/wsrp_rewrite";
WSRPPortletURL url = WSRPPortletURL.create(expected);
assertTrue(url instanceof WSRPActionURL);
@@ -195,25 +195,27 @@
checkInvalidURL(invalid, "Should have detected invalid URL: ",
"invalidURL");
}
- private void checkInvalidURL(String invalid, String message, String
mustBeInException)
+ public void testNullURL()
{
try
{
- WSRPPortletURL.create(invalid);
- fail(message + mustBeInException);
+ WSRPPortletURL.create(null);
+ fail("Should have detected null URL");
}
catch (IllegalArgumentException e)
{
- assertTrue(e.getLocalizedMessage().contains(mustBeInException));
+ // expected
}
}
- public void testNullURL()
+ public void testInvalidURLType()
{
+ String wrongURLType =
"wsrp_rewrite?wsrp-urlType=pipo&wsrp-mode=help/wsrp_rewrite";
+
try
{
- WSRPPortletURL.create(null);
- fail("Should have detected null URL");
+ WSRPPortletURL.create(wrongURLType);
+ fail("Should have detected wrong URL type");
}
catch (IllegalArgumentException e)
{
@@ -221,18 +223,36 @@
}
}
- public void testInvalidURLType()
+ public void testProperEndTokenInRelaxedMode()
{
- String wrongURLType =
"wsrp_rewrite?wsrp-urlType=pipo&wsrp-mode=help/wsrp_rewrite";
+ WSRPPortletURL.setStrict(false);
+ WSRPPortletURL url = new WSRPPortletURL()
+ {
+ @Override
+ protected String getURLType()
+ {
+ return WSRPRewritingConstants.URL_TYPE_BLOCKING_ACTION;
+ }
+
+ @Override
+ protected void appendEnd(StringBuffer sb)
+ {
+ }
+ };
+ assertTrue(url.toString().contains(WSRPRewritingConstants.END_WSRP_REWRITE));
+ }
+
+ private void checkInvalidURL(String invalid, String message, String
mustBeInException)
+ {
try
{
- WSRPPortletURL.create(wrongURLType);
- fail("Should have detected wrong URL type");
+ WSRPPortletURL.create(invalid);
+ fail(message + mustBeInException);
}
catch (IllegalArgumentException e)
{
- // expected
+ assertTrue(e.getLocalizedMessage().contains(mustBeInException));
}
}
}
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPPortletURL.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPPortletURL.java 2009-02-10
12:39:07 UTC (rev 12803)
+++
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPPortletURL.java 2009-02-10
12:45:05 UTC (rev 12804)
@@ -144,7 +144,7 @@
}
encodedURL = encodedURL.substring(0, endTokenIndex)
- + encodedURL.substring(endTokenIndex +
WSRPRewritingConstants.WSRP_REWRITE_SUFFIX_LENGTH);
+ + encodedURL.substring(endTokenIndex +
WSRPRewritingConstants.WSRP_REWRITE_SUFFIX_LENGTH);
// remember that we should position the extra params after the end token
extraAfterEnd = true;
@@ -154,7 +154,7 @@
{
// remove prefix and suffix
encodedURL =
encodedURL.substring(WSRPRewritingConstants.WSRP_REWRITE_PREFIX_LENGTH,
- encodedURL.length() -
WSRPRewritingConstants.WSRP_REWRITE_SUFFIX_LENGTH);
+ encodedURL.length() - WSRPRewritingConstants.WSRP_REWRITE_SUFFIX_LENGTH);
}
// next param should be the url type
@@ -191,7 +191,7 @@
else
{
throw new IllegalArgumentException("Unrecognized URL type: " +
encodedURL.substring(0, encodedURL.indexOf(PARAM_SEPARATOR))
- + "in " + originalURL);
+ + "in " + originalURL);
}
// other parameters
@@ -208,7 +208,7 @@
else if (WSRPRewritingConstants.URL_TYPE_RESOURCE.equals(urlType))
{
throw new IllegalArgumentException("Both the 'wsrp-url' and
'wsrp-requiresRewrite' parameters MUST also be specified for resource URL
'"
- + originalURL + "'");
+ + originalURL + "'");
}
url.setParams(params, originalURL);
@@ -327,7 +327,7 @@
//
sb.append(WSRPRewritingConstants.BEGIN_WSRP_REWRITE).append(WSRPRewritingConstants.URL_TYPE_NAME)
- .append(EQUALS).append(getURLType());
+ .append(EQUALS).append(getURLType());
//
if (secure)
@@ -360,19 +360,15 @@
else
{
// we're in relaxed mode so we need to deal with extra params if they exist
- StringBuffer extras = null;
if (extraParams != null && !extraParams.isEmpty())
{
- extras = new StringBuffer();
+ StringBuffer extras = new StringBuffer();
for (Map.Entry<String, String> entry : extraParams.entrySet())
{
createURLParameter(extras, entry.getKey(), entry.getValue());
}
- }
- // if we had extra params, we need to figure out where thwy should be positioned
wrt end token
- if (extras != null)
- {
+ // if we had extra params, we need to figure out where thwy should be
positioned wrt end token
if (extraParamsAfterEndToken)
{
sb.append(WSRPRewritingConstants.END_WSRP_REWRITE);
@@ -384,6 +380,10 @@
sb.append(WSRPRewritingConstants.END_WSRP_REWRITE);
}
}
+ else
+ {
+ sb.append(WSRPRewritingConstants.END_WSRP_REWRITE);
+ }
}
return sb.toString();
}
@@ -430,7 +430,7 @@
if (strict)
{
throw new IllegalArgumentException("Invalid parameter name in strict
validation mode (see documentation): '"
- + name + "' in " + originalURL);
+ + name + "' in " + originalURL);
}
else
{