Package net.jadler.stubbing
Class StubResponse.Builder
- java.lang.Object
-
- net.jadler.stubbing.StubResponse.Builder
-
- Enclosing class:
- StubResponse
public static class StubResponse.Builder extends Object
A builder class for creating newStubResponseinstances.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StubResponse.Builderbody(byte[] body)Sets the response body as an array of bytes.StubResponse.Builderbody(String body, Charset encoding)Sets the response body as a string.StubResponsebuild()StubResponse.Builderdelay(long delayValue, TimeUnit delayUnit)Sets the response delay.StubResponse.Builderheader(String name, String value)Adds a new stub response header.StubResponse.Builderheaders(KeyValues headers)Sets new stub response headers (all previously set headers are discarded).StubResponse.Builderstatus(int status)Sets the stub response http status.
-
-
-
Method Detail
-
status
public StubResponse.Builder status(int status)
Sets the stub response http status. If not called,200will be used as a default.- Parameters:
status- stub response status (cannot be negative)- Returns:
- this builder
-
body
public StubResponse.Builder body(byte[] body)
Sets the response body as an array of bytes. Calling this method resets all data previously provided bybody(String, Charset). If the response body is not set at all, an empty body is used.- Parameters:
body- stub response body as an array of bytes (cannot be null).- Returns:
- this builder
-
body
public StubResponse.Builder body(String body, Charset encoding)
Sets the response body as a string. Calling this method resets all data previously provided bybody(byte[]). If the response body is not set at all, an empty body is used.- Parameters:
body- stub response body as a string (cannot benull)encoding- encoding of the body (cannot benull)- Returns:
- this builder
-
headers
public StubResponse.Builder headers(KeyValues headers)
Sets new stub response headers (all previously set headers are discarded).- Parameters:
headers- stub response headers (cannot benull)- Returns:
- this builder
-
header
public StubResponse.Builder header(String name, String value)
Adds a new stub response header. Supports multivalue headers (if a header with the same name has already been added before, adds another value to it)- Parameters:
name- header name (cannot be empty)value- header value (cannot benull, however can be empty for valueless headers)- Returns:
- this headers
-
delay
public StubResponse.Builder delay(long delayValue, TimeUnit delayUnit)
Sets the response delay. If not called0will be used as a default.- Parameters:
delayValue- a delay (in units defined by thedelayUnitparameter) this stub response will be returned afterdelayUnit- unit of the delay parameter- Returns:
- this builder
-
build
public StubResponse build()
- Returns:
- a
StubResponseinstance built from values stored in this builder
-
-