|
From: Jeff M. <cus...@us...> - 2003-05-14 15:07:38
|
Update of /cvsroot/mockobjects/mockobjects-java/src/extensions/com/mockobjects/apache/commons/httpclient
In directory sc8-pr-cvs1:/tmp/cvs-serv20576/src/extensions/com/mockobjects/apache/commons/httpclient
Modified Files:
MockGetMethod.java MockHttpMethod.java
Added Files:
MockMethodHelper.java
Log Message:
Added getResponseHeaders to both HttpMethod and GetMethod
--- NEW FILE: MockMethodHelper.java ---
package com.mockobjects.apache.commons.httpclient;
import com.mockobjects.ReturnObjectBag;
import com.mockobjects.MockObject;
import org.apache.commons.httpclient.Header;
/**
* @version $Revision: 1.1 $
*/
class MockMethodHelper extends MockObject{
private final ReturnObjectBag header = new ReturnObjectBag("response header");
public Header getResponseHeader(String key) {
return (Header) header.getNextReturnObject(key);
}
public void addGetResponseHeader(String key, Header header) {
this.header.putObjectToReturn(key, header);
}
}
Index: MockGetMethod.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/extensions/com/mockobjects/apache/commons/httpclient/MockGetMethod.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MockGetMethod.java 19 Jun 2002 15:26:16 -0000 1.2
+++ MockGetMethod.java 14 May 2003 15:07:35 -0000 1.3
@@ -1,18 +1,16 @@
package com.mockobjects.apache.commons.httpclient;
-import org.apache.commons.httpclient.methods.GetMethod;
+import com.mockobjects.*;
+import com.mockobjects.util.AssertMo;
+import com.mockobjects.util.Verifier;
import org.apache.commons.httpclient.*;
+import org.apache.commons.httpclient.methods.GetMethod;
import java.io.File;
-import java.io.InputStream;
import java.io.IOException;
-import java.io.OutputStream;
-
-import com.mockobjects.util.AssertMo;
-import com.mockobjects.util.Verifier;
-import com.mockobjects.*;
+import java.io.InputStream;
-public class MockGetMethod extends GetMethod implements Verifiable{
+public class MockGetMethod extends GetMethod implements Verifiable {
private ExpectationValue myFollowRedirects; // lazy initialise because of super constructor
private ExpectationValue myPath = new ExpectationValue("path");
@@ -20,8 +18,9 @@
private ReturnObjectList myStatusCodes = new ReturnObjectList("status code");
private String myResponseBody;
private String myStatusText;
+ private final MockMethodHelper helper = new MockMethodHelper();
- public void setExpectedPath(String aPath){
+ public void setExpectedPath(String aPath) {
myPath.setExpected(aPath);
}
@@ -105,15 +104,15 @@
return null;
}
- public void setExpectedFollowRedirects(boolean aFollowRedirects){
- if(myFollowRedirects==null){
+ public void setExpectedFollowRedirects(boolean aFollowRedirects) {
+ if (myFollowRedirects == null) {
myFollowRedirects = new ExpectationValue("follow redirects");
}
myFollowRedirects.setExpected(aFollowRedirects);
}
public void setFollowRedirects(boolean aFollowRedirects) {
- if(myFollowRedirects==null){
+ if (myFollowRedirects == null) {
myFollowRedirects = new ExpectationValue("follow redirects");
}
myFollowRedirects.setActual(aFollowRedirects);
@@ -132,12 +131,12 @@
return null;
}
- public void addExpectedQueryString(NameValuePair aPair){
+ 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++ ){
+ for (int i = 0; i < aPairs.length; i++) {
myPairs.addActual(new MapEntry(
aPairs[i].getName(), aPairs[i].getValue()));
}
@@ -162,7 +161,7 @@
return null;
}
- public void setupGetResponseBodyAsString(String aResponseBody){
+ public void setupGetResponseBodyAsString(String aResponseBody) {
myResponseBody = aResponseBody;
}
@@ -180,15 +179,15 @@
return null;
}
- public void addGetStatusCode(int aStatusCode){
+ public void addGetStatusCode(int aStatusCode) {
myStatusCodes.addObjectToReturn(new Integer(aStatusCode));
}
public int getStatusCode() {
- return ((Integer)myStatusCodes.nextReturnObject()).intValue();
+ return ((Integer) myStatusCodes.nextReturnObject()).intValue();
}
- public void setupGetStatusText(String aStatusText){
+ public void setupGetStatusText(String aStatusText) {
myStatusText = aStatusText;
}
@@ -201,9 +200,12 @@
return new Header[]{};
}
- public Header getResponseHeader(String s) {
- AssertMo.notImplemented(getClass().getName());
- return null;
+ public Header getResponseHeader(String key) {
+ return helper.getResponseHeader(key);
+ }
+
+ public void addGetResponseHeader(String key, Header header) {
+ helper.addGetResponseHeader(key, header);
}
public boolean hasBeenUsed() {
@@ -212,7 +214,7 @@
}
public int execute(HttpState state, HttpConnection connection)
- throws HttpException, IOException {
+ throws HttpException, IOException {
AssertMo.notImplemented(getClass().getName());
return 0;
}
@@ -226,7 +228,7 @@
AssertMo.notImplemented(getClass().getName());
}
- public void verify(){
+ public void verify() {
Verifier.verifyObject(this);
}
Index: MockHttpMethod.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/extensions/com/mockobjects/apache/commons/httpclient/MockHttpMethod.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MockHttpMethod.java 19 Jun 2002 15:26:16 -0000 1.2
+++ MockHttpMethod.java 14 May 2003 15:07:35 -0000 1.3
@@ -1,12 +1,15 @@
package com.mockobjects.apache.commons.httpclient;
import com.mockobjects.MockObject;
+import com.mockobjects.ReturnObjectBag;
import org.apache.commons.httpclient.*;
-import java.io.InputStream;
import java.io.IOException;
+import java.io.InputStream;
+
+public class MockHttpMethod extends MockMethodHelper implements HttpMethod {
+
-public class MockHttpMethod extends MockObject implements HttpMethod {
public String getName() {
notImplemented();
@@ -100,11 +103,6 @@
}
public Header getResponseHeaders()[] {
- notImplemented();
- return null;
- }
-
- public Header getResponseHeader(String name) {
notImplemented();
return null;
}
|