From do-not-reply at jboss.org Tue Mar 29 08:55:04 2011 Content-Type: multipart/mixed; boundary="===============8789650653671952708==" MIME-Version: 1.0 From: do-not-reply at jboss.org To: gatein-commits at lists.jboss.org Subject: [gatein-commits] gatein SVN: r6132 - in components/wsrp/trunk: common/src/test/java/org/gatein/wsrp and 1 other directories. Date: Tue, 29 Mar 2011 08:55:04 -0400 Message-ID: <201103291255.p2TCt4vn024204@svn01.web.mwc.hst.phx2.redhat.com> --===============8789650653671952708== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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/ConsumerBe= anTestCase.java components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/WSRPPortletUR= LTestCase.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/WSRPPor= tletURLTestCase.java Log: - Moved tests to proper directories. Copied: components/wsrp/trunk/admin-gui/src/test/java/org/gatein/wsrp/Consu= merBeanTestCase.java (from rev 6131, components/wsrp/trunk/admin-gui/src/te= st/java/org/gatein/wsrp/other/ConsumerBeanTestCase.java) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- components/wsrp/trunk/admin-gui/src/test/java/org/gatein/wsrp/ConsumerB= eanTestCase.java (rev 0) +++ components/wsrp/trunk/admin-gui/src/test/java/org/gatein/wsrp/ConsumerB= eanTestCase.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 Chris Laprun + * @version $Revision: 12612 $ + * @since 2.6 + */ +public class ConsumerBeanTestCase extends TestCase +{ + private static final String CONSUMER_ID =3D "foo"; + + /** Since our consumers use the MockEndpointConfigurationInfo, this is = the WSDL they are configured with */ + private static final String WSDL =3D BehaviorBackedServiceFactory.DEFAU= LT_WSDL_URL; + private ConsumerBean bean; + + protected void setUp() throws Exception + { + bean =3D new ConsumerBean(); + ConsumerRegistry registry =3D 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 =3D 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 =3D "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 s= everity, 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 getSessionMap() + { + throw new NotYetImplemented(); + } + } + + private static class TestInMemoryConsumerRegistry extends InMemoryConsu= merRegistry + { + @Override + public WSRPConsumer createConsumer(String id, Integer expirationCach= eSeconds, String wsdlURL) + { + // Use a "real" consumer but with a fake endpoint configuration s= o we can fake WS access + WSRPConsumer consumer =3D super.createConsumer(id, expirationCach= eSeconds, wsdlURL); + consumer.getProducerInfo().setEndpointConfigurationInfo(new MockE= ndpointConfigurationInfo()); + return consumer; + } + } +} Copied: components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/WSRPPort= letURLTestCase.java (from rev 6131, components/wsrp/trunk/common/src/test/j= ava/org/gatein/wsrp/other/WSRPPortletURLTestCase.java) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/WSRPPortletU= RLTestCase.java (rev 0) +++ components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/WSRPPortletU= RLTestCase.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 Chris Laprun + * @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 =3D "wsrp_rewrite?wsrp-urlType=3Dresource&wsrp-u= rl=3Dhttp%3A%2F%2Ftest.com%2Fimages%2Ftest.gif" + + "&wsrp-requiresRewrite=3Dfalse/wsrp_rewrite"; + WSRPPortletURL url =3D WSRPPortletURL.create(expected); + + assertTrue(url instanceof WSRPResourceURL); + WSRPResourceURL resource =3D (WSRPResourceURL)url; + assertFalse(resource.requiresRewrite()); + assertEquals("http://test.com/images/test.gif", resource.getResource= URL().toExternalForm()); + + //resource.getResourceId will not return the actual resource id, but= an encoded resource map used to determine how to access the resource + Map resourceMap =3D WSRPResourceURL.decodeResource(r= esource.getResourceId()); + String resourceURL =3D resourceMap.get(WSRPRewritingConstants.RESOUR= CE_URL); + assertEquals("http://test.com/images/test.gif", resourceURL); + + assertNull(resourceMap.get(WSRP2RewritingConstants.RESOURCE_ID)); + assertEquals("false", resourceMap.get(WSRP2RewritingConstants.RESOUR= CE_PREFER_OPERATION)); + } + + public void testResourceID() + { + String expected =3D "wsrp_rewrite?wsrp-urlType=3Dresource&wsrp-r= esourceID=3Dresource_123" + + "&wsrp-requiresRewrite=3Dfalse/wsrp_rewrite"; + WSRPPortletURL url =3D WSRPPortletURL.create(expected); + + assertTrue(url instanceof WSRPResourceURL); + WSRPResourceURL resource =3D (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 resourceMap =3D WSRPResourceURL.decodeResource(r= esource.getResourceId()); + String resourceID =3D resourceMap.get(WSRP2RewritingConstants.RESOUR= CE_ID); + assertEquals("resource_123", resourceID); + + assertNull(resourceMap.get(WSRPRewritingConstants.RESOURCE_URL)); + assertEquals("false", resourceMap.get(WSRP2RewritingConstants.RESOUR= CE_PREFER_OPERATION)); + } + + public void testResourceIDToken() + { + //Test what happens in the case where the url is created via token w= srp rewriting on the producer side + //In this case the resource ID will not be an encoded resource map. + + Map resourceMap =3D WSRPResourceURL.decodeResource("= resource_123"); + String resourceID =3D resourceMap.get(WSRP2RewritingConstants.RESOUR= CE_ID); + assertEquals("resource_123", resourceID); + + assertNull(resourceMap.get(WSRPRewritingConstants.RESOURCE_URL)); + assertNull(resourceMap.get(WSRP2RewritingConstants.RESOURCE_PREFER_O= PERATION)); + } + + public void testResources() + { + String expected =3D "wsrp_rewrite?wsrp-urlType=3Dresource&wsrp-r= esourceID=3Dresource_123" + + "&wsrp-url=3Dhttp%3A%2F%2Ftest.com%2Fimages%2Ftest.gif&ws= rp-requiresRewrite=3Dfalse/wsrp_rewrite"; + WSRPPortletURL url =3D WSRPPortletURL.create(expected); + + assertTrue(url instanceof WSRPResourceURL); + WSRPResourceURL resource =3D (WSRPResourceURL)url; + assertFalse(resource.requiresRewrite()); + assertEquals("http://test.com/images/test.gif", resource.getResource= URL().toExternalForm()); + + //resource.getResourceId will not return the actual resource id, but= an encoded resource map used to determine how to access the resource + Map resourceMap =3D WSRPResourceURL.decodeResource(r= esource.getResourceId()); + String resourceID =3D resourceMap.get(WSRP2RewritingConstants.RESOUR= CE_ID); + assertEquals("resource_123", resourceID); + + String resourceURL =3D resourceMap.get(WSRPRewritingConstants.RESOUR= CE_URL); + assertEquals("http://test.com/images/test.gif", resourceURL); + assertEquals("false", resourceMap.get(WSRP2RewritingConstants.RESOUR= CE_PREFER_OPERATION)); + } + + public void testResourcesNoRequiresRewrite() + { + String expected =3D "wsrp_rewrite?wsrp-urlType=3Dresource&wsrp-r= esourceID=3Dresource_123" + + "&wsrp-url=3Dhttp%3A%2F%2Ftest.com%2Fimages%2Ftest.gif&/w= srp_rewrite"; + WSRPPortletURL url =3D WSRPPortletURL.create(expected); + + assertTrue(url instanceof WSRPResourceURL); + WSRPResourceURL resource =3D (WSRPResourceURL)url; + assertFalse(resource.requiresRewrite()); + assertEquals("http://test.com/images/test.gif", resource.getResource= URL().toExternalForm()); + + //resource.getResourceId will not return the actual resource id, but= an encoded resource map used to determine how to access the resource + Map resourceMap =3D WSRPResourceURL.decodeResource(r= esource.getResourceId()); + String resourceID =3D resourceMap.get(WSRP2RewritingConstants.RESOUR= CE_ID); + assertEquals("resource_123", resourceID); + + String resourceURL =3D resourceMap.get(WSRPRewritingConstants.RESOUR= CE_URL); + assertEquals("http://test.com/images/test.gif", resourceURL); + assertEquals("false", resourceMap.get(WSRP2RewritingConstants.RESOUR= CE_PREFER_OPERATION)); + } + + public void testResourcesNoResourceURL() + { + String expected =3D "wsrp_rewrite?wsrp-urlType=3Dresource&wsrp-r= esourceID=3Dresource_123" + + "&wsrp-requiresRewrite=3Dfalse/wsrp_rewrite"; + WSRPPortletURL url =3D WSRPPortletURL.create(expected); + + assertTrue(url instanceof WSRPResourceURL); + WSRPResourceURL resource =3D (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 resourceMap =3D WSRPResourceURL.decodeResource(r= esource.getResourceId()); + String resourceID =3D resourceMap.get(WSRP2RewritingConstants.RESOUR= CE_ID); + assertEquals("resource_123", resourceID); + + assertEquals("false", resourceMap.get(WSRP2RewritingConstants.RESOUR= CE_PREFER_OPERATION)); + } + + public void testPreferOperation() + { + String expected =3D "wsrp_rewrite?wsrp-urlType=3Dresource&wsrp-r= esourceID=3Dresource_123" + + "&wsrp-url=3Dhttp%3A%2F%2Ftest.com%2Fimages%2Ftest.gif&ws= rp-preferOperation=3Dtrue&wsrp-requiresRewrite=3Dfalse/wsrp_rewrite"; + WSRPPortletURL url =3D WSRPPortletURL.create(expected); + + assertTrue(url instanceof WSRPResourceURL); + WSRPResourceURL resource =3D (WSRPResourceURL)url; + assertFalse(resource.requiresRewrite()); + assertEquals("http://test.com/images/test.gif", resource.getResource= URL().toExternalForm()); + + //resource.getResourceId will not return the actual resource id, but= an encoded resource map used to determine how to access the resource + Map resourceMap =3D WSRPResourceURL.decodeResource(r= esource.getResourceId()); + String resourceID =3D resourceMap.get(WSRP2RewritingConstants.RESOUR= CE_ID); + assertEquals("resource_123", resourceID); + + String resourceURL =3D resourceMap.get(WSRPRewritingConstants.RESOUR= CE_URL); + assertEquals("http://test.com/images/test.gif", resourceURL); + + String preferOperation =3D resourceMap.get(WSRP2RewritingConstants.R= ESOURCE_PREFER_OPERATION); + assertEquals("true", preferOperation); + } + + public void testShouldSetPreferOperationToTrueWhenResourceIdIsPresent() + { + ResourceURL resourceURL =3D new TestResourceURL(TestResourceURL.RESI= D, TestResourceURL.DEFAULT_NS, CacheLevel.FULL); + WSRPPortletURL url =3D WSRPPortletURL.create(resourceURL, false, WSR= PPortletURL.URLContext.EMPTY); + + String actual =3D url.toString(); + assertTrue(actual.contains("wsrp-urlType=3Dresource")); + assertTrue(actual.contains("wsrp-resourceID=3D" + TestResourceURL.RE= SID)); + assertTrue(actual.contains("wsrp-preferOperation=3Dtrue")); + } + + public void testShouldProperlyTransmitResourceState() + { + // create URL from container + ResourceURL resourceURL =3D new TestResourceURL("resparam", "resvalu= e"); + WSRPPortletURL url =3D WSRPPortletURL.create(resourceURL, false, WSR= PPortletURL.URLContext.EMPTY); + + assertTrue(url instanceof WSRPResourceURL); + WSRPResourceURL resource =3D (WSRPResourceURL)url; + StateString resourceState =3D resource.getResourceState(); + assertNotNull(resourceState); + + // serialize URL to WSRP string format + String resourceAsString =3D resource.toString(); + + // and re-create it + url =3D WSRPPortletURL.create(resourceAsString); + + // check that we have indeed the same state + assertTrue(url instanceof WSRPResourceURL); + resource =3D (WSRPResourceURL)url; + resourceState =3D resource.getResourceState(); + assertNotNull(resourceState); + Map state =3D StateString.decodeOpaqueValue(resour= ceState.getStringValue()); + assertEquals("resvalue", state.get("resparam")[0]); + } + + /** Declare a secure interaction back to the Portlet */ + public void testSecureInteraction() + { + String expected =3D "wsrp_rewrite?wsrp-urlType=3DblockingAction&= wsrp-secureURL=3Dtrue" + + "&wsrp-navigationalState=3Da8h4K5JD9&wsrp-interactionStat= e=3Dfg4h923mdk/wsrp_rewrite"; + WSRPPortletURL url =3D WSRPPortletURL.create(expected); + + assertTrue(url instanceof WSRPActionURL); + WSRPActionURL actionURL =3D (WSRPActionURL)url; + assertTrue(url.isSecure()); + assertEquals("a8h4K5JD9", actionURL.getNavigationalState().getString= Value()); + assertEquals("fg4h923mdk", actionURL.getInteractionState().getString= Value()); + } + + /** Request the Consumer render the Portlet in a different mode and win= dow state */ + public void testDifferentModeAndWindowState() + { + String expected =3D "wsrp_rewrite?wsrp-urlType=3Drender&wsrp-mod= e=3Dwsrp:help&wsrp-windowState=3Dwsrp:maximized/wsrp_rewrite"; + WSRPPortletURL url =3D WSRPPortletURL.create(expected); + + assertTrue(url instanceof WSRPRenderURL); + assertEquals(Mode.HELP, url.getMode()); + assertEquals(WindowState.MAXIMIZED, url.getWindowState()); + } + + public void testMinimal() + { + String minimalURLType =3D "wsrp_rewrite?wsrp-urlType=3Drender/wsrp_r= ewrite"; + WSRPPortletURL url =3D WSRPPortletURL.create(minimalURLType); + + assertTrue(url instanceof WSRPRenderURL); + } + + public void testInvalidParameterName() + { + String message =3D "Should have detected invalid parameter: "; + + String invalid =3D "wsrp_rewrite?wsrp-urlType=3Drender&foo=3Dbar= /wsrp_rewrite"; + checkInvalidURL(invalid, message, "foo"); + } + + public void testDoublyEncodedAmpersand() + { + String expected =3D "wsrp_rewrite?wsrp-urlType=3Drender&amp;wsrp= -mode=3Dwsrp:help&amp;wsrp-windowState=3Dwsrp: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 =3D "wsrp_rewrite?wsrp-urlType=3Drender&am= p;foo=3Dbar/wsrp_rewrite"; + + WSRPPortletURL url =3D WSRPPortletURL.create(validInRelaxedMode); + assertTrue(url instanceof WSRPRenderURL); + assertTrue(url.toString().contains("foo=3Dbar")); + + validInRelaxedMode =3D "wsrp_rewrite?wsrp-urlType=3Drender/wsrp_rewr= ite&foo=3Dbar"; + url =3D WSRPPortletURL.create(validInRelaxedMode); + assertTrue(url instanceof WSRPRenderURL); + assertTrue(url.toString().endsWith("foo=3Dbar")); + + String stillInvalid =3D "wsrp_rewrite?wsrp-urlType=3Drender&foo= =3Dbar"; + checkInvalidURL(stillInvalid, "Should have detected missing end toke= n", WSRPRewritingConstants.END_WSRP_REWRITE); + } + + /*public void testExtraRelaxedValidation() + { + String valid =3D "wsrp_rewrite?wsrp-urlType=3Dresource&wsrp-url=3Dht= tp%3A%2F%2Flocalhost%3A8080%2Fhelloworld&wsrp-requiresRewrite=3Dtrue/wsrp_r= ewrite/helloworld.jar"; + WSRPPortletURL url =3D WSRPPortletURL.create(valid); + assertEquals("http://localhost:8080/helloworld/helloworld.jar", url.= toString()); + + String invalid =3D "wsrp_rewrite?wsrp-urlType=3Dresource&wsrp-url=3D= http%3A%2F%2Flocalhost%3A8080%2Fhelloworld&wsrp-requiresRewrite=3Dtrue/wsrp= _rewrite&foo=3Dbar/helloworld.jar"; + checkInvalidURL(invalid, "Should have detected improper position of = end token", WSRPRewritingConstants.END_WSRP_REWRITE); + + WSRPPortletURL.setStrict(false); + String validInRelaxedMode =3D "wsrp_rewrite?wsrp-urlType=3Dresource&= wsrp-url=3Dhttp%3A%2F%2Flocalhost%3A8080%2Fhelloworld&wsrp-requiresRewrite= =3Dtrue/wsrp_rewrite&foo=3Dbar/helloworld.jar"; + url =3D WSRPPortletURL.create(validInRelaxedMode); + assertEquals("http://localhost:8080/helloworld&foo=3Dbar/helloworld.= jar", url.toString()); + }*/ + + public void testExtraParameters() + { + String validInRelaxedMode =3D "wsrp_rewrite?wsrp-urlType=3Drender&am= p;foo=3Dbar/wsrp_rewrite"; + checkInvalidURL(validInRelaxedMode, "Should have detected invalid pa= rameter: ", "foo"); + + validInRelaxedMode =3D "wsrp_rewrite?wsrp-urlType=3Drender/wsrp_rewr= ite&foo=3Dbar"; + checkInvalidURL(validInRelaxedMode, "Should have detected URL doesn'= t end with end token", WSRPRewritingConstants.END_WSRP_REWRITE); + } + + public void testInvalidMode() + { + String message =3D "Should have detected invalid mode: "; + + String invalid =3D "wsrp_rewrite?wsrp-urlType=3Drender&wsrp-mode=3Df= oo/wsrp_rewrite"; + checkInvalidURL(invalid, message, "foo"); + } + + public void testCustomModeAndWindowState() + { + Set modes =3D new HashSet(); + modes.add("urn:foo"); + + Set windowStates =3D new HashSet(); + windowStates.add("urn:bar"); + + String urlString =3D "wsrp_rewrite?wsrp-urlType=3Drender&wsrp-mode= =3Durn%3Afoo&wsrp-windowState=3Durn%3Abar/wsrp_rewrite"; + WSRPPortletURL url =3D WSRPPortletURL.create(urlString, modes, windo= wStates); + assertEquals("urn:foo", url.getMode().toString()); + assertEquals("urn:bar", url.getWindowState().toString()); + } + + public void testEncodedMode() + { + String encoded =3D "wsrp_rewrite?wsrp-urlType=3Drender&wsrp-mode=3Dw= srp%3Aview/wsrp_rewrite"; + WSRPPortletURL url =3D WSRPPortletURL.create(encoded); + assertEquals(Mode.VIEW, url.getMode()); + + encoded =3D "wsrp_rewrite?wsrp-urlType=3Drender&wsrp-mode=3Dwsrp%3ae= dit/wsrp_rewrite"; + url =3D WSRPPortletURL.create(encoded); + assertEquals(Mode.EDIT, url.getMode()); + } + + public void testEncodedWindowState() + { + String encoded =3D "wsrp_rewrite?wsrp-urlType=3Drender&wsrp-windowSt= ate=3Dwsrp%3Amaximized/wsrp_rewrite"; + WSRPPortletURL url =3D WSRPPortletURL.create(encoded); + assertEquals(WindowState.MAXIMIZED, url.getWindowState()); + + encoded =3D "wsrp_rewrite?wsrp-urlType=3Drender&wsrp-windowState=3Dw= srp%3aminimized/wsrp_rewrite"; + url =3D WSRPPortletURL.create(encoded); + assertEquals(WindowState.MINIMIZED, url.getWindowState()); + } + + public void testInvalidResourceURLV1() + { + String message =3D "Should have detected missing parameter: "; + + /* + // We now allow requiresRewrite to be missing and assume false inste= ad... See GTNWSRP-103. + String invalid =3D "wsrp_rewrite?wsrp-urlType=3Dresource&wsrp-ur= l=3Dhttp%3A%2F%2Flocalhost%2F/wsrp_rewrite"; + checkInvalidURL(invalid, message, WSRPRewritingConstants.RESOURCE_RE= QUIRES_REWRITE); + */ + + String invalid =3D "wsrp_rewrite?wsrp-urlType=3Dresource&wsrp-re= quiresRewrite=3Dtrue/wsrp_rewrite"; + checkInvalidURL(invalid, message, WSRPRewritingConstants.RESOURCE_UR= L); + + invalid =3D "wsrp_rewrite?wsrp-urlType=3Dresource&wsrp-url=3Dinv= alidURL&wsrp-requiresRewrite=3Dtrue/wsrp_rewrite"; + checkInvalidURL(invalid, "Should have detected invalid URL: ", "inva= lidURL"); + } + + public void testNullURL() + { + try + { + WSRPPortletURL.create(null); + fail("Should have detected null URL"); + } + catch (IllegalArgumentException e) + { + // expected + } + } + + public void testInvalidURLType() + { + String wrongURLType =3D "wsrp_rewrite?wsrp-urlType=3Dpipo&wsrp-m= ode=3Dhelp/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 =3D 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_R= EWRITE)); + } + + private void checkInvalidURL(String invalid, String message, String mus= tBeInException) + { + 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 props; + + static final StateString DEFAULT_NS; + static final Map DEFAULT_PARAMS =3D new HashMap(3); + static final String PARAM =3D "param"; + static final String VALUE =3D "value"; + + static + { + DEFAULT_PARAMS.put(PARAM, new String[]{VALUE}); + DEFAULT_NS =3D ParametersStateString.create(DEFAULT_PARAMS); + } + + private TestContainerURL(Mode mode, WindowState ws, StateString ns, = Map props) + { + this.mode =3D mode; + this.ws =3D ws; + this.ns =3D ns; + this.props =3D props; + } + + public Mode getMode() + { + return mode; + } + + public WindowState getWindowState() + { + return ws; + } + + public StateString getNavigationalState() + { + return ns; + } + + public Map getProperties() + { + return props; + } + } + + private static class TestResourceURL extends TestContainerURL implement= s ResourceURL + { + private static final String RESID =3D "resid"; + private String id; + private StateString state; + private CacheLevel cache; + + private TestResourceURL(String id, StateString state, CacheLevel cac= he) + { + super(Mode.VIEW, WindowState.NORMAL, DEFAULT_NS, null); + init(id, state, cache); + } + + private void init(String id, StateString state, CacheLevel cache) + { + this.id =3D id; + this.state =3D state; + this.cache =3D cache; + } + + private TestResourceURL(String param, String value) + { + super(Mode.VIEW, WindowState.NORMAL, DEFAULT_NS, null); + + HashMap params =3D new HashMap(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/W= SRPPortletURLTestCase.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/other/WSRPPo= rtletURLTestCase.java 2011-03-29 12:06:50 UTC (rev 6131) +++ components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/other/WSRPPo= rtletURLTestCase.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 Chris Laprun - * @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 =3D "wsrp_rewrite?wsrp-urlType=3Dresource&wsrp-u= rl=3Dhttp%3A%2F%2Ftest.com%2Fimages%2Ftest.gif" + - "&wsrp-requiresRewrite=3Dfalse/wsrp_rewrite"; - WSRPPortletURL url =3D WSRPPortletURL.create(expected); - - assertTrue(url instanceof WSRPResourceURL); - WSRPResourceURL resource =3D (WSRPResourceURL)url; - assertFalse(resource.requiresRewrite()); - assertEquals("http://test.com/images/test.gif", resource.getResource= URL().toExternalForm()); - - //resource.getResourceId will not return the actual resource id, but= an encoded resource map used to determine how to access the resource - Map resourceMap =3D WSRPResourceURL.decodeResource(r= esource.getResourceId()); - String resourceURL =3D resourceMap.get(WSRPRewritingConstants.RESOUR= CE_URL); - assertEquals("http://test.com/images/test.gif", resourceURL); - - assertNull(resourceMap.get(WSRP2RewritingConstants.RESOURCE_ID)); - assertEquals("false", resourceMap.get(WSRP2RewritingConstants.RESOUR= CE_PREFER_OPERATION)); - } - - public void testResourceID() - { - String expected =3D "wsrp_rewrite?wsrp-urlType=3Dresource&wsrp-r= esourceID=3Dresource_123" + - "&wsrp-requiresRewrite=3Dfalse/wsrp_rewrite"; - WSRPPortletURL url =3D WSRPPortletURL.create(expected); - - assertTrue(url instanceof WSRPResourceURL); - WSRPResourceURL resource =3D (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 resourceMap =3D WSRPResourceURL.decodeResource(r= esource.getResourceId()); - String resourceID =3D resourceMap.get(WSRP2RewritingConstants.RESOUR= CE_ID); - assertEquals("resource_123", resourceID); - - assertNull(resourceMap.get(WSRPRewritingConstants.RESOURCE_URL)); - assertEquals("false", resourceMap.get(WSRP2RewritingConstants.RESOUR= CE_PREFER_OPERATION)); - } - - public void testResourceIDToken() - { - //Test what happens in the case where the url is created via token w= srp rewriting on the producer side - //In this case the resource ID will not be an encoded resource map. - - Map resourceMap =3D WSRPResourceURL.decodeResource("= resource_123"); - String resourceID =3D resourceMap.get(WSRP2RewritingConstants.RESOUR= CE_ID); - assertEquals("resource_123", resourceID); - - assertNull(resourceMap.get(WSRPRewritingConstants.RESOURCE_URL)); - assertNull(resourceMap.get(WSRP2RewritingConstants.RESOURCE_PREFER_O= PERATION)); - } - - public void testResources() - { - String expected =3D "wsrp_rewrite?wsrp-urlType=3Dresource&wsrp-r= esourceID=3Dresource_123" + - "&wsrp-url=3Dhttp%3A%2F%2Ftest.com%2Fimages%2Ftest.gif&ws= rp-requiresRewrite=3Dfalse/wsrp_rewrite"; - WSRPPortletURL url =3D WSRPPortletURL.create(expected); - - assertTrue(url instanceof WSRPResourceURL); - WSRPResourceURL resource =3D (WSRPResourceURL)url; - assertFalse(resource.requiresRewrite()); - assertEquals("http://test.com/images/test.gif", resource.getResource= URL().toExternalForm()); - - //resource.getResourceId will not return the actual resource id, but= an encoded resource map used to determine how to access the resource - Map resourceMap =3D WSRPResourceURL.decodeResource(r= esource.getResourceId()); - String resourceID =3D resourceMap.get(WSRP2RewritingConstants.RESOUR= CE_ID); - assertEquals("resource_123", resourceID); - - String resourceURL =3D resourceMap.get(WSRPRewritingConstants.RESOUR= CE_URL); - assertEquals("http://test.com/images/test.gif", resourceURL); - assertEquals("false", resourceMap.get(WSRP2RewritingConstants.RESOUR= CE_PREFER_OPERATION)); - } - - public void testResourcesNoRequiresRewrite() - { - String expected =3D "wsrp_rewrite?wsrp-urlType=3Dresource&wsrp-r= esourceID=3Dresource_123" + - "&wsrp-url=3Dhttp%3A%2F%2Ftest.com%2Fimages%2Ftest.gif&/w= srp_rewrite"; - WSRPPortletURL url =3D WSRPPortletURL.create(expected); - - assertTrue(url instanceof WSRPResourceURL); - WSRPResourceURL resource =3D (WSRPResourceURL)url; - assertFalse(resource.requiresRewrite()); - assertEquals("http://test.com/images/test.gif", resource.getResource= URL().toExternalForm()); - - //resource.getResourceId will not return the actual resource id, but= an encoded resource map used to determine how to access the resource - Map resourceMap =3D WSRPResourceURL.decodeResource(r= esource.getResourceId()); - String resourceID =3D resourceMap.get(WSRP2RewritingConstants.RESOUR= CE_ID); - assertEquals("resource_123", resourceID); - - String resourceURL =3D resourceMap.get(WSRPRewritingConstants.RESOUR= CE_URL); - assertEquals("http://test.com/images/test.gif", resourceURL); - assertEquals("false", resourceMap.get(WSRP2RewritingConstants.RESOUR= CE_PREFER_OPERATION)); - } - - public void testResourcesNoResourceURL() - { - String expected =3D "wsrp_rewrite?wsrp-urlType=3Dresource&wsrp-r= esourceID=3Dresource_123" + - "&wsrp-requiresRewrite=3Dfalse/wsrp_rewrite"; - WSRPPortletURL url =3D WSRPPortletURL.create(expected); - - assertTrue(url instanceof WSRPResourceURL); - WSRPResourceURL resource =3D (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 resourceMap =3D WSRPResourceURL.decodeResource(r= esource.getResourceId()); - String resourceID =3D resourceMap.get(WSRP2RewritingConstants.RESOUR= CE_ID); - assertEquals("resource_123", resourceID); - - assertEquals("false", resourceMap.get(WSRP2RewritingConstants.RESOUR= CE_PREFER_OPERATION)); - } - - public void testPreferOperation() - { - String expected =3D "wsrp_rewrite?wsrp-urlType=3Dresource&wsrp-r= esourceID=3Dresource_123" + - "&wsrp-url=3Dhttp%3A%2F%2Ftest.com%2Fimages%2Ftest.gif&ws= rp-preferOperation=3Dtrue&wsrp-requiresRewrite=3Dfalse/wsrp_rewrite"; - WSRPPortletURL url =3D WSRPPortletURL.create(expected); - - assertTrue(url instanceof WSRPResourceURL); - WSRPResourceURL resource =3D (WSRPResourceURL)url; - assertFalse(resource.requiresRewrite()); - assertEquals("http://test.com/images/test.gif", resource.getResource= URL().toExternalForm()); - - //resource.getResourceId will not return the actual resource id, but= an encoded resource map used to determine how to access the resource - Map resourceMap =3D WSRPResourceURL.decodeResource(r= esource.getResourceId()); - String resourceID =3D resourceMap.get(WSRP2RewritingConstants.RESOUR= CE_ID); - assertEquals("resource_123", resourceID); - - String resourceURL =3D resourceMap.get(WSRPRewritingConstants.RESOUR= CE_URL); - assertEquals("http://test.com/images/test.gif", resourceURL); - - String preferOperation =3D resourceMap.get(WSRP2RewritingConstants.R= ESOURCE_PREFER_OPERATION); - assertEquals("true", preferOperation); - } - - public void testShouldSetPreferOperationToTrueWhenResourceIdIsPresent() - { - ResourceURL resourceURL =3D new TestResourceURL(TestResourceURL.RESI= D, TestResourceURL.DEFAULT_NS, CacheLevel.FULL); - WSRPPortletURL url =3D WSRPPortletURL.create(resourceURL, false, WSR= PPortletURL.URLContext.EMPTY); - - String actual =3D url.toString(); - assertTrue(actual.contains("wsrp-urlType=3Dresource")); - assertTrue(actual.contains("wsrp-resourceID=3D" + TestResourceURL.RE= SID)); - assertTrue(actual.contains("wsrp-preferOperation=3Dtrue")); - } - - public void testShouldProperlyTransmitResourceState() - { - // create URL from container - ResourceURL resourceURL =3D new TestResourceURL("resparam", "resvalu= e"); - WSRPPortletURL url =3D WSRPPortletURL.create(resourceURL, false, WSR= PPortletURL.URLContext.EMPTY); - - assertTrue(url instanceof WSRPResourceURL); - WSRPResourceURL resource =3D (WSRPResourceURL)url; - StateString resourceState =3D resource.getResourceState(); - assertNotNull(resourceState); - - // serialize URL to WSRP string format - String resourceAsString =3D resource.toString(); - - // and re-create it - url =3D WSRPPortletURL.create(resourceAsString); - - // check that we have indeed the same state - assertTrue(url instanceof WSRPResourceURL); - resource =3D (WSRPResourceURL)url; - resourceState =3D resource.getResourceState(); - assertNotNull(resourceState); - Map state =3D StateString.decodeOpaqueValue(resour= ceState.getStringValue()); - assertEquals("resvalue", state.get("resparam")[0]); - } - - /** Declare a secure interaction back to the Portlet */ - public void testSecureInteraction() - { - String expected =3D "wsrp_rewrite?wsrp-urlType=3DblockingAction&= wsrp-secureURL=3Dtrue" + - "&wsrp-navigationalState=3Da8h4K5JD9&wsrp-interactionStat= e=3Dfg4h923mdk/wsrp_rewrite"; - WSRPPortletURL url =3D WSRPPortletURL.create(expected); - - assertTrue(url instanceof WSRPActionURL); - WSRPActionURL actionURL =3D (WSRPActionURL)url; - assertTrue(url.isSecure()); - assertEquals("a8h4K5JD9", actionURL.getNavigationalState().getString= Value()); - assertEquals("fg4h923mdk", actionURL.getInteractionState().getString= Value()); - } - - /** Request the Consumer render the Portlet in a different mode and win= dow state */ - public void testDifferentModeAndWindowState() - { - String expected =3D "wsrp_rewrite?wsrp-urlType=3Drender&wsrp-mod= e=3Dwsrp:help&wsrp-windowState=3Dwsrp:maximized/wsrp_rewrite"; - WSRPPortletURL url =3D WSRPPortletURL.create(expected); - - assertTrue(url instanceof WSRPRenderURL); - assertEquals(Mode.HELP, url.getMode()); - assertEquals(WindowState.MAXIMIZED, url.getWindowState()); - } - - public void testMinimal() - { - String minimalURLType =3D "wsrp_rewrite?wsrp-urlType=3Drender/wsrp_r= ewrite"; - WSRPPortletURL url =3D WSRPPortletURL.create(minimalURLType); - - assertTrue(url instanceof WSRPRenderURL); - } - - public void testInvalidParameterName() - { - String message =3D "Should have detected invalid parameter: "; - - String invalid =3D "wsrp_rewrite?wsrp-urlType=3Drender&foo=3Dbar= /wsrp_rewrite"; - checkInvalidURL(invalid, message, "foo"); - } - - public void testDoublyEncodedAmpersand() - { - String expected =3D "wsrp_rewrite?wsrp-urlType=3Drender&amp;wsrp= -mode=3Dwsrp:help&amp;wsrp-windowState=3Dwsrp: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 =3D "wsrp_rewrite?wsrp-urlType=3Drender&am= p;foo=3Dbar/wsrp_rewrite"; - - WSRPPortletURL url =3D WSRPPortletURL.create(validInRelaxedMode); - assertTrue(url instanceof WSRPRenderURL); - assertTrue(url.toString().contains("foo=3Dbar")); - - validInRelaxedMode =3D "wsrp_rewrite?wsrp-urlType=3Drender/wsrp_rewr= ite&foo=3Dbar"; - url =3D WSRPPortletURL.create(validInRelaxedMode); - assertTrue(url instanceof WSRPRenderURL); - assertTrue(url.toString().endsWith("foo=3Dbar")); - - String stillInvalid =3D "wsrp_rewrite?wsrp-urlType=3Drender&foo= =3Dbar"; - checkInvalidURL(stillInvalid, "Should have detected missing end toke= n", WSRPRewritingConstants.END_WSRP_REWRITE); - } - - /*public void testExtraRelaxedValidation() - { - String valid =3D "wsrp_rewrite?wsrp-urlType=3Dresource&wsrp-url=3Dht= tp%3A%2F%2Flocalhost%3A8080%2Fhelloworld&wsrp-requiresRewrite=3Dtrue/wsrp_r= ewrite/helloworld.jar"; - WSRPPortletURL url =3D WSRPPortletURL.create(valid); - assertEquals("http://localhost:8080/helloworld/helloworld.jar", url.= toString()); - - String invalid =3D "wsrp_rewrite?wsrp-urlType=3Dresource&wsrp-url=3D= http%3A%2F%2Flocalhost%3A8080%2Fhelloworld&wsrp-requiresRewrite=3Dtrue/wsrp= _rewrite&foo=3Dbar/helloworld.jar"; - checkInvalidURL(invalid, "Should have detected improper position of = end token", WSRPRewritingConstants.END_WSRP_REWRITE); - - WSRPPortletURL.setStrict(false); - String validInRelaxedMode =3D "wsrp_rewrite?wsrp-urlType=3Dresource&= wsrp-url=3Dhttp%3A%2F%2Flocalhost%3A8080%2Fhelloworld&wsrp-requiresRewrite= =3Dtrue/wsrp_rewrite&foo=3Dbar/helloworld.jar"; - url =3D WSRPPortletURL.create(validInRelaxedMode); - assertEquals("http://localhost:8080/helloworld&foo=3Dbar/helloworld.= jar", url.toString()); - }*/ - - public void testExtraParameters() - { - String validInRelaxedMode =3D "wsrp_rewrite?wsrp-urlType=3Drender&am= p;foo=3Dbar/wsrp_rewrite"; - checkInvalidURL(validInRelaxedMode, "Should have detected invalid pa= rameter: ", "foo"); - - validInRelaxedMode =3D "wsrp_rewrite?wsrp-urlType=3Drender/wsrp_rewr= ite&foo=3Dbar"; - checkInvalidURL(validInRelaxedMode, "Should have detected URL doesn'= t end with end token", WSRPRewritingConstants.END_WSRP_REWRITE); - } - - public void testInvalidMode() - { - String message =3D "Should have detected invalid mode: "; - - String invalid =3D "wsrp_rewrite?wsrp-urlType=3Drender&wsrp-mode=3Df= oo/wsrp_rewrite"; - checkInvalidURL(invalid, message, "foo"); - } - - public void testCustomModeAndWindowState() - { - Set modes =3D new HashSet(); - modes.add("urn:foo"); - - Set windowStates =3D new HashSet(); - windowStates.add("urn:bar"); - - String urlString =3D "wsrp_rewrite?wsrp-urlType=3Drender&wsrp-mode= =3Durn%3Afoo&wsrp-windowState=3Durn%3Abar/wsrp_rewrite"; - WSRPPortletURL url =3D WSRPPortletURL.create(urlString, modes, windo= wStates); - assertEquals("urn:foo", url.getMode().toString()); - assertEquals("urn:bar", url.getWindowState().toString()); - } - - public void testEncodedMode() - { - String encoded =3D "wsrp_rewrite?wsrp-urlType=3Drender&wsrp-mode=3Dw= srp%3Aview/wsrp_rewrite"; - WSRPPortletURL url =3D WSRPPortletURL.create(encoded); - assertEquals(Mode.VIEW, url.getMode()); - - encoded =3D "wsrp_rewrite?wsrp-urlType=3Drender&wsrp-mode=3Dwsrp%3ae= dit/wsrp_rewrite"; - url =3D WSRPPortletURL.create(encoded); - assertEquals(Mode.EDIT, url.getMode()); - } - - public void testEncodedWindowState() - { - String encoded =3D "wsrp_rewrite?wsrp-urlType=3Drender&wsrp-windowSt= ate=3Dwsrp%3Amaximized/wsrp_rewrite"; - WSRPPortletURL url =3D WSRPPortletURL.create(encoded); - assertEquals(WindowState.MAXIMIZED, url.getWindowState()); - - encoded =3D "wsrp_rewrite?wsrp-urlType=3Drender&wsrp-windowState=3Dw= srp%3aminimized/wsrp_rewrite"; - url =3D WSRPPortletURL.create(encoded); - assertEquals(WindowState.MINIMIZED, url.getWindowState()); - } - - public void testInvalidResourceURLV1() - { - String message =3D "Should have detected missing parameter: "; - - /* - // We now allow requiresRewrite to be missing and assume false inste= ad... See GTNWSRP-103. - String invalid =3D "wsrp_rewrite?wsrp-urlType=3Dresource&wsrp-ur= l=3Dhttp%3A%2F%2Flocalhost%2F/wsrp_rewrite"; - checkInvalidURL(invalid, message, WSRPRewritingConstants.RESOURCE_RE= QUIRES_REWRITE); - */ - - String invalid =3D "wsrp_rewrite?wsrp-urlType=3Dresource&wsrp-re= quiresRewrite=3Dtrue/wsrp_rewrite"; - checkInvalidURL(invalid, message, WSRPRewritingConstants.RESOURCE_UR= L); - - invalid =3D "wsrp_rewrite?wsrp-urlType=3Dresource&wsrp-url=3Dinv= alidURL&wsrp-requiresRewrite=3Dtrue/wsrp_rewrite"; - checkInvalidURL(invalid, "Should have detected invalid URL: ", "inva= lidURL"); - } - - public void testNullURL() - { - try - { - WSRPPortletURL.create(null); - fail("Should have detected null URL"); - } - catch (IllegalArgumentException e) - { - // expected - } - } - - public void testInvalidURLType() - { - String wrongURLType =3D "wsrp_rewrite?wsrp-urlType=3Dpipo&wsrp-m= ode=3Dhelp/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 =3D 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_R= EWRITE)); - } - - private void checkInvalidURL(String invalid, String message, String mus= tBeInException) - { - 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 props; - - static final StateString DEFAULT_NS; - static final Map DEFAULT_PARAMS =3D new HashMap(3); - static final String PARAM =3D "param"; - static final String VALUE =3D "value"; - - static - { - DEFAULT_PARAMS.put(PARAM, new String[]{VALUE}); - DEFAULT_NS =3D ParametersStateString.create(DEFAULT_PARAMS); - } - - private TestContainerURL(Mode mode, WindowState ws, StateString ns, = Map props) - { - this.mode =3D mode; - this.ws =3D ws; - this.ns =3D ns; - this.props =3D props; - } - - public Mode getMode() - { - return mode; - } - - public WindowState getWindowState() - { - return ws; - } - - public StateString getNavigationalState() - { - return ns; - } - - public Map getProperties() - { - return props; - } - } - - private static class TestResourceURL extends TestContainerURL implement= s ResourceURL - { - private static final String RESID =3D "resid"; - private String id; - private StateString state; - private CacheLevel cache; - - private TestResourceURL(String id, StateString state, CacheLevel cac= he) - { - super(Mode.VIEW, WindowState.NORMAL, DEFAULT_NS, null); - init(id, state, cache); - } - - private void init(String id, StateString state, CacheLevel cache) - { - this.id =3D id; - this.state =3D state; - this.cache =3D cache; - } - - private TestResourceURL(String param, String value) - { - super(Mode.VIEW, WindowState.NORMAL, DEFAULT_NS, null); - - HashMap params =3D new HashMap(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 --===============8789650653671952708==--