Class MockHttpTransport
- java.lang.Object
-
- com.google.api.client.http.HttpTransport
-
- com.google.api.client.testing.http.MockHttpTransport
-
@Beta public class MockHttpTransport extends HttpTransport
Beta
Mock forHttpTransport.Implementation is thread-safe. For maximum efficiency, applications should use a single globally-shared instance of the HTTP transport.
- Since:
- 1.3
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMockHttpTransport.Builder
-
Field Summary
Fields Modifier and Type Field Description private MockLowLevelHttpRequestlowLevelHttpRequestTheMockLowLevelHttpRequestto be returned bybuildRequest(java.lang.String, java.lang.String).private MockLowLevelHttpResponselowLevelHttpResponseTheMockLowLevelHttpResponseto be returned when thisMockHttpTransportexecutes the associated request.private java.util.Set<java.lang.String>supportedMethodsSupported HTTP methods ornullto specify that all methods are supported.
-
Constructor Summary
Constructors Modifier Constructor Description MockHttpTransport()protectedMockHttpTransport(MockHttpTransport.Builder builder)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description LowLevelHttpRequestbuildRequest(java.lang.String method, java.lang.String url)Builds a low level HTTP request for the given HTTP method.MockLowLevelHttpRequestgetLowLevelHttpRequest()Returns theMockLowLevelHttpRequestthat is associated with thisMockHttpTransport.Builder, ornullif no such instance exists.java.util.Set<java.lang.String>getSupportedMethods()Returns the unmodifiable set of supported HTTP methods ornullto specify that all methods are supported.booleansupportsMethod(java.lang.String method)Returns whether a specified HTTP method is supported by this transport.-
Methods inherited from class com.google.api.client.http.HttpTransport
createRequestFactory, createRequestFactory, isMtls, isShutdown, shutdown
-
-
-
-
Field Detail
-
supportedMethods
private java.util.Set<java.lang.String> supportedMethods
Supported HTTP methods ornullto specify that all methods are supported.
-
lowLevelHttpRequest
private MockLowLevelHttpRequest lowLevelHttpRequest
TheMockLowLevelHttpRequestto be returned bybuildRequest(java.lang.String, java.lang.String). If this field isnull,buildRequest(java.lang.String, java.lang.String)will create a new instance from its arguments.
-
lowLevelHttpResponse
private MockLowLevelHttpResponse lowLevelHttpResponse
TheMockLowLevelHttpResponseto be returned when thisMockHttpTransportexecutes the associated request. Note that this field is ignored if the caller provided a non-nullMockLowLevelHttpRequestwith thisMockHttpTransportwas built.
-
-
Constructor Detail
-
MockHttpTransport
public MockHttpTransport()
-
MockHttpTransport
protected MockHttpTransport(MockHttpTransport.Builder builder)
- Parameters:
builder- builder- Since:
- 1.14
-
-
Method Detail
-
supportsMethod
public boolean supportsMethod(java.lang.String method) throws java.io.IOExceptionDescription copied from class:HttpTransportReturns whether a specified HTTP method is supported by this transport.Default implementation returns true if and only if the request method is
"DELETE","GET","POST", or"PUT". Subclasses should override.- Overrides:
supportsMethodin classHttpTransport- Parameters:
method- HTTP method- Throws:
java.io.IOException- I/O exception
-
buildRequest
public LowLevelHttpRequest buildRequest(java.lang.String method, java.lang.String url) throws java.io.IOException
Description copied from class:HttpTransportBuilds a low level HTTP request for the given HTTP method.- Specified by:
buildRequestin classHttpTransport- Parameters:
method- HTTP methodurl- URL- Returns:
- new low level HTTP request
- Throws:
java.io.IOException
-
getSupportedMethods
public final java.util.Set<java.lang.String> getSupportedMethods()
Returns the unmodifiable set of supported HTTP methods ornullto specify that all methods are supported.
-
getLowLevelHttpRequest
public final MockLowLevelHttpRequest getLowLevelHttpRequest()
Returns theMockLowLevelHttpRequestthat is associated with thisMockHttpTransport.Builder, ornullif no such instance exists.- Since:
- 1.18
-
-