Author: chris.laprun(a)jboss.com
Date: 2011-03-29 08:55:03 -0400 (Tue, 29 Mar 2011)
New Revision: 6132
Added:
components/wsrp/trunk/admin-gui/src/test/java/org/gatein/wsrp/ConsumerBeanTestCase.java
components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/WSRPPortletURLTestCase.java
Removed:
components/wsrp/trunk/admin-gui/src/test/java/org/gatein/wsrp/other/
components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/other/WSRPPortletURLTestCase.java
Log:
- Moved tests to proper directories.
Copied:
components/wsrp/trunk/admin-gui/src/test/java/org/gatein/wsrp/ConsumerBeanTestCase.java
(from rev 6131,
components/wsrp/trunk/admin-gui/src/test/java/org/gatein/wsrp/other/ConsumerBeanTestCase.java)
===================================================================
---
components/wsrp/trunk/admin-gui/src/test/java/org/gatein/wsrp/ConsumerBeanTestCase.java
(rev 0)
+++
components/wsrp/trunk/admin-gui/src/test/java/org/gatein/wsrp/ConsumerBeanTestCase.java 2011-03-29
12:55:03 UTC (rev 6132)
@@ -0,0 +1,175 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.wsrp;
+
+import junit.framework.TestCase;
+import org.gatein.common.NotYetImplemented;
+import org.gatein.wsrp.admin.ui.BeanContext;
+import org.gatein.wsrp.admin.ui.ConsumerBean;
+import org.gatein.wsrp.consumer.registry.ConsumerRegistry;
+import org.gatein.wsrp.consumer.registry.InMemoryConsumerRegistry;
+import org.gatein.wsrp.services.SOAPServiceFactory;
+import org.gatein.wsrp.test.protocol.v2.BehaviorBackedServiceFactory;
+import org.gatein.wsrp.test.support.MockEndpointConfigurationInfo;
+
+import javax.faces.model.DataModel;
+import java.util.Locale;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 12612 $
+ * @since 2.6
+ */
+public class ConsumerBeanTestCase extends TestCase
+{
+ private static final String CONSUMER_ID = "foo";
+
+ /** Since our consumers use the MockEndpointConfigurationInfo, this is the WSDL they
are configured with */
+ private static final String WSDL = BehaviorBackedServiceFactory.DEFAULT_WSDL_URL;
+ private ConsumerBean bean;
+
+ protected void setUp() throws Exception
+ {
+ bean = new ConsumerBean();
+ ConsumerRegistry registry = new TestInMemoryConsumerRegistry();
+ registry.createConsumer(CONSUMER_ID, null, WSDL);
+ bean.setRegistry(registry);
+ bean.setBeanContext(new TestBeanContext());
+
+ // consumer associated with bean is null at this point so it should be loaded from
the registry
+ bean.setId(CONSUMER_ID);
+ }
+
+ public void testInitialState()
+ {
+ assertEquals(CONSUMER_ID, bean.getId());
+ assertEquals(bean.getProducerInfo().getId(), bean.getId());
+
+ assertEquals(WSDL, bean.getWsdl());
+ assertEquals(SOAPServiceFactory.DEFAULT_TIMEOUT_MS, bean.getTimeout().intValue());
+
+ assertFalse(bean.isModified());
+ assertTrue(bean.isRefreshNeeded());
+
+ assertFalse(bean.isActive());
+
+ assertFalse(bean.isRegistrationChecked());
+ assertTrue(bean.isRegistrationCheckNeeded());
+ assertFalse(bean.isRegistered());
+ assertFalse(bean.isRegistrationLocallyModified());
+ assertFalse(bean.isRegistrationPropertiesExisting());
+
+ assertNull(bean.getCurrentExport());
+
+ DataModel existingExports = bean.getExistingExports();
+ assertNotNull(existingExports);
+ assertEquals(0, existingExports.getRowCount());
+
+ try
+ {
+ assertFalse(bean.isRegistrationRequired());
+ fail("Can't know if registration is required without a refresh");
+ }
+ catch (IllegalStateException e)
+ {
+ // expected
+ }
+ try
+ {
+ assertFalse(bean.isRegistrationValid());
+ fail("Can't know if registration is valid without a refresh");
+ }
+ catch (Exception e)
+ {
+ // expected
+ }
+ }
+
+ public void testSetId()
+ {
+ String newId = "newId";
+ bean.setId(newId);
+ assertEquals(newId, bean.getId());
+
+ assertTrue(bean.isModified());
+ }
+
+ public void testSetCache()
+ {
+ bean.setCache(300);
+ assertEquals(300, bean.getCache().intValue());
+ assertTrue(bean.isModified());
+ }
+
+ private static class TestBeanContext extends BeanContext
+ {
+ public String getParameter(String key)
+ {
+ throw new NotYetImplemented();
+ }
+
+ protected void createMessage(String target, String message, Object severity,
Object... addtionalParams)
+ {
+ // ignore for tests
+ }
+
+ protected Object getErrorSeverity()
+ {
+ return null;
+ }
+
+ protected Object getInfoSeverity()
+ {
+ return null;
+ }
+
+ protected Locale getLocale()
+ {
+ return Locale.getDefault();
+ }
+
+ public String getServerAddress()
+ {
+ throw new NotYetImplemented();
+ }
+
+ public Map<String, Object> getSessionMap()
+ {
+ throw new NotYetImplemented();
+ }
+ }
+
+ private static class TestInMemoryConsumerRegistry extends InMemoryConsumerRegistry
+ {
+ @Override
+ public WSRPConsumer createConsumer(String id, Integer expirationCacheSeconds,
String wsdlURL)
+ {
+ // Use a "real" consumer but with a fake endpoint configuration so we
can fake WS access
+ WSRPConsumer consumer = super.createConsumer(id, expirationCacheSeconds,
wsdlURL);
+ consumer.getProducerInfo().setEndpointConfigurationInfo(new
MockEndpointConfigurationInfo());
+ return consumer;
+ }
+ }
+}
Copied:
components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/WSRPPortletURLTestCase.java
(from rev 6131,
components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/other/WSRPPortletURLTestCase.java)
===================================================================
---
components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/WSRPPortletURLTestCase.java
(rev 0)
+++
components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/WSRPPortletURLTestCase.java 2011-03-29
12:55:03 UTC (rev 6132)
@@ -0,0 +1,541 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.wsrp;
+
+import junit.framework.TestCase;
+import org.gatein.pc.api.ContainerURL;
+import org.gatein.pc.api.Mode;
+import org.gatein.pc.api.ParametersStateString;
+import org.gatein.pc.api.ResourceURL;
+import org.gatein.pc.api.StateString;
+import org.gatein.pc.api.WindowState;
+import org.gatein.pc.api.cache.CacheLevel;
+import org.gatein.wsrp.spec.v2.WSRP2RewritingConstants;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 13470 $
+ * @since 2.4 (Apr 28, 2006)
+ */
+public class WSRPPortletURLTestCase extends TestCase
+{
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ WSRPPortletURL.setStrict(true);
+ }
+
+ public void testResourceURL()
+ {
+ String expected =
"wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http%3A%2F%2Ftest.com%2Fimages%2Ftest.gif"
+
+ "&wsrp-requiresRewrite=false/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 resourceURL = resourceMap.get(WSRPRewritingConstants.RESOURCE_URL);
+
assertEquals("http://test.com/images/test.gif", resourceURL);
+
+ assertNull(resourceMap.get(WSRP2RewritingConstants.RESOURCE_ID));
+ assertEquals("false",
resourceMap.get(WSRP2RewritingConstants.RESOURCE_PREFER_OPERATION));
+ }
+
+ public void testResourceID()
+ {
+ 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());
+ assertNull(resource.getResourceURL());
+
+ //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);
+
+ assertNull(resourceMap.get(WSRPRewritingConstants.RESOURCE_URL));
+ assertEquals("false",
resourceMap.get(WSRP2RewritingConstants.RESOURCE_PREFER_OPERATION));
+ }
+
+ public void testResourceIDToken()
+ {
+ //Test what happens in the case where the url is created via token wsrp rewriting
on the producer side
+ //In this case the resource ID will not be an encoded resource map.
+
+ Map<String, String> resourceMap =
WSRPResourceURL.decodeResource("resource_123");
+ String resourceID = resourceMap.get(WSRP2RewritingConstants.RESOURCE_ID);
+ assertEquals("resource_123", resourceID);
+
+ assertNull(resourceMap.get(WSRPRewritingConstants.RESOURCE_URL));
+ assertNull(resourceMap.get(WSRP2RewritingConstants.RESOURCE_PREFER_OPERATION));
+ }
+
+ public void testResources()
+ {
+ String expected =
"wsrp_rewrite?wsrp-urlType=resource&wsrp-resourceID=resource_123" +
+
"&wsrp-url=http%3A%2F%2Ftest.com%2Fimages%2Ftest.gif&wsrp-requiresRewrite=false/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 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" +
+
"&wsrp-url=http%3A%2F%2Ftest.com%2Fimages%2Ftest.gif&wsrp-preferOperation=true&wsrp-requiresRewrite=false/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);
+
+ String preferOperation =
resourceMap.get(WSRP2RewritingConstants.RESOURCE_PREFER_OPERATION);
+ assertEquals("true", preferOperation);
+ }
+
+ public void testShouldSetPreferOperationToTrueWhenResourceIdIsPresent()
+ {
+ ResourceURL resourceURL = new TestResourceURL(TestResourceURL.RESID,
TestResourceURL.DEFAULT_NS, CacheLevel.FULL);
+ WSRPPortletURL url = WSRPPortletURL.create(resourceURL, false,
WSRPPortletURL.URLContext.EMPTY);
+
+ String actual = url.toString();
+ assertTrue(actual.contains("wsrp-urlType=resource"));
+ assertTrue(actual.contains("wsrp-resourceID=" + TestResourceURL.RESID));
+ assertTrue(actual.contains("wsrp-preferOperation=true"));
+ }
+
+ public void testShouldProperlyTransmitResourceState()
+ {
+ // create URL from container
+ ResourceURL resourceURL = new TestResourceURL("resparam",
"resvalue");
+ WSRPPortletURL url = WSRPPortletURL.create(resourceURL, false,
WSRPPortletURL.URLContext.EMPTY);
+
+ assertTrue(url instanceof WSRPResourceURL);
+ WSRPResourceURL resource = (WSRPResourceURL)url;
+ StateString resourceState = resource.getResourceState();
+ assertNotNull(resourceState);
+
+ // serialize URL to WSRP string format
+ String resourceAsString = resource.toString();
+
+ // and re-create it
+ url = WSRPPortletURL.create(resourceAsString);
+
+ // check that we have indeed the same state
+ assertTrue(url instanceof WSRPResourceURL);
+ resource = (WSRPResourceURL)url;
+ resourceState = resource.getResourceState();
+ assertNotNull(resourceState);
+ Map<String, String[]> state =
StateString.decodeOpaqueValue(resourceState.getStringValue());
+ assertEquals("resvalue", state.get("resparam")[0]);
+ }
+
+ /** Declare a secure interaction back to the Portlet */
+ public void testSecureInteraction()
+ {
+ String expected =
"wsrp_rewrite?wsrp-urlType=blockingAction&wsrp-secureURL=true" +
+
"&wsrp-navigationalState=a8h4K5JD9&wsrp-interactionState=fg4h923mdk/wsrp_rewrite";
+ WSRPPortletURL url = WSRPPortletURL.create(expected);
+
+ assertTrue(url instanceof WSRPActionURL);
+ WSRPActionURL actionURL = (WSRPActionURL)url;
+ assertTrue(url.isSecure());
+ assertEquals("a8h4K5JD9",
actionURL.getNavigationalState().getStringValue());
+ assertEquals("fg4h923mdk",
actionURL.getInteractionState().getStringValue());
+ }
+
+ /** Request the Consumer render the Portlet in a different mode and window state */
+ public void testDifferentModeAndWindowState()
+ {
+ String expected =
"wsrp_rewrite?wsrp-urlType=render&wsrp-mode=wsrp:help&wsrp-windowState=wsrp:maximized/wsrp_rewrite";
+ WSRPPortletURL url = WSRPPortletURL.create(expected);
+
+ assertTrue(url instanceof WSRPRenderURL);
+ assertEquals(Mode.HELP, url.getMode());
+ assertEquals(WindowState.MAXIMIZED, url.getWindowState());
+ }
+
+ public void testMinimal()
+ {
+ String minimalURLType = "wsrp_rewrite?wsrp-urlType=render/wsrp_rewrite";
+ WSRPPortletURL url = WSRPPortletURL.create(minimalURLType);
+
+ assertTrue(url instanceof WSRPRenderURL);
+ }
+
+ public void testInvalidParameterName()
+ {
+ String message = "Should have detected invalid parameter: ";
+
+ String invalid =
"wsrp_rewrite?wsrp-urlType=render&foo=bar/wsrp_rewrite";
+ checkInvalidURL(invalid, message, "foo");
+ }
+
+ public void testDoublyEncodedAmpersand()
+ {
+ String expected =
"wsrp_rewrite?wsrp-urlType=render&amp;wsrp-mode=wsrp:help&amp;wsrp-windowState=wsrp:maximized/wsrp_rewrite";
+ try
+ {
+ WSRPPortletURL.create(expected);
+ fail("Should have thrown an exception on doubly encoded &!");
+ }
+ catch (Exception e)
+ {
+ // expected
+ }
+ }
+
+ /** Relax validation and test that we now accept normally invalid URLs. */
+ public void testExtraParametersRelaxedValidation()
+ {
+ WSRPPortletURL.setStrict(false);
+
+ String validInRelaxedMode =
"wsrp_rewrite?wsrp-urlType=render&foo=bar/wsrp_rewrite";
+
+ WSRPPortletURL url = WSRPPortletURL.create(validInRelaxedMode);
+ assertTrue(url instanceof WSRPRenderURL);
+ assertTrue(url.toString().contains("foo=bar"));
+
+ validInRelaxedMode =
"wsrp_rewrite?wsrp-urlType=render/wsrp_rewrite&foo=bar";
+ url = WSRPPortletURL.create(validInRelaxedMode);
+ assertTrue(url instanceof WSRPRenderURL);
+ assertTrue(url.toString().endsWith("foo=bar"));
+
+ String stillInvalid =
"wsrp_rewrite?wsrp-urlType=render&foo=bar";
+ checkInvalidURL(stillInvalid, "Should have detected missing end token",
WSRPRewritingConstants.END_WSRP_REWRITE);
+ }
+
+ /*public void testExtraRelaxedValidation()
+ {
+ String valid =
"wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http%3A%2F%2Flocalhost%3A8080%2Fhelloworld&wsrp-requiresRewrite=true/wsrp_rewrite/helloworld.jar";
+ WSRPPortletURL url = WSRPPortletURL.create(valid);
+ assertEquals("http://localhost:8080/helloworld/helloworld.jar",
url.toString());
+
+ String invalid =
"wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http%3A%2F%2Flocalhost%3A8080%2Fhelloworld&wsrp-requiresRewrite=true/wsrp_rewrite&foo=bar/helloworld.jar";
+ checkInvalidURL(invalid, "Should have detected improper position of end
token", WSRPRewritingConstants.END_WSRP_REWRITE);
+
+ WSRPPortletURL.setStrict(false);
+ String validInRelaxedMode =
"wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http%3A%2F%2Flocalhost%3A8080%2Fhelloworld&wsrp-requiresRewrite=true/wsrp_rewrite&foo=bar/helloworld.jar";
+ url = WSRPPortletURL.create(validInRelaxedMode);
+
assertEquals("http://localhost:8080/helloworld&foo=bar/helloworld.jar",
url.toString());
+ }*/
+
+ public void testExtraParameters()
+ {
+ String validInRelaxedMode =
"wsrp_rewrite?wsrp-urlType=render&foo=bar/wsrp_rewrite";
+ checkInvalidURL(validInRelaxedMode, "Should have detected invalid parameter:
", "foo");
+
+ validInRelaxedMode =
"wsrp_rewrite?wsrp-urlType=render/wsrp_rewrite&foo=bar";
+ checkInvalidURL(validInRelaxedMode, "Should have detected URL doesn't end
with end token", WSRPRewritingConstants.END_WSRP_REWRITE);
+ }
+
+ public void testInvalidMode()
+ {
+ String message = "Should have detected invalid mode: ";
+
+ String invalid =
"wsrp_rewrite?wsrp-urlType=render&wsrp-mode=foo/wsrp_rewrite";
+ checkInvalidURL(invalid, message, "foo");
+ }
+
+ public void testCustomModeAndWindowState()
+ {
+ Set<String> modes = new HashSet<String>();
+ modes.add("urn:foo");
+
+ Set<String> windowStates = new HashSet<String>();
+ windowStates.add("urn:bar");
+
+ String urlString =
"wsrp_rewrite?wsrp-urlType=render&wsrp-mode=urn%3Afoo&wsrp-windowState=urn%3Abar/wsrp_rewrite";
+ WSRPPortletURL url = WSRPPortletURL.create(urlString, modes, windowStates);
+ assertEquals("urn:foo", url.getMode().toString());
+ assertEquals("urn:bar", url.getWindowState().toString());
+ }
+
+ public void testEncodedMode()
+ {
+ String encoded =
"wsrp_rewrite?wsrp-urlType=render&wsrp-mode=wsrp%3Aview/wsrp_rewrite";
+ WSRPPortletURL url = WSRPPortletURL.create(encoded);
+ assertEquals(Mode.VIEW, url.getMode());
+
+ encoded =
"wsrp_rewrite?wsrp-urlType=render&wsrp-mode=wsrp%3aedit/wsrp_rewrite";
+ url = WSRPPortletURL.create(encoded);
+ assertEquals(Mode.EDIT, url.getMode());
+ }
+
+ public void testEncodedWindowState()
+ {
+ String encoded =
"wsrp_rewrite?wsrp-urlType=render&wsrp-windowState=wsrp%3Amaximized/wsrp_rewrite";
+ WSRPPortletURL url = WSRPPortletURL.create(encoded);
+ assertEquals(WindowState.MAXIMIZED, url.getWindowState());
+
+ encoded =
"wsrp_rewrite?wsrp-urlType=render&wsrp-windowState=wsrp%3aminimized/wsrp_rewrite";
+ url = WSRPPortletURL.create(encoded);
+ assertEquals(WindowState.MINIMIZED, url.getWindowState());
+ }
+
+ public void testInvalidResourceURLV1()
+ {
+ String message = "Should have detected missing parameter: ";
+
+ /*
+ // We now allow requiresRewrite to be missing and assume false instead... See
GTNWSRP-103.
+ String invalid =
"wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http%3A%2F%2Flocalhost%2F/wsrp_rewrite";
+ checkInvalidURL(invalid, message,
WSRPRewritingConstants.RESOURCE_REQUIRES_REWRITE);
+ */
+
+ String invalid =
"wsrp_rewrite?wsrp-urlType=resource&wsrp-requiresRewrite=true/wsrp_rewrite";
+ checkInvalidURL(invalid, message, WSRPRewritingConstants.RESOURCE_URL);
+
+ invalid =
"wsrp_rewrite?wsrp-urlType=resource&wsrp-url=invalidURL&wsrp-requiresRewrite=true/wsrp_rewrite";
+ checkInvalidURL(invalid, "Should have detected invalid URL: ",
"invalidURL");
+ }
+
+ public void testNullURL()
+ {
+ try
+ {
+ WSRPPortletURL.create(null);
+ fail("Should have detected null URL");
+ }
+ catch (IllegalArgumentException e)
+ {
+ // expected
+ }
+ }
+
+ public void testInvalidURLType()
+ {
+ String wrongURLType =
"wsrp_rewrite?wsrp-urlType=pipo&wsrp-mode=help/wsrp_rewrite";
+
+ try
+ {
+ WSRPPortletURL.create(wrongURLType);
+ fail("Should have detected wrong URL type");
+ }
+ catch (IllegalArgumentException e)
+ {
+ // expected
+ }
+ }
+
+ public void testProperEndTokenInRelaxedMode()
+ {
+ 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(invalid);
+ fail(message + mustBeInException);
+ }
+ catch (IllegalArgumentException e)
+ {
+ assertTrue(e.getLocalizedMessage().contains(mustBeInException));
+ }
+ }
+
+ private static class TestContainerURL implements ContainerURL
+ {
+ private Mode mode;
+ private WindowState ws;
+ private StateString ns;
+ private Map<String, String> props;
+
+ static final StateString DEFAULT_NS;
+ static final Map<String, String[]> DEFAULT_PARAMS = new HashMap<String,
String[]>(3);
+ static final String PARAM = "param";
+ static final String VALUE = "value";
+
+ static
+ {
+ DEFAULT_PARAMS.put(PARAM, new String[]{VALUE});
+ DEFAULT_NS = ParametersStateString.create(DEFAULT_PARAMS);
+ }
+
+ private TestContainerURL(Mode mode, WindowState ws, StateString ns, Map<String,
String> props)
+ {
+ this.mode = mode;
+ this.ws = ws;
+ this.ns = ns;
+ this.props = props;
+ }
+
+ public Mode getMode()
+ {
+ return mode;
+ }
+
+ public WindowState getWindowState()
+ {
+ return ws;
+ }
+
+ public StateString getNavigationalState()
+ {
+ return ns;
+ }
+
+ public Map<String, String> getProperties()
+ {
+ return props;
+ }
+ }
+
+ private static class TestResourceURL extends TestContainerURL implements ResourceURL
+ {
+ private static final String RESID = "resid";
+ private String id;
+ private StateString state;
+ private CacheLevel cache;
+
+ private TestResourceURL(String id, StateString state, CacheLevel cache)
+ {
+ super(Mode.VIEW, WindowState.NORMAL, DEFAULT_NS, null);
+ init(id, state, cache);
+ }
+
+ private void init(String id, StateString state, CacheLevel cache)
+ {
+ this.id = id;
+ this.state = state;
+ this.cache = cache;
+ }
+
+ private TestResourceURL(String param, String value)
+ {
+ super(Mode.VIEW, WindowState.NORMAL, DEFAULT_NS, null);
+
+ HashMap<String, String[]> params = new HashMap<String,
String[]>(3);
+ params.put(param, new String[]{value});
+
+ init(RESID, ParametersStateString.create(params), CacheLevel.FULL);
+ }
+
+ public String getResourceId()
+ {
+ return id;
+ }
+
+ public StateString getResourceState()
+ {
+ return state;
+ }
+
+ public CacheLevel getCacheability()
+ {
+ return cache;
+ }
+ }
+}
\ No newline at end of file
Property changes on:
components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/WSRPPortletURLTestCase.java
___________________________________________________________________
Added: svn:executable
+ *
Deleted:
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 2011-03-29
12:06:50 UTC (rev 6131)
+++
components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/other/WSRPPortletURLTestCase.java 2011-03-29
12:55:03 UTC (rev 6132)
@@ -1,546 +0,0 @@
-/*
- * JBoss, a division of Red Hat
- * Copyright 2010, Red Hat Middleware, LLC, and individual
- * contributors as indicated by the @authors tag. See the
- * copyright.txt in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-
-package org.gatein.wsrp.other;
-
-import junit.framework.TestCase;
-import org.gatein.pc.api.ContainerURL;
-import org.gatein.pc.api.Mode;
-import org.gatein.pc.api.ParametersStateString;
-import org.gatein.pc.api.ResourceURL;
-import org.gatein.pc.api.StateString;
-import org.gatein.pc.api.WindowState;
-import org.gatein.pc.api.cache.CacheLevel;
-import org.gatein.wsrp.WSRPActionURL;
-import org.gatein.wsrp.WSRPPortletURL;
-import org.gatein.wsrp.WSRPRenderURL;
-import org.gatein.wsrp.WSRPResourceURL;
-import org.gatein.wsrp.WSRPRewritingConstants;
-import org.gatein.wsrp.spec.v2.WSRP2RewritingConstants;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
- * @version $Revision: 13470 $
- * @since 2.4 (Apr 28, 2006)
- */
-public class WSRPPortletURLTestCase extends TestCase
-{
- @Override
- protected void setUp() throws Exception
- {
- super.setUp();
- WSRPPortletURL.setStrict(true);
- }
-
- public void testResourceURL()
- {
- String expected =
"wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http%3A%2F%2Ftest.com%2Fimages%2Ftest.gif"
+
- "&wsrp-requiresRewrite=false/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 resourceURL = resourceMap.get(WSRPRewritingConstants.RESOURCE_URL);
-
assertEquals("http://test.com/images/test.gif", resourceURL);
-
- assertNull(resourceMap.get(WSRP2RewritingConstants.RESOURCE_ID));
- assertEquals("false",
resourceMap.get(WSRP2RewritingConstants.RESOURCE_PREFER_OPERATION));
- }
-
- public void testResourceID()
- {
- 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());
- assertNull(resource.getResourceURL());
-
- //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);
-
- assertNull(resourceMap.get(WSRPRewritingConstants.RESOURCE_URL));
- assertEquals("false",
resourceMap.get(WSRP2RewritingConstants.RESOURCE_PREFER_OPERATION));
- }
-
- public void testResourceIDToken()
- {
- //Test what happens in the case where the url is created via token wsrp rewriting
on the producer side
- //In this case the resource ID will not be an encoded resource map.
-
- Map<String, String> resourceMap =
WSRPResourceURL.decodeResource("resource_123");
- String resourceID = resourceMap.get(WSRP2RewritingConstants.RESOURCE_ID);
- assertEquals("resource_123", resourceID);
-
- assertNull(resourceMap.get(WSRPRewritingConstants.RESOURCE_URL));
- assertNull(resourceMap.get(WSRP2RewritingConstants.RESOURCE_PREFER_OPERATION));
- }
-
- public void testResources()
- {
- String expected =
"wsrp_rewrite?wsrp-urlType=resource&wsrp-resourceID=resource_123" +
-
"&wsrp-url=http%3A%2F%2Ftest.com%2Fimages%2Ftest.gif&wsrp-requiresRewrite=false/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 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" +
-
"&wsrp-url=http%3A%2F%2Ftest.com%2Fimages%2Ftest.gif&wsrp-preferOperation=true&wsrp-requiresRewrite=false/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);
-
- String preferOperation =
resourceMap.get(WSRP2RewritingConstants.RESOURCE_PREFER_OPERATION);
- assertEquals("true", preferOperation);
- }
-
- public void testShouldSetPreferOperationToTrueWhenResourceIdIsPresent()
- {
- ResourceURL resourceURL = new TestResourceURL(TestResourceURL.RESID,
TestResourceURL.DEFAULT_NS, CacheLevel.FULL);
- WSRPPortletURL url = WSRPPortletURL.create(resourceURL, false,
WSRPPortletURL.URLContext.EMPTY);
-
- String actual = url.toString();
- assertTrue(actual.contains("wsrp-urlType=resource"));
- assertTrue(actual.contains("wsrp-resourceID=" + TestResourceURL.RESID));
- assertTrue(actual.contains("wsrp-preferOperation=true"));
- }
-
- public void testShouldProperlyTransmitResourceState()
- {
- // create URL from container
- ResourceURL resourceURL = new TestResourceURL("resparam",
"resvalue");
- WSRPPortletURL url = WSRPPortletURL.create(resourceURL, false,
WSRPPortletURL.URLContext.EMPTY);
-
- assertTrue(url instanceof WSRPResourceURL);
- WSRPResourceURL resource = (WSRPResourceURL)url;
- StateString resourceState = resource.getResourceState();
- assertNotNull(resourceState);
-
- // serialize URL to WSRP string format
- String resourceAsString = resource.toString();
-
- // and re-create it
- url = WSRPPortletURL.create(resourceAsString);
-
- // check that we have indeed the same state
- assertTrue(url instanceof WSRPResourceURL);
- resource = (WSRPResourceURL)url;
- resourceState = resource.getResourceState();
- assertNotNull(resourceState);
- Map<String, String[]> state =
StateString.decodeOpaqueValue(resourceState.getStringValue());
- assertEquals("resvalue", state.get("resparam")[0]);
- }
-
- /** Declare a secure interaction back to the Portlet */
- public void testSecureInteraction()
- {
- String expected =
"wsrp_rewrite?wsrp-urlType=blockingAction&wsrp-secureURL=true" +
-
"&wsrp-navigationalState=a8h4K5JD9&wsrp-interactionState=fg4h923mdk/wsrp_rewrite";
- WSRPPortletURL url = WSRPPortletURL.create(expected);
-
- assertTrue(url instanceof WSRPActionURL);
- WSRPActionURL actionURL = (WSRPActionURL)url;
- assertTrue(url.isSecure());
- assertEquals("a8h4K5JD9",
actionURL.getNavigationalState().getStringValue());
- assertEquals("fg4h923mdk",
actionURL.getInteractionState().getStringValue());
- }
-
- /** Request the Consumer render the Portlet in a different mode and window state */
- public void testDifferentModeAndWindowState()
- {
- String expected =
"wsrp_rewrite?wsrp-urlType=render&wsrp-mode=wsrp:help&wsrp-windowState=wsrp:maximized/wsrp_rewrite";
- WSRPPortletURL url = WSRPPortletURL.create(expected);
-
- assertTrue(url instanceof WSRPRenderURL);
- assertEquals(Mode.HELP, url.getMode());
- assertEquals(WindowState.MAXIMIZED, url.getWindowState());
- }
-
- public void testMinimal()
- {
- String minimalURLType = "wsrp_rewrite?wsrp-urlType=render/wsrp_rewrite";
- WSRPPortletURL url = WSRPPortletURL.create(minimalURLType);
-
- assertTrue(url instanceof WSRPRenderURL);
- }
-
- public void testInvalidParameterName()
- {
- String message = "Should have detected invalid parameter: ";
-
- String invalid =
"wsrp_rewrite?wsrp-urlType=render&foo=bar/wsrp_rewrite";
- checkInvalidURL(invalid, message, "foo");
- }
-
- public void testDoublyEncodedAmpersand()
- {
- String expected =
"wsrp_rewrite?wsrp-urlType=render&amp;wsrp-mode=wsrp:help&amp;wsrp-windowState=wsrp:maximized/wsrp_rewrite";
- try
- {
- WSRPPortletURL.create(expected);
- fail("Should have thrown an exception on doubly encoded &!");
- }
- catch (Exception e)
- {
- // expected
- }
- }
-
- /** Relax validation and test that we now accept normally invalid URLs. */
- public void testExtraParametersRelaxedValidation()
- {
- WSRPPortletURL.setStrict(false);
-
- String validInRelaxedMode =
"wsrp_rewrite?wsrp-urlType=render&foo=bar/wsrp_rewrite";
-
- WSRPPortletURL url = WSRPPortletURL.create(validInRelaxedMode);
- assertTrue(url instanceof WSRPRenderURL);
- assertTrue(url.toString().contains("foo=bar"));
-
- validInRelaxedMode =
"wsrp_rewrite?wsrp-urlType=render/wsrp_rewrite&foo=bar";
- url = WSRPPortletURL.create(validInRelaxedMode);
- assertTrue(url instanceof WSRPRenderURL);
- assertTrue(url.toString().endsWith("foo=bar"));
-
- String stillInvalid =
"wsrp_rewrite?wsrp-urlType=render&foo=bar";
- checkInvalidURL(stillInvalid, "Should have detected missing end token",
WSRPRewritingConstants.END_WSRP_REWRITE);
- }
-
- /*public void testExtraRelaxedValidation()
- {
- String valid =
"wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http%3A%2F%2Flocalhost%3A8080%2Fhelloworld&wsrp-requiresRewrite=true/wsrp_rewrite/helloworld.jar";
- WSRPPortletURL url = WSRPPortletURL.create(valid);
- assertEquals("http://localhost:8080/helloworld/helloworld.jar",
url.toString());
-
- String invalid =
"wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http%3A%2F%2Flocalhost%3A8080%2Fhelloworld&wsrp-requiresRewrite=true/wsrp_rewrite&foo=bar/helloworld.jar";
- checkInvalidURL(invalid, "Should have detected improper position of end
token", WSRPRewritingConstants.END_WSRP_REWRITE);
-
- WSRPPortletURL.setStrict(false);
- String validInRelaxedMode =
"wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http%3A%2F%2Flocalhost%3A8080%2Fhelloworld&wsrp-requiresRewrite=true/wsrp_rewrite&foo=bar/helloworld.jar";
- url = WSRPPortletURL.create(validInRelaxedMode);
-
assertEquals("http://localhost:8080/helloworld&foo=bar/helloworld.jar",
url.toString());
- }*/
-
- public void testExtraParameters()
- {
- String validInRelaxedMode =
"wsrp_rewrite?wsrp-urlType=render&foo=bar/wsrp_rewrite";
- checkInvalidURL(validInRelaxedMode, "Should have detected invalid parameter:
", "foo");
-
- validInRelaxedMode =
"wsrp_rewrite?wsrp-urlType=render/wsrp_rewrite&foo=bar";
- checkInvalidURL(validInRelaxedMode, "Should have detected URL doesn't end
with end token", WSRPRewritingConstants.END_WSRP_REWRITE);
- }
-
- public void testInvalidMode()
- {
- String message = "Should have detected invalid mode: ";
-
- String invalid =
"wsrp_rewrite?wsrp-urlType=render&wsrp-mode=foo/wsrp_rewrite";
- checkInvalidURL(invalid, message, "foo");
- }
-
- public void testCustomModeAndWindowState()
- {
- Set<String> modes = new HashSet<String>();
- modes.add("urn:foo");
-
- Set<String> windowStates = new HashSet<String>();
- windowStates.add("urn:bar");
-
- String urlString =
"wsrp_rewrite?wsrp-urlType=render&wsrp-mode=urn%3Afoo&wsrp-windowState=urn%3Abar/wsrp_rewrite";
- WSRPPortletURL url = WSRPPortletURL.create(urlString, modes, windowStates);
- assertEquals("urn:foo", url.getMode().toString());
- assertEquals("urn:bar", url.getWindowState().toString());
- }
-
- public void testEncodedMode()
- {
- String encoded =
"wsrp_rewrite?wsrp-urlType=render&wsrp-mode=wsrp%3Aview/wsrp_rewrite";
- WSRPPortletURL url = WSRPPortletURL.create(encoded);
- assertEquals(Mode.VIEW, url.getMode());
-
- encoded =
"wsrp_rewrite?wsrp-urlType=render&wsrp-mode=wsrp%3aedit/wsrp_rewrite";
- url = WSRPPortletURL.create(encoded);
- assertEquals(Mode.EDIT, url.getMode());
- }
-
- public void testEncodedWindowState()
- {
- String encoded =
"wsrp_rewrite?wsrp-urlType=render&wsrp-windowState=wsrp%3Amaximized/wsrp_rewrite";
- WSRPPortletURL url = WSRPPortletURL.create(encoded);
- assertEquals(WindowState.MAXIMIZED, url.getWindowState());
-
- encoded =
"wsrp_rewrite?wsrp-urlType=render&wsrp-windowState=wsrp%3aminimized/wsrp_rewrite";
- url = WSRPPortletURL.create(encoded);
- assertEquals(WindowState.MINIMIZED, url.getWindowState());
- }
-
- public void testInvalidResourceURLV1()
- {
- String message = "Should have detected missing parameter: ";
-
- /*
- // We now allow requiresRewrite to be missing and assume false instead... See
GTNWSRP-103.
- String invalid =
"wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http%3A%2F%2Flocalhost%2F/wsrp_rewrite";
- checkInvalidURL(invalid, message,
WSRPRewritingConstants.RESOURCE_REQUIRES_REWRITE);
- */
-
- String invalid =
"wsrp_rewrite?wsrp-urlType=resource&wsrp-requiresRewrite=true/wsrp_rewrite";
- checkInvalidURL(invalid, message, WSRPRewritingConstants.RESOURCE_URL);
-
- invalid =
"wsrp_rewrite?wsrp-urlType=resource&wsrp-url=invalidURL&wsrp-requiresRewrite=true/wsrp_rewrite";
- checkInvalidURL(invalid, "Should have detected invalid URL: ",
"invalidURL");
- }
-
- public void testNullURL()
- {
- try
- {
- WSRPPortletURL.create(null);
- fail("Should have detected null URL");
- }
- catch (IllegalArgumentException e)
- {
- // expected
- }
- }
-
- public void testInvalidURLType()
- {
- String wrongURLType =
"wsrp_rewrite?wsrp-urlType=pipo&wsrp-mode=help/wsrp_rewrite";
-
- try
- {
- WSRPPortletURL.create(wrongURLType);
- fail("Should have detected wrong URL type");
- }
- catch (IllegalArgumentException e)
- {
- // expected
- }
- }
-
- public void testProperEndTokenInRelaxedMode()
- {
- 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(invalid);
- fail(message + mustBeInException);
- }
- catch (IllegalArgumentException e)
- {
- assertTrue(e.getLocalizedMessage().contains(mustBeInException));
- }
- }
-
- private static class TestContainerURL implements ContainerURL
- {
- private Mode mode;
- private WindowState ws;
- private StateString ns;
- private Map<String, String> props;
-
- static final StateString DEFAULT_NS;
- static final Map<String, String[]> DEFAULT_PARAMS = new HashMap<String,
String[]>(3);
- static final String PARAM = "param";
- static final String VALUE = "value";
-
- static
- {
- DEFAULT_PARAMS.put(PARAM, new String[]{VALUE});
- DEFAULT_NS = ParametersStateString.create(DEFAULT_PARAMS);
- }
-
- private TestContainerURL(Mode mode, WindowState ws, StateString ns, Map<String,
String> props)
- {
- this.mode = mode;
- this.ws = ws;
- this.ns = ns;
- this.props = props;
- }
-
- public Mode getMode()
- {
- return mode;
- }
-
- public WindowState getWindowState()
- {
- return ws;
- }
-
- public StateString getNavigationalState()
- {
- return ns;
- }
-
- public Map<String, String> getProperties()
- {
- return props;
- }
- }
-
- private static class TestResourceURL extends TestContainerURL implements ResourceURL
- {
- private static final String RESID = "resid";
- private String id;
- private StateString state;
- private CacheLevel cache;
-
- private TestResourceURL(String id, StateString state, CacheLevel cache)
- {
- super(Mode.VIEW, WindowState.NORMAL, DEFAULT_NS, null);
- init(id, state, cache);
- }
-
- private void init(String id, StateString state, CacheLevel cache)
- {
- this.id = id;
- this.state = state;
- this.cache = cache;
- }
-
- private TestResourceURL(String param, String value)
- {
- super(Mode.VIEW, WindowState.NORMAL, DEFAULT_NS, null);
-
- HashMap<String, String[]> params = new HashMap<String,
String[]>(3);
- params.put(param, new String[]{value});
-
- init(RESID, ParametersStateString.create(params), CacheLevel.FULL);
- }
-
- public String getResourceId()
- {
- return id;
- }
-
- public StateString getResourceState()
- {
- return state;
- }
-
- public CacheLevel getCacheability()
- {
- return cache;
- }
- }
-}
\ No newline at end of file