[gatein-commits] gatein SVN: r530 - in components/wsrp/trunk/common: src and 8 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Nov 9 14:58:03 EST 2009


Author: chris.laprun at jboss.com
Date: 2009-11-09 14:58:03 -0500 (Mon, 09 Nov 2009)
New Revision: 530

Added:
   components/wsrp/trunk/common/src/test/
   components/wsrp/trunk/common/src/test/java/
   components/wsrp/trunk/common/src/test/java/org/
   components/wsrp/trunk/common/src/test/java/org/gatein/
   components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/
   components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/handler/
   components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/handler/MockSOAPBody.java
   components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/handler/MockSOAPMessage.java
   components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/handler/MockSOAPMessageContext.java
   components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/handler/WSRPExtensionHandlerTestCase.java
   components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/other/
   components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/other/UserContextConverterTestCase.java
   components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/other/WSRPPortletURLTestCase.java
Modified:
   components/wsrp/trunk/common/pom.xml
   components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPPortletURL.java
   components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPResourceURL.java
Log:
- Better handling of extra parameters in WSRP URLs.
- Started migrrating tests.

Modified: components/wsrp/trunk/common/pom.xml
===================================================================
--- components/wsrp/trunk/common/pom.xml	2009-11-09 11:58:06 UTC (rev 529)
+++ components/wsrp/trunk/common/pom.xml	2009-11-09 19:58:03 UTC (rev 530)
@@ -20,7 +20,8 @@
   ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
   ~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
   -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <parent>
       <groupId>org.gatein.wsrp</groupId>
       <artifactId>wsrp-parent</artifactId>
@@ -57,8 +58,15 @@
          <artifactId>jbossxb</artifactId>
       </dependency>
       <dependency>
-        <groupId>javax.xml.soap</groupId>
-        <artifactId>saaj-api</artifactId>
+         <groupId>javax.xml.soap</groupId>
+         <artifactId>saaj-api</artifactId>
       </dependency>
+
+      <!-- tests -->
+      <dependency>
+         <groupId>org.slf4j</groupId>
+         <artifactId>slf4j-jdk14</artifactId>
+         <scope>test</scope>
+      </dependency>
    </dependencies>
 </project>
\ No newline at end of file

Modified: components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPPortletURL.java
===================================================================
--- components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPPortletURL.java	2009-11-09 11:58:06 UTC (rev 529)
+++ components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPPortletURL.java	2009-11-09 19:58:03 UTC (rev 530)
@@ -23,17 +23,17 @@
 
 package org.gatein.wsrp;
 
-import org.gatein.pc.api.Mode;
-import org.gatein.pc.api.WindowState;
 import org.gatein.common.NotYetImplemented;
 import org.gatein.common.text.FastURLDecoder;
 import org.gatein.common.util.Tools;
 import org.gatein.pc.api.ActionURL;
+import org.gatein.pc.api.Mode;
 import org.gatein.pc.api.ParametersStateString;
 import org.gatein.pc.api.PortletURL;
 import org.gatein.pc.api.RenderURL;
 import org.gatein.pc.api.ResourceURL;
 import org.gatein.pc.api.StateString;
+import org.gatein.pc.api.WindowState;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -44,7 +44,7 @@
 
 /**
  * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
- * @version $Revision: 13120 $
+ * @version $Revision: 13470 $
  * @since 2.4 (Apr 28, 2006)
  */
 public abstract class WSRPPortletURL implements PortletURL
@@ -66,9 +66,11 @@
    private WindowState windowState;
 
    /** Are we using strict rewriting parameters validation mode? */
-   private static boolean strict = true;
+   protected static boolean strict = true;
    /** Holds extra parameters if we are in relaxed validation mode */
    private Map<String, String> extraParams;
+   /** Holds extra data after URL in relaxed mode */
+   protected String extra;
    /** Remember position of extra parameters wrt end token */
    private boolean extraParamsAfterEndToken = false;
 
@@ -116,6 +118,7 @@
       {
          WSRPPortletURL other = (WSRPPortletURL)portletURL;
          url.setParams(other.extraParams, other.toString());
+         url.setExtra(other.extra);
       }
 
       return url;
@@ -132,6 +135,7 @@
 
       String originalURL = encodedURL;
       boolean extraAfterEnd = false;
+      String extra = null;
 
       // URL needs to start wsrp_rewrite? and end with /wsrp_rewrite in strict validation mode
       if (!encodedURL.startsWith(WSRPRewritingConstants.BEGIN_WSRP_REWRITE))
@@ -140,25 +144,44 @@
       }
       if (!encodedURL.endsWith(WSRPRewritingConstants.END_WSRP_REWRITE))
       {
-         if (strict)
+         // first remove prefix only (as suffix is not at the end of the string)
+         encodedURL = encodedURL.substring(WSRPRewritingConstants.WSRP_REWRITE_PREFIX_LENGTH);
+
+         // end token should be marked by the first / in the URL and extract it
+         int endTokenIndex = encodedURL.indexOf('/');
+         if (endTokenIndex < 0)
          {
-            throw new IllegalArgumentException(encodedURL + " does not end with " + WSRPRewritingConstants.END_WSRP_REWRITE);
+            throw new IllegalArgumentException(originalURL + " does not contain " + WSRPRewritingConstants.END_WSRP_REWRITE);
          }
+
+         encodedURL = encodedURL.substring(0, endTokenIndex)
+            + encodedURL.substring(endTokenIndex + WSRPRewritingConstants.WSRP_REWRITE_SUFFIX_LENGTH);
+
+         /*
+         we need to deal with the case when a WSRP URL is concatenated to a context path using something similar to:
+         renderResponse.encodeURL(renderRequest.getContextPath()) in which case, there should be a slash still present.
+         How to process further depends on whether we're in strict mode or not...
+         */
+         int concatenationIndex = encodedURL.indexOf('/');
+
+         if (strict && concatenationIndex != endTokenIndex)
+         {
+            // in strict mode, the only character available after the end token is the concatenating slash
+            throw new IllegalArgumentException(encodedURL + " does not end with "
+               + WSRPRewritingConstants.END_WSRP_REWRITE + " or does not appear to be a valid concatenation of URLs.");
+         }
          else
          {
-            // first remove prefix only (as suffix is not at the end of the string)
-            encodedURL = encodedURL.substring(WSRPRewritingConstants.WSRP_REWRITE_PREFIX_LENGTH);
-
-            // find end token and extract it
-            int endTokenIndex = encodedURL.indexOf('/');
-            if (endTokenIndex < 0)
+            // deal with extra characters: this should only happen when the URL is concatenated to form a longer one
+            // hence, it should be possible to have param-value pairs followed by a slash '/' then characters.
+            // Anything after the slash will be kept as is, uninterpreted.
+            if (concatenationIndex != -1)
             {
-               throw new IllegalArgumentException(originalURL + " does not contain " + WSRPRewritingConstants.END_WSRP_REWRITE);
+               String tmp = encodedURL;
+               encodedURL = encodedURL.substring(0, concatenationIndex);
+               extra = tmp.substring(concatenationIndex);
             }
 
-            encodedURL = encodedURL.substring(0, endTokenIndex)
-               + encodedURL.substring(endTokenIndex + WSRPRewritingConstants.WSRP_REWRITE_SUFFIX_LENGTH);
-
             // remember that we should position the extra params after the end token
             extraAfterEnd = true;
          }
@@ -229,6 +252,7 @@
 
       url.setParams(params, originalURL);
       url.setExtraParamsAfterEndToken(extraAfterEnd);
+      url.setExtra(extra);
       return url;
    }
 
@@ -379,16 +403,17 @@
          if (extraParams != null && !extraParams.isEmpty())
          {
             StringBuffer extras = new StringBuffer();
-            for (Map.Entry<String, String> entry : extraParams.entrySet())
-            {
-               createURLParameter(extras, entry.getKey(), entry.getValue());
-            }
+            appendExtraParams(extras);
 
             // if we had extra params, we need to figure out where thwy should be positioned wrt end token
             if (extraParamsAfterEndToken)
             {
                sb.append(WSRPRewritingConstants.END_WSRP_REWRITE);
                sb.append(extras);
+               if (extra != null)
+               {
+                  sb.append(extra);
+               }
             }
             else
             {
@@ -404,6 +429,17 @@
       return sb.toString();
    }
 
+   protected void appendExtraParams(StringBuffer buffer)
+   {
+      if (extraParams != null)
+      {
+         for (Map.Entry<String, String> entry : extraParams.entrySet())
+         {
+            createURLParameter(buffer, entry.getKey(), entry.getValue());
+         }
+      }
+   }
+
    protected abstract void appendEnd(StringBuffer sb);
 
    protected final void createURLParameter(StringBuffer sb, String name, String value)
@@ -523,4 +559,9 @@
    {
       this.extraParamsAfterEndToken = extraParamsAfterEndToken;
    }
+
+   public void setExtra(String extra)
+   {
+      this.extra = extra;
+   }
 }

Modified: components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPResourceURL.java
===================================================================
--- components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPResourceURL.java	2009-11-09 11:58:06 UTC (rev 529)
+++ components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPResourceURL.java	2009-11-09 19:58:03 UTC (rev 530)
@@ -1,49 +1,47 @@
-/*
- * JBoss, a division of Red Hat
- * Copyright 2009, 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.
- */
+/******************************************************************************
+ * JBoss, a division of Red Hat                                               *
+ * Copyright 2009, 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 org.gatein.common.net.URLTools;
+import org.gatein.common.net.media.MediaType;
 import org.gatein.pc.api.Mode;
 import org.gatein.pc.api.WindowState;
-import org.gatein.common.net.URLTools;
-import org.gatein.common.net.media.MediaType;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.jboss.logging.Logger;
 
-import javax.activation.MimeTypeParseException;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.HashMap;
 import java.util.Map;
-import java.util.HashMap;
 
 /**
  * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
- * @version $Revision: 11404 $
+ * @version $Revision: 13470 $
  * @since 2.4
  */
 public class WSRPResourceURL extends WSRPPortletURL
 {
-   private final static Logger log = LoggerFactory.getLogger(WSRPResourceURL.class);
+   private final static Logger log = Logger.getLogger(WSRPResourceURL.class);
 
    private URL resourceURL;
    private boolean requiresRewrite = false;
@@ -102,6 +100,7 @@
       if (paramValue != null)
       {
          requiresRewrite = Boolean.valueOf(paramValue);
+         params.remove(WSRPRewritingConstants.RESOURCE_REQUIRES_REWRITE);
       }
       else
       {
@@ -126,11 +125,13 @@
             String file = resourceURL.getFile();
 
             MediaType mediaType = SUPPORTED_RESOURCE_TYPES.get(file);
-            if(mediaType == null)
+            if (mediaType == null)
             {
                log.debug("Couldn't determine (based on extension) MIME type of file: " + file
                   + "\nRetrieving the associated resource will probably fail.");
             }
+
+            params.remove(WSRPRewritingConstants.RESOURCE_URL);
          }
          catch (MalformedURLException e)
          {
@@ -146,6 +147,16 @@
 
    public String toString()
    {
-      return resourceURL.toExternalForm();
+      StringBuffer result = new StringBuffer(resourceURL.toExternalForm());
+
+      appendExtraParams(result);
+
+      // append extra characters if we have some
+      if (extra != null)
+      {
+         result.append(extra);
+      }
+
+      return result.toString();
    }
 }

Added: components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/handler/MockSOAPBody.java
===================================================================
--- components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/handler/MockSOAPBody.java	                        (rev 0)
+++ components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/handler/MockSOAPBody.java	2009-11-09 19:58:03 UTC (rev 530)
@@ -0,0 +1,57 @@
+/*
+* 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.handler;
+
+import org.jboss.util.xml.DOMUtils;
+import org.w3c.dom.Element;
+
+import javax.xml.soap.SOAPBody;
+import java.io.IOException;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+/**
+ * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
+ * @version $Revision$
+ */
+public class MockSOAPBody implements InvocationHandler
+{
+   Element body;
+
+   public MockSOAPBody(Element body)
+   {
+      this.body = body;
+   }
+
+   public static SOAPBody newInstance(String body) throws IOException
+   {
+      return (SOAPBody)Proxy.newProxyInstance(MockSOAPBody.class.getClassLoader(), new Class[]{SOAPBody.class},
+         new MockSOAPBody(DOMUtils.parse(body)));
+   }
+
+   public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+   {
+      return method.invoke(body, args);
+   }
+}


Property changes on: components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/handler/MockSOAPBody.java
___________________________________________________________________
Name: svn:executable
   + *

Added: components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/handler/MockSOAPMessage.java
===================================================================
--- components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/handler/MockSOAPMessage.java	                        (rev 0)
+++ components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/handler/MockSOAPMessage.java	2009-11-09 19:58:03 UTC (rev 530)
@@ -0,0 +1,158 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat                                               *
+ * Copyright 2006, 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.handler;
+
+import javax.xml.soap.AttachmentPart;
+import javax.xml.soap.MimeHeaders;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.soap.SOAPPart;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Iterator;
+
+/**
+ * @author <a href="mailto:chris.laprun at jboss.com?subject=org.gatein.wsrp.wsrp.handler.MockSOAPMessage">Chris
+ *         Laprun</a>
+ * @version $Revision: 12277 $
+ * @since 2.4
+ */
+public class MockSOAPMessage extends SOAPMessage
+{
+   MimeHeaders headers;
+   String messageBody;
+
+   public MockSOAPMessage()
+   {
+      headers = new MimeHeaders();
+   }
+
+   public MockSOAPMessage(MimeHeaders headers)
+   {
+      this.headers = headers;
+   }
+
+   public void setMessageBody(String messageBody)
+   {
+      this.messageBody = messageBody;
+   }
+
+   @Override
+   public SOAPBody getSOAPBody() throws SOAPException
+   {
+      try
+      {
+         return MockSOAPBody.newInstance(messageBody);
+      }
+      catch (IOException e)
+      {
+         throw new SOAPException(e);
+      }
+   }
+
+   public MimeHeaders getMimeHeaders()
+   {
+      return headers;
+   }
+
+   public void setMimeHeaders(MimeHeaders mimeHeaders)
+   {
+      this.headers = mimeHeaders;
+   }
+
+   public void addAttachmentPart(AttachmentPart attachmentPart)
+   {
+      throw new UnsupportedOperationException();
+   }
+
+   public AttachmentPart createAttachmentPart()
+   {
+      throw new UnsupportedOperationException();
+   }
+
+   public String getContentDescription()
+   {
+      throw new UnsupportedOperationException();
+   }
+
+   public void setContentDescription(String string)
+   {
+      throw new UnsupportedOperationException();
+   }
+
+   public SOAPPart getSOAPPart()
+   {
+      throw new UnsupportedOperationException();
+   }
+
+   public void removeAllAttachments()
+   {
+      throw new UnsupportedOperationException();
+   }
+
+   public int countAttachments()
+   {
+      throw new UnsupportedOperationException();
+   }
+
+   public Iterator getAttachments()
+   {
+      throw new UnsupportedOperationException();
+   }
+
+   /*
+    * For JDK 1.6
+    */
+   public AttachmentPart getAttachment(SOAPElement element)
+   {
+      throw new UnsupportedOperationException();
+   }
+
+   public Iterator getAttachments(MimeHeaders mimeHeaders)
+   {
+      throw new UnsupportedOperationException();
+   }
+
+   public void saveChanges() throws SOAPException
+   {
+      throw new UnsupportedOperationException();
+   }
+
+   public boolean saveRequired()
+   {
+      throw new UnsupportedOperationException();
+   }
+
+   public void writeTo(OutputStream outputStream) throws SOAPException, IOException
+   {
+      throw new UnsupportedOperationException();
+   }
+
+   public void removeAttachments(MimeHeaders mimeHeaders)
+   {
+      throw new UnsupportedOperationException();
+   }
+}


Property changes on: components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/handler/MockSOAPMessage.java
___________________________________________________________________
Name: svn:executable
   + *

Added: components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/handler/MockSOAPMessageContext.java
===================================================================
--- components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/handler/MockSOAPMessageContext.java	                        (rev 0)
+++ components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/handler/MockSOAPMessageContext.java	2009-11-09 19:58:03 UTC (rev 530)
@@ -0,0 +1,82 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat                                               *
+ * Copyright 2006, 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.handler;
+
+import javax.xml.ws.handler.soap.SOAPMessageContext;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+/**
+ * @author <a href="mailto:chris.laprun at jboss.com?subject=org.gatein.wsrp.wsrp.handler.MockSOAPMessageContext">Chris
+ *         Laprun</a>
+ * @version $Revision: 8784 $
+ * @since 2.4
+ */
+public class MockSOAPMessageContext implements InvocationHandler
+{
+   MockSOAPMessage message;
+
+
+   public MockSOAPMessageContext(MockSOAPMessage message)
+   {
+      this.message = message;
+   }
+
+   public MockSOAPMessage getMessage()
+   {
+      return message;
+   }
+
+   public void setMessage(MockSOAPMessage message)
+   {
+      this.message = message;
+   }
+
+   public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+   {
+      String methodName = method.getName();
+
+      if ("getMessage".equals(methodName))
+      {
+         return getMessage();
+      }
+      else if ("getProperty".equals(methodName))
+      {
+         return "http://jboss.com"; // should only be called to get the endpoint address
+      }
+      else if ("toString".equals(methodName))
+      {
+         return this.toString();
+      }
+
+      throw new UnsupportedOperationException("MockSOAPMessageContext does not support " + methodName + " method");
+   }
+
+   public static SOAPMessageContext createMessageContext(MockSOAPMessage message, ClassLoader classLoader)
+   {
+      return (SOAPMessageContext)Proxy.newProxyInstance(classLoader, new Class[]{SOAPMessageContext.class},
+         new MockSOAPMessageContext(message));
+   }
+}


Property changes on: components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/handler/MockSOAPMessageContext.java
___________________________________________________________________
Name: svn:executable
   + *

Added: components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/handler/WSRPExtensionHandlerTestCase.java
===================================================================
--- components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/handler/WSRPExtensionHandlerTestCase.java	                        (rev 0)
+++ components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/handler/WSRPExtensionHandlerTestCase.java	2009-11-09 19:58:03 UTC (rev 530)
@@ -0,0 +1,228 @@
+/*
+* 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.handler;
+
+import junit.framework.TestCase;
+
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPException;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
+
+/**
+ * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
+ * @version $Revision$
+ */
+public class WSRPExtensionHandlerTestCase extends TestCase
+{
+   private WSRPExtensionHandler handler;
+
+   @Override
+   protected void setUp() throws Exception
+   {
+      handler = new WSRPExtensionHandler();
+   }
+
+   public void testRemoveExtensions() throws SOAPException
+   {
+      MockSOAPMessage message = new MockSOAPMessage();
+      message.setMessageBody("<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'\n" +
+         "\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'\n" +
+         "\txmlns:xsd='http://www.w3.org/2001/XMLSchema'\n" +
+         "\txmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>\n" +
+         "\t<env:Body>\n" +
+         "\t\t<ns0:getMarkup xmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t<ns0:registrationContext\n" +
+         "\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t<ns0:registrationHandle\n" +
+         "\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t17\n" +
+         "\t\t\t\t</ns0:registrationHandle>\n" +
+         "\t\t\t\t<ns0:registrationState\n" +
+         "\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types' />\n" +
+         "\t\t\t</ns0:registrationContext>\n" +
+         "\t\t\t<ns0:portletContext\n" +
+         "\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t<ns0:portletHandle\n" +
+         "\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t_18\n" +
+         "\t\t\t\t</ns0:portletHandle>\n" +
+         "\t\t\t\t<ns0:portletState\n" +
+         "\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types' />\n" +
+         "\t\t\t</ns0:portletContext>\n" +
+         "\t\t\t<ns0:runtimeContext\n" +
+         "\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t<ns0:userAuthentication xmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\twsrp:none\n" +
+         "\t\t\t\t</ns0:userAuthentication>\n" +
+         "\t\t\t\t<ns0:portletInstanceKey\n" +
+         "\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t949994222\n" +
+         "\t\t\t\t</ns0:portletInstanceKey>\n" +
+         "\t\t\t\t<ns0:namespacePrefix\n" +
+         "\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t__ns949994222_\n" +
+         "\t\t\t\t</ns0:namespacePrefix>\n" +
+         "\t\t\t</ns0:runtimeContext>\n" +
+         "\t\t\t<ns0:userContext\n" +
+         "\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t<ns0:userContextKey\n" +
+         "\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\twsrp:minimal\n" +
+         "\t\t\t\t</ns0:userContextKey>\n" +
+         "\t\t\t\t<ns0:profile\n" +
+         "\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types' />\n" +
+         "\t\t\t</ns0:userContext>\n" +
+         "\t\t\t<ns0:markupParams\n" +
+         "\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t<ns0:secureClientCommunication xmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\tfalse\n" +
+         "\t\t\t\t\t</ns0:secureClientCommunication>\n" +
+         "\t\t\t\t\t<ns0:locales\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\ten-US\n" +
+         "\t\t\t\t\t</ns0:locales>\n" +
+         "\t\t\t\t\t<ns0:mimeTypes\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\ttext/html\n" +
+         "\t\t\t\t\t</ns0:mimeTypes>\n" +
+         "\t\t\t\t\t<ns0:mimeTypes\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\ttext/xml\n" +
+         "\t\t\t\t\t</ns0:mimeTypes>\n" +
+         "\t\t\t\t\t<ns0:mimeTypes\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\ttext/vnd.oracle.mobilexml\n" +
+         "\t\t\t\t\t</ns0:mimeTypes>\n" +
+         "\t\t\t\t\t<ns0:mimeTypes\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\t*\n" +
+         "\t\t\t\t\t</ns0:mimeTypes>\n" +
+         "\t\t\t\t\t<ns0:mode\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\twsrp:view\n" +
+         "\t\t\t\t\t</ns0:mode>\n" +
+         "\t\t\t\t\t<ns0:windowState\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\twsrp:normal\n" +
+         "\t\t\t\t\t</ns0:windowState>\n" +
+         "\t\t\t\t\t<ns0:clientData\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\t<ns0:userAgent\n" +
+         "\t\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\t\tMozilla/5.0 (Windows; U; Windows NT 5.1;\n" +
+         "\t\t\t\t\t\t\ten-US; rv:1.9.0.3) Gecko/2008092417\n" +
+         "\t\t\t\t\t\t\tFirefox/3.0.3\n" +
+         "\t\t\t\t\t\t</ns0:userAgent>\n" +
+         "\t\t\t\t\t\t<ns0:extensions\n" +
+         "\t\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\t\t<ns1:GenericExtension\n" +
+         "\t\t\t\t\t\t\t\txmlns:ns1='http://xmlns.oracle.com/portal/wsrp/v1'>\n" +
+         "\t\t\t\t\t\t\t\t<ns0:NamedString name='CONNECTION'\n" +
+         "\t\t\t\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\t\t\t\t<ns0:value\n" +
+         "\t\t\t\t\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\t\t\t\t\tkeep-alive\n" +
+         "\t\t\t\t\t\t\t\t\t</ns0:value>\n" +
+         "\t\t\t\t\t\t\t\t</ns0:NamedString>\n" +
+         "\t\t\t\t\t\t\t\t<ns0:NamedString name='ACCEPT-ENCODING'\n" +
+         "\t\t\t\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\t\t\t\t<ns0:value xmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\t\t\t\t\tgzip,deflate\n" +
+         "\t\t\t\t\t\t\t\t\t\t</ns0:value>\n" +
+         "\t\t\t\t\t\t\t\t</ns0:NamedString>\n" +
+         "\t\t\t\t\t\t\t\t<ns0:NamedString name='KEEP-ALIVE'\n" +
+         "\t\t\t\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\t\t\t\t<ns0:value xmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\t\t\t\t\t300\n" +
+         "\t\t\t\t\t\t\t\t\t</ns0:value>\n" +
+         "\t\t\t\t\t\t\t\t</ns0:NamedString>\n" +
+         "\t\t\t\t\t\t\t\t<ns0:NamedString name='HOST'\n" +
+         "\t\t\t\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\t\t\t\t<ns0:value xmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\t\t\t\t\t127.0.0.1:8988\n" +
+         "\t\t\t\t\t\t\t\t\t</ns0:value>\n" +
+         "\t\t\t\t\t\t\t\t</ns0:NamedString>\n" +
+         "\t\t\t\t\t\t\t</ns1:GenericExtension>\n" +
+         "\t\t\t\t\t\t</ns0:extensions>\n" +
+         "\t\t\t\t\t</ns0:clientData>\n" +
+         "\t\t\t\t\t<ns0:markupCharacterSets\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\tUTF-8\n" +
+         "\t\t\t\t\t</ns0:markupCharacterSets>\n" +
+         "\t\t\t\t\t<ns0:validNewModes\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\twsrp:view\n" +
+         "\t\t\t\t\t</ns0:validNewModes>\n" +
+         "\t\t\t\t\t<ns0:validNewModes\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\turn:javax:portlet:mode:custo m:edit_defaults\n" +
+         "\t\t\t\t\t</ns0:validNewModes>\n" +
+         "\t\t\t\t\t<ns0:validNewModes\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\twsrp:edit\n" +
+         "\t\t\t\t\t</ns0:validNewModes>\n" +
+         "\t\t\t\t\t<ns0:validNewModes\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\twsrp:help\n" +
+         "\t\t\t\t\t</ns0:validNewModes>\n" +
+         "\t\t\t\t\t<ns0:validNewModes\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\turn:javax:portlet:mode:custo m:about\n" +
+         "\t\t\t\t\t</ns0:validNewModes>\n" +
+         "\t\t\t\t\t<ns0:validNewModes\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\turn:javax:portlet:mode:custo m:print\n" +
+         "\t\t\t\t\t</ns0:validNewModes>\n" +
+         "\t\t\t\t\t<ns0:validNewModes\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\turn:javax:portlet:mode:custo m:config\n" +
+         "\t\t\t\t\t</ns0:validNewModes>\n" +
+         "\t\t\t\t\t<ns0:validNewWindowStates\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\twsrp:normal\n" +
+         "\t\t\t\t\t</ns0:validNewWindowStates>\n" +
+         "\t\t\t\t\t<ns0:validNewWindowStates\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\twsrp:maximized\n" +
+         "\t\t\t\t\t</ns0:validNewWindowStates>\n" +
+         "\t\t\t\t\t<ns0:validNewWindowStates\n" +
+         "\t\t\t\t\t\txmlns:ns0='urn:oasis:names:tc:wsrp:v1:types'>\n" +
+         "\t\t\t\t\t\twsrp:minimized\n" +
+         "\t\t\t\t\t</ns0:validNewWindowStates>\n" +
+         "\t\t\t</ns0:markupParams>\n" +
+         "\t\t</ns0:getMarkup>\n" +
+         "\t</env:Body>\n" +
+         "</env:Envelope>");
+
+
+      SOAPMessageContext msgContext = MockSOAPMessageContext.createMessageContext(message, getClass().getClassLoader());
+
+      handler.handleMessage(msgContext);
+
+      SOAPBody body = msgContext.getMessage().getSOAPBody();
+      String asString = body.toString();
+      assertFalse(asString.contains("ns0:extensions"));
+      assertFalse(asString.contains("ns1:GenericExtensions"));
+      assertFalse(asString.contains("ACCEPT-ENCODING"));
+   }
+}


Property changes on: components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/handler/WSRPExtensionHandlerTestCase.java
___________________________________________________________________
Name: svn:executable
   + *

Added: components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/other/UserContextConverterTestCase.java
===================================================================
--- components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/other/UserContextConverterTestCase.java	                        (rev 0)
+++ components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/other/UserContextConverterTestCase.java	2009-11-09 19:58:03 UTC (rev 530)
@@ -0,0 +1,47 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat                                               *
+ * Copyright 2007, 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.jboss.xb.binding.SimpleTypeBindings;
+
+import java.util.Calendar;
+
+/**
+ * Needs more complete tests!!
+ *
+ * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
+ * @version $Revision: 8784 $
+ * @since 2.4
+ */
+public class UserContextConverterTestCase extends TestCase
+{
+   public void testDateFormat()
+   {
+      String dateAsString = "1983-12-11T00:00:00.000+01:00";
+      Calendar bdate = SimpleTypeBindings.unmarshalDateTime(dateAsString);
+      String result = SimpleTypeBindings.marshalDateTime(bdate);
+      assertEquals(dateAsString, result);
+   }
+}


Property changes on: components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/other/UserContextConverterTestCase.java
___________________________________________________________________
Name: svn:executable
   + *

Added: components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/other/WSRPPortletURLTestCase.java
===================================================================
--- components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/other/WSRPPortletURLTestCase.java	                        (rev 0)
+++ components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/other/WSRPPortletURLTestCase.java	2009-11-09 19:58:03 UTC (rev 530)
@@ -0,0 +1,277 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat                                               *
+ * Copyright 2009, 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.Mode;
+import org.gatein.pc.api.WindowState;
+import org.gatein.wsrp.WSRPActionURL;
+import org.gatein.wsrp.WSRPPortletURL;
+import org.gatein.wsrp.WSRPRenderURL;
+import org.gatein.wsrp.WSRPRewritingConstants;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
+ * @version $Revision: 13470 $
+ * @since 2.4 (Apr 28, 2006)
+ */
+public class WSRPPortletURLTestCase extends TestCase
+{
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      WSRPPortletURL.setStrict(true);
+   }
+
+   public void testResource()
+   {
+      String expected = "wsrp_rewrite?wsrp-urlType=resource&amp;wsrp-url=http%3A%2F%2Ftest.com%2Fimages%2Ftest.gif" +
+         "&amp;wsrp-requiresRewrite=true/wsrp_rewrite";
+      WSRPPortletURL url = WSRPPortletURL.create(expected);
+
+      assertEquals("http://test.com/images/test.gif", url.toString());
+   }
+
+   /** Declare a secure interaction back to the Portlet */
+   public void testSecureInteraction()
+   {
+      String expected = "wsrp_rewrite?wsrp-urlType=blockingAction&amp;wsrp-secureURL=true" +
+         "&amp;wsrp-navigationalState=a8h4K5JD9&amp;wsrp-interactionState=fg4h923mdk/wsrp_rewrite";
+      WSRPPortletURL url = WSRPPortletURL.create(expected);
+
+      assertTrue(url instanceof WSRPActionURL);
+      WSRPActionURL actionURL = (WSRPActionURL)url;
+      assertTrue(url.isSecure());
+      assertEquals("a8h4K5JD9", actionURL.getNavigationalState().getStringValue());
+      assertEquals("fg4h923mdk", actionURL.getInteractionState().getStringValue());
+   }
+
+   /** Request the Consumer render the Portlet in a different mode and window state */
+   public void testDifferentModeAndWindowState()
+   {
+      String expected = "wsrp_rewrite?wsrp-urlType=render&amp;wsrp-mode=wsrp:help&amp;wsrp-windowState=wsrp:maximized/wsrp_rewrite";
+      WSRPPortletURL url = WSRPPortletURL.create(expected);
+
+      assertTrue(url instanceof WSRPRenderURL);
+      assertEquals(Mode.HELP, url.getMode());
+      assertEquals(WindowState.MAXIMIZED, url.getWindowState());
+   }
+
+   public void testMinimal()
+   {
+      String minimalURLType = "wsrp_rewrite?wsrp-urlType=render/wsrp_rewrite";
+      WSRPPortletURL url = WSRPPortletURL.create(minimalURLType);
+
+      assertTrue(url instanceof WSRPRenderURL);
+   }
+
+   public void testInvalidParameterName()
+   {
+      String message = "Should have detected invalid parameter: ";
+
+      String invalid = "wsrp_rewrite?wsrp-urlType=render&amp;foo=bar/wsrp_rewrite";
+      checkInvalidURL(invalid, message, "foo");
+   }
+
+   public void testDoublyEncodedAmpersand()
+   {
+      String expected = "wsrp_rewrite?wsrp-urlType=render&amp;amp;wsrp-mode=wsrp:help&amp;amp;wsrp-windowState=wsrp:maximized/wsrp_rewrite";
+      try
+      {
+         WSRPPortletURL.create(expected);
+         fail("Should have thrown an exception on doubly encoded &!");
+      }
+      catch (Exception e)
+      {
+         // expected
+      }
+   }
+
+   /** Relax validation and test that we now accept normally invalid URLs. */
+   public void testExtraParametersRelaxedValidation()
+   {
+      WSRPPortletURL.setStrict(false);
+
+      String validInRelaxedMode = "wsrp_rewrite?wsrp-urlType=render&amp;foo=bar/wsrp_rewrite";
+
+      WSRPPortletURL url = WSRPPortletURL.create(validInRelaxedMode);
+      assertTrue(url instanceof WSRPRenderURL);
+      assertTrue(url.toString().contains("foo=bar"));
+
+      validInRelaxedMode = "wsrp_rewrite?wsrp-urlType=render/wsrp_rewrite&amp;foo=bar";
+      url = WSRPPortletURL.create(validInRelaxedMode);
+      assertTrue(url instanceof WSRPRenderURL);
+      assertTrue(url.toString().endsWith("foo=bar"));
+
+      String stillInvalid = "wsrp_rewrite?wsrp-urlType=render&amp;foo=bar";
+      checkInvalidURL(stillInvalid, "Should have detected missing end token", WSRPRewritingConstants.END_WSRP_REWRITE);
+   }
+
+   public void testExtraRelaxedValidation()
+   {
+      String valid = "wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http%3A%2F%2Flocalhost%3A8080%2Fhelloworld&wsrp-requiresRewrite=true/wsrp_rewrite/helloworld.jar";
+      WSRPPortletURL url = WSRPPortletURL.create(valid);
+      assertEquals("http://localhost:8080/helloworld/helloworld.jar", url.toString());
+
+      String invalid = "wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http%3A%2F%2Flocalhost%3A8080%2Fhelloworld&wsrp-requiresRewrite=true/wsrp_rewrite&amp;foo=bar/helloworld.jar";
+      checkInvalidURL(invalid, "Should have detected improper position of end token", WSRPRewritingConstants.END_WSRP_REWRITE);
+
+      WSRPPortletURL.setStrict(false);
+      String validInRelaxedMode = "wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http%3A%2F%2Flocalhost%3A8080%2Fhelloworld&wsrp-requiresRewrite=true/wsrp_rewrite&amp;foo=bar/helloworld.jar";
+      url = WSRPPortletURL.create(validInRelaxedMode);
+      assertEquals("http://localhost:8080/helloworld&foo=bar/helloworld.jar", url.toString());
+   }
+
+   public void testExtraParameters()
+   {
+      String validInRelaxedMode = "wsrp_rewrite?wsrp-urlType=render&amp;foo=bar/wsrp_rewrite";
+      checkInvalidURL(validInRelaxedMode, "Should have detected invalid parameter: ", "foo");
+
+      validInRelaxedMode = "wsrp_rewrite?wsrp-urlType=render/wsrp_rewrite&amp;foo=bar";
+      checkInvalidURL(validInRelaxedMode, "Should have detected URL doesn't end with end token", WSRPRewritingConstants.END_WSRP_REWRITE);
+   }
+
+   public void testInvalidMode()
+   {
+      String message = "Should have detected invalid mode: ";
+
+      String invalid = "wsrp_rewrite?wsrp-urlType=render&wsrp-mode=foo/wsrp_rewrite";
+      checkInvalidURL(invalid, message, "foo");
+   }
+
+   public void testCustomModeAndWindowState()
+   {
+      Set<String> modes = new HashSet<String>();
+      modes.add("urn:foo");
+
+      Set<String> windowStates = new HashSet<String>();
+      windowStates.add("urn:bar");
+
+      String urlString = "wsrp_rewrite?wsrp-urlType=render&wsrp-mode=urn%3Afoo&wsrp-windowState=urn%3Abar/wsrp_rewrite";
+      WSRPPortletURL url = WSRPPortletURL.create(urlString, modes, windowStates);
+      assertEquals("urn:foo", url.getMode().toString());
+      assertEquals("urn:bar", url.getWindowState().toString());
+   }
+
+   public void testEncodedMode()
+   {
+      String encoded = "wsrp_rewrite?wsrp-urlType=render&wsrp-mode=wsrp%3Aview/wsrp_rewrite";
+      WSRPPortletURL url = WSRPPortletURL.create(encoded);
+      assertEquals(Mode.VIEW, url.getMode());
+
+      encoded = "wsrp_rewrite?wsrp-urlType=render&wsrp-mode=wsrp%3aedit/wsrp_rewrite";
+      url = WSRPPortletURL.create(encoded);
+      assertEquals(Mode.EDIT, url.getMode());
+   }
+
+   public void testEncodedWindowState()
+   {
+      String encoded = "wsrp_rewrite?wsrp-urlType=render&wsrp-windowState=wsrp%3Amaximized/wsrp_rewrite";
+      WSRPPortletURL url = WSRPPortletURL.create(encoded);
+      assertEquals(WindowState.MAXIMIZED, url.getWindowState());
+
+      encoded = "wsrp_rewrite?wsrp-urlType=render&wsrp-windowState=wsrp%3aminimized/wsrp_rewrite";
+      url = WSRPPortletURL.create(encoded);
+      assertEquals(WindowState.MINIMIZED, url.getWindowState());
+   }
+
+   public void testInvalidResourceURLV1()
+   {
+      String message = "Should have detected missing parameter: ";
+
+      String invalid = "wsrp_rewrite?wsrp-urlType=resource&amp;wsrp-url=http%3A%2F%2Flocalhost%2F/wsrp_rewrite";
+      checkInvalidURL(invalid, message, WSRPRewritingConstants.RESOURCE_REQUIRES_REWRITE);
+
+      invalid = "wsrp_rewrite?wsrp-urlType=resource&amp;wsrp-requiresRewrite=true/wsrp_rewrite";
+      checkInvalidURL(invalid, message, WSRPRewritingConstants.RESOURCE_URL);
+
+      invalid = "wsrp_rewrite?wsrp-urlType=resource&amp;wsrp-url=invalidURL&amp;wsrp-requiresRewrite=true/wsrp_rewrite";
+      checkInvalidURL(invalid, "Should have detected invalid URL: ", "invalidURL");
+   }
+
+   public void testNullURL()
+   {
+      try
+      {
+         WSRPPortletURL.create(null);
+         fail("Should have detected null URL");
+      }
+      catch (IllegalArgumentException e)
+      {
+         // expected
+      }
+   }
+
+   public void testInvalidURLType()
+   {
+      String wrongURLType = "wsrp_rewrite?wsrp-urlType=pipo&amp;wsrp-mode=help/wsrp_rewrite";
+
+      try
+      {
+         WSRPPortletURL.create(wrongURLType);
+         fail("Should have detected wrong URL type");
+      }
+      catch (IllegalArgumentException e)
+      {
+         // expected
+      }
+   }
+
+   public void testProperEndTokenInRelaxedMode()
+   {
+      WSRPPortletURL.setStrict(false);
+
+      WSRPPortletURL url = new WSRPPortletURL()
+      {
+         @Override
+         protected String getURLType()
+         {
+            return WSRPRewritingConstants.URL_TYPE_BLOCKING_ACTION;
+         }
+
+         @Override
+         protected void appendEnd(StringBuffer sb)
+         {
+         }
+      };
+      assertTrue(url.toString().contains(WSRPRewritingConstants.END_WSRP_REWRITE));
+   }
+
+   private void checkInvalidURL(String invalid, String message, String mustBeInException)
+   {
+      try
+      {
+         WSRPPortletURL.create(invalid);
+         fail(message + mustBeInException);
+      }
+      catch (IllegalArgumentException e)
+      {
+         assertTrue(e.getLocalizedMessage().contains(mustBeInException));
+      }
+   }
+}
\ No newline at end of file


Property changes on: components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/other/WSRPPortletURLTestCase.java
___________________________________________________________________
Name: svn:executable
   + *



More information about the gatein-commits mailing list