Package net.jadler.stubbing
Interface ResponseStubbing
-
- All Known Implementing Classes:
Stubbing
public interface ResponseStubbingThis interface defines methods for the http stubbing THEN part. These methods provide a way to define one or more http responses for this stubbing.Multiple responses can be defined for one stubbing. These responses are returned in the same order as were defined. Once there is no next response left, the last one is used for all following requests (if you define only one response, which is a common scenario, this response will be used for every request that meets the WHEN part).
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description ResponseStubbingthenRespond()Starts a definition of a subsequent stub response.ResponseStubbingwithBody(byte[] responseBody)Sets the stub http response body as an array of bytes.ResponseStubbingwithBody(InputStream is)Sets the stub http response body as the content of the given input stream.ResponseStubbingwithBody(Reader reader)Sets the stub http response body as the content of the given reader.ResponseStubbingwithBody(String responseBody)Sets the stub http response body as a string.ResponseStubbingwithContentType(String contentType)Sets the content type of the http stub response.ResponseStubbingwithDelay(long delayValue, TimeUnit delayUnit)Sets the response delay.ResponseStubbingwithEncoding(Charset encoding)Sets the character encoding of the http stub response.ResponseStubbingwithHeader(String name, String value)Adds a stub http response header.ResponseStubbingwithStatus(int status)Sets the http stub response status.
-
-
-
Method Detail
-
withContentType
ResponseStubbing withContentType(String contentType)
Sets the content type of the http stub response. Calling this method overrides any previous calls. The content type information is communicated via the http Content-Type response header.This method either adds this header or overwrites any existing Content-Type header ensuring at most one such header will be present in the stub response.
- Parameters:
contentType- response content type- Returns:
- this ongoing stubbing
-
withEncoding
ResponseStubbing withEncoding(Charset encoding)
Sets the character encoding of the http stub response. Calling this method overrides any previous calls or the default encoding (set byJadler.OngoingConfiguration.respondsWithDefaultEncoding(java.nio.charset.Charset)).Please note this method doesn't set the Content-Type header charset part,
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.- Parameters:
encoding- response body encoding- Returns:
- this ongoing stubbing
-
withStatus
ResponseStubbing withStatus(int status)
Sets the http stub response status. Calling this method overrides any previous calls or the default status (set byJadler.OngoingConfiguration.respondsWithDefaultStatus(int)).- Parameters:
status- http status code- Returns:
- this ongoing stubbing
-
withHeader
ResponseStubbing withHeader(String name, String value)
Adds a stub http response header. This method can be called multiple times for the same header name. The response will contain a header with all (multiple) values.- Parameters:
name- header namevalue- header value- Returns:
- this ongoing stubbing
-
withBody
ResponseStubbing withBody(String responseBody)
Sets the stub http response body as a string. This string will be encoded using an encoding set bywithEncoding(java.nio.charset.Charset)Calling this method overrides any previous calls of this or any other withBody method.- Parameters:
responseBody- response body- Returns:
- this ongoing stubbing
-
withBody
ResponseStubbing withBody(Reader reader)
Sets the stub http response body as the content of the given reader. The string retrieved from the given reader will be encoded using an encoding set bywithEncoding(java.nio.charset.Charset)Calling this method overrides any previous calls of this or any other withBody method.- Parameters:
reader- response body source- Returns:
- this ongoing stubbing
-
withBody
ResponseStubbing withBody(InputStream is)
Sets the stub http response body as the content of the given input stream. The source input stream is copied to the stub response body as-is, it is not affected by the encoding set bywithEncoding(java.nio.charset.Charset)in any way. Calling this method overrides any previous calls of this or any other withBody method.- Parameters:
is- response body source- Returns:
- this ongoing stubbing
-
withBody
ResponseStubbing withBody(byte[] responseBody)
Sets the stub http response body as an array of bytes. The given array of bytes is used as the stub response body as-is, it is not affected by the encoding set bywithEncoding(java.nio.charset.Charset)in any way. Calling this method overrides any previous calls of this or any other withBody method.- Parameters:
responseBody- response body- Returns:
- this ongoing stubbing
-
withDelay
ResponseStubbing withDelay(long delayValue, TimeUnit delayUnit)
Sets the response delay. The stub http response is returned after the specified amount of time. Calling this method overrides any previous calls of this method.- Parameters:
delayValue- a delay (in units defined by thedelayUnitparameter) this stub response will be returned afterdelayUnit- unit of the delay parameter- Returns:
- this ongoing stubbing
-
thenRespond
ResponseStubbing thenRespond()
Starts a definition of a subsequent stub response.- Returns:
- this ongoing stubbing
-
-