1 37 package net.sourceforge.cruisecontrol.mock; 38 39 import java.io.BufferedReader ; 40 import java.io.IOException ; 41 import java.security.Principal ; 42 import java.util.Enumeration ; 43 import java.util.Locale ; 44 import java.util.Map ; 45 import java.util.HashMap ; 46 import java.util.Collections ; 47 import java.util.ArrayList ; 48 import javax.servlet.RequestDispatcher ; 49 import javax.servlet.ServletInputStream ; 50 import javax.servlet.http.Cookie ; 51 import javax.servlet.http.HttpServletRequest ; 52 import javax.servlet.http.HttpSession ; 53 54 58 public class MockServletRequest implements HttpServletRequest { 59 private String contextPath = ""; 60 private String servletPath; 61 private Map params = new HashMap (); 62 private String pathInfo; 63 private Locale locale; 64 65 public MockServletRequest() { 66 } 67 68 public MockServletRequest(String contextPath, String servletPath) { 69 this.contextPath = contextPath; 70 this.servletPath = servletPath; 71 } 72 73 public Object getAttribute(String name) { 74 return null; 75 } 76 77 public Enumeration getAttributeNames() { 78 return null; 79 } 80 81 public String getCharacterEncoding() { 82 return null; 83 } 84 85 public int getContentLength() { 86 return 0; 87 } 88 89 public String getContentType() { 90 return null; 91 } 92 93 public ServletInputStream getInputStream() throws IOException { 94 return null; 95 } 96 97 public String getParameter(String paramName) { 98 ArrayList values = (ArrayList ) params.get(paramName); 99 if (values == null || values.isEmpty()) { 100 return null; } 102 return (String ) values.get(0); 103 } 104 105 public Enumeration getParameterNames() { 106 return Collections.enumeration(params.keySet()); 107 } 108 109 public String [] getParameterValues(String paramName) { 110 ArrayList values = (ArrayList ) params.get(paramName); 111 if (values == null || values.isEmpty()) { 112 return null; } 114 return (String []) values.toArray(new String [] {}); 115 } 116 117 public String getProtocol() { 118 return null; 119 } 120 121 public String getScheme() { 122 return null; 123 } 124 125 public String getServerName() { 126 return null; 127 } 128 129 public int getServerPort() { 130 return 0; 131 } 132 133 public BufferedReader getReader() throws IOException { 134 return null; 135 } 136 137 public String getRemoteAddr() { 138 return null; 139 } 140 141 public String getRemoteHost() { 142 return null; 143 } 144 145 public void setAttribute(String s, Object o) { 146 } 147 148 public void removeAttribute(String s) { 149 } 150 151 public Locale getLocale() { 152 return locale; 153 } 154 155 public Enumeration getLocales() { 156 return null; 157 } 158 159 public boolean isSecure() { 160 return false; 161 } 162 163 public RequestDispatcher getRequestDispatcher(String s) { 164 return null; 165 } 166 167 public String getRealPath(String s) { 168 return null; 169 } 170 171 public String getAuthType() { 172 return null; 173 } 174 175 public Cookie [] getCookies() { 176 return new Cookie [0]; 177 } 178 179 public long getDateHeader(String s) { 180 return 0; 181 } 182 183 public String getHeader(String s) { 184 return null; 185 } 186 187 public Enumeration getHeaders(String s) { 188 return null; 189 } 190 191 public Enumeration getHeaderNames() { 192 return null; 193 } 194 195 public int getIntHeader(String s) { 196 return 0; 197 } 198 199 public String getMethod() { 200 return null; 201 } 202 203 public String getPathInfo() { 204 return pathInfo; 205 } 206 207 public String getPathTranslated() { 208 return null; 209 } 210 211 public String getContextPath() { 212 return (contextPath.length() == 0 ? "" : "/" + contextPath); 213 } 214 215 public String getQueryString() { 216 return null; 217 } 218 219 public String getRemoteUser() { 220 return null; 221 } 222 223 public boolean isUserInRole(String s) { 224 return false; 225 } 226 227 public Principal getUserPrincipal() { 228 return null; 229 } 230 231 public String getRequestedSessionId() { 232 return null; 233 } 234 235 public String getRequestURI() { 236 return null; 237 } 238 239 public String getServletPath() { 240 return "/" + servletPath; 241 } 242 243 public HttpSession getSession(boolean b) { 244 return null; 245 } 246 247 public HttpSession getSession() { 248 return null; 249 } 250 251 public boolean isRequestedSessionIdValid() { 252 return false; 253 } 254 255 public boolean isRequestedSessionIdFromCookie() { 256 return false; 257 } 258 259 public boolean isRequestedSessionIdFromURL() { 260 return false; 261 } 262 263 public boolean isRequestedSessionIdFromUrl() { 264 return false; 265 } 266 267 public void addParameter(String paramName, String paramValue) { 268 ArrayList values = (ArrayList ) params.get(paramName); 269 if (values == null) { 270 values = new ArrayList (); 271 params.put(paramName, values); 272 } 273 values.add(paramValue); 274 } 275 276 public ArrayList removeParameter(String paramName) { 277 ArrayList values = (ArrayList ) params.remove(paramName); 278 return values; 279 } 280 281 public void setPathInfo(String info) { 282 pathInfo = info; 283 } 284 285 288 public void setLocale(Locale locale) { 289 this.locale = locale; 290 } 291 } 292 | Popular Tags |