You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by aj...@apache.org on 2008/04/01 06:02:33 UTC

svn commit: r643268 - in /incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki: TestFilterChain.java TestFilterConfig.java TestHttpServletResponse.java TestServletContext.java

Author: ajaquith
Date: Mon Mar 31 21:02:32 2008
New Revision: 643268

URL: http://svn.apache.org/viewvc?rev=643268&view=rev
Log:
To support the auth refactoring, we introduce several *temporary* new servlet mock objects for unit testing: TestFilterChain, TestFilterConfig, TestHttpServletResponse, and TestServletContext. These are "temporary" because they will be replaced by Stripes mock objects later in the 2.7 release cycle.

Added:
    incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/TestFilterChain.java
    incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/TestFilterConfig.java
    incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/TestHttpServletResponse.java
    incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/TestServletContext.java

Added: incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/TestFilterChain.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/TestFilterChain.java?rev=643268&view=auto
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/TestFilterChain.java (added)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/TestFilterChain.java Mon Mar 31 21:02:32 2008
@@ -0,0 +1,44 @@
+/*
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.    
+ */
+package com.ecyrd.jspwiki;
+
+import java.io.IOException;
+
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+/**
+  * Mock servlet filter chain that does nothing. This is a temporary class and will go
+  * away in JSPWiki 3.0.
+  * @author Andrew Jaquith
+  * @deprecated
+  */
+public class TestFilterChain implements FilterChain
+{
+
+    public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException
+    {
+        return;
+    }
+
+}

Added: incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/TestFilterConfig.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/TestFilterConfig.java?rev=643268&view=auto
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/TestFilterConfig.java (added)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/TestFilterConfig.java Mon Mar 31 21:02:32 2008
@@ -0,0 +1,71 @@
+/*
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.    
+ */
+package com.ecyrd.jspwiki;
+
+import java.util.Enumeration;
+
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletContext;
+
+/**
+ * Mock servlet filter configuration. This is a temporary class and will go away in JSPWiki 3.0.
+ * @author Andrew Jaquith
+ * @deprecated
+ */
+public class TestFilterConfig implements FilterConfig
+{
+    private ServletContext m_servletContext;
+
+    public TestFilterConfig(ServletContext servletContext)
+    {
+        m_servletContext = servletContext;
+    }
+    
+    public String getFilterName()
+    {
+        return "Mock servlet config";
+    }
+
+    /**
+     * Returns null for all values.
+     */
+    public String getInitParameter(String arg0)
+    {
+        return null;
+    }
+
+    /**
+     * Returns null, for now.
+     */
+    public Enumeration getInitParameterNames()
+    {
+        return null;
+    }
+
+    /**
+     * Returns the servlet context used to create this config.
+     */
+    public ServletContext getServletContext()
+    {
+        return m_servletContext;
+    }
+
+}

Added: incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/TestHttpServletResponse.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/TestHttpServletResponse.java?rev=643268&view=auto
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/TestHttpServletResponse.java (added)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/TestHttpServletResponse.java Mon Mar 31 21:02:32 2008
@@ -0,0 +1,237 @@
+/*
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.    
+ */
+package com.ecyrd.jspwiki;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.HashSet;
+import java.util.Locale;
+import java.util.Set;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Mock response object that does absolutely nothing but allow cookies to be set.
+ * This is a temporary class and will go away in JSPWiki 3.0.
+ * @author Andrew Jaquith
+ * @deprecated
+ */
+public class TestHttpServletResponse implements HttpServletResponse
+{
+    private Set m_cookies = new HashSet();
+    
+    public Cookie[] getCookies() {
+        return (Cookie[])m_cookies.toArray(new Cookie[m_cookies.size()]);
+    }
+    
+    public void addCookie(Cookie arg0)
+    {
+        m_cookies.add(arg0);
+    }
+
+    public void addDateHeader(String arg0, long arg1)
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void addHeader(String arg0, String arg1)
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void addIntHeader(String arg0, int arg1)
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    public boolean containsHeader(String arg0)
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    public String encodeRedirectURL(String arg0)
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public String encodeRedirectUrl(String arg0)
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public String encodeURL(String arg0)
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public String encodeUrl(String arg0)
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public void sendError(int arg0) throws IOException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void sendError(int arg0, String arg1) throws IOException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void sendRedirect(String arg0) throws IOException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void setDateHeader(String arg0, long arg1)
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void setHeader(String arg0, String arg1)
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void setIntHeader(String arg0, int arg1)
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void setStatus(int arg0)
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void setStatus(int arg0, String arg1)
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void flushBuffer() throws IOException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    public int getBufferSize()
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    public String getCharacterEncoding()
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+    
+    public String getContentType()
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Locale getLocale()
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public ServletOutputStream getOutputStream() throws IOException
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public PrintWriter getWriter() throws IOException
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public boolean isCommitted()
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    public void reset()
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void resetBuffer()
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void setBufferSize(int arg0)
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void setCharacterEncoding( String arg0 )
+    {
+        // TODO Auto-generated method stub
+    }
+    
+    public void setContentLength(int arg0)
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void setContentType(String arg0)
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void setLocale(Locale arg0)
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+}

Added: incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/TestServletContext.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/TestServletContext.java?rev=643268&view=auto
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/TestServletContext.java (added)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/TestServletContext.java Mon Mar 31 21:02:32 2008
@@ -0,0 +1,199 @@
+/*
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.    
+ */
+package com.ecyrd.jspwiki;
+
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Set;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+
+/**
+ * Mock response object that stashes a WikiEngine object and returns it later.
+ * This is a temporary class and will go away in JSPWiki 3.0.
+ * @author Andrew Jaquith
+ * @deprecated
+ */
+public class TestServletContext implements ServletContext
+{
+    private WikiEngine m_engine;
+    
+    public TestServletContext(WikiEngine engine)
+    {
+        super();
+        m_engine = engine;
+    }
+    
+    /**
+     * If the attribute requested is for the magic WikiEngine, we return it; otherwise this always returns null.
+     */
+    public Object getAttribute(String arg0)
+    {
+        if ("com.ecyrd.jspwiki.WikiEngine".equals(arg0))
+        {
+            return m_engine;
+        }
+        return null;
+    }
+
+    public Enumeration getAttributeNames()
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public ServletContext getContext(String arg0)
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public String getInitParameter(String arg0)
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Enumeration getInitParameterNames()
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public int getMajorVersion()
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    public String getMimeType(String arg0)
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public int getMinorVersion()
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    public RequestDispatcher getNamedDispatcher(String arg0)
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public String getRealPath(String arg0)
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public RequestDispatcher getRequestDispatcher(String arg0)
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public URL getResource(String arg0) throws MalformedURLException
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public InputStream getResourceAsStream(String arg0)
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Set getResourcePaths(String arg0)
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public String getServerInfo()
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Servlet getServlet(String arg0) throws ServletException
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public String getServletContextName()
+    {
+        return "Test servlet context";
+    }
+
+    public Enumeration getServletNames()
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Enumeration getServlets()
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public void log(String arg0)
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void log(Exception arg0, String arg1)
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void log(String arg0, Throwable arg1)
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void removeAttribute(String arg0)
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void setAttribute(String arg0, Object arg1)
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+}