1 37 package net.sourceforge.cruisecontrol.mock; 38 39 import java.io.IOException ; 40 import java.util.Enumeration ; 41 import java.util.HashMap ; 42 import javax.servlet.Servlet ; 43 import javax.servlet.ServletConfig ; 44 import javax.servlet.ServletContext ; 45 import javax.servlet.ServletException ; 46 import javax.servlet.ServletRequest ; 47 import javax.servlet.ServletResponse ; 48 import javax.servlet.http.HttpSession ; 49 import javax.servlet.jsp.JspWriter ; 50 import javax.servlet.jsp.PageContext ; 51 52 56 public class MockPageContext extends PageContext { 57 private MockServletRequest request = new MockServletRequest(); 58 private JspWriter out = new MockBodyContent(); 59 60 private HashMap [] scopes = { new HashMap (), new HashMap (), new HashMap (), new HashMap () }; 61 private MockServletContext servletContext = new MockServletContext(); 62 private MockServletConfig servletConfig = new MockServletConfig(); 63 64 public MockPageContext() { 65 servletConfig.setServletContext(servletContext); 66 } 67 68 public void initialize(Servlet servlet, ServletRequest servletRequest, ServletResponse servletResponse, 69 String errorPageURL, boolean needsSession, int bufferSize, boolean autoFlush) 70 throws IOException , IllegalStateException , IllegalArgumentException { 71 } 72 73 public void release() { 74 } 75 76 public void setAttribute(String name, Object attribute) { 77 setAttribute(name, attribute, PageContext.PAGE_SCOPE); 78 } 79 80 public void setAttribute(String name, Object attribute, int scope) { 81 scopeToMap(scope).put(name, attribute); 82 } 83 84 private HashMap scopeToMap(int scope) { 85 return scopes[scope - 1]; 86 } 87 88 public Object getAttribute(String name) { 89 return getAttribute(name, PageContext.PAGE_SCOPE); 90 } 91 92 public Object getAttribute(String name, int scope) { 93 return scopeToMap(scope).get(name); 94 } 95 96 public Object findAttribute(String name) { 97 return null; 98 } 99 100 public void removeAttribute(String name) { 101 removeAttribute(name, PageContext.PAGE_SCOPE); 102 } 103 104 public void removeAttribute(String name, int scope) { 105 } 106 107 public int getAttributesScope(String name) { 108 return 0; 109 } 110 111 public Enumeration getAttributeNamesInScope(int scope) { 112 return null; 113 } 114 115 public JspWriter getOut() { 116 return out; 117 } 118 119 public HttpSession getSession() { 120 return null; 121 } 122 123 public Object getPage() { 124 return null; 125 } 126 127 public ServletRequest getRequest() { 128 return request; 129 } 130 131 public ServletResponse getResponse() { 132 return null; 133 } 134 135 public Exception getException() { 136 return null; 137 } 138 139 public ServletConfig getServletConfig() { 140 return servletConfig; 141 } 142 143 public ServletContext getServletContext() { 144 return servletContext; 145 } 146 147 public void forward(String relativeUrlPath) throws ServletException , IOException { 148 } 149 150 public void include(String relativeUrlPath) throws ServletException , IOException { 151 } 152 153 public void handlePageException(Exception e) throws ServletException , IOException { 154 } 155 156 public void setHttpServletRequest(MockServletRequest mockRequest) { 157 request = mockRequest; 158 } 159 } 160 | Popular Tags |