velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cbris...@apache.org
Subject svn commit: r1765877 - in /velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox: RequestAdaptor.java ResponseAdaptor.java ServletAdaptor.java ServletContextAdaptor.java
Date Thu, 20 Oct 2016 20:33:30 GMT
Author: cbrisson
Date: Thu Oct 20 20:33:29 2016
New Revision: 1765877

URL: http://svn.apache.org/viewvc?rev=1765877&view=rev
Log:
[tools] debugging tests for servlet api 3.0.1

Added:
    velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/RequestAdaptor.java
      - copied, changed from r1764870, velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/ServletAdaptor.java
    velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/ResponseAdaptor.java
      - copied, changed from r1764870, velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/ServletAdaptor.java
    velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/ServletContextAdaptor.java
      - copied, changed from r1764870, velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/ServletAdaptor.java
Removed:
    velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/ServletAdaptor.java

Copied: velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/RequestAdaptor.java
(from r1764870, velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/ServletAdaptor.java)
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/RequestAdaptor.java?p2=velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/RequestAdaptor.java&p1=velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/ServletAdaptor.java&r1=1764870&r2=1765877&rev=1765877&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/ServletAdaptor.java
(original)
+++ velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/RequestAdaptor.java
Thu Oct 20 20:33:29 2016
@@ -19,6 +19,8 @@ package org.apache.velocity.tools.test.b
  * under the License.
  */
 
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.util.Collections;
@@ -26,10 +28,6 @@ import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
-import javax.servlet.ServletContext;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
 /**
  * <p>Helper class for LinkToolTests class</p>
@@ -37,7 +35,7 @@ import javax.servlet.http.HttpServletRes
  * @author Christopher Schultz
  * @version $Id$
  */
-public class ServletAdaptor implements InvocationHandler
+public class RequestAdaptor implements InvocationHandler
 {
     // helper class
     public class IteratorEnumeration implements Enumeration
@@ -53,18 +51,18 @@ public class ServletAdaptor implements I
     private String _contextPath;
     private String _pathInfo;
 
-    public ServletAdaptor(Map cookies)
+    public RequestAdaptor(Map cookies)
     {
         this(null, null, cookies);
     }
 
-    public ServletAdaptor(String contextPath,
+    public RequestAdaptor(String contextPath,
                           Map params)
     {
         this(contextPath, "", params);
     }
 
-    public ServletAdaptor(String contextPath, String pathInfo, Map params)
+    public RequestAdaptor(String contextPath, String pathInfo, Map params)
     {
         _contextPath = contextPath;
         if(null == _contextPath)
@@ -95,14 +93,6 @@ public class ServletAdaptor implements I
         {
             return request(proxy, method, args);
         }
-        else if(clazz.isAssignableFrom(HttpServletResponse.class))
-        {
-            return response(proxy, method, args);
-        }
-        else if(clazz.isAssignableFrom(ServletContext.class))
-        {
-            return context(proxy, method, args);
-        }
         else
         {
             throw new IllegalStateException("Unexpected proxy interface: "
@@ -110,38 +100,6 @@ public class ServletAdaptor implements I
         }
     }
 
-    protected Object response(Object proxy,
-                              Method method,
-                              Object[] args)
-    {
-        String methodName = method.getName();
-
-        if("encodeURL".equals(methodName)
-           || "encodeUrl".equals(methodName))
-        {
-            // Don't worry about adding ";jsessionid" or anything.
-            return args[0];
-        }
-        else if ("addCookie".equals(methodName))
-        {
-            Cookie c = (Cookie)args[0];
-            if (c.getMaxAge() == 0)
-            {
-                _params.remove(c.getName());
-            }
-            else
-            {
-                _params.put(c.getName(), c);
-            }
-            return null;
-        }
-        else
-        {
-            throw new IllegalStateException("Unexpected method call: "
-                                            + method);
-        }
-    }
-
     protected Object request(Object proxy,
                              Method method,
                              Object[] args)
@@ -262,22 +220,4 @@ public class ServletAdaptor implements I
                                             + method);
         }
     }
-
-    protected Object context(Object proxy,
-                             Method method,
-                             Object[] args)
-    {
-        String methodName = method.getName();
-
-        if("getContextPath".equals(methodName))
-        {
-            return _contextPath;
-        }
-        else
-        {
-            throw new IllegalStateException("Unexpected method call: "
-                                            + methodName);
-        }
-    }
-
 }

Copied: velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/ResponseAdaptor.java
(from r1764870, velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/ServletAdaptor.java)
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/ResponseAdaptor.java?p2=velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/ResponseAdaptor.java&p1=velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/ServletAdaptor.java&r1=1764870&r2=1765877&rev=1765877&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/ServletAdaptor.java
(original)
+++ velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/ResponseAdaptor.java
Thu Oct 20 20:33:29 2016
@@ -19,17 +19,12 @@ package org.apache.velocity.tools.test.b
  * under the License.
  */
 
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletResponse;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
-import java.util.Collections;
-import java.util.Enumeration;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
-import javax.servlet.ServletContext;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
 /**
  * <p>Helper class for LinkToolTests class</p>
@@ -37,46 +32,13 @@ import javax.servlet.http.HttpServletRes
  * @author Christopher Schultz
  * @version $Id$
  */
-public class ServletAdaptor implements InvocationHandler
+public class ResponseAdaptor implements InvocationHandler
 {
-    // helper class
-    public class IteratorEnumeration implements Enumeration
-    {
-        private Iterator iterator;
-        public IteratorEnumeration( Iterator iterator ) { this.iterator = iterator; }
-        public boolean hasMoreElements() { return iterator.hasNext(); }
-        public Object nextElement() { return iterator.next(); }
-    }
-
     // the params now also serve as a cookie jar for CookieToolTests
     private Map _params;
-    private String _contextPath;
-    private String _pathInfo;
-
-    public ServletAdaptor(Map cookies)
-    {
-        this(null, null, cookies);
-    }
-
-    public ServletAdaptor(String contextPath,
-                          Map params)
-    {
-        this(contextPath, "", params);
-    }
 
-    public ServletAdaptor(String contextPath, String pathInfo, Map params)
+    public ResponseAdaptor(Map params)
     {
-        _contextPath = contextPath;
-        if(null == _contextPath)
-        {
-            _contextPath = "";
-        }
-        _pathInfo = pathInfo;
-        if(null == _pathInfo)
-        {
-            _pathInfo = "";
-        }
-
         _params = params;
 
         if(null == _params)
@@ -91,18 +53,10 @@ public class ServletAdaptor implements I
     {
         Class clazz = method.getDeclaringClass();
 
-        if(clazz.isAssignableFrom(HttpServletRequest.class))
-        {
-            return request(proxy, method, args);
-        }
-        else if(clazz.isAssignableFrom(HttpServletResponse.class))
+        if(clazz.isAssignableFrom(HttpServletResponse.class))
         {
             return response(proxy, method, args);
         }
-        else if(clazz.isAssignableFrom(ServletContext.class))
-        {
-            return context(proxy, method, args);
-        }
         else
         {
             throw new IllegalStateException("Unexpected proxy interface: "
@@ -135,149 +89,14 @@ public class ServletAdaptor implements I
             }
             return null;
         }
-        else
-        {
-            throw new IllegalStateException("Unexpected method call: "
-                                            + method);
-        }
-    }
-
-    protected Object request(Object proxy,
-                             Method method,
-                             Object[] args)
-    {
-        String methodName = method.getName();
-
-        if("getContextPath".equals(methodName))
-        {
-            return _contextPath;
-        }
-        else if("getParameter".equals(methodName))
-        {
-            Object value = _params.get(args[0]);
-
-            if(value instanceof String)
-            {
-                return value;
-            }
-            else if (value instanceof String[])
-            {
-                return ((String[])value)[0];
-            }
-            else
-            {
-                throw new IllegalStateException("Parameter value must be either String or
String[].");
-            }
-        }
-        else if("getParameterValues".equals(methodName))
-        {
-            Object value = _params.get(args[0]);
-
-            if(value instanceof String)
-            {
-                return new String[] { (String)value };
-            }
-            else if (value instanceof String[])
-            {
-                return value;
-            }
-            else
-            {
-                throw new IllegalStateException("Parameter value must be either String or
String[].");
-            }
-        }
-        else if("getParameterMap".equals(methodName))
-        {
-            return Collections.unmodifiableMap(_params);
-        }
-        else if("getParameterNames".equals(methodName))
-        {
-            return new IteratorEnumeration(_params.keySet().iterator());
-        }
-        else if("getSession".equals(methodName))
-        {
-            return null;
-        }
-        else if("getAttribute".equals(methodName))
-        {
-            if(((String)args[0]).equals("XHTML"))
-            {
-                return Boolean.TRUE; // xhtml = true
-            }
-            else
-            {
-                return null;
-            }
-        }
-        else if ("getScheme".equals(methodName))
-        {
-            return "http";
-        }
-        else if ("getServerPort".equals(methodName))
-        {
-            return new Integer(8081);
-        }
-        else if ("getServerName".equals(methodName))
-        {
-            return "localhost";
-        }
-        else if ("getServletPath".equals(methodName))
-        {
-            return _contextPath;
-        }
-        else if ("getPathInfo".equals(methodName))
-        {
-            return _pathInfo;
-        }
-        else if("getCharacterEncoding".equals(methodName))
+        else if ("getCharacterEncoding".equals(methodName))
         {
             return "UTF-8";
         }
-        else if ("getCookies".equals(methodName))
-        {
-            // just let params double as the cookie store
-            Cookie[] jar = new Cookie[_params.size()];
-            int i = 0;
-            for (Iterator iter = _params.keySet().iterator(); iter.hasNext(); i++)
-            {
-                Object key = iter.next();
-                Object val = _params.get(key);
-                if (val instanceof Cookie)
-                {
-                    jar[i] = (Cookie)val;
-                }
-                else
-                {
-                    String name = String.valueOf(key);
-                    String value = String.valueOf(val);
-                    jar[i] = new Cookie(name, value);
-                    _params.put(name, jar[i]);
-                }
-            }
-            return jar;
-        }
         else
         {
             throw new IllegalStateException("Unexpected method call: "
                                             + method);
         }
     }
-
-    protected Object context(Object proxy,
-                             Method method,
-                             Object[] args)
-    {
-        String methodName = method.getName();
-
-        if("getContextPath".equals(methodName))
-        {
-            return _contextPath;
-        }
-        else
-        {
-            throw new IllegalStateException("Unexpected method call: "
-                                            + methodName);
-        }
-    }
-
 }

Copied: velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/ServletContextAdaptor.java
(from r1764870, velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/ServletAdaptor.java)
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/ServletContextAdaptor.java?p2=velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/ServletContextAdaptor.java&p1=velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/ServletAdaptor.java&r1=1764870&r2=1765877&rev=1765877&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/ServletAdaptor.java
(original)
+++ velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/test/blackbox/ServletContextAdaptor.java
Thu Oct 20 20:33:29 2016
@@ -19,17 +19,9 @@ package org.apache.velocity.tools.test.b
  * under the License.
  */
 
+import javax.servlet.ServletContext;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import javax.servlet.ServletContext;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
 /**
  * <p>Helper class for LinkToolTests class</p>
@@ -37,52 +29,17 @@ import javax.servlet.http.HttpServletRes
  * @author Christopher Schultz
  * @version $Id$
  */
-public class ServletAdaptor implements InvocationHandler
+public class ServletContextAdaptor implements InvocationHandler
 {
-    // helper class
-    public class IteratorEnumeration implements Enumeration
-    {
-        private Iterator iterator;
-        public IteratorEnumeration( Iterator iterator ) { this.iterator = iterator; }
-        public boolean hasMoreElements() { return iterator.hasNext(); }
-        public Object nextElement() { return iterator.next(); }
-    }
-
-    // the params now also serve as a cookie jar for CookieToolTests
-    private Map _params;
     private String _contextPath;
-    private String _pathInfo;
-
-    public ServletAdaptor(Map cookies)
-    {
-        this(null, null, cookies);
-    }
-
-    public ServletAdaptor(String contextPath,
-                          Map params)
-    {
-        this(contextPath, "", params);
-    }
 
-    public ServletAdaptor(String contextPath, String pathInfo, Map params)
+    public ServletContextAdaptor(String contextPath)
     {
         _contextPath = contextPath;
         if(null == _contextPath)
         {
             _contextPath = "";
         }
-        _pathInfo = pathInfo;
-        if(null == _pathInfo)
-        {
-            _pathInfo = "";
-        }
-
-        _params = params;
-
-        if(null == _params)
-        {
-            _params = new HashMap();
-        }
     }
 
     public Object invoke(Object proxy,
@@ -90,16 +47,7 @@ public class ServletAdaptor implements I
                          Object[] args)
     {
         Class clazz = method.getDeclaringClass();
-
-        if(clazz.isAssignableFrom(HttpServletRequest.class))
-        {
-            return request(proxy, method, args);
-        }
-        else if(clazz.isAssignableFrom(HttpServletResponse.class))
-        {
-            return response(proxy, method, args);
-        }
-        else if(clazz.isAssignableFrom(ServletContext.class))
+        if(clazz.isAssignableFrom(ServletContext.class))
         {
             return context(proxy, method, args);
         }
@@ -110,159 +58,6 @@ public class ServletAdaptor implements I
         }
     }
 
-    protected Object response(Object proxy,
-                              Method method,
-                              Object[] args)
-    {
-        String methodName = method.getName();
-
-        if("encodeURL".equals(methodName)
-           || "encodeUrl".equals(methodName))
-        {
-            // Don't worry about adding ";jsessionid" or anything.
-            return args[0];
-        }
-        else if ("addCookie".equals(methodName))
-        {
-            Cookie c = (Cookie)args[0];
-            if (c.getMaxAge() == 0)
-            {
-                _params.remove(c.getName());
-            }
-            else
-            {
-                _params.put(c.getName(), c);
-            }
-            return null;
-        }
-        else
-        {
-            throw new IllegalStateException("Unexpected method call: "
-                                            + method);
-        }
-    }
-
-    protected Object request(Object proxy,
-                             Method method,
-                             Object[] args)
-    {
-        String methodName = method.getName();
-
-        if("getContextPath".equals(methodName))
-        {
-            return _contextPath;
-        }
-        else if("getParameter".equals(methodName))
-        {
-            Object value = _params.get(args[0]);
-
-            if(value instanceof String)
-            {
-                return value;
-            }
-            else if (value instanceof String[])
-            {
-                return ((String[])value)[0];
-            }
-            else
-            {
-                throw new IllegalStateException("Parameter value must be either String or
String[].");
-            }
-        }
-        else if("getParameterValues".equals(methodName))
-        {
-            Object value = _params.get(args[0]);
-
-            if(value instanceof String)
-            {
-                return new String[] { (String)value };
-            }
-            else if (value instanceof String[])
-            {
-                return value;
-            }
-            else
-            {
-                throw new IllegalStateException("Parameter value must be either String or
String[].");
-            }
-        }
-        else if("getParameterMap".equals(methodName))
-        {
-            return Collections.unmodifiableMap(_params);
-        }
-        else if("getParameterNames".equals(methodName))
-        {
-            return new IteratorEnumeration(_params.keySet().iterator());
-        }
-        else if("getSession".equals(methodName))
-        {
-            return null;
-        }
-        else if("getAttribute".equals(methodName))
-        {
-            if(((String)args[0]).equals("XHTML"))
-            {
-                return Boolean.TRUE; // xhtml = true
-            }
-            else
-            {
-                return null;
-            }
-        }
-        else if ("getScheme".equals(methodName))
-        {
-            return "http";
-        }
-        else if ("getServerPort".equals(methodName))
-        {
-            return new Integer(8081);
-        }
-        else if ("getServerName".equals(methodName))
-        {
-            return "localhost";
-        }
-        else if ("getServletPath".equals(methodName))
-        {
-            return _contextPath;
-        }
-        else if ("getPathInfo".equals(methodName))
-        {
-            return _pathInfo;
-        }
-        else if("getCharacterEncoding".equals(methodName))
-        {
-            return "UTF-8";
-        }
-        else if ("getCookies".equals(methodName))
-        {
-            // just let params double as the cookie store
-            Cookie[] jar = new Cookie[_params.size()];
-            int i = 0;
-            for (Iterator iter = _params.keySet().iterator(); iter.hasNext(); i++)
-            {
-                Object key = iter.next();
-                Object val = _params.get(key);
-                if (val instanceof Cookie)
-                {
-                    jar[i] = (Cookie)val;
-                }
-                else
-                {
-                    String name = String.valueOf(key);
-                    String value = String.valueOf(val);
-                    jar[i] = new Cookie(name, value);
-                    _params.put(name, jar[i]);
-                }
-            }
-            return jar;
-        }
-        else
-        {
-            throw new IllegalStateException("Unexpected method call: "
-                                            + method);
-        }
-    }
-
     protected Object context(Object proxy,
                              Method method,
                              Object[] args)



Mime
View raw message