public class Stubbing extends AbstractRequestMatching<RequestStubbing> implements RequestStubbing, ResponseStubbing
Jadler.onRequest()
for more information on creating instances of this class.predicates
Modifier and Type | Method and Description |
---|---|
HttpStub |
createRule()
Creates a
HttpStub instance from this Stubbing instance. |
ResponseStubbing |
respond()
Finishes the WHEN part of this stubbing and starts the THEN part.
|
void |
respondUsing(Responder responder)
Finishes the WHEN part of this stubbing and allows to define the THEN part in
a dynamic way.
|
ResponseStubbing |
thenRespond()
Starts a definition of a subsequent stub response.
|
ResponseStubbing |
withBody(byte[] responseBody)
Sets the stub http response body as an array of bytes.
|
ResponseStubbing |
withBody(InputStream is)
Sets the stub http response body as the content of the given input stream.
|
ResponseStubbing |
withBody(Reader reader)
Sets the stub http response body as the content of the given reader.
|
ResponseStubbing |
withBody(String responseBody)
Sets the stub http response body as a string.
|
ResponseStubbing |
withContentType(String contentType)
Sets the content type of the http stub response.
|
ResponseStubbing |
withDelay(long delayValue,
TimeUnit delayUnit)
Sets the response delay.
|
ResponseStubbing |
withEncoding(Charset encoding)
Sets the character encoding of the http stub response.
|
ResponseStubbing |
withHeader(String name,
String value)
Adds a stub http response header.
|
ResponseStubbing |
withStatus(int status)
Sets the http stub response status.
|
havingBody, havingBodyEqualTo, havingHeader, havingHeader, havingHeaderEqualTo, havingHeaders, havingMethod, havingMethodEqualTo, havingParameter, havingParameter, havingParameterEqualTo, havingParameters, havingPath, havingPathEqualTo, havingQueryString, havingQueryStringEqualTo, havingRawBodyEqualTo, that
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
havingBody, havingBodyEqualTo, havingHeader, havingHeader, havingHeaderEqualTo, havingHeaders, havingMethod, havingMethodEqualTo, havingParameter, havingParameter, havingParameterEqualTo, havingParameters, havingPath, havingPathEqualTo, havingQueryString, havingQueryStringEqualTo, havingRawBodyEqualTo, that
public ResponseStubbing respond()
respond
in interface RequestStubbing
public ResponseStubbing thenRespond()
thenRespond
in interface ResponseStubbing
public void respondUsing(Responder responder)
respondUsing
in interface RequestStubbing
responder
- Responder
instance (usually in a form of an anonymous inner class) which dynamically
creates an http response to be returned when an incoming http request matches the WHEN part.public ResponseStubbing withContentType(String contentType)
withContentType
in interface ResponseStubbing
contentType
- response content typepublic ResponseStubbing withEncoding(Charset encoding)
Jadler.OngoingConfiguration.respondsWithDefaultEncoding(java.nio.charset.Charset)
).
Please note this method doesn't set the Content-Type header charset part,
ResponseStubbing.withContentType(java.lang.String)
must be called to do so. You can even set different
stub response body encoding and Content-Type if your testing scenario requires it.withEncoding
in interface ResponseStubbing
encoding
- response body encodingpublic ResponseStubbing withBody(String responseBody)
ResponseStubbing.withEncoding(java.nio.charset.Charset)
Calling this method overrides any previous calls of this or any other withBody method.withBody
in interface ResponseStubbing
responseBody
- response bodypublic ResponseStubbing withBody(Reader reader)
ResponseStubbing.withEncoding(java.nio.charset.Charset)
Calling this method overrides any previous calls of this or any other withBody method.withBody
in interface ResponseStubbing
reader
- response body sourcepublic ResponseStubbing withBody(InputStream is)
ResponseStubbing.withEncoding(java.nio.charset.Charset)
in any way.
Calling this method overrides any previous calls of this or any other withBody method.withBody
in interface ResponseStubbing
is
- response body sourcepublic ResponseStubbing withBody(byte[] responseBody)
ResponseStubbing.withEncoding(java.nio.charset.Charset)
in any way.
Calling this method overrides any previous calls of this or any other withBody method.withBody
in interface ResponseStubbing
responseBody
- response bodypublic ResponseStubbing withHeader(String name, String value)
withHeader
in interface ResponseStubbing
name
- header namevalue
- header valuepublic ResponseStubbing withStatus(int status)
Jadler.OngoingConfiguration.respondsWithDefaultStatus(int)
).withStatus
in interface ResponseStubbing
status
- http status codepublic ResponseStubbing withDelay(long delayValue, TimeUnit delayUnit)
withDelay
in interface ResponseStubbing
delayValue
- a delay (in units defined by the delayUnit
parameter)
this stub response will be returned afterdelayUnit
- unit of the delay parameterCopyright © 2016. All Rights Reserved.