Clover coverage report - Code Coverage for tapestry release 4.0-beta-2
Coverage timestamp: Sat Jul 9 2005 22:02:17 EDT
file stats: LOC: 443   Methods: 63
NCLOC: 310   Classes: 1
30 day Evaluation License registered to hlship@comcast.net Your 30 day evaluation period has expired. Please visit http://www.cenqua.com to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
MockRequest.java 50% 57.1% 55.6% 55.8%
coverage coverage
 1    // Copyright 2004, 2005 The Apache Software Foundation
 2    //
 3    // Licensed under the Apache License, Version 2.0 (the "License");
 4    // you may not use this file except in compliance with the License.
 5    // You may obtain a copy of the License at
 6    //
 7    // http://www.apache.org/licenses/LICENSE-2.0
 8    //
 9    // Unless required by applicable law or agreed to in writing, software
 10    // distributed under the License is distributed on an "AS IS" BASIS,
 11    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12    // See the License for the specific language governing permissions and
 13    // limitations under the License.
 14   
 15    package org.apache.tapestry.test.mock;
 16   
 17    import java.io.BufferedReader;
 18    import java.io.IOException;
 19    import java.io.UnsupportedEncodingException;
 20    import java.security.Principal;
 21    import java.util.ArrayList;
 22    import java.util.Arrays;
 23    import java.util.Collections;
 24    import java.util.Enumeration;
 25    import java.util.HashMap;
 26    import java.util.List;
 27    import java.util.Locale;
 28    import java.util.Map;
 29   
 30    import javax.servlet.RequestDispatcher;
 31    import javax.servlet.ServletInputStream;
 32    import javax.servlet.http.Cookie;
 33    import javax.servlet.http.HttpServletRequest;
 34    import javax.servlet.http.HttpSession;
 35   
 36    /**
 37    * Mock implementation of {@link javax.servlet.http.HttpServletRequest}.
 38    *
 39    *
 40    * @author Howard Lewis Ship
 41    * @since 4.0
 42    */
 43   
 44    public class MockRequest extends AttributeHolder implements HttpServletRequest
 45    {
 46    /**
 47    * HTTP content type header name.
 48    */
 49    private static final String CONTENT_TYPE_HEADER_KEY = "Content-type";
 50    /**
 51    * Map of String[].
 52    *
 53    */
 54   
 55    private Map _parameters = new HashMap();
 56   
 57    /**
 58    * Map of String[]
 59    *
 60    */
 61   
 62    private Map _headers = new HashMap();
 63   
 64    private String _method = "GET";
 65   
 66    private String _contextPath;
 67   
 68    private MockContext _servletContext;
 69    private MockSession _session;
 70    private String _servletPath;
 71    private List _cookies = new ArrayList();
 72    private String _contentPath;
 73   
 74    /**
 75    * This can be stored within the header, but doing it this way emulates a browser that
 76    * does not put the encoding in the request, which appears to be the general case.
 77    */
 78    private String _encoding = null;
 79   
 80  143 public MockRequest(MockContext servletContext, String servletPath)
 81    {
 82  143 _servletContext = servletContext;
 83   
 84  143 _contextPath = "/" + servletContext.getServletContextName();
 85  143 _servletPath = servletPath;
 86   
 87  143 _session = _servletContext.getSession();
 88    }
 89   
 90  21 public String getAuthType()
 91    {
 92  21 return null;
 93    }
 94   
 95  244 public Cookie[] getCookies()
 96    {
 97  244 return (Cookie[]) _cookies.toArray(new Cookie[_cookies.size()]);
 98    }
 99   
 100  0 public long getDateHeader(String arg0)
 101    {
 102  0 return 0;
 103    }
 104   
 105  159 public String getHeader(String key)
 106    {
 107  159 String getHeader = null;
 108   
 109  159 if (key != null)
 110    {
 111  159 getHeader = (String) _headers.get(key.toLowerCase());
 112    }
 113  159 return getHeader;
 114    }
 115   
 116  0 public Enumeration getHeaders(String name)
 117    {
 118  0 String[] headers = (String[]) _headers.get(name);
 119   
 120  0 if (headers == null)
 121  0 return Collections.enumeration(Collections.EMPTY_LIST);
 122   
 123  0 return Collections.enumeration(Arrays.asList(headers));
 124    }
 125   
 126  21 public Enumeration getHeaderNames()
 127    {
 128  21 return getEnumeration(_headers);
 129    }
 130   
 131  0 public int getIntHeader(String arg0)
 132    {
 133  0 return 0;
 134    }
 135   
 136  153 public String getMethod()
 137    {
 138  153 return _method;
 139    }
 140   
 141  153 public String getPathInfo()
 142    {
 143  153 return null;
 144    }
 145   
 146  21 public String getPathTranslated()
 147    {
 148  21 return null;
 149    }
 150   
 151  192 public String getContextPath()
 152    {
 153  192 return _contextPath;
 154    }
 155   
 156  21 public String getQueryString()
 157    {
 158  21 return null;
 159    }
 160   
 161  0 public String getRemoteUser()
 162    {
 163  0 return null;
 164    }
 165   
 166  0 public boolean isUserInRole(String arg0)
 167    {
 168  0 return false;
 169    }
 170   
 171  21 public Principal getUserPrincipal()
 172    {
 173  21 return null;
 174    }
 175   
 176  0 public String getRequestedSessionId()
 177    {
 178  0 return null;
 179    }
 180   
 181  153 public String getRequestURI()
 182    {
 183  153 return null;
 184    }
 185   
 186  0 public StringBuffer getRequestURL()
 187    {
 188  0 return null;
 189    }
 190   
 191  153 public String getServletPath()
 192    {
 193  153 return _servletPath;
 194    }
 195   
 196  270 public HttpSession getSession(boolean create)
 197    {
 198  270 if (create && _session == null)
 199  10 _session = _servletContext.createSession();
 200   
 201  270 return _session;
 202    }
 203   
 204  2 public HttpSession getSession()
 205    {
 206  2 return _session;
 207    }
 208   
 209  0 public boolean isRequestedSessionIdValid()
 210    {
 211  0 return false;
 212    }
 213   
 214  0 public boolean isRequestedSessionIdFromCookie()
 215    {
 216  0 return false;
 217    }
 218   
 219  0 public boolean isRequestedSessionIdFromURL()
 220    {
 221  0 return false;
 222    }
 223   
 224  0 public boolean isRequestedSessionIdFromUrl()
 225    {
 226  0 return false;
 227    }
 228   
 229  301 public String getCharacterEncoding()
 230    {
 231  301 return _encoding;
 232    }
 233   
 234  132 public void setCharacterEncoding(String arg0) throws UnsupportedEncodingException
 235    {
 236  132 _encoding = arg0;
 237    }
 238   
 239  26 public int getContentLength()
 240    {
 241  26 return 0;
 242    }
 243   
 244  153 public String getContentType()
 245    {
 246  153 return getHeader(CONTENT_TYPE_HEADER_KEY);
 247    }
 248   
 249  5 public void setContentType(String contentType)
 250    {
 251  5 setHeader(CONTENT_TYPE_HEADER_KEY, contentType);
 252    }
 253   
 254  5 public ServletInputStream getInputStream() throws IOException
 255    {
 256  5 if (_contentPath == null)
 257  0 return null;
 258   
 259  5 return new MockServletInputStream(_contentPath);
 260    }
 261   
 262  0 public String getParameter(String name)
 263    {
 264  0 String[] values = getParameterValues(name);
 265   
 266  0 if (values == null || values.length == 0)
 267  0 return null;
 268   
 269  0 return values[0];
 270    }
 271   
 272  400 public Enumeration getParameterNames()
 273    {
 274  400 return Collections.enumeration(_parameters.keySet());
 275    }
 276   
 277  392 public String[] getParameterValues(String name)
 278    {
 279  392 return (String[]) _parameters.get(name);
 280    }
 281   
 282    /**
 283    * Not part of 2.1 API, not used by Tapestry.
 284    *
 285    */
 286   
 287  0 public Map getParameterMap()
 288    {
 289  0 return null;
 290    }
 291   
 292  21 public String getProtocol()
 293    {
 294  21 return null;
 295    }
 296   
 297  140 public String getScheme()
 298    {
 299  140 return "http";
 300    }
 301   
 302  140 public String getServerName()
 303    {
 304  140 return "junit-test";
 305    }
 306   
 307  140 public int getServerPort()
 308    {
 309  140 return 80;
 310    }
 311   
 312  0 public BufferedReader getReader() throws IOException
 313    {
 314  0 return null;
 315    }
 316   
 317  0 public String getRemoteAddr()
 318    {
 319  0 return null;
 320    }
 321   
 322  0 public String getRemoteHost()
 323    {
 324  0 return null;
 325    }
 326   
 327    private Locale _locale = Locale.ENGLISH;
 328   
 329  144 public Locale getLocale()
 330    {
 331  144 return _locale;
 332    }
 333   
 334  2 public void setLocale(Locale locale)
 335    {
 336  2 _locale = locale;
 337    }
 338   
 339  0 public Enumeration getLocales()
 340    {
 341  0 return Collections.enumeration(Collections.singleton(_locale));
 342    }
 343   
 344  21 public boolean isSecure()
 345    {
 346  21 return false;
 347    }
 348   
 349  0 public RequestDispatcher getRequestDispatcher(String path)
 350    {
 351  0 return _servletContext.getRequestDispatcher(path);
 352    }
 353   
 354  0 public String getRealPath(String arg0)
 355    {
 356  0 return null;
 357    }
 358   
 359  0 public void setContextPath(String contextPath)
 360    {
 361  0 _contextPath = contextPath;
 362    }
 363   
 364  0 public void setMethod(String method)
 365    {
 366  0 _method = method;
 367    }
 368   
 369  343 public void setParameter(String name, String[] values)
 370    {
 371  343 _parameters.put(name, values);
 372    }
 373   
 374  0 public void setParameter(String name, String value)
 375    {
 376  0 setParameter(name, new String[] { value });
 377    }
 378   
 379  31 public void addCookie(Cookie cookie)
 380    {
 381  31 _cookies.add(cookie);
 382    }
 383   
 384  223 public void addCookies(Cookie[] cookies)
 385    {
 386  223 if (cookies == null)
 387  41 return;
 388   
 389  182 for (int i = 0; i < cookies.length; i++)
 390  31 addCookie(cookies[i]);
 391    }
 392   
 393  5 private void setHeader(String key, String value)
 394    {
 395  5 if (key != null)
 396    {
 397  5 _headers.put(key.toLowerCase(), value);
 398    }
 399    }
 400   
 401    /**
 402    * Delegates this to the {@link org.apache.tapestry.junit.mock.MockSession}, if
 403    * it exists.
 404    *
 405    */
 406   
 407  0 public void simulateFailover()
 408    {
 409  0 if (_session != null)
 410  0 _session.simulateFailover();
 411    }
 412   
 413  0 public String getContentPath()
 414    {
 415  0 return _contentPath;
 416    }
 417   
 418  5 public void setContentPath(String contentPath)
 419    {
 420  5 _contentPath = contentPath;
 421    }
 422   
 423  0 public int getRemotePort()
 424    {
 425  0 return 0;
 426    }
 427   
 428  0 public String getLocalName()
 429    {
 430  0 return null;
 431    }
 432   
 433  0 public String getLocalAddr()
 434    {
 435  0 return null;
 436    }
 437   
 438  0 public int getLocalPort()
 439    {
 440  0 return 0;
 441    }
 442   
 443    }