1 package com.mockobjects.servlet; 2 3 import com.mockobjects.*; 4 5 import javax.servlet.ServletOutputStream ; 6 import javax.servlet.http.Cookie ; 7 import javax.servlet.http.HttpServletResponse ; 8 import java.io.IOException ; 9 import java.io.PrintWriter ; 10 import java.util.Locale ; 11 12 public class MockHttpServletResponse extends MockObject 13 implements HttpServletResponse { 14 15 private final ExpectationList myContentTypes = 16 new ExpectationList("MockHttpServletResponse.setContentType"); 17 private final ExpectationList myHeaders = 18 new ExpectationList("MockHttpServletResponse.setHeader"); 19 private final ExpectationCounter mySetStatusCalls = 20 new ExpectationCounter("MockHttpServletResponse.setStatus"); 21 private final ExpectationList myRedirects = 22 new ExpectationList("MockHttpServletResponse.sendRedirect"); 23 private MockServletOutputStream myOutputStream = 24 new MockServletOutputStream(); 25 private final ExpectationValue myErrorCode = 26 new ExpectationValue("MockHttpServletResponse.sendError"); 27 private final ExpectationValue myErrorMessage = 28 new ExpectationValue("MockHttpServletResponse.sendError"); 29 private final ExpectationValue length = new ExpectationValue("MockHttpServletResponse.length"); 30 31 34 public void addCookie(Cookie arg1) { 35 notImplemented(); 36 } 37 38 41 public void addDateHeader(String arg1, long arg2) { 42 notImplemented(); 43 } 44 45 48 public void addHeader(String arg1, String arg2) { 49 notImplemented(); 50 } 51 52 55 public void addIntHeader(String arg1, int arg2) { 56 notImplemented(); 57 } 58 59 62 public boolean containsHeader(String arg1) { 63 notImplemented(); 64 return false; 65 } 66 67 70 public String encodeRedirectUrl(String arg1) { 71 notImplemented(); 72 return null; 73 } 74 75 78 public String encodeRedirectURL(String arg1) { 79 notImplemented(); 80 return null; 81 } 82 83 86 public String encodeUrl(String arg1) { 87 notImplemented(); 88 return null; 89 } 90 91 94 public String encodeURL(String arg1) { 95 notImplemented(); 96 return null; 97 } 98 99 102 public void flushBuffer() throws java.io.IOException { 103 notImplemented(); 104 } 105 106 109 public int getBufferSize() { 110 notImplemented(); 111 return 0; 112 } 113 114 117 public String getCharacterEncoding() { 118 notImplemented(); 119 return null; 120 } 121 122 125 public Locale getLocale() { 126 notImplemented(); 127 return null; 128 } 129 130 public ServletOutputStream getOutputStream() 131 throws IOException { 132 return myOutputStream; 133 } 134 135 public String getOutputStreamContents() { 136 return myOutputStream.getContents(); 137 } 138 139 public PrintWriter getWriter() throws IOException { 140 return new PrintWriter (myOutputStream, true); 141 } 142 143 146 public boolean isCommitted() { 147 notImplemented(); 148 return false; 149 } 150 151 154 public void reset() { 155 notImplemented(); 156 } 157 158 161 public void resetBuffer() { 162 notImplemented(); 163 } 164 165 public void setExpectedError(int anErrorCode) { 166 myErrorCode.setExpected(anErrorCode); 167 } 168 169 public void setExpectedError(int anErrorCode, String anErrorMessage) { 170 setExpectedError(anErrorCode); 171 myErrorMessage.setExpected(anErrorMessage); 172 } 173 174 public void setExpectedErrorNothing() { 175 myErrorCode.setExpectNothing(); 176 myErrorMessage.setExpectNothing(); 177 } 178 179 public void sendError(int anErrorCode) throws java.io.IOException { 180 myErrorCode.setActual(anErrorCode); 181 } 182 183 public void sendError(int anErrorCode, String anErrorMessage) 184 throws IOException { 185 sendError(anErrorCode); 186 myErrorMessage.setActual(anErrorMessage); 187 } 188 189 public void sendRedirect(String aURL) throws java.io.IOException { 190 myRedirects.addActual(aURL); 191 } 192 193 196 public void setBufferSize(int arg1) { 197 notImplemented(); 198 } 199 200 public void setContentLength(int length) { 201 this.length.setActual(length); 202 } 203 204 public void setExpectedContentLength(int length){ 205 this.length.setExpected(length); 206 } 207 208 public void setContentType(String contentType) { 209 myContentTypes.addActual(contentType); 210 } 211 212 215 public void setDateHeader(String arg1, long arg2) { 216 notImplemented(); 217 } 218 219 public void setExpectedContentType(String contentType) { 220 myContentTypes.addExpected(contentType); 221 } 222 223 public void setExpectedHeader(String key, String value) { 224 myHeaders.addExpected(new MapEntry(key, value)); 225 } 226 227 public void setExpectedRedirect(String aURL) throws IOException { 228 myRedirects.addExpected(aURL); 229 } 230 231 public void setExpectedSetStatusCalls(int callCount) { 232 mySetStatusCalls.setExpected(callCount); 233 } 234 235 public void setHeader(String key, String value) { 236 myHeaders.addActual(new MapEntry(key, value)); 237 } 238 239 242 public void setIntHeader(String arg1, int arg2) { 243 notImplemented(); 244 } 245 246 249 public void setLocale(Locale arg1) { 250 notImplemented(); 251 } 252 253 public void setStatus(int status) { 254 mySetStatusCalls.inc(); 255 } 256 257 260 public void setStatus(int arg1, String arg2) { 261 notImplemented(); 262 } 263 264 public void setupOutputStream(MockServletOutputStream anOutputStream) { 265 myOutputStream = anOutputStream; 266 } 267 } 268 | Popular Tags |