[exo-jcr-commits] exo-jcr SVN: r165 - ws/trunk/testframework/src/main/java/org/exoplatform/testframework.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Sep 10 07:21:01 EDT 2009


Author: aparfonov
Date: 2009-09-10 07:21:01 -0400 (Thu, 10 Sep 2009)
New Revision: 165

Added:
   ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensetiveMap.java
   ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensitiveMultivaluedMap.java
Removed:
   ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensitiveMap.java
Modified:
   ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletRequest.java
   ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletResponse.java
   ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockPrincipal.java
Log:
EXOJCR-152 : 

Added: ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensetiveMap.java
===================================================================
--- ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensetiveMap.java	                        (rev 0)
+++ ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensetiveMap.java	2009-09-10 11:21:01 UTC (rev 165)
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2003-2008 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ * 
+ * This program 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 General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+
+package org.exoplatform.testframework;
+
+/**
+ * @author <a href="mailto:andrew00x at gmail.com">Andrey Parfonov</a>
+ * @version $Id$
+ */
+public class CaseInsensetiveMap<T> extends java.util.HashMap<String, T>
+{
+
+   private static final long serialVersionUID = -8562529039657285360L;
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public boolean containsKey(Object key)
+   {
+      return super.containsKey(getKey(key));
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public T get(Object key)
+   {
+      return super.get(getKey(key));
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public T put(String key, T value)
+   {
+      return super.put(getKey(key), value);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public T remove(Object key)
+   {
+      return super.remove(getKey(key));
+   }
+
+   private String getKey(Object key)
+   {
+      if (key == null)
+      {
+         return null;
+      }
+      return key.toString().toLowerCase();
+   }
+
+}


Property changes on: ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensetiveMap.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Deleted: ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensitiveMap.java
===================================================================
--- ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensitiveMap.java	2009-09-10 10:56:44 UTC (rev 164)
+++ ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensitiveMap.java	2009-09-10 11:21:01 UTC (rev 165)
@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * 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.exoplatform.testframework;
-
-import java.util.HashMap;
-
-
-/**
- * @author <a href="mailto:andrew00x at gmail.com">Andrey Parfonov</a>
- * @version $Id: CaseInsensitiveMap.java 2822 2009-08-27 14:14:41Z andrew00x $
- */
-public class CaseInsensitiveMap extends HashMap<String, String>
-{
-
-   private static final long serialVersionUID = 6637313979061607685L;
-
-   /**
-    * {@inheritDoc}
-    */
-   @Override
-   public boolean containsKey(Object key)
-   {
-      return super.containsKey(getKey(key));
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   @Override
-   public String get(Object key)
-   {
-      return super.get(getKey(key));
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   @Override
-   public String put(String key, String value)
-   {
-      return super.put(getKey(key), value);
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   @Override
-   public String remove(Object key)
-   {
-      return super.remove(getKey(key));
-   }
-
-   private String getKey(Object key)
-   {
-      if (key == null)
-      {
-         return null;
-      }
-      return key.toString().toLowerCase();
-   }
-
-}
\ No newline at end of file

Copied: ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensitiveMultivaluedMap.java (from rev 160, ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensitiveMap.java)
===================================================================
--- ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensitiveMultivaluedMap.java	                        (rev 0)
+++ ws/trunk/testframework/src/main/java/org/exoplatform/testframework/CaseInsensitiveMultivaluedMap.java	2009-09-10 11:21:01 UTC (rev 165)
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * 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.exoplatform.testframework;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+
+/**
+ * @author <a href="mailto:andrew00x at gmail.com">Andrey Parfonov</a>
+ * @version $Id: CaseInsensitiveMap.java 2822 2009-08-27 14:14:41Z andrew00x $
+ */
+public class CaseInsensitiveMultivaluedMap<T> extends HashMap<String, List<T>>
+{
+
+   private static final long serialVersionUID = 6637313979061607685L;
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public boolean containsKey(Object key)
+   {
+      return super.containsKey(getKey(key));
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public List<T> get(Object key)
+   {
+      return getList(getKey(key));
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public List<T> put(String key, List<T> value)
+   {
+      return super.put(getKey(key), value);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public List<T> remove(Object key)
+   {
+      return super.remove(getKey(key));
+   }
+   
+   public T getFirst(String key)
+   {
+      List<T> l = getList(key);
+      if (l.size() == 0)
+         return null;
+      return l.get(0);
+   }
+   
+   private List<T> getList(String key)
+   {
+      List<T> l = super.get(key);
+      if (l == null)
+         l = new ArrayList<T>();
+      put(key, l);
+      return l;
+   }
+
+   private String getKey(Object key)
+   {
+      if (key == null)
+      {
+         return null;
+      }
+      return key.toString().toLowerCase();
+   }
+
+}
\ No newline at end of file

Modified: ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletRequest.java
===================================================================
--- ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletRequest.java	2009-09-10 10:56:44 UTC (rev 164)
+++ ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletRequest.java	2009-09-10 11:21:01 UTC (rev 165)
@@ -1,18 +1,20 @@
-/**
- * Copyright (C) 2003-2009 eXo Platform SAS.
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Affero General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
+ * 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 General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ * 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.exoplatform.testframework;
@@ -63,10 +65,10 @@
    private InputStream data;
 
    /** Headers. */
-   private Map headers = new CaseInsensitiveMap();
+   private Map<String, List<String>> headers = new CaseInsensitiveMultivaluedMap<String>();
 
    /** The parameters. */
-   private Map<String, ArrayList> parameters = new HashMap();
+   private Map<String, List<String>> parameters = new HashMap<String, List<String>>();
 
    /** The session. */
    private HttpSession session;
@@ -83,6 +85,8 @@
    /** The attributes. */
    private Map<String, Object> attributes = new HashMap<String, Object>();
 
+   private Principal principal;
+
    /**
     * Instantiates a new mock http servlet request.
     * 
@@ -97,18 +101,21 @@
     * @param headers
     *           the headers
     */
-   public MockHttpServletRequest(String url, InputStream data, int length, String method, HashMap<String, List> headers)
+   public MockHttpServletRequest(String url, InputStream data, int length, String method,
+      Map<String, List<String>> headers)
    {
       this.requestURL = url;
       this.data = data;
       this.length = length;
       this.method = method;
-      this.headers = headers;
+      if (headers != null)
+         this.headers.putAll(headers);
       String queryString = getQueryString();
       if (queryString != null)
       {
          parameters.putAll(parseQueryString(queryString));
       }
+      session = new MockHttpSession();
    }
 
    /**
@@ -165,12 +172,8 @@
     */
    public String getContentType()
    {
-      // return headers.getFirst("content-type");
-      synchronized (headers)
-      {
-         if (headers.get("content-type") != null)
-            return (String)headers.get("content-type");
-      }
+      if (headers.get("content-type") != null)
+         return headers.get("content-type").get(0);
       return (null);
    }
 
@@ -198,12 +201,8 @@
     */
    public long getDateHeader(String name)
    {
-      // return Long.valueOf(headers.get(name));
-      synchronized (headers)
-      {
-         if (headers.get(name) != null)
-            return (Long)headers.get(0);
-      }
+      if (headers.get(name) != null)
+         return Long.valueOf(headers.get(name).get(0));
       return -1L;
    }
 
@@ -212,12 +211,8 @@
     */
    public String getHeader(String name)
    {
-      // return headers.get(name);
-      synchronized (headers)
-      {
-         if (headers.get(name) != null)
-            return (String)headers.get(name);
-      }
+      if (headers.get(name) != null)
+         return headers.get(name).get(0);
       return (null);
    }
 
@@ -265,18 +260,8 @@
     */
    public int getIntHeader(String name)
    {
-      // return Integer.valueOf(headers.get(name));
-      synchronized (headers)
-      {
-         if (headers.get(name) != null)
-            try
-            {
-               return Integer.parseInt((String)headers.get(name));
-            }
-            catch (NumberFormatException e)
-            {
-            }
-      }
+      if (headers.get(name) != null)
+         return Integer.parseInt(headers.get(name).get(0));
       return -1;
    }
 
@@ -565,7 +550,7 @@
     */
    public HttpSession getSession()
    {
-      return null;
+      return session;
    }
 
    /**
@@ -573,7 +558,7 @@
     */
    public HttpSession getSession(boolean b)
    {
-      return null;
+      return session;
    }
 
    /**
@@ -581,14 +566,7 @@
     */
    public Principal getUserPrincipal()
    {
-      return new Principal()
-      {
-
-         public String getName()
-         {
-            return "root";
-         }
-      };
+      return principal == null ? principal = new MockPrincipal("root") : principal;
    }
 
    /**
@@ -628,7 +606,7 @@
     */
    public boolean isSecure()
    {
-      return false;
+      return secure;
    }
 
    /**
@@ -677,9 +655,9 @@
       parameters.put(name, arr);
    }
 
-   public static Map<String, ArrayList> parseQueryString(String rawQuery)
+   public static Map<String, List<String>> parseQueryString(String rawQuery)
    {
-      HashMap<String, ArrayList> m = new HashMap();
+      HashMap<String, List<String>> m = new HashMap<String, List<String>>();
       if (rawQuery == null || rawQuery.length() == 0)
          return m;
       int p = 0;
@@ -707,13 +685,13 @@
 
          if (m.get(name) == null)
          {
-            ArrayList<String> arr = new ArrayList<String>();
+            List<String> arr = new ArrayList<String>();
             arr.add(value);
             m.put(name, arr);
          }
          else
          {
-            ArrayList<String> arr = m.get(name);
+            List<String> arr = m.get(name);
             arr.add(value);
          }
          p = n + 1;

Modified: ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletResponse.java
===================================================================
--- ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletResponse.java	2009-09-10 10:56:44 UTC (rev 164)
+++ ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockHttpServletResponse.java	2009-09-10 11:21:01 UTC (rev 165)
@@ -26,6 +26,7 @@
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Locale;
 import java.util.TimeZone;
 
@@ -60,10 +61,10 @@
    private int bufferCount = 0;
 
    /** The cookies. */
-   private ArrayList cookies = new ArrayList();
+   private List<Cookie> cookies = new ArrayList<Cookie>();
 
    /** The headers. */
-   private HashMap headers = new CaseInsensitiveMap();
+   private HashMap<String, List<String>> headers = new CaseInsensitiveMultivaluedMap<String>();
 
    /** The status. */
    private int status = HttpServletResponse.SC_OK;

Modified: ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockPrincipal.java
===================================================================
--- ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockPrincipal.java	2009-09-10 10:56:44 UTC (rev 164)
+++ ws/trunk/testframework/src/main/java/org/exoplatform/testframework/MockPrincipal.java	2009-09-10 11:21:01 UTC (rev 165)
@@ -23,11 +23,19 @@
  */
 public class MockPrincipal implements java.security.Principal
 {
+   
+   private final String username;
+   
+   public MockPrincipal(String username)
+   {
+      this.username = username;
+   }
+   
    /**
     * {@inheritDoc}
     */
    public String getName()
    {
-      return "PrincipalMackName";
+      return username;
    }
 }



More information about the exo-jcr-commits mailing list