From: Steve F. <sm...@us...> - 2002-02-22 16:25:08
|
Update of /cvsroot/mockobjects/mockobjects-java/src/j2ee/common/com/mockobjects/servlet In directory usw-pr-cvs1:/tmp/cvs-serv13797/com/mockobjects/servlet Added Files: MockHttpServletRequest.java MockHttpServletResponse.java MockHttpSession.java MockRequestDispatcher.java MockServletOutputStream.java Log Message: Setup files common to all j2ee versions --- NEW FILE: MockHttpServletRequest.java --- package com.mockobjects.servlet; import java.util.*; import javax.servlet.http.*; import com.mockobjects.*; public class MockHttpServletRequest implements HttpServletRequest { private Dictionary myParameters = new Hashtable(); private String myPathInfo; public MockHttpServletRequest() { super(); } /** * @deprecated */ public void addActualParameter(String paramName, String[] values) { setupAddParameter(paramName, values); } /** * @deprecated */ public void addActualParameter(String paramName, String value) { setupAddParameter(paramName, value); } /** * getAttribute method comment. */ public Object getAttribute(String arg1) { return null; } /** * getAttributeNames method comment. */ public java.util.Enumeration getAttributeNames() { return null; } /** * getAuthType method comment. */ public String getAuthType() { return null; } /** * getCharacterEncoding method comment. */ public String getCharacterEncoding() { return null; } /** * getContentLength method comment. */ public int getContentLength() { return 0; } /** * getContentType method comment. */ public String getContentType() { return null; } /** * getContextPath method comment. */ public java.lang.String getContextPath() { return null; } /** * getCookies method comment. */ public javax.servlet.http.Cookie[] getCookies() { return null; } /** * getDateHeader method comment. */ public long getDateHeader(String arg1) { return 0; } /** * getHeader method comment. */ public String getHeader(String arg1) { return null; } /** * getHeaderNames method comment. */ public java.util.Enumeration getHeaderNames() { return null; } /** * getHeaders method comment. */ public java.util.Enumeration getHeaders(java.lang.String arg1) { return null; } /** * getInputStream method comment. */ public javax.servlet.ServletInputStream getInputStream() throws java.io.IOException { return null; } /** * getIntHeader method comment. */ public int getIntHeader(String arg1) { return 0; } /** * getLocale method comment. */ public java.util.Locale getLocale() { return null; } /** * getLocales method comment. */ public java.util.Enumeration getLocales() { return null; } /** * getMethod method comment. */ public String getMethod() { return null; } public String getParameter(String paramName) { String[] values = getParameterValues(paramName); return (values == null ? null : values[0]); } public java.util.Enumeration getParameterNames() { return myParameters.keys(); } public String[] getParameterValues(String key) { return (String[]) myParameters.get(key); } public String getPathInfo() { return myPathInfo; } /** * getPathTranslated method comment. */ public String getPathTranslated() { return null; } /** * getProtocol method comment. */ public String getProtocol() { return null; } /** * getQueryString method comment. */ public String getQueryString() { return null; } /** * getReader method comment. */ public java.io.BufferedReader getReader() throws java.io.IOException { return null; } /** * getRealPath method comment. */ public String getRealPath(String arg1) { return null; } /** * getRemoteAddr method comment. */ public String getRemoteAddr() { return null; } /** * getRemoteHost method comment. */ public String getRemoteHost() { return null; } /** * getRemoteUser method comment. */ public String getRemoteUser() { return null; } /** * getRequestDispatcher method comment. */ public javax.servlet.RequestDispatcher getRequestDispatcher( java.lang.String arg1) { return null; } /** * getRequestedSessionId method comment. */ public String getRequestedSessionId() { return null; } /** * getRequestURI method comment. */ public String getRequestURI() { return null; } /** * getScheme method comment. */ public String getScheme() { return null; } /** * getServerName method comment. */ public String getServerName() { return null; } /** * getServerPort method comment. */ public int getServerPort() { return 0; } /** * getServletPath method comment. */ public String getServletPath() { return null; } /** * getSession method comment. */ public javax.servlet.http.HttpSession getSession() { return null; } /** * getSession method comment. */ public javax.servlet.http.HttpSession getSession(boolean arg1) { return null; } /** * getUserPrincipal method comment. */ public java.security.Principal getUserPrincipal() { return null; } /** * isRequestedSessionIdFromCookie method comment. */ public boolean isRequestedSessionIdFromCookie() { return false; } /** * isRequestedSessionIdFromUrl method comment. */ public boolean isRequestedSessionIdFromUrl() { return false; } /** * isRequestedSessionIdFromURL method comment. */ public boolean isRequestedSessionIdFromURL() { return false; } /** * isRequestedSessionIdValid method comment. */ public boolean isRequestedSessionIdValid() { return false; } /** * isSecure method comment. */ public boolean isSecure() { return false; } /** * isUserInRole method comment. */ public boolean isUserInRole(java.lang.String arg1) { return false; } /** * removeAttribute method comment. */ public void removeAttribute(java.lang.String arg1) { } /** * setAttribute method comment. */ public void setAttribute(String arg1, Object arg2) { } /** * @deprecated */ public void setNoActualParameters() { setupNoParameters(); } public void setupAddParameter(String paramName, String[] values) { myParameters.put(paramName, values); } public void setupAddParameter(String paramName, String value) { setupAddParameter(paramName, new String[] { value }); } public void setupNoParameters() { myParameters = new Hashtable(); } public void setupPathInfo(String pathInfo) { myPathInfo = pathInfo; } } --- NEW FILE: MockHttpServletResponse.java --- package com.mockobjects.servlet; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import junit.framework.Assert; import com.mockobjects.*; public class MockHttpServletResponse extends MockObject implements HttpServletResponse, Verifiable { private ExpectationList myContentTypes = new ExpectationList("MockHttpServletResponse.setContentType"); private ExpectationList myHeaders = new ExpectationList("MockHttpServletResponse.setHeader"); private ExpectationCounter mySetStatusCalls = new ExpectationCounter("MockHttpServletResponse.setStatus"); private ExpectationList myRedirects = new ExpectationList("MockHttpServletResponse.sendRedirect"); private ServletOutputStream myOutputStream = new MockServletOutputStream(); /** * MockHttpServletResponse constructor comment. */ public MockHttpServletResponse() { super(); } public void addCookie(javax.servlet.http.Cookie arg1) { fail("Not implemented"); } /** * addDateHeader method comment. */ public void addDateHeader(java.lang.String arg1, long arg2) { } /** * addHeader method comment. */ public void addHeader(java.lang.String arg1, java.lang.String arg2) { } /** * addIntHeader method comment. */ public void addIntHeader(java.lang.String arg1, int arg2) { } public boolean containsHeader(String arg1) { fail("Not implemented"); return false; } public String encodeRedirectUrl(String arg1) { fail("Not implemented"); return null; } public String encodeRedirectURL(String arg1) { fail("Not implemented"); return null; } public String encodeUrl(String arg1) { fail("Not implemented"); return null; } public String encodeURL(String arg1) { fail("Not implemented"); return null; } /** * flushBuffer method comment. */ public void flushBuffer() throws java.io.IOException { } /** * getBufferSize method comment. */ public int getBufferSize() { return 0; } public String getCharacterEncoding() { fail("Not implemented"); return null; } /** * getLocale method comment. */ public java.util.Locale getLocale() { return null; } public javax.servlet.ServletOutputStream getOutputStream() throws java.io.IOException { return myOutputStream; } public String getOutputStreamContents() { return ((MockServletOutputStream) myOutputStream).getContents(); } public java.io.PrintWriter getWriter() throws java.io.IOException { return new PrintWriter(myOutputStream, true); } /** * isCommitted method comment. */ public boolean isCommitted() { return false; } /** * reset method comment. */ public void reset() { } public void sendError(int arg1) throws java.io.IOException { fail("Not implemented"); } public void sendError(int arg1, String arg2) throws java.io.IOException { fail("Not implemented"); } public void sendRedirect(String aURL) throws java.io.IOException { myRedirects.addActual(aURL); } /** * setBufferSize method comment. */ public void setBufferSize(int arg1) { } public void setContentLength(int arg1) { fail("Not implemented"); } public void setContentType(String contentType) { myContentTypes.addActual(contentType); } public void setDateHeader(String arg1, long arg2) { fail("Not implemented"); } public void setExpectedContentType(String contentType) { myContentTypes.addExpected(contentType); } public void setExpectedHeader(String key, String value) { myHeaders.addExpected(new MapEntry(key, value)); } public void setExpectedRedirect(String aURL) throws IOException { myRedirects.addExpected(aURL); } public void setExpectedSetStatusCalls(int callCount) { mySetStatusCalls.setExpected(callCount); } public void setHeader(String key, String value) { myHeaders.addActual(new MapEntry(key, value)); } public void setIntHeader(String arg1, int arg2) { Assert.fail("Not implemented"); } /** * setLocale method comment. */ public void setLocale(java.util.Locale arg1) { } public void setStatus(int status) { mySetStatusCalls.inc(); } public void setStatus(int arg1, String arg2) { Assert.fail("Not implemented"); } public void setupOutputStream(ServletOutputStream anOutputStream) { myOutputStream = anOutputStream; } } --- NEW FILE: MockHttpSession.java --- package com.mockobjects.servlet; import java.util.*; import javax.servlet.http.HttpSessionContext; import javax.servlet.http.HttpSession; import com.mockobjects.*; public class MockHttpSession extends MockObject implements HttpSession, Verifiable { public ExpectationSet myAttributes = new ExpectationSet("session attributes"); public MockHttpSession() { super(); } public Object getAttribute(String arg1) { notImplemented(); return null; } public Enumeration getAttributeNames() { return null; } public long getCreationTime() { notImplemented(); return 0; } public String getId() { notImplemented(); return null; } public long getLastAccessedTime() { notImplemented(); return 0; } public int getMaxInactiveInterval() { return 0; } public HttpSessionContext getSessionContext() { return null; } public Object getValue(String arg1) { notImplemented(); return null; } public java.lang.String[] getValueNames() { notImplemented(); return null; } public void invalidate() { } public boolean isNew() { return false; } public void putValue(String arg1, Object arg2) { } public void removeAttribute(String arg1) { } public void removeValue(String arg1) { } public void setAttribute(String aKey, Object aValue) { myAttributes.addActual(new MapEntry(aKey, aValue)); } public void setExpectedAttribute(String aKey, Object aValue) { myAttributes.addExpected(new MapEntry(aKey, aValue)); } public void setMaxInactiveInterval(int arg1) { } public void verify() { myAttributes.verify(); } } --- NEW FILE: MockRequestDispatcher.java --- package com.mockobjects.servlet; import java.io.IOException; import javax.servlet.*; public class MockRequestDispatcher implements RequestDispatcher { /** * MockRequestDispatcher constructor comment. */ public MockRequestDispatcher() { super(); } public void forward(ServletRequest arg1, ServletResponse arg2) throws ServletException, IOException { } public void include(ServletRequest arg1, ServletResponse arg2) throws ServletException, IOException { } } --- NEW FILE: MockServletOutputStream.java --- package com.mockobjects.servlet; import java.io.ByteArrayOutputStream; import java.io.IOException; import javax.servlet.ServletOutputStream; import com.mockobjects.ExpectationCounter; import com.mockobjects.ExpectationValue; public class MockServletOutputStream extends ServletOutputStream { private ExpectationValue myWriteCalled = new ExpectationValue("MockServletOutputStream.write()"); private boolean myThrowException = false; private ExpectationCounter myCloseCallCount = new ExpectationCounter("MockServletOutputstream.close()"); private ByteArrayOutputStream myBuffer; public MockServletOutputStream() { super(); setupClearContents(); } public void setExpectedCloseCalls(int closeCall) { myCloseCallCount.setExpected(closeCall); } public void setExpectingWriteCalls(boolean expectingWriteCall) { myWriteCalled.setExpected(expectingWriteCall); } public void setThrowIOException(boolean throwException) { myThrowException = throwException; } public void close() throws IOException { myCloseCallCount.inc(); } public String toString() { return getContents(); } public void write(int b) throws IOException { myWriteCalled.setActual(true); if (myThrowException) throw new IOException("Test IOException generated by request"); myBuffer.write(b); } public void setupClearContents () { myBuffer = new ByteArrayOutputStream(); } public String getContents() { return myBuffer.toString(); } public void verify() { myWriteCalled.verify(); myCloseCallCount.verify(); } } |