From: Dave G. <dg...@hy...> - 2003-01-31 16:17:47
|
Here are a few patches for both MockHttpServletResponse and MockHttpServletRequest in src/j2ee/1.3/com/mockobjects/servlet/ The first patch adds support for addCookie() to MockHttpServletResponse: ----------- Index: src/j2ee/1.3/com/mockobjects/servlet/MockHttpServletResponse.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/1.3/com/mockobjects/servlet/MockHttpServletResponse.java,v retrieving revision 1.2 diff -u -3 -p -r1.2 MockHttpServletResponse.java --- src/j2ee/1.3/com/mockobjects/servlet/MockHttpServletResponse.java 20 Nov 2002 19:08:58 -0000 1.2 +++ src/j2ee/1.3/com/mockobjects/servlet/MockHttpServletResponse.java 31 Jan 2003 16:13:12 -0000 @@ -14,6 +14,8 @@ public class MockHttpServletResponse ext private final ExpectationList myContentTypes = new ExpectationList("MockHttpServletResponse.setContentType"); + private ExpectationList myCookies = + new ExpectationList("MockHttpServletResponse.addCookie"); private final ExpectationList myHeaders = new ExpectationList("MockHttpServletResponse.setHeader"); private final ExpectationCounter mySetStatusCalls = @@ -32,7 +34,7 @@ public class MockHttpServletResponse ext * Not Implemented */ public void addCookie(Cookie arg1) { - notImplemented(); + myCookies.addActual(arg1); } /** @@ -47,6 +49,10 @@ public class MockHttpServletResponse ext */ public void addHeader(String arg1, String arg2) { notImplemented(); + } + + public void addExpectedCookie(javax.servlet.http.Cookie cookie) { + myCookies.addExpected(cookie); } /** ----------- I broke up the MockHttpServletRequest patch into 4 parts to make it easier to see which bits go together. The first patch is a simple typo fix: ----------- Index: src/j2ee/1.3/com/mockobjects/servlet/MockHttpServletRequest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/1.3/com/mockobjects/servlet/MockHttpServletRequest.java,v retrieving revision 1.12 diff -u -3 -p -r1.12 MockHttpServletRequest.java --- src/j2ee/1.3/com/mockobjects/servlet/MockHttpServletRequest.java 23 Jan 2003 11:43:00 -0000 1.12 +++ src/j2ee/1.3/com/mockobjects/servlet/MockHttpServletRequest.java 31 Jan 2003 15:55:43 -0000 @@ -57,7 +57,7 @@ public class MockHttpServletRequest exte return myAttributesToReturn.nextReturnObject(); } - public void setupGetAttrubuteNames(Vector attributeNames){ + public void setupGetAttributeNames(Vector attributeNames){ myAttributesNames = attributeNames; } ----------- Second, implementations of getAuthType(), getRemoteHost() and getRemoteUser(): ----------- Index: src/j2ee/1.3/com/mockobjects/servlet/MockHttpServletRequest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/1.3/com/mockobjects/servlet/MockHttpServletRequest.java,v retrieving revision 1.12 diff -u -3 -p -r1.12 MockHttpServletRequest.java --- src/j2ee/1.3/com/mockobjects/servlet/MockHttpServletRequest.java 23 Jan 2003 11:43:00 -0000 1.12 +++ src/j2ee/1.3/com/mockobjects/servlet/MockHttpServletRequest.java 31 Jan 2003 15:57:56 -0000 @@ -27,6 +27,9 @@ public class MockHttpServletRequest exte private String myContextPath; private String myPathInfo; private String myRemoteAddress; + private final ReturnValue myAuthType = new ReturnValue("authentication type"); + private final ReturnValue myRemoteHost = new ReturnValue("remote host"); + private final ReturnValue myRemoteUser = new ReturnValue("remote user"); private final ReturnValue myRequestURI = new ReturnValue("request URI"); private final ReturnValue method = new ReturnValue("method"); private final ReturnValue protocol = new ReturnValue("protocol"); @@ -65,9 +68,12 @@ public class MockHttpServletRequest exte return myAttributesNames.elements(); } + public void setupGetAuthType(String authType) { + myAuthType.setValue(authType); + } + public String getAuthType() { - notImplemented(); - return null; + return (String)myAuthType.getValue(); } public String getCharacterEncoding() { @@ -212,14 +218,20 @@ public class MockHttpServletRequest exte return myRemoteAddress; } + public void setupGetRemoteHost(String remoteHost) { + myRemoteHost.setValue(remoteHost); + } + public String getRemoteHost() { - notImplemented(); - return null; + return (String)myRemoteHost.getValue(); + } + + public void setupGetRemoteUser(String remoteUser) { + myRemoteUser.setValue(remoteUser); } public String getRemoteUser() { - notImplemented(); - return null; + return (String)myRemoteUser.getValue(); } public RequestDispatcher getRequestDispatcher( ----------- Third is an implementation of getHeaderNames(). I *think* this is right, but I'm not totally sure: ----------- Index: src/j2ee/1.3/com/mockobjects/servlet/MockHttpServletRequest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/1.3/com/mockobjects/servlet/MockHttpServletRequest.java,v retrieving revision 1.12 diff -u -3 -p -r1.12 MockHttpServletRequest.java --- src/j2ee/1.3/com/mockobjects/servlet/MockHttpServletRequest.java 23 Jan 2003 11:43:00 -0000 1.12 +++ src/j2ee/1.3/com/mockobjects/servlet/MockHttpServletRequest.java 31 Jan 2003 15:59:26 -0000 @@ -117,8 +117,7 @@ public class MockHttpServletRequest exte } public Enumeration getHeaderNames() { - notImplemented(); - return null; + return myHeaders.keys(); } public Enumeration getHeaders(String arg1) { ----------- And finally, I know this is the wrong way to implement getCookies(), but I'm not sure what the right way is: ----------- Index: src/j2ee/1.3/com/mockobjects/servlet/MockHttpServletRequest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/1.3/com/mockobjects/servlet/MockHttpServletRequest.java,v retrieving revision 1.12 diff -u -3 -p -r1.12 MockHttpServletRequest.java --- src/j2ee/1.3/com/mockobjects/servlet/MockHttpServletRequest.java 23 Jan 2003 11:43:00 -0000 1.12 +++ src/j2ee/1.3/com/mockobjects/servlet/MockHttpServletRequest.java 31 Jan 2003 16:04:46 -0000 @@ -44,6 +44,8 @@ public class MockHttpServletRequest exte private ExpectationList myGetAttributeNames = new ExpectationList("get attribute names"); private final ReturnValue servletPath = new ReturnValue("servlet path"); + private Cookie[] myCookies; + public void setupGetAttribute(Object anAttributeToReturn) { myAttributesToReturn.addObjectToReturn(anAttributeToReturn); } @@ -103,9 +105,12 @@ public class MockHttpServletRequest exte myContextPath = contextPath; } + public void setupGetCookies(Cookie[] cookies){ + myCookies = cookies; + } + public Cookie[] getCookies() { - notImplemented(); - return null; + return myCookies; } public long getDateHeader(String arg1) { ----------- |