From: Jeff M. <cus...@us...> - 2003-08-11 09:52:56
|
Update of /cvsroot/mockobjects/mockobjects-java/src/extensions/com/mockobjects/apache/commons/httpclient In directory sc8-pr-cvs1:/tmp/cvs-serv24799/src/extensions/com/mockobjects/apache/commons/httpclient Modified Files: MockGetMethod.java MockMethodHelper.java Added Files: MockPutMethod.java Log Message: Added support for PUT in HTTPClient mocks --- NEW FILE: MockPutMethod.java --- package com.mockobjects.apache.commons.httpclient; import com.mockobjects.*; import com.mockobjects.util.AssertMo; import com.mockobjects.util.Verifier; import org.apache.commons.httpclient.*; import org.apache.commons.httpclient.methods.PutMethod; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.URL; public class MockPutMethod extends PutMethod implements Verifiable { private ExpectationValue myFollowRedirects; // lazy initialise because of super constructor private ExpectationSet myPairs = new ExpectationSet("pairs"); private ReturnObjectList myStatusCodes = new ReturnObjectList("status code"); private String myResponseBody; private String myStatusText; private final MockMethodHelper helper = new MockMethodHelper(); private final ExpectationValue requestBody = new ExpectationValue("request body"); public void setExpectedPath(String aPath) { helper.setExpectedPath(aPath); } public void setPath(String aPath) { helper.setPath(aPath); } public void setExpectedFollowRedirects(boolean aFollowRedirects) { if (myFollowRedirects == null) { myFollowRedirects = new ExpectationValue("follow redirects"); } myFollowRedirects.setExpected(aFollowRedirects); } public void setFollowRedirects(boolean aFollowRedirects) { if (myFollowRedirects == null) { myFollowRedirects = new ExpectationValue("follow redirects"); } myFollowRedirects.setActual(aFollowRedirects); } public void addExpectedQueryString(NameValuePair aPair) { myPairs.addExpected(new MapEntry(aPair.getName(), aPair.getValue())); } public void setQueryString(NameValuePair[] aPairs) { for (int i = 0; i < aPairs.length; i++) { myPairs.addActual(new MapEntry( aPairs[i].getName(), aPairs[i].getValue())); } } public void setupGetResponseBodyAsString(String aResponseBody) { myResponseBody = aResponseBody; } public String getResponseBodyAsString() { return myResponseBody; } public void addGetStatusCode(int aStatusCode) { myStatusCodes.addObjectToReturn(new Integer(aStatusCode)); } public int getStatusCode() { return ((Integer) myStatusCodes.nextReturnObject()).intValue(); } public void setupGetStatusText(String aStatusText) { myStatusText = aStatusText; } public String getStatusText() { return myStatusText; } public Header getResponseHeader(String key) { return helper.getResponseHeader(key); } public void addGetResponseHeader(String key, Header header) { helper.addGetResponseHeader(key, header); } private void notImplemented() { AssertMo.notImplemented(getClass().getName()); } public String getName() { notImplemented(); return null; } public void recycle() { notImplemented(); } public void verify() { Verifier.verifyObject(this); } public void setRequestBody(File file) throws IOException { notImplemented(); } public void setRequestBody(URL url) throws IOException { notImplemented(); } public void setRequestBody(byte[] bytes) { notImplemented(); } public void setRequestBody(String body) { requestBody.setActual(body); } public void setExpectedRequestBody(String body) { requestBody.setExpected(body); } public void setRequestBody(InputStream inputStream) throws IOException { notImplemented(); } protected void addRequestHeaders(HttpState httpState, HttpConnection httpConnection) throws IOException, HttpException { notImplemented(); } protected boolean writeRequestBody(HttpState httpState, HttpConnection httpConnection) throws IOException, HttpException { notImplemented(); return false; } protected int getRequestContentLength() { notImplemented(); return 0; } public String getPath() { return helper.getPath(); } public void setStrictMode(boolean b) { helper.setStrictMode(b); } public boolean isStrictMode() { return helper.isStrictMode(); } public void setRequestHeader(String s, String s1) { helper.setRequestHeader(s, s1); } public void setRequestHeader(Header header) { helper.setRequestHeader(header); } public void addRequestHeader(String s, String s1) { helper.addRequestHeader(s, s1); } public void addRequestHeader(Header header) { helper.addRequestHeader(header); } public Header getRequestHeader(String s) { return helper.getRequestHeader(s); } public void removeRequestHeader(String s) { helper.removeRequestHeader(s); } public boolean getFollowRedirects() { return helper.getFollowRedirects(); } public void setQueryString(String s) { helper.setQueryString(s); } public String getQueryString() { return helper.getQueryString(); } public Header[] getRequestHeaders() { return helper.getRequestHeaders(); } public boolean validate() { return helper.validate(); } public Header[] getResponseHeaders() { return helper.getResponseHeaders(); } public byte[] getResponseBody() { return helper.getResponseBody(); } public InputStream getResponseBodyAsStream() throws IOException { return helper.getResponseBodyAsStream(); } public boolean hasBeenUsed() { return helper.hasBeenUsed(); } public int execute(HttpState httpState, HttpConnection httpConnection) throws HttpException, IOException { return helper.execute(httpState, httpConnection); } protected void writeRequest(HttpState httpState, HttpConnection httpConnection) throws IOException, HttpException { helper.writeRequest(httpState, httpConnection); } protected void writeRequestLine(HttpState httpState, HttpConnection httpConnection) throws IOException, HttpException { helper.writeRequestLine(httpState, httpConnection); } protected void writeRequestHeaders(HttpState httpState, HttpConnection httpConnection) throws IOException, HttpException { helper.writeRequestHeaders(httpState, httpConnection); } protected void addUserAgentRequestHeader(HttpState httpState, HttpConnection httpConnection) throws IOException, HttpException { helper.addUserAgentRequestHeader(httpState, httpConnection); } protected void addHostRequestHeader(HttpState httpState, HttpConnection httpConnection) throws IOException, HttpException { helper.addHostRequestHeader(httpState, httpConnection); } protected void addCookieRequestHeader(HttpState httpState, HttpConnection httpConnection) throws IOException, HttpException { helper.addCookieRequestHeader(httpState, httpConnection); } protected void addAuthorizationRequestHeader(HttpState httpState, HttpConnection httpConnection) throws IOException, HttpException { helper.addAuthorizationRequestHeader(httpState, httpConnection); } protected void addContentLengthRequestHeader(HttpState httpState, HttpConnection httpConnection) throws IOException, HttpException { helper.addContentLengthRequestHeader(httpState, httpConnection); } protected void readResponse(HttpState httpState, HttpConnection httpConnection) throws IOException, HttpException { helper.readResponse(httpState, httpConnection); } protected void readStatusLine(HttpState httpState, HttpConnection httpConnection) throws IOException, HttpException { helper.readStatusLine(httpState, httpConnection); } protected void processStatusLine(HttpState httpState, HttpConnection httpConnection) { helper.processStatusLine(httpState, httpConnection); } protected void readResponseHeaders(HttpState httpState, HttpConnection httpConnection) throws IOException, HttpException { helper.readResponseHeaders(httpState, httpConnection); } protected void processResponseHeaders(HttpState httpState, HttpConnection httpConnection) { helper.processResponseHeaders(httpState, httpConnection); } protected void readResponseBody(HttpState httpState, HttpConnection httpConnection) throws IOException, HttpException { helper.readResponseBody(httpState, httpConnection); } protected void readResponseBody(HttpState httpState, HttpConnection httpConnection, OutputStream outputStream) throws IOException { helper.readResponseBody(httpState, httpConnection, outputStream); } protected void processResponseBody(HttpState httpState, HttpConnection httpConnection) { helper.processResponseBody(httpState, httpConnection); } public boolean isHttp11() { return helper.isHttp11(); } public void setHttp11(boolean b) { helper.setHttp11(b); } protected void checkNotUsed() { helper.checkNotUsed(); } protected void checkUsed() { helper.checkUsed(); } } Index: MockGetMethod.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/extensions/com/mockobjects/apache/commons/httpclient/MockGetMethod.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- MockGetMethod.java 14 May 2003 15:07:35 -0000 1.3 +++ MockGetMethod.java 11 Aug 2003 09:52:53 -0000 1.4 @@ -13,7 +13,6 @@ public class MockGetMethod extends GetMethod implements Verifiable { private ExpectationValue myFollowRedirects; // lazy initialise because of super constructor - private ExpectationValue myPath = new ExpectationValue("path"); private ExpectationSet myPairs = new ExpectationSet("pairs"); private ReturnObjectList myStatusCodes = new ReturnObjectList("status code"); private String myResponseBody; @@ -21,86 +20,86 @@ private final MockMethodHelper helper = new MockMethodHelper(); public void setExpectedPath(String aPath) { - myPath.setExpected(aPath); + helper.setExpectedPath(aPath); } public void setPath(String aPath) { - myPath.setActual(aPath); + helper.setPath(aPath); } public String getPath() { - AssertMo.notImplemented(getClass().getName()); - return null; + return helper.getPath(); } public void setStrictMode(boolean b) { - AssertMo.notImplemented(getClass().getName()); + helper.setStrictMode(b); } public boolean isStrictMode() { - AssertMo.notImplemented(getClass().getName()); - return false; + return helper.isStrictMode(); } public void setRequestHeader(String s, String s1) { - AssertMo.notImplemented(getClass().getName()); + helper.setRequestHeader(s, s1); } public void setUseDisk(boolean b) { + notImplemented(); + } + + private void notImplemented() { AssertMo.notImplemented(getClass().getName()); } public void setRequestHeader(Header header) { - AssertMo.notImplemented(getClass().getName()); + helper.setRequestHeader(header); } public boolean getUseDisk() { - AssertMo.notImplemented(getClass().getName()); + notImplemented(); return false; } public void addRequestHeader(String s, String s1) { - AssertMo.notImplemented(getClass().getName()); + helper.addRequestHeader(s, s1); } public void setTempDir(String s) { - AssertMo.notImplemented(getClass().getName()); + notImplemented(); } public void addRequestHeader(Header header) { - AssertMo.notImplemented(getClass().getName()); + helper.addRequestHeader(header); } public String getTempDir() { - AssertMo.notImplemented(getClass().getName()); + notImplemented(); return null; } public Header getRequestHeader(String s) { - AssertMo.notImplemented(getClass().getName()); - return null; + return helper.getRequestHeader(s); } public void setTempFile(String s) { - AssertMo.notImplemented(getClass().getName()); + notImplemented(); } public void removeRequestHeader(String s) { - AssertMo.notImplemented(getClass().getName()); + helper.removeRequestHeader(s); } public String getTempFile() { - AssertMo.notImplemented(getClass().getName()); + notImplemented(); return null; } public boolean getFollowRedirects() { - AssertMo.notImplemented(getClass().getName()); - return false; + return helper.getFollowRedirects(); } public File getFileData() { - AssertMo.notImplemented(getClass().getName()); + notImplemented(); return null; } @@ -119,15 +118,15 @@ } public void setFileData(File file) { - AssertMo.notImplemented(getClass().getName()); + notImplemented(); } public void setQueryString(String s) { - AssertMo.notImplemented(getClass().getName()); + helper.setQueryString(s); } public String getName() { - AssertMo.notImplemented(getClass().getName()); + notImplemented(); return null; } Index: MockMethodHelper.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/extensions/com/mockobjects/apache/commons/httpclient/MockMethodHelper.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MockMethodHelper.java 14 May 2003 15:07:35 -0000 1.1 +++ MockMethodHelper.java 11 Aug 2003 09:52:53 -0000 1.2 @@ -1,14 +1,31 @@ package com.mockobjects.apache.commons.httpclient; -import com.mockobjects.ReturnObjectBag; import com.mockobjects.MockObject; +import com.mockobjects.ReturnObjectBag; +import com.mockobjects.ExpectationValue; import org.apache.commons.httpclient.Header; +import org.apache.commons.httpclient.HttpConnection; +import org.apache.commons.httpclient.HttpException; +import org.apache.commons.httpclient.HttpState; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; /** * @version $Revision$ */ class MockMethodHelper extends MockObject{ private final ReturnObjectBag header = new ReturnObjectBag("response header"); + private final ExpectationValue myPath = new ExpectationValue("path"); + + public void setExpectedPath(String aPath) { + myPath.setExpected(aPath); + } + + public void setPath(String aPath) { + myPath.setActual(aPath); + } public Header getResponseHeader(String key) { return (Header) header.getNextReturnObject(key); @@ -17,4 +34,175 @@ public void addGetResponseHeader(String key, Header header) { this.header.putObjectToReturn(key, header); } + + + public String getPath() { + notImplemented(); + return null; + } + + public void setStrictMode(boolean b) { + notImplemented(); + } + + public boolean isStrictMode() { + notImplemented(); + return false; + } + + public void setRequestHeader(String s, String s1) { + notImplemented(); + } + + public void setRequestHeader(Header header) { + notImplemented(); + } + + public void addRequestHeader(String s, String s1) { + notImplemented(); + } + + public void addRequestHeader(Header header) { + notImplemented(); + } + + public Header getRequestHeader(String s) { + notImplemented(); + return null; + } + + public void removeRequestHeader(String s) { + notImplemented(); + } + + public boolean getFollowRedirects() { + notImplemented(); + return false; + } + + public void setQueryString(String s) { + notImplemented(); + } + + public String getQueryString() { + notImplemented(); + return null; + } + + public Header[] getRequestHeaders() { + notImplemented(); + return null; + } + + public boolean validate() { + notImplemented(); + return false; + } + + public Header[] getResponseHeaders() { + notImplemented(); + return null; + } + + public byte[] getResponseBody() { + notImplemented(); + return null; + } + + public InputStream getResponseBodyAsStream() throws IOException { + notImplemented(); + return null; + } + + public boolean hasBeenUsed() { + notImplemented(); + return false; + } + + public int execute(HttpState httpState, HttpConnection httpConnection) throws HttpException, IOException { + notImplemented(); + return 0; + } + + protected void writeRequest(HttpState httpState, HttpConnection httpConnection) throws IOException, HttpException { + notImplemented(); + } + + protected void writeRequestLine(HttpState httpState, HttpConnection httpConnection) throws IOException, HttpException { + notImplemented(); + } + + protected void writeRequestHeaders(HttpState httpState, HttpConnection httpConnection) throws IOException, HttpException { + notImplemented(); + } + + protected void addUserAgentRequestHeader(HttpState httpState, HttpConnection httpConnection) throws IOException, HttpException { + notImplemented(); + } + + protected void addHostRequestHeader(HttpState httpState, HttpConnection httpConnection) throws IOException, HttpException { + notImplemented(); + } + + protected void addCookieRequestHeader(HttpState httpState, HttpConnection httpConnection) throws IOException, HttpException { + notImplemented(); + } + + protected void addAuthorizationRequestHeader(HttpState httpState, HttpConnection httpConnection) throws IOException, HttpException { + notImplemented(); + } + + protected void addContentLengthRequestHeader(HttpState httpState, HttpConnection httpConnection) throws IOException, HttpException { + notImplemented(); + } + + protected void readResponse(HttpState httpState, HttpConnection httpConnection) throws IOException, HttpException { + notImplemented(); + } + + protected void readStatusLine(HttpState httpState, HttpConnection httpConnection) throws IOException, HttpException { + notImplemented(); + } + + protected void processStatusLine(HttpState httpState, HttpConnection httpConnection) { + notImplemented(); + } + + protected void readResponseHeaders(HttpState httpState, HttpConnection httpConnection) throws IOException, HttpException { + notImplemented(); + } + + protected void processResponseHeaders(HttpState httpState, HttpConnection httpConnection) { + notImplemented(); + } + + protected void readResponseBody(HttpState httpState, HttpConnection httpConnection) throws IOException, HttpException { + notImplemented(); + } + + protected void readResponseBody(HttpState httpState, HttpConnection httpConnection, OutputStream outputStream) throws IOException { + notImplemented(); + } + + protected void processResponseBody(HttpState httpState, HttpConnection httpConnection) { + notImplemented(); + } + + public boolean isHttp11() { + notImplemented(); + return false; + } + + public void setHttp11(boolean b) { + notImplemented(); + } + + protected void checkNotUsed() { + notImplemented(); + } + + protected void checkUsed() { + notImplemented(); + } + } |