Clover coverage report - angkor - 0.4
Coverage timestamp: ti okt 15 2002 22:32:48 CEST
file stats: LOC: 139   Methods: 19
NCLOC: 104   Classes: 1
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
MockRenderContext.java 0% 81,5% 78,9% 77,1%
 1   
 /*
 2   
  * Angkor Web Framework
 3   
  *
 4   
  * Distributable under LGPL license.
 5   
  * See terms of license at gnu.org.
 6   
  */
 7   
 
 8   
 package com.tirsen.angkor.test.unit.mock;
 9   
 
 10   
 import com.tirsen.angkor.*;
 11   
 import com.tirsen.angkor.test.unit.mock.MockServletRequest;
 12   
 import com.tirsen.angkor.test.unit.mock.MockServletResponse;
 13   
 import com.tirsen.angkor.test.unit.MockApplication;
 14   
 
 15   
 import java.io.*;
 16   
 import java.util.Map;
 17   
 import java.util.HashMap;
 18   
 
 19   
 import org.w3c.dom.Document;
 20   
 import org.w3c.tidy.Tidy;
 21   
 
 22   
 import javax.servlet.ServletException;
 23   
 
 24   
 /**
 25   
  * Mock object for the render context.
 26   
  */
 27   
 public class MockRenderContext extends RenderContext
 28   
 {
 29   
     private ByteArrayOutputStream bytes;
 30   
     private PrintStream output;
 31   
     private Map session = new HashMap();
 32   
     private Map requestParams = new HashMap();
 33   
     private Map requestAttribs = new HashMap();
 34   
     private Application application = new MockApplication();
 35   
 
 36  17
     public MockRenderContext()
 37   
     {
 38  17
         super(new MockServletRequest(), new MockServletResponse());
 39  17
         resetStreams();
 40   
     }
 41   
 
 42  65
     public Application getApplication()
 43   
     {
 44  65
         return application;
 45   
     }
 46   
 
 47  24
     private void resetStreams()
 48   
     {
 49  24
         bytes = new ByteArrayOutputStream();
 50  24
         output = new PrintStream(bytes);
 51   
     }
 52   
 
 53  10
     public void setApplication(Application application)
 54   
     {
 55  10
         this.application = application;
 56   
     }
 57   
 
 58  3
     protected void setSessionAttribute(String attribute, Object value)
 59   
     {
 60  3
         session.put(attribute, value);
 61   
     }
 62   
 
 63  3
     protected Object getSessionAttribute(String attribute)
 64   
     {
 65  3
         return session.get(attribute);
 66   
     }
 67   
 
 68  70
     public void println(String line) throws IOException
 69   
     {
 70  70
         System.out.println(line);
 71  70
         output.println(line);
 72   
     }
 73   
 
 74  5
     public InputStream getRenderedInputStream()
 75   
     {
 76  5
         return new ByteArrayInputStream(bytes.toByteArray());
 77   
     }
 78   
 
 79  3
     public Document parseRenderedHTML()
 80   
     {
 81  3
         Tidy tidy = new Tidy();
 82  3
         Document doc = tidy.parseDOM(getRenderedInputStream(), System.out);
 83  3
         return doc;
 84   
     }
 85   
 
 86  1
     public boolean isRegisteredForParsing(View view)
 87   
     {
 88  1
         return getApplication().getParsingComponents().contains(view);
 89   
     }
 90   
 
 91  18
     public String getRequestParameter(String name)
 92   
     {
 93  18
         return (String) requestParams.get(name);
 94   
     }
 95   
 
 96  8
     public void setRequestParameter(String name, String value)
 97   
     {
 98  8
         requestParams.put(name, value);
 99   
     }
 100   
 
 101  0
     protected Object getRequestAttribute(String name)
 102   
     {
 103  0
         return requestAttribs.get(name);
 104   
     }
 105   
 
 106  0
     protected void setRequestAttribute(String name, Object value)
 107   
     {
 108  0
         requestAttribs.put(name, value);
 109   
     }
 110   
 
 111  0
     public void indent() throws IOException
 112   
     {
 113  0
         for(int j = 0; j < indent; j++)
 114  0
             output.print("\t");
 115   
     }
 116   
 
 117  0
     protected boolean isFirstRequest()
 118   
     {
 119  0
         return false;
 120   
     }
 121   
 
 122  2
     public String getRequestPath()
 123   
     {
 124  2
         return "mock/request/path";
 125   
     }
 126   
 
 127  2
     public String encodeURL(String url)
 128   
     {
 129  2
         return url;
 130   
     }
 131   
 
 132  7
     public void afterRequest() throws IOException, ServletException
 133   
     {
 134  7
         super.afterRequest();
 135  7
         ((MockServletResponse) getResponse()).resetStreams();
 136  7
         resetStreams();
 137   
     }
 138   
 }
 139