Author: chris.laprun(a)jboss.com
Date: 2010-12-16 09:38:05 -0500 (Thu, 16 Dec 2010)
New Revision: 5596
Added:
components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/spi/
components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/spi/WSRPConsumerSPI.java
components/wsrp/branches/2.0.x/consumer/src/test/java/org/gatein/wsrp/consumer/handlers/MimeResponseHandlerTestCase.java
components/wsrp/branches/2.0.x/consumer/src/test/java/org/gatein/wsrp/test/support/TestActionInvocation.java
components/wsrp/branches/2.0.x/consumer/src/test/java/org/gatein/wsrp/test/support/TestRenderInvocation.java
components/wsrp/branches/2.0.x/consumer/src/test/java/org/gatein/wsrp/test/support/TestResourceInvocation.java
components/wsrp/branches/2.0.x/consumer/src/test/java/org/gatein/wsrp/test/support/TestWindowContext.java
Removed:
components/wsrp/branches/2.0.x/consumer/src/test/java/org/gatein/wsrp/consumer/handlers/RenderHandlerTestCase.java
Modified:
components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java
components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/DirectResourceServingHandler.java
components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/InvocationHandler.java
components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/MimeResponseHandler.java
components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/RenderHandler.java
components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/ResourceHandler.java
components/wsrp/branches/2.0.x/consumer/src/test/java/org/gatein/wsrp/test/support/MockWSRPConsumer.java
Log:
- GTNWSRP-189: attempt to rewrite textual content that's sent as binary. Added test
cases.
- Introduced WSRPConsumerSPI interface and made WSPRConsumerImpl implement so that we
could refactor the code to be more easily testable.
- Added support test classes.
Modified:
components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java
===================================================================
---
components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java 2010-12-15
17:18:21 UTC (rev 5595)
+++
components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java 2010-12-16
14:38:05 UTC (rev 5596)
@@ -57,6 +57,7 @@
import org.gatein.wsrp.consumer.migration.MigrationService;
import org.gatein.wsrp.consumer.portlet.WSRPPortlet;
import org.gatein.wsrp.consumer.portlet.info.WSRPPortletInfo;
+import org.gatein.wsrp.consumer.spi.WSRPConsumerSPI;
import org.gatein.wsrp.services.MarkupService;
import org.gatein.wsrp.services.PortletManagementService;
import org.gatein.wsrp.services.RegistrationService;
@@ -106,7 +107,7 @@
* @version $Revision: 11692 $
* @since 2.4
*/
-public class WSRPConsumerImpl implements WSRPConsumer
+public class WSRPConsumerImpl implements WSRPConsumerSPI
{
private final SessionHandler sessionHandler;
@@ -518,12 +519,6 @@
return Collections.unmodifiableSet(supportedUserScopes);
}
- /**
- * Determines whether the specified user scope (for markup caching) is supported.
- *
- * @param userScope the user scope which support is to be determined
- * @return <code>true</code> if the given user scope is supported,
<code>false</code> otherwise
- */
public boolean supportsUserScope(String userScope)
{
return supportedUserScopes.contains(userScope);
Modified:
components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/DirectResourceServingHandler.java
===================================================================
---
components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/DirectResourceServingHandler.java 2010-12-15
17:18:21 UTC (rev 5595)
+++
components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/DirectResourceServingHandler.java 2010-12-16
14:38:05 UTC (rev 5596)
@@ -27,12 +27,11 @@
import org.gatein.common.io.IOTools;
import org.gatein.common.net.media.MediaType;
import org.gatein.common.net.media.SubtypeDef;
-import org.gatein.common.net.media.TypeDef;
import org.gatein.common.util.MultiValuedPropertyMap;
import org.gatein.common.util.Tools;
import org.gatein.pc.api.invocation.response.ResponseProperties;
import org.gatein.wsrp.WSRPTypeFactory;
-import org.gatein.wsrp.consumer.WSRPConsumerImpl;
+import org.gatein.wsrp.consumer.spi.WSRPConsumerSPI;
import org.gatein.wsrp.handler.CookieUtil;
import org.gatein.wsrp.handler.RequestHeaderClientHandler;
import org.oasis.wsrp.v2.GetResource;
@@ -50,7 +49,7 @@
*/
public class DirectResourceServingHandler extends ResourceHandler
{
- protected DirectResourceServingHandler(WSRPConsumerImpl consumer)
+ protected DirectResourceServingHandler(WSRPConsumerSPI consumer)
{
super(consumer);
}
@@ -119,9 +118,8 @@
ResourceContext resourceContext;
MediaType type = MediaType.create(contentType);
- //TODO: handle this better, we should probably have a class in the common module to
determine if the MediaType should be treated as a text
- // file or as binary content. We also need to implement the algorithm to determine
the character encoding.
- if (TypeDef.TEXT.equals(type.getType()) ||
(TypeDef.APPLICATION.equals(type.getType()) &&
(type.getSubtype().getName().contains("javascript"))))
+ // GTNCOMMON-14
+ if (isInterpretableAsText(type))
{
// determine the charset of the content, if any
String charset = "UTF-8";
Modified:
components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/InvocationHandler.java
===================================================================
---
components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/InvocationHandler.java 2010-12-15
17:18:21 UTC (rev 5595)
+++
components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/InvocationHandler.java 2010-12-16
14:38:05 UTC (rev 5596)
@@ -39,6 +39,7 @@
import org.gatein.wsrp.WSRPUtils;
import org.gatein.wsrp.consumer.ProducerInfo;
import org.gatein.wsrp.consumer.WSRPConsumerImpl;
+import org.gatein.wsrp.consumer.spi.WSRPConsumerSPI;
import org.gatein.wsrp.spec.v2.WSRP2RewritingConstants;
import org.oasis.wsrp.v2.InvalidCookie;
import org.oasis.wsrp.v2.InvalidRegistration;
@@ -65,7 +66,7 @@
*/
public abstract class InvocationHandler<Invocation extends PortletInvocation, Request,
Response>
{
- protected final WSRPConsumerImpl consumer;
+ protected final WSRPConsumerSPI consumer;
protected static Logger log = LoggerFactory.getLogger(InvocationHandler.class);
protected static boolean debug = log.isDebugEnabled();
@@ -80,7 +81,7 @@
/** Maximum number of tries before giving up. */
private static final int MAXIMUM_RETRY_NUMBER = 3;
- protected InvocationHandler(WSRPConsumerImpl consumer)
+ protected InvocationHandler(WSRPConsumerSPI consumer)
{
this.consumer = consumer;
}
@@ -318,7 +319,7 @@
private static final String STREAM_INFO = "stream info in invocation
context";
private static final String USER_AGENT = "User-Agent";
- public RequestPrecursor(WSRPConsumerImpl wsrpConsumer, Invocation invocation)
throws PortletInvokerException
+ public RequestPrecursor(WSRPConsumerSPI wsrpConsumer, Invocation invocation) throws
PortletInvokerException
{
// retrieve handle
portletContext =
WSRPUtils.convertToWSRPPortletContext(WSRPConsumerImpl.getPortletContext(invocation));
Modified:
components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/MimeResponseHandler.java
===================================================================
---
components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/MimeResponseHandler.java 2010-12-15
17:18:21 UTC (rev 5595)
+++
components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/MimeResponseHandler.java 2010-12-16
14:38:05 UTC (rev 5596)
@@ -23,6 +23,8 @@
package org.gatein.wsrp.consumer.handlers;
+import org.gatein.common.net.media.MediaType;
+import org.gatein.common.net.media.TypeDef;
import org.gatein.common.text.TextTools;
import org.gatein.common.util.ParameterValidation;
import org.gatein.pc.api.PortletInvokerException;
@@ -34,17 +36,19 @@
import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
import org.gatein.pc.api.invocation.response.ResponseProperties;
import org.gatein.pc.api.spi.PortletInvocationContext;
+import org.gatein.pc.api.spi.SecurityContext;
import org.gatein.wsrp.WSRPConstants;
import org.gatein.wsrp.WSRPConsumer;
import org.gatein.wsrp.WSRPPortletURL;
import org.gatein.wsrp.WSRPRewritingConstants;
import org.gatein.wsrp.WSRPTypeFactory;
import org.gatein.wsrp.consumer.ProducerInfo;
-import org.gatein.wsrp.consumer.WSRPConsumerImpl;
+import org.gatein.wsrp.consumer.spi.WSRPConsumerSPI;
import org.oasis.wsrp.v2.CacheControl;
import org.oasis.wsrp.v2.MimeResponse;
import org.oasis.wsrp.v2.SessionContext;
+import java.io.UnsupportedEncodingException;
import java.util.Map;
import java.util.Set;
@@ -56,11 +60,24 @@
{
private static final org.gatein.pc.api.cache.CacheControl DEFAULT_CACHE_CONTROL = new
org.gatein.pc.api.cache.CacheControl(0, CacheScope.PRIVATE, null);
- protected MimeResponseHandler(WSRPConsumerImpl consumer)
+ protected MimeResponseHandler(WSRPConsumerSPI consumer)
{
super(consumer);
}
+ /**
+ * TODO: handle this better, we should probably have a class in the common module to
determine if the MediaType
+ * should be treated as a text file or as binary content. We also need to implement
the algorithm to determine the
+ * character encoding. See GTNCOMMON-14
+ *
+ * @param type
+ * @return
+ */
+ public static boolean isInterpretableAsText(MediaType type)
+ {
+ return TypeDef.TEXT.equals(type.getType()) ||
(TypeDef.APPLICATION.equals(type.getType()) &&
(type.getSubtype().getName().contains("javascript")));
+ }
+
protected abstract SessionContext getSessionContextFrom(Response response);
protected abstract LocalMimeResponse getMimeResponseFrom(Response response);
@@ -72,6 +89,11 @@
requestPrecursor.getPortletHandle());
LocalMimeResponse mimeResponse = getMimeResponseFrom(response);
+ return rewriteResponseIfNeeded(mimeResponse, invocation);
+ }
+
+ PortletInvocationResponse rewriteResponseIfNeeded(final LocalMimeResponse
mimeResponse, final Invocation invocation) throws PortletInvokerException
+ {
String markup = mimeResponse.getItemString();
byte[] binary = mimeResponse.getItemBinary();
if (markup != null && binary != null)
@@ -85,6 +107,7 @@
if (mimeResponse.isUseCachedItem() != null &&
mimeResponse.isUseCachedItem())
{
//todo: deal with cache GTNWSRP-40
+ log.debug("Consumer " + consumer.getProducerId() + " requested
cached data. Not implemented yet!");
}
else
{
@@ -93,30 +116,57 @@
}
}
- if (!ParameterValidation.isNullOrEmpty(markup))
- {
- if (Boolean.TRUE.equals(mimeResponse.isRequiresRewriting()))
- {
- markup = processMarkup(
- markup,
- WSRPTypeFactory.getNamespaceFrom(invocation.getWindowContext()),
- invocation.getContext(),
- invocation.getTarget(),
- new URLFormat(invocation.getSecurityContext().isSecure(),
invocation.getSecurityContext().isAuthenticated(), true, true),
- consumer
- );
- }
- }
-
String mimeType = mimeResponse.getMimeType();
if (ParameterValidation.isNullOrEmpty(mimeType))
{
return new ErrorResponse(new IllegalArgumentException("No MIME type was
provided for portlet content."));
}
+ if (Boolean.TRUE.equals(mimeResponse.isRequiresRewriting()))
+ {
+ if (!ParameterValidation.isNullOrEmpty(markup))
+ {
+ markup = processMarkup(markup, invocation);
+ }
+
+ // GTNWSRP-189:
+ // if we have binary and we require rewriting, convert binary to a string
assuming UTF-8 encoding and process
+ // this is seen with NetUnity producer's resource download portlet which
sends CSS and JS as binary for example
+ if (binary != null && binary.length > 0 &&
isInterpretableAsText(MediaType.create(mimeType)))
+ {
+ try
+ {
+ String binaryAsString = new String(binary, "UTF-8");
+ binaryAsString = processMarkup(binaryAsString, invocation);
+
+ // reconvert to binary
+ binary = binaryAsString.getBytes("UTF-8");
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ // shouldn't happen since UTF-8 is always supported...
+ throw new PortletInvokerException("Couldn't convert binary as
String.", e);
+ }
+ }
+ }
+
return createContentResponse(mimeResponse, invocation, null, null, mimeType,
binary, markup, createCacheControl(mimeResponse));
}
+ private String processMarkup(String markup, Invocation invocation)
+ {
+ SecurityContext securityContext = invocation.getSecurityContext();
+ markup = processMarkup(
+ markup,
+ WSRPTypeFactory.getNamespaceFrom(invocation.getWindowContext()),
+ invocation.getContext(),
+ invocation.getTarget(),
+ new URLFormat(securityContext.isSecure(), securityContext.isAuthenticated(),
true, true),
+ consumer
+ );
+ return markup;
+ }
+
protected PortletInvocationResponse createContentResponse(LocalMimeResponse
mimeResponse, Invocation invocation,
ResponseProperties
properties, Map<String, Object> attributes,
String mimeType, byte[]
bytes, String markup,
Modified:
components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/RenderHandler.java
===================================================================
---
components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/RenderHandler.java 2010-12-15
17:18:21 UTC (rev 5595)
+++
components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/RenderHandler.java 2010-12-16
14:38:05 UTC (rev 5596)
@@ -28,7 +28,7 @@
import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
import org.gatein.pc.api.invocation.response.ResponseProperties;
import org.gatein.wsrp.WSRPTypeFactory;
-import org.gatein.wsrp.consumer.WSRPConsumerImpl;
+import org.gatein.wsrp.consumer.spi.WSRPConsumerSPI;
import org.oasis.wsrp.v2.Extension;
import org.oasis.wsrp.v2.GetMarkup;
import org.oasis.wsrp.v2.MarkupContext;
@@ -49,7 +49,7 @@
public class RenderHandler extends MimeResponseHandler<RenderInvocation, GetMarkup,
MarkupResponse, MarkupContext>
{
- public RenderHandler(WSRPConsumerImpl consumer)
+ public RenderHandler(WSRPConsumerSPI consumer)
{
super(consumer);
}
@@ -116,7 +116,7 @@
consumer.getMarkupService().getMarkup(request.getRegistrationContext(),
request.getPortletContext(),
request.getRuntimeContext(), request.getUserContext(),
request.getMarkupParams(),
markupContextHolder, sessionContextHolder, new
Holder<List<Extension>>());
-
+
MarkupResponse markupResponse =
WSRPTypeFactory.createMarkupResponse(markupContextHolder.value);
markupResponse.setSessionContext(sessionContextHolder.value);
return markupResponse;
Modified:
components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/ResourceHandler.java
===================================================================
---
components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/ResourceHandler.java 2010-12-15
17:18:21 UTC (rev 5595)
+++
components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/ResourceHandler.java 2010-12-16
14:38:05 UTC (rev 5596)
@@ -31,7 +31,7 @@
import org.gatein.wsrp.WSRPRewritingConstants;
import org.gatein.wsrp.WSRPTypeFactory;
import org.gatein.wsrp.WSRPUtils;
-import org.gatein.wsrp.consumer.WSRPConsumerImpl;
+import org.gatein.wsrp.consumer.spi.WSRPConsumerSPI;
import org.gatein.wsrp.spec.v2.WSRP2RewritingConstants;
import org.oasis.wsrp.v2.Extension;
import org.oasis.wsrp.v2.GetResource;
@@ -54,7 +54,7 @@
public class ResourceHandler extends MimeResponseHandler<ResourceInvocation,
GetResource, ResourceResponse, ResourceContext>
{
- public ResourceHandler(WSRPConsumerImpl consumer)
+ public ResourceHandler(WSRPConsumerSPI consumer)
{
super(consumer);
}
Added:
components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/spi/WSRPConsumerSPI.java
===================================================================
---
components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/spi/WSRPConsumerSPI.java
(rev 0)
+++
components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/spi/WSRPConsumerSPI.java 2010-12-16
14:38:05 UTC (rev 5596)
@@ -0,0 +1,64 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2008, 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.consumer.spi;
+
+import org.gatein.pc.api.PortletInvokerException;
+import org.gatein.pc.api.invocation.PortletInvocation;
+import org.gatein.wsrp.WSRPConsumer;
+import org.gatein.wsrp.consumer.ProducerInfo;
+import org.gatein.wsrp.consumer.handlers.SessionHandler;
+import org.gatein.wsrp.services.MarkupService;
+import org.oasis.wsrp.v2.RegistrationContext;
+import org.oasis.wsrp.v2.RuntimeContext;
+import org.oasis.wsrp.v2.UserContext;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public interface WSRPConsumerSPI extends WSRPConsumer
+{
+ RegistrationContext getRegistrationContext() throws PortletInvokerException;
+
+ UserContext getUserContextFrom(PortletInvocation invocation, RuntimeContext
runtimeContext) throws PortletInvokerException;
+
+ SessionHandler getSessionHandler();
+
+ void setTemplatesIfNeeded(PortletInvocation invocation, RuntimeContext runtimeContext)
throws PortletInvokerException;
+
+ void refreshProducerInfo() throws PortletInvokerException;
+
+ void handleInvalidRegistrationFault() throws PortletInvokerException;
+
+ ProducerInfo getProducerInfo();
+
+ MarkupService getMarkupService() throws PortletInvokerException;
+
+ /**
+ * Determines whether the specified user scope (for markup caching) is supported.
+ *
+ * @param userScope the user scope which support is to be determined
+ * @return <code>true</code> if the given user scope is supported,
<code>false</code> otherwise
+ */
+ boolean supportsUserScope(String userScope);
+}
Copied:
components/wsrp/branches/2.0.x/consumer/src/test/java/org/gatein/wsrp/consumer/handlers/MimeResponseHandlerTestCase.java
(from rev 5555,
components/wsrp/branches/2.0.x/consumer/src/test/java/org/gatein/wsrp/consumer/handlers/RenderHandlerTestCase.java)
===================================================================
---
components/wsrp/branches/2.0.x/consumer/src/test/java/org/gatein/wsrp/consumer/handlers/MimeResponseHandlerTestCase.java
(rev 0)
+++
components/wsrp/branches/2.0.x/consumer/src/test/java/org/gatein/wsrp/consumer/handlers/MimeResponseHandlerTestCase.java 2010-12-16
14:38:05 UTC (rev 5596)
@@ -0,0 +1,272 @@
+/*
+ * 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.consumer.handlers;
+
+import junit.framework.TestCase;
+import org.gatein.pc.api.PortletContext;
+import org.gatein.pc.api.PortletInvokerException;
+import org.gatein.pc.api.URLFormat;
+import org.gatein.pc.api.invocation.PortletInvocation;
+import org.gatein.pc.api.invocation.response.ContentResponse;
+import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
+import org.gatein.wsrp.WSRPRewritingConstants;
+import org.gatein.wsrp.WSRPTypeFactory;
+import org.gatein.wsrp.test.ExtendedAssert;
+import org.gatein.wsrp.test.support.MockWSRPConsumer;
+import org.gatein.wsrp.test.support.TestPortletInvocationContext;
+import org.gatein.wsrp.test.support.TestRenderInvocation;
+import org.gatein.wsrp.test.support.TestResourceInvocation;
+import org.gatein.wsrp.test.support.TestWindowContext;
+import org.oasis.wsrp.v2.MarkupContext;
+import org.oasis.wsrp.v2.MimeResponse;
+import org.oasis.wsrp.v2.ResourceContext;
+
+import java.io.UnsupportedEncodingException;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 10507 $
+ * @since 2.6
+ */
+public class MimeResponseHandlerTestCase extends TestCase
+{
+ public static final String NAMESPACE = "NAMESPACE";
+ public static final String PORTLETID = "PORTLETID";
+ public static final MockWSRPConsumer CONSUMER = new
MockWSRPConsumer("foo");
+ public static final PortletContext PORTLET_CONTEXT =
PortletContext.createPortletContext(PORTLETID);
+ public static final TestPortletInvocationContext CONTEXT = new
TestPortletInvocationContext();
+ public static final URLFormat FORMAT = new URLFormat(false, false, true, true);
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ CONSUMER.setUsingWSRP2(true);
+ }
+
+ public void testProcessMarkupV1()
+ {
+ // fake using WSRP 1
+ CONSUMER.setUsingWSRP2(false);
+
+ String markup;
+ String expected;
+ markup =
"khlaksdhjflkjhsadljkwsrp_rewrite?wsrp-urlType=blockingAction&wsrp-interactionState=JBPNS_/wsrp_rewrite"
+
+
"fadsfadswsrp_rewrite?wsrp-urlType=render&wsrp-navigationalState=JBPNS_/wsrp_rewritefajdshfkjdshgfgrept";
+ expected = "khlaksdhjflkjhsadljkAction is=JBPNS_ ns=null ws=null m=null"
+
+ "fadsfadsRender ns=JBPNS_ ws=null m=nullfajdshfkjdshgfgrept";
+ processMarkupAndCheck(markup, expected);
+
+ markup = "<form method='post'
action='wsrp_rewrite?wsrp-urlType=blockingAction&wsrp" +
+ "-interactionState=JBPNS_/wsrp_rewrite'
id='wsrp_rewrite_portfolioManager'><table><tr><td>Stock
symbol</t" +
+ "d><td><input
name='symbol'/></td></tr><tr><td><input
type='submit'
value='Submit'></td></tr></table></form>";
+ expected = "<form method='post' action='Action is=JBPNS_
ns=null ws=null m=null' id='" + NAMESPACE
+ + "portfolioManager'><table><tr><td>Stock
symbol</t" +
+ "d><td><input
name='symbol'/></td></tr><tr><td><input
type='submit'
value='Submit'></td></tr></table></form>";
+ processMarkupAndCheck(markup, expected);
+ }
+
+ public void testProcessMarkupV2()
+ {
+ String markup;
+ String expected;
+ markup =
"khlaksdhjflkjhsadljkwsrp_rewrite?wsrp-urlType=blockingAction&wsrp-interactionState=JBPNS_/wsrp_rewrite"
+
+
"fadsfadswsrp_rewrite?wsrp-urlType=render&wsrp-navigationalState=JBPNS_/wsrp_rewritefajdshfkjdshgfgrept";
+ expected = "khlaksdhjflkjhsadljkAction is=JBPNS_ ns=null ws=null m=null"
+
+ "fadsfadsRender ns=JBPNS_ ws=null m=nullfajdshfkjdshgfgrept";
+ processMarkupAndCheck(markup, expected);
+
+ markup = "<form method='post'
action='wsrp_rewrite?wsrp-urlType=blockingAction&wsrp" +
+ "-interactionState=JBPNS_/wsrp_rewrite'
id='wsrp_rewrite_portfolioManager'><table><tr><td>Stock
symbol</t" +
+ "d><td><input
name='symbol'/></td></tr><tr><td><input
type='submit'
value='Submit'></td></tr></table></form>";
+ expected = "<form method='post' action='Action is=JBPNS_
ns=null ws=null m=null' id='" + NAMESPACE +
"portfolioManager'><table><tr><td>Stock symbol</t"
+
+ "d><td><input
name='symbol'/></td></tr><tr><td><input
type='submit'
value='Submit'></td></tr></table></form>";
+ processMarkupAndCheck(markup, expected);
+ }
+
+ /*public void testResourceURLs()
+ {
+ String markup;
+ String expected;
+ markup = "<img
src='wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http%3A%2F%2Flocalhost%3A8080%2Ftest-resource-portlet%2Fgif%2Flogo.gif&wsrp-requiresRewrite=true/wsrp_rewrite'/>";
+ expected = "<img
src='http://localhost:8080/test-resource-portlet/gif/logo.gif'/>";
+ processMarkupAndCheck(markup, expected);
+
+ markup = "<img
src='http://localhost:8080/test-resourcenoencodeurl-portlet/gif/logo.gif'/>";
+ processMarkupAndCheck(markup, markup);
+
+ markup =
"wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http%3A%2F%2Flocalhost%3A8080%2Fhelloworld&wsrp-requiresRewrite=true/wsrp_rewrite/helloworld.jar";
+ processMarkupAndCheck(markup,
"http://localhost:8080/helloworld/helloworld.jar");
+
+ markup =
"wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http%3A%2F%2Flocalhost%3A8080%2Fhelloworld&wsrp-requiresRewrite=true/wsrp_rewrite&foo=bar/helloworld.jar";
+ processMarkupAndCheck(markup,
"http://localhost:8080/helloworld&foo=bar/helloworld.jar");
+ }*/
+
+ public void testRegularURLIsNotAffected()
+ {
+ String markup;
+ markup = "<a
href=\"/portal/portal/default/Test/EXAMPLE/EXAMPLE?action=1d&windowstate=&mode="
+
+
"&ns=_next%3D%2Fdk%2Fskat%2Fportal%2Ffront%2Fportlets%2Fexample%2Findex.jsp"
+
+
"&is=_action%3D%252Fdk%252Fskat%252Fportal%252Ffront%252Fportlets%252Fexample%252FprocessLink"
+
+
"%26jbpns_2fdefault_2fTest_2fEXAMPLE_2fEXAMPLEsnpbjname%3DChris\">Press to
use default name.</a>";
+ processMarkupAndCheck(markup, markup);
+ }
+
+ /*public void testProcessMarkupResourceFromTemplate()
+ {
+ String url =
"http%3a%2f%2fwsrp.netunitysoftware.com%2fWSRPTestService%2fWSRPTestService.asmx%3ftimeout%3d30000%2fgetResource%3fportletHandle%3d781F3EE5-22DF-4ef9-9664-F5FC759065DB%26Function%3dResource%26Name%3dNetUnity%26Type%3dGIF";
+ String markup = "<table cellpadding=\"2\"
cellspacing=\"0\" border=\"0\" width=\"100%\">\n" +
+ "\t<tr class=\"portlet-table-header\">\n" +
+ "\t\t<td>Symbol</td>\n" +
+ "\t\t<td>Name</td>\n" +
+ "\t\t<td align=\"right\">Price</td>\n" +
+ "\t\t<td></td>\n" +
+ "\t\t<td align=\"right\">Change</td>\n" +
+ "\t\t<td align=\"right\">% Chg</td>\n" +
+ "\t</tr>\n" +
+ "</table>\n" +
+ "<A HREF=\"http://www.netunitysoftware.com\"
TITLE=\"NetUnity WSRP .NET Framework\" >" +
+ "<img src=\"" + getResourceURL(url, false) + "\"
border=\"0\" /></A>";
+
+ String expected = "<table cellpadding=\"2\"
cellspacing=\"0\" border=\"0\" width=\"100%\">\n" +
+ "\t<tr class=\"portlet-table-header\">\n" +
+ "\t\t<td>Symbol</td>\n" +
+ "\t\t<td>Name</td>\n" +
+ "\t\t<td align=\"right\">Price</td>\n" +
+ "\t\t<td></td>\n" +
+ "\t\t<td align=\"right\">Change</td>\n" +
+ "\t\t<td align=\"right\">% Chg</td>\n" +
+ "\t</tr>\n" +
+ "</table>\n" +
+ "<A HREF=\"http://www.netunitysoftware.com\"
TITLE=\"NetUnity WSRP .NET Framework\" >" +
+ "<img src=\"" + URLTools.decodeXWWWFormURL(url) +
"\" border=\"0\" /></A>";
+ processMarkupAndCheck(markup, expected);
+ }*/
+
+ public void testGTNWSRP12Workaround()
+ {
+ String timeout = "%3ftimeout%3d100000";
+ String beforeTimeout =
"http%3a%2f%2fwsrp.netunitysoftware.com%2fWSRPTestService%2fWSRPTestService.asmx";
+ String afterTimeout =
"%2fgetResource%3fportletHandle%3d781F3EE5-22DF-4ef9-9664-F5FC759065DB%26Function%3dResource%26Name%3dNetUnity%26Type%3dGIF";
+ String originalURL = beforeTimeout + timeout + afterTimeout;
+ String markup = "<table cellpadding=\"2\"
cellspacing=\"0\" border=\"0\" width=\"100%\">\n" +
+ "\t<tr class=\"portlet-table-header\">\n" +
+ "\t\t<td>Symbol</td>\n" +
+ "\t\t<td>Name</td>\n" +
+ "\t\t<td align=\"right\">Price</td>\n" +
+ "\t\t<td></td>\n" +
+ "\t\t<td align=\"right\">Change</td>\n" +
+ "\t\t<td align=\"right\">% Chg</td>\n" +
+ "\t</tr>\n" +
+ "</table>\n" +
+ "<A HREF=\"http://www.netunitysoftware.com\"
TITLE=\"NetUnity WSRP .NET Framework\" >" +
+ "<img src=\"" + originalURL + "\"
border=\"0\" /></A>";
+
+ String expected = "<table cellpadding=\"2\"
cellspacing=\"0\" border=\"0\" width=\"100%\">\n" +
+ "\t<tr class=\"portlet-table-header\">\n" +
+ "\t\t<td>Symbol</td>\n" +
+ "\t\t<td>Name</td>\n" +
+ "\t\t<td align=\"right\">Price</td>\n" +
+ "\t\t<td></td>\n" +
+ "\t\t<td align=\"right\">Change</td>\n" +
+ "\t\t<td align=\"right\">% Chg</td>\n" +
+ "\t</tr>\n" +
+ "</table>\n" +
+ "<A HREF=\"http://www.netunitysoftware.com\"
TITLE=\"NetUnity WSRP .NET Framework\" >" +
+ "<img src=\"" + beforeTimeout + afterTimeout + "\"
border=\"0\" /></A>";
+
+ processMarkupAndCheck(markup, expected);
+ }
+
+ public void testRewritingRequiredWithBinaryContent() throws
UnsupportedEncodingException, PortletInvokerException
+ {
+ String expected = "/* Style Sheet */\n" +
+ "." + TestWindowContext.NAMESPACE + "ExternalStyleClass\n"
+
+ "{\n" +
+ "\tfont-weight: bold;\n" +
+ "\tcolor: green;\n" +
+ "\tfont-family: Arial;\n" +
+ "\tborder:dashed 1px black; \n" +
+ "\tpadding: 15px;\n" +
+ "}";
+ byte[] expectedBinary = expected.getBytes("UTF-8");
+ String original = "/* Style Sheet */\n" +
+ ".wsrp_rewrite_ExternalStyleClass\n" +
+ "{\n" +
+ "\tfont-weight: bold;\n" +
+ "\tcolor: green;\n" +
+ "\tfont-family: Arial;\n" +
+ "\tborder:dashed 1px black; \n" +
+ "\tpadding: 15px;\n" +
+ "}";
+ byte[] originalBinary = original.getBytes("UTF-8");
+
+ processBinaryAndCheck(expectedBinary, new RenderHandler(CONSUMER), new
TestRenderInvocation(CONTEXT), WSRPTypeFactory.createMimeResponse("text/css",
null, originalBinary, MarkupContext.class));
+ processBinaryAndCheck(expectedBinary, new ResourceHandler(CONSUMER), new
TestResourceInvocation(CONTEXT), WSRPTypeFactory.createMimeResponse("text/css",
null, originalBinary, ResourceContext.class));
+
+ original = "//JScript file\n" +
+ "function wsrp_rewrite_ExternalScriptFunction()\n" +
+ "{\n" +
+ "\talert('Script Function in Script File');\n" +
+ "}";
+ originalBinary = original.getBytes("UTF-8");
+ expected = "//JScript file\n" +
+ "function " + TestWindowContext.NAMESPACE +
"ExternalScriptFunction()\n" +
+ "{\n" +
+ "\talert('Script Function in Script File');\n" +
+ "}";
+ expectedBinary = expected.getBytes("UTF-8");
+
+ processBinaryAndCheck(expectedBinary, new RenderHandler(CONSUMER), new
TestRenderInvocation(CONTEXT),
WSRPTypeFactory.createMimeResponse("application/x-javascript", null,
originalBinary, MarkupContext.class));
+ processBinaryAndCheck(expectedBinary, new ResourceHandler(CONSUMER), new
TestResourceInvocation(CONTEXT),
WSRPTypeFactory.createMimeResponse("application/x-javascript", null,
originalBinary, ResourceContext.class));
+ }
+
+ private void processBinaryAndCheck(byte[] expectedBinary, final MimeResponseHandler
handler, final PortletInvocation invocation, final MimeResponse mimeResponse) throws
PortletInvokerException
+ {
+ mimeResponse.setRequiresRewriting(true);
+ PortletInvocationResponse response = handler.rewriteResponseIfNeeded(mimeResponse,
invocation);
+ assertTrue(response instanceof ContentResponse);
+ ContentResponse contentResponse = (ContentResponse)response;
+ ExtendedAssert.assertEquals(expectedBinary, contentResponse.getBytes());
+ }
+
+ private void processMarkupAndCheck(String markup, String expected)
+ {
+ String result = MimeResponseHandler.processMarkup(
+ markup,
+ NAMESPACE,
+ CONTEXT,
+ PORTLET_CONTEXT,
+ FORMAT,
+ CONSUMER
+ );
+ assertEquals(expected, result);
+ }
+
+ private String getResourceURL(String encodedURL, boolean requiresRewrite)
+ {
+ String result =
WSRPRewritingConstants.FAKE_RESOURCE_URL.replace(WSRPRewritingConstants.WSRP_URL,
encodedURL);
+ result = result.replace(WSRPRewritingConstants.WSRP_REQUIRES_REWRITE,
Boolean.toString(requiresRewrite));
+ return result;
+ }
+}
Property changes on:
components/wsrp/branches/2.0.x/consumer/src/test/java/org/gatein/wsrp/consumer/handlers/MimeResponseHandlerTestCase.java
___________________________________________________________________
Name: svn:executable
+ *
Deleted:
components/wsrp/branches/2.0.x/consumer/src/test/java/org/gatein/wsrp/consumer/handlers/RenderHandlerTestCase.java
===================================================================
---
components/wsrp/branches/2.0.x/consumer/src/test/java/org/gatein/wsrp/consumer/handlers/RenderHandlerTestCase.java 2010-12-15
17:18:21 UTC (rev 5595)
+++
components/wsrp/branches/2.0.x/consumer/src/test/java/org/gatein/wsrp/consumer/handlers/RenderHandlerTestCase.java 2010-12-16
14:38:05 UTC (rev 5596)
@@ -1,206 +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.consumer.handlers;
-
-import junit.framework.TestCase;
-import org.gatein.pc.api.PortletContext;
-import org.gatein.pc.api.URLFormat;
-import org.gatein.wsrp.WSRPRewritingConstants;
-import org.gatein.wsrp.test.support.MockWSRPConsumer;
-import org.gatein.wsrp.test.support.TestPortletInvocationContext;
-
-/**
- * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
- * @version $Revision: 10507 $
- * @since 2.6
- */
-public class RenderHandlerTestCase extends TestCase
-{
- public static final String NAMESPACE = "NAMESPACE";
- public static final String PORTLETID = "PORTLETID";
- public static final MockWSRPConsumer CONSUMER = new
MockWSRPConsumer("foo");
- public static final PortletContext PORTLET_CONTEXT =
PortletContext.createPortletContext(PORTLETID);
- public static final TestPortletInvocationContext CONTEXT = new
TestPortletInvocationContext();
- public static final URLFormat FORMAT = new URLFormat(false, false, true, true);
-
- @Override
- protected void setUp() throws Exception
- {
- CONSUMER.setUsingWSRP2(true);
- }
-
- public void testProcessMarkupV1()
- {
- // fake using WSRP 1
- CONSUMER.setUsingWSRP2(false);
-
- String markup;
- String expected;
- markup =
"khlaksdhjflkjhsadljkwsrp_rewrite?wsrp-urlType=blockingAction&wsrp-interactionState=JBPNS_/wsrp_rewrite"
+
-
"fadsfadswsrp_rewrite?wsrp-urlType=render&wsrp-navigationalState=JBPNS_/wsrp_rewritefajdshfkjdshgfgrept";
- expected = "khlaksdhjflkjhsadljkAction is=JBPNS_ ns=null ws=null m=null"
+
- "fadsfadsRender ns=JBPNS_ ws=null m=nullfajdshfkjdshgfgrept";
- processMarkupAndCheck(markup, expected);
-
- markup = "<form method='post'
action='wsrp_rewrite?wsrp-urlType=blockingAction&wsrp" +
- "-interactionState=JBPNS_/wsrp_rewrite'
id='wsrp_rewrite_portfolioManager'><table><tr><td>Stock
symbol</t" +
- "d><td><input
name='symbol'/></td></tr><tr><td><input
type='submit'
value='Submit'></td></tr></table></form>";
- expected = "<form method='post' action='Action is=JBPNS_
ns=null ws=null m=null' id='" + NAMESPACE
- + "portfolioManager'><table><tr><td>Stock
symbol</t" +
- "d><td><input
name='symbol'/></td></tr><tr><td><input
type='submit'
value='Submit'></td></tr></table></form>";
- processMarkupAndCheck(markup, expected);
- }
-
- public void testProcessMarkupV2()
- {
- String markup;
- String expected;
- markup =
"khlaksdhjflkjhsadljkwsrp_rewrite?wsrp-urlType=blockingAction&wsrp-interactionState=JBPNS_/wsrp_rewrite"
+
-
"fadsfadswsrp_rewrite?wsrp-urlType=render&wsrp-navigationalState=JBPNS_/wsrp_rewritefajdshfkjdshgfgrept";
- expected = "khlaksdhjflkjhsadljkAction is=JBPNS_ ns=null ws=null m=null"
+
- "fadsfadsRender ns=JBPNS_ ws=null m=nullfajdshfkjdshgfgrept";
- processMarkupAndCheck(markup, expected);
-
- markup = "<form method='post'
action='wsrp_rewrite?wsrp-urlType=blockingAction&wsrp" +
- "-interactionState=JBPNS_/wsrp_rewrite'
id='wsrp_rewrite_portfolioManager'><table><tr><td>Stock
symbol</t" +
- "d><td><input
name='symbol'/></td></tr><tr><td><input
type='submit'
value='Submit'></td></tr></table></form>";
- expected = "<form method='post' action='Action is=JBPNS_
ns=null ws=null m=null' id='" + NAMESPACE +
"portfolioManager'><table><tr><td>Stock symbol</t"
+
- "d><td><input
name='symbol'/></td></tr><tr><td><input
type='submit'
value='Submit'></td></tr></table></form>";
- processMarkupAndCheck(markup, expected);
- }
-
- /*public void testResourceURLs()
- {
- String markup;
- String expected;
- markup = "<img
src='wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http%3A%2F%2Flocalhost%3A8080%2Ftest-resource-portlet%2Fgif%2Flogo.gif&wsrp-requiresRewrite=true/wsrp_rewrite'/>";
- expected = "<img
src='http://localhost:8080/test-resource-portlet/gif/logo.gif'/>";
- processMarkupAndCheck(markup, expected);
-
- markup = "<img
src='http://localhost:8080/test-resourcenoencodeurl-portlet/gif/logo.gif'/>";
- processMarkupAndCheck(markup, markup);
-
- markup =
"wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http%3A%2F%2Flocalhost%3A8080%2Fhelloworld&wsrp-requiresRewrite=true/wsrp_rewrite/helloworld.jar";
- processMarkupAndCheck(markup,
"http://localhost:8080/helloworld/helloworld.jar");
-
- markup =
"wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http%3A%2F%2Flocalhost%3A8080%2Fhelloworld&wsrp-requiresRewrite=true/wsrp_rewrite&foo=bar/helloworld.jar";
- processMarkupAndCheck(markup,
"http://localhost:8080/helloworld&foo=bar/helloworld.jar");
- }*/
-
- public void testRegularURLIsNotAffected()
- {
- String markup;
- markup = "<a
href=\"/portal/portal/default/Test/EXAMPLE/EXAMPLE?action=1d&windowstate=&mode="
+
-
"&ns=_next%3D%2Fdk%2Fskat%2Fportal%2Ffront%2Fportlets%2Fexample%2Findex.jsp"
+
-
"&is=_action%3D%252Fdk%252Fskat%252Fportal%252Ffront%252Fportlets%252Fexample%252FprocessLink"
+
-
"%26jbpns_2fdefault_2fTest_2fEXAMPLE_2fEXAMPLEsnpbjname%3DChris\">Press to
use default name.</a>";
- processMarkupAndCheck(markup, markup);
- }
-
- /*public void testProcessMarkupResourceFromTemplate()
- {
- String url =
"http%3a%2f%2fwsrp.netunitysoftware.com%2fWSRPTestService%2fWSRPTestService.asmx%3ftimeout%3d30000%2fgetResource%3fportletHandle%3d781F3EE5-22DF-4ef9-9664-F5FC759065DB%26Function%3dResource%26Name%3dNetUnity%26Type%3dGIF";
- String markup = "<table cellpadding=\"2\"
cellspacing=\"0\" border=\"0\" width=\"100%\">\n" +
- "\t<tr class=\"portlet-table-header\">\n" +
- "\t\t<td>Symbol</td>\n" +
- "\t\t<td>Name</td>\n" +
- "\t\t<td align=\"right\">Price</td>\n" +
- "\t\t<td></td>\n" +
- "\t\t<td align=\"right\">Change</td>\n" +
- "\t\t<td align=\"right\">% Chg</td>\n" +
- "\t</tr>\n" +
- "</table>\n" +
- "<A HREF=\"http://www.netunitysoftware.com\"
TITLE=\"NetUnity WSRP .NET Framework\" >" +
- "<img src=\"" + getResourceURL(url, false) + "\"
border=\"0\" /></A>";
-
- String expected = "<table cellpadding=\"2\"
cellspacing=\"0\" border=\"0\" width=\"100%\">\n" +
- "\t<tr class=\"portlet-table-header\">\n" +
- "\t\t<td>Symbol</td>\n" +
- "\t\t<td>Name</td>\n" +
- "\t\t<td align=\"right\">Price</td>\n" +
- "\t\t<td></td>\n" +
- "\t\t<td align=\"right\">Change</td>\n" +
- "\t\t<td align=\"right\">% Chg</td>\n" +
- "\t</tr>\n" +
- "</table>\n" +
- "<A HREF=\"http://www.netunitysoftware.com\"
TITLE=\"NetUnity WSRP .NET Framework\" >" +
- "<img src=\"" + URLTools.decodeXWWWFormURL(url) +
"\" border=\"0\" /></A>";
- processMarkupAndCheck(markup, expected);
- }*/
-
- public void testGTNWSRP12Workaround()
- {
- String timeout = "%3ftimeout%3d100000";
- String beforeTimeout =
"http%3a%2f%2fwsrp.netunitysoftware.com%2fWSRPTestService%2fWSRPTestService.asmx";
- String afterTimeout =
"%2fgetResource%3fportletHandle%3d781F3EE5-22DF-4ef9-9664-F5FC759065DB%26Function%3dResource%26Name%3dNetUnity%26Type%3dGIF";
- String originalURL = beforeTimeout + timeout + afterTimeout;
- String markup = "<table cellpadding=\"2\"
cellspacing=\"0\" border=\"0\" width=\"100%\">\n" +
- "\t<tr class=\"portlet-table-header\">\n" +
- "\t\t<td>Symbol</td>\n" +
- "\t\t<td>Name</td>\n" +
- "\t\t<td align=\"right\">Price</td>\n" +
- "\t\t<td></td>\n" +
- "\t\t<td align=\"right\">Change</td>\n" +
- "\t\t<td align=\"right\">% Chg</td>\n" +
- "\t</tr>\n" +
- "</table>\n" +
- "<A HREF=\"http://www.netunitysoftware.com\"
TITLE=\"NetUnity WSRP .NET Framework\" >" +
- "<img src=\"" + originalURL + "\"
border=\"0\" /></A>";
-
- String expected = "<table cellpadding=\"2\"
cellspacing=\"0\" border=\"0\" width=\"100%\">\n" +
- "\t<tr class=\"portlet-table-header\">\n" +
- "\t\t<td>Symbol</td>\n" +
- "\t\t<td>Name</td>\n" +
- "\t\t<td align=\"right\">Price</td>\n" +
- "\t\t<td></td>\n" +
- "\t\t<td align=\"right\">Change</td>\n" +
- "\t\t<td align=\"right\">% Chg</td>\n" +
- "\t</tr>\n" +
- "</table>\n" +
- "<A HREF=\"http://www.netunitysoftware.com\"
TITLE=\"NetUnity WSRP .NET Framework\" >" +
- "<img src=\"" + beforeTimeout + afterTimeout + "\"
border=\"0\" /></A>";
-
- processMarkupAndCheck(markup, expected);
- }
-
- private void processMarkupAndCheck(String markup, String expected)
- {
- String result = RenderHandler.processMarkup(
- markup,
- NAMESPACE,
- CONTEXT,
- PORTLET_CONTEXT,
- FORMAT,
- CONSUMER
- );
- assertEquals(expected, result);
- }
-
- private String getResourceURL(String encodedURL, boolean requiresRewrite)
- {
- String result =
WSRPRewritingConstants.FAKE_RESOURCE_URL.replace(WSRPRewritingConstants.WSRP_URL,
encodedURL);
- result = result.replace(WSRPRewritingConstants.WSRP_REQUIRES_REWRITE,
Boolean.toString(requiresRewrite));
- return result;
- }
-}
Modified:
components/wsrp/branches/2.0.x/consumer/src/test/java/org/gatein/wsrp/test/support/MockWSRPConsumer.java
===================================================================
---
components/wsrp/branches/2.0.x/consumer/src/test/java/org/gatein/wsrp/test/support/MockWSRPConsumer.java 2010-12-15
17:18:21 UTC (rev 5595)
+++
components/wsrp/branches/2.0.x/consumer/src/test/java/org/gatein/wsrp/test/support/MockWSRPConsumer.java 2010-12-16
14:38:05 UTC (rev 5596)
@@ -33,14 +33,19 @@
import org.gatein.pc.api.state.DestroyCloneFailure;
import org.gatein.pc.api.state.PropertyChange;
import org.gatein.pc.api.state.PropertyMap;
-import org.gatein.wsrp.WSRPConsumer;
import org.gatein.wsrp.api.session.SessionEvent;
import org.gatein.wsrp.consumer.ProducerInfo;
import org.gatein.wsrp.consumer.RefreshResult;
import org.gatein.wsrp.consumer.handlers.ProducerSessionInformation;
+import org.gatein.wsrp.consumer.handlers.SessionHandler;
import org.gatein.wsrp.consumer.migration.ExportInfo;
import org.gatein.wsrp.consumer.migration.ImportInfo;
import org.gatein.wsrp.consumer.migration.MigrationService;
+import org.gatein.wsrp.consumer.spi.WSRPConsumerSPI;
+import org.gatein.wsrp.services.MarkupService;
+import org.oasis.wsrp.v2.RegistrationContext;
+import org.oasis.wsrp.v2.RuntimeContext;
+import org.oasis.wsrp.v2.UserContext;
import javax.servlet.http.HttpSession;
import java.util.List;
@@ -51,7 +56,7 @@
* @version $Revision: 8784 $
* @since 2.6
*/
-public class MockWSRPConsumer implements WSRPConsumer
+public class MockWSRPConsumer implements WSRPConsumerSPI
{
private ProducerInfo producerInfo;
private boolean useWSRP2 = true;
@@ -83,10 +88,46 @@
return producerInfo;
}
+ public MarkupService getMarkupService() throws PortletInvokerException
+ {
+ throw new NotYetImplemented();
+ }
+
+ public boolean supportsUserScope(String userScope)
+ {
+ throw new NotYetImplemented();
+ }
+
+ public RegistrationContext getRegistrationContext() throws PortletInvokerException
+ {
+ throw new NotYetImplemented();
+ }
+
+ public UserContext getUserContextFrom(PortletInvocation invocation, RuntimeContext
runtimeContext) throws PortletInvokerException
+ {
+ throw new NotYetImplemented();
+ }
+
+ public SessionHandler getSessionHandler()
+ {
+ throw new NotYetImplemented();
+ }
+
+ public void setTemplatesIfNeeded(PortletInvocation invocation, RuntimeContext
runtimeContext) throws PortletInvokerException
+ {
+ throw new NotYetImplemented();
+ }
+
public void refreshProducerInfo() throws PortletInvokerException
{
+ throw new NotYetImplemented();
}
+ public void handleInvalidRegistrationFault() throws PortletInvokerException
+ {
+ throw new NotYetImplemented();
+ }
+
public void releaseSessions()
{
}
Added:
components/wsrp/branches/2.0.x/consumer/src/test/java/org/gatein/wsrp/test/support/TestActionInvocation.java
===================================================================
---
components/wsrp/branches/2.0.x/consumer/src/test/java/org/gatein/wsrp/test/support/TestActionInvocation.java
(rev 0)
+++
components/wsrp/branches/2.0.x/consumer/src/test/java/org/gatein/wsrp/test/support/TestActionInvocation.java 2010-12-16
14:38:05 UTC (rev 5596)
@@ -0,0 +1,43 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2008, 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.test.support;
+
+import org.gatein.pc.api.invocation.ActionInvocation;
+import org.gatein.pc.api.spi.PortletInvocationContext;
+import org.gatein.pc.portlet.impl.spi.AbstractPortalContext;
+import org.gatein.pc.portlet.impl.spi.AbstractSecurityContext;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class TestActionInvocation extends ActionInvocation
+{
+ public TestActionInvocation(PortletInvocationContext ctx) throws
IllegalArgumentException
+ {
+ super(ctx);
+ setPortalContext(new AbstractPortalContext());
+ setSecurityContext(new
AbstractSecurityContext(MockHttpServletRequest.createMockRequest(null)));
+ setWindowContext(new TestWindowContext());
+ }
+}
Added:
components/wsrp/branches/2.0.x/consumer/src/test/java/org/gatein/wsrp/test/support/TestRenderInvocation.java
===================================================================
---
components/wsrp/branches/2.0.x/consumer/src/test/java/org/gatein/wsrp/test/support/TestRenderInvocation.java
(rev 0)
+++
components/wsrp/branches/2.0.x/consumer/src/test/java/org/gatein/wsrp/test/support/TestRenderInvocation.java 2010-12-16
14:38:05 UTC (rev 5596)
@@ -0,0 +1,43 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2008, 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.test.support;
+
+import org.gatein.pc.api.invocation.RenderInvocation;
+import org.gatein.pc.api.spi.PortletInvocationContext;
+import org.gatein.pc.portlet.impl.spi.AbstractPortalContext;
+import org.gatein.pc.portlet.impl.spi.AbstractSecurityContext;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class TestRenderInvocation extends RenderInvocation
+{
+ public TestRenderInvocation(PortletInvocationContext ctx) throws
IllegalArgumentException
+ {
+ super(ctx);
+ setPortalContext(new AbstractPortalContext());
+ setSecurityContext(new
AbstractSecurityContext(MockHttpServletRequest.createMockRequest(null)));
+ setWindowContext(new TestWindowContext());
+ }
+}
Added:
components/wsrp/branches/2.0.x/consumer/src/test/java/org/gatein/wsrp/test/support/TestResourceInvocation.java
===================================================================
---
components/wsrp/branches/2.0.x/consumer/src/test/java/org/gatein/wsrp/test/support/TestResourceInvocation.java
(rev 0)
+++
components/wsrp/branches/2.0.x/consumer/src/test/java/org/gatein/wsrp/test/support/TestResourceInvocation.java 2010-12-16
14:38:05 UTC (rev 5596)
@@ -0,0 +1,43 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2008, 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.test.support;
+
+import org.gatein.pc.api.invocation.ResourceInvocation;
+import org.gatein.pc.api.spi.PortletInvocationContext;
+import org.gatein.pc.portlet.impl.spi.AbstractPortalContext;
+import org.gatein.pc.portlet.impl.spi.AbstractSecurityContext;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class TestResourceInvocation extends ResourceInvocation
+{
+ public TestResourceInvocation(PortletInvocationContext ctx) throws
IllegalArgumentException
+ {
+ super(ctx);
+ setPortalContext(new AbstractPortalContext());
+ setSecurityContext(new
AbstractSecurityContext(MockHttpServletRequest.createMockRequest(null)));
+ setWindowContext(new TestWindowContext());
+ }
+}
Added:
components/wsrp/branches/2.0.x/consumer/src/test/java/org/gatein/wsrp/test/support/TestWindowContext.java
===================================================================
---
components/wsrp/branches/2.0.x/consumer/src/test/java/org/gatein/wsrp/test/support/TestWindowContext.java
(rev 0)
+++
components/wsrp/branches/2.0.x/consumer/src/test/java/org/gatein/wsrp/test/support/TestWindowContext.java 2010-12-16
14:38:05 UTC (rev 5596)
@@ -0,0 +1,45 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2008, 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.test.support;
+
+import org.gatein.pc.api.spi.WindowContext;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class TestWindowContext implements WindowContext
+{
+ public static final String NAMESPACE = "namespace";
+ private static final String ID = "id";
+
+ public String getId()
+ {
+ return ID;
+ }
+
+ public String getNamespace()
+ {
+ return NAMESPACE;
+ }
+}