Clover coverage report - Diasparsoft Toolkit - 0.22
Coverage timestamp: Mon Jun 7 2004 22:02:31 EDT
file stats: LOC: 80   Methods: 5
NCLOC: 47   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
HttpUtil.java 100% 57.9% 20% 57.1%
coverage coverage
 1   
 package com.diasparsoftware.javax.servlet.http;
 2   
 
 3   
 import java.util.*;
 4   
 
 5   
 import javax.servlet.RequestDispatcher;
 6   
 import javax.servlet.http.*;
 7   
 
 8   
 import org.apache.catalina.connector.HttpRequestBase;
 9   
 
 10   
 import com.diasparsoftware.java.util.*;
 11   
 
 12   
 public class HttpUtil {
 13   
     /**
 14   
      * Create an HttpServletRequest from the specified URI and request
 15   
      * parameters.
 16   
      * 
 17   
      * @param uri
 18   
      * @param parameters
 19   
      * @return
 20   
      */
 21  0
     public static HttpServletRequest makeRequestIgnoreSession(
 22   
         String uri,
 23   
         Map parameters) {
 24   
 
 25  0
         final HttpRequestBase httpServletRequest =
 26   
             new HttpRequestBase() {
 27   
 
 28  0
             public HttpSession getSession(boolean create) {
 29  0
                 return new FakeHttpSession(Collections.EMPTY_MAP);
 30   
             }
 31   
 
 32  0
             public RequestDispatcher getRequestDispatcher(String path) {
 33  0
                 return new RequestDispatcherAdapter();
 34   
             }
 35   
         };
 36   
 
 37  0
         httpServletRequest.setRequestURI(uri);
 38  0
         httpServletRequest.clearParameters();
 39   
 
 40  0
         CollectionUtil.forEachDo(parameters, new MapEntryClosure() {
 41  0
             public void eachMapEntry(Object key, Object value) {
 42  0
                 httpServletRequest.addParameter(
 43   
                     (String) key,
 44   
                     (String[]) value);
 45   
             }
 46   
         });
 47   
 
 48  0
         return httpServletRequest;
 49   
     }
 50   
 
 51   
     /**
 52   
      * Provides a human-readable string representation of an <code>HttpSession</code>.
 53   
      * 
 54   
      * @param session
 55   
      * @return For now, just the session attributes.
 56   
      */
 57  24
     public static String sessionToString(HttpSession session) {
 58  24
         StringBuffer buffer = new StringBuffer("HttpSession {");
 59  24
         boolean needComma = false;
 60   
 
 61  24
         for (Enumeration e = session.getAttributeNames();
 62  48
             e.hasMoreElements();
 63   
             ) {
 64   
 
 65  24
             String eachName = (String) e.nextElement();
 66  24
             Object eachValue = session.getAttribute(eachName);
 67   
 
 68  24
             if (needComma)
 69  8
                 buffer.append(",");
 70   
 
 71  24
             buffer.append(eachName).append("=").append(eachValue);
 72   
 
 73  24
             needComma = true;
 74   
         }
 75   
 
 76  24
         buffer.append("}");
 77  24
         return buffer.toString();
 78   
     }
 79   
 }
 80