1 package com.mockobjects.apache.commons.httpclient; 2 3 import com.mockobjects.*; 4 import com.mockobjects.util.AssertMo; 5 import com.mockobjects.util.Verifier; 6 import org.apache.commons.httpclient.*; 7 import org.apache.commons.httpclient.methods.GetMethod; 8 9 import java.io.File ; 10 import java.io.IOException ; 11 import java.io.InputStream ; 12 13 public class MockGetMethod extends GetMethod implements Verifiable { 14 15 private ExpectationValue myFollowRedirects; private ExpectationValue myPath = new ExpectationValue("path"); 17 private ExpectationSet myPairs = new ExpectationSet("pairs"); 18 private ReturnObjectList myStatusCodes = new ReturnObjectList("status code"); 19 private String myResponseBody; 20 private String myStatusText; 21 private final MockMethodHelper helper = new MockMethodHelper(); 22 23 public void setExpectedPath(String aPath) { 24 myPath.setExpected(aPath); 25 } 26 27 public void setPath(String aPath) { 28 myPath.setActual(aPath); 29 } 30 31 public String getPath() { 32 AssertMo.notImplemented(getClass().getName()); 33 return null; 34 } 35 36 public void setStrictMode(boolean b) { 37 AssertMo.notImplemented(getClass().getName()); 38 } 39 40 public boolean isStrictMode() { 41 AssertMo.notImplemented(getClass().getName()); 42 return false; 43 } 44 45 public void setRequestHeader(String s, String s1) { 46 AssertMo.notImplemented(getClass().getName()); 47 } 48 49 public void setUseDisk(boolean b) { 50 AssertMo.notImplemented(getClass().getName()); 51 } 52 53 public void setRequestHeader(Header header) { 54 AssertMo.notImplemented(getClass().getName()); 55 } 56 57 public boolean getUseDisk() { 58 AssertMo.notImplemented(getClass().getName()); 59 return false; 60 } 61 62 public void addRequestHeader(String s, String s1) { 63 AssertMo.notImplemented(getClass().getName()); 64 } 65 66 public void setTempDir(String s) { 67 AssertMo.notImplemented(getClass().getName()); 68 } 69 70 public void addRequestHeader(Header header) { 71 AssertMo.notImplemented(getClass().getName()); 72 } 73 74 public String getTempDir() { 75 AssertMo.notImplemented(getClass().getName()); 76 return null; 77 } 78 79 public Header getRequestHeader(String s) { 80 AssertMo.notImplemented(getClass().getName()); 81 return null; 82 } 83 84 public void setTempFile(String s) { 85 AssertMo.notImplemented(getClass().getName()); 86 } 87 88 public void removeRequestHeader(String s) { 89 AssertMo.notImplemented(getClass().getName()); 90 } 91 92 public String getTempFile() { 93 AssertMo.notImplemented(getClass().getName()); 94 return null; 95 } 96 97 public boolean getFollowRedirects() { 98 AssertMo.notImplemented(getClass().getName()); 99 return false; 100 } 101 102 public File getFileData() { 103 AssertMo.notImplemented(getClass().getName()); 104 return null; 105 } 106 107 public void setExpectedFollowRedirects(boolean aFollowRedirects) { 108 if (myFollowRedirects == null) { 109 myFollowRedirects = new ExpectationValue("follow redirects"); 110 } 111 myFollowRedirects.setExpected(aFollowRedirects); 112 } 113 114 public void setFollowRedirects(boolean aFollowRedirects) { 115 if (myFollowRedirects == null) { 116 myFollowRedirects = new ExpectationValue("follow redirects"); 117 } 118 myFollowRedirects.setActual(aFollowRedirects); 119 } 120 121 public void setFileData(File file) { 122 AssertMo.notImplemented(getClass().getName()); 123 } 124 125 public void setQueryString(String s) { 126 AssertMo.notImplemented(getClass().getName()); 127 } 128 129 public String getName() { 130 AssertMo.notImplemented(getClass().getName()); 131 return null; 132 } 133 134 public void addExpectedQueryString(NameValuePair aPair) { 135 myPairs.addExpected(new MapEntry(aPair.getName(), aPair.getValue())); 136 } 137 138 public void setQueryString(NameValuePair[] aPairs) { 139 for (int i = 0; i < aPairs.length; i++) { 140 myPairs.addActual(new MapEntry( 141 aPairs[i].getName(), aPairs[i].getValue())); 142 } 143 } 144 145 public void recycle() { 146 AssertMo.notImplemented(getClass().getName()); 147 } 148 149 public String getQueryString() { 150 AssertMo.notImplemented(getClass().getName()); 151 return null; 152 } 153 154 public byte[] getResponseBody() { 155 AssertMo.notImplemented(getClass().getName()); 156 return new byte[]{}; 157 } 158 159 public Header[] getRequestHeaders() { 160 AssertMo.notImplemented(getClass().getName()); 161 return null; 162 } 163 164 public void setupGetResponseBodyAsString(String aResponseBody) { 165 myResponseBody = aResponseBody; 166 } 167 168 public String getResponseBodyAsString() { 169 return myResponseBody; 170 } 171 172 public boolean validate() { 173 AssertMo.notImplemented(getClass().getName()); 174 return false; 175 } 176 177 public InputStream getResponseBodyAsStream() throws IOException { 178 AssertMo.notImplemented(getClass().getName()); 179 return null; 180 } 181 182 public void addGetStatusCode(int aStatusCode) { 183 myStatusCodes.addObjectToReturn(new Integer (aStatusCode)); 184 } 185 186 public int getStatusCode() { 187 return ((Integer ) myStatusCodes.nextReturnObject()).intValue(); 188 } 189 190 public void setupGetStatusText(String aStatusText) { 191 myStatusText = aStatusText; 192 } 193 194 public String getStatusText() { 195 return myStatusText; 196 } 197 198 public Header[] getResponseHeaders() { 199 AssertMo.notImplemented(getClass().getName()); 200 return new Header[]{}; 201 } 202 203 public Header getResponseHeader(String key) { 204 return helper.getResponseHeader(key); 205 } 206 207 public void addGetResponseHeader(String key, Header header) { 208 helper.addGetResponseHeader(key, header); 209 } 210 211 public boolean hasBeenUsed() { 212 AssertMo.notImplemented(getClass().getName()); 213 return false; 214 } 215 216 public int execute(HttpState state, HttpConnection connection) 217 throws HttpException, IOException { 218 AssertMo.notImplemented(getClass().getName()); 219 return 0; 220 } 221 222 public boolean isHttp11() { 223 AssertMo.notImplemented(getClass().getName()); 224 return false; 225 } 226 227 public void setHttp11(boolean b) { 228 AssertMo.notImplemented(getClass().getName()); 229 } 230 231 public void verify() { 232 Verifier.verifyObject(this); 233 } 234 235 } 236 | Popular Tags |