1 20 package org.apache.cactus.mock; 21 22 import java.io.InputStream ; 23 24 import java.net.HttpURLConnection ; 25 import java.net.URL ; 26 27 32 public class MockHttpURLConnection extends HttpURLConnection 33 { 34 38 private String getHeaderFieldValue; 39 40 44 private InputStream getInputStreamValue; 45 46 50 53 public MockHttpURLConnection(URL theURL) 54 { 55 super(theURL); 56 } 57 58 62 68 public void setExpectedGetHeaderField(String theValue) 69 { 70 this.getHeaderFieldValue = theValue; 71 } 72 73 79 public void setExpectedGetInputStream(InputStream theValue) 80 { 81 this.getInputStreamValue = theValue; 82 } 83 84 87 public String getHeaderField(int theFieldNumber) 88 { 89 if (this.getHeaderFieldValue == null) 90 { 91 throw new RuntimeException ( 92 "Must call setExpectedGetHeaderField() first !"); 93 } 94 95 return this.getHeaderFieldValue; 96 } 97 98 101 public InputStream getInputStream() 102 { 103 if (this.getInputStreamValue == null) 104 { 105 throw new RuntimeException ( 106 "Must call setExpectedGetInputStream() first !"); 107 } 108 109 return this.getInputStreamValue; 110 } 111 112 116 119 public boolean usingProxy() 120 { 121 return false; 122 } 123 124 127 public void disconnect() 128 { 129 } 130 131 134 public void connect() 135 { 136 } 137 } 138 | Popular Tags |