/******************************************************************************** * CruiseControl, a Continuous Integration Toolkit * Copyright (c) 2003, ThoughtWorks, Inc. * 200 E. Randolph, 25th Floor * Chicago, IL 60601 USA * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * + Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * + Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the * names of its contributors may be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ********************************************************************************/ package net.sourceforge.cruisecontrol.mock; import java.io.BufferedReader; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.security.Principal; import java.util.Enumeration; import java.util.Locale; import java.util.Map; import java.util.HashMap; import java.util.Collections; import java.util.ArrayList; import javax.servlet.RequestDispatcher; import javax.servlet.ServletInputStream; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; /** * * @author <a href="mailto:robertdw@sourceforge.net">Robert Watkins</a> */ public class MockServletRequest implements HttpServletRequest { private String contextPath = ""; private String servletPath; private Map params = new HashMap(); private String pathInfo; private Locale locale; public MockServletRequest() { } public MockServletRequest(String contextPath, String servletPath) { this.contextPath = contextPath; this.servletPath = servletPath; } public Object getAttribute(String name) { return null; } public Enumeration getAttributeNames() { return null; } public String getCharacterEncoding() { return null; } public int getContentLength() { return 0; } public String getContentType() { return null; } public ServletInputStream getInputStream() throws IOException { return null; } public String getParameter(String paramName) { ArrayList values = (ArrayList) params.get(paramName); if (values == null || values.isEmpty()) { return null; // param not found } return (String) values.get(0); } public Enumeration getParameterNames() { return Collections.enumeration(params.keySet()); } public String[] getParameterValues(String paramName) { ArrayList values = (ArrayList) params.get(paramName); if (values == null || values.isEmpty()) { return null; // param not found } return (String[]) values.toArray(new String[] {}); } public String getProtocol() { return null; } public String getScheme() { return null; } public String getServerName() { return null; } public int getServerPort() { return 0; } public BufferedReader getReader() throws IOException { return null; } public String getRemoteAddr() { return null; } public String getRemoteHost() { return null; } public void setAttribute(String s, Object o) { } public void removeAttribute(String s) { } public Locale getLocale() { return locale; } public Enumeration getLocales() { return null; } public boolean isSecure() { return false; } public RequestDispatcher getRequestDispatcher(String s) { return null; } public String getRealPath(String s) { return null; } public String getAuthType() { return null; } public Cookie[] getCookies() { return new Cookie[0]; } public long getDateHeader(String s) { return 0; } public String getHeader(String s) { return null; } public Enumeration getHeaders(String s) { return null; } public Enumeration getHeaderNames() { return null; } public int getIntHeader(String s) { return 0; } public String getMethod() { return null; } public String getPathInfo() { return pathInfo; } public String getPathTranslated() { return null; } public String getContextPath() { return (contextPath.length() == 0 ? "" : "/" + contextPath); } public String getQueryString() { return null; } public String getRemoteUser() { return null; } public boolean isUserInRole(String s) { return false; } public Principal getUserPrincipal() { return null; } public String getRequestedSessionId() { return null; } public String getRequestURI() { return null; } public String getServletPath() { return "/" + servletPath; } public HttpSession getSession(boolean b) { return null; } public HttpSession getSession() { return null; } public boolean isRequestedSessionIdValid() { return false; } public boolean isRequestedSessionIdFromCookie() { return false; } public boolean isRequestedSessionIdFromURL() { return false; } public boolean isRequestedSessionIdFromUrl() { return false; } public void addParameter(String paramName, String paramValue) { ArrayList values = (ArrayList) params.get(paramName); if (values == null) { values = new ArrayList(); params.put(paramName, values); } values.add(paramValue); } public ArrayList removeParameter(String paramName) { ArrayList values = (ArrayList) params.remove(paramName); return values; } public void setPathInfo(String info) { pathInfo = info; } /** * @param locale */ public void setLocale(Locale locale) { this.locale = locale; } public StringBuffer getRequestURL() { return null; } public String getLocalAddr() { return null; } public String getLocalName() { return null; } public int getLocalPort() { return 0; } public Map getParameterMap() { return null; } public int getRemotePort() { return 0; } public void setCharacterEncoding(String arg0) throws UnsupportedEncodingException { } }