public final class GenericResponseBuilder extends java.lang.Object implements ResponseBuilder
Response
objects in the most generic way
possible. When writing a protocol specific response builder, this will likely be used to
ultimately construct the underlying Response
object. It can also be used directly in the
API to build Response
s manually, but this would be an advanced use case which most people
will have no need for.Modifier and Type | Method and Description |
---|---|
Response |
build()
This method is primarily intended to be called by the framework to produce the
Response
object which will be used during playback. |
GenericResponseBuilder |
clearMetaData()
Removes all meta-data entries previously added.
|
GenericResponseBuilder |
disableMagicDates()
Disables magic dates.
|
GenericResponseBuilder |
disableMagicStrings()
Disables magic strings.
|
GenericResponseBuilder |
enableMagicDates()
This is the default and is provided to undo the effects of
disableMagicDates() . |
GenericResponseBuilder |
enableMagicStrings()
This is the default and is provided to undo the effects of
disableMagicStrings() . |
static GenericResponseBuilder |
get() |
GenericResponseBuilder |
removeMetaDataEntries(java.lang.String key)
Removes all meta-data entries for the specified key.
|
GenericResponseBuilder |
removeMetaDataEntry(java.lang.String key,
java.lang.String value)
Removes a particular meta-data mapping.
|
GenericResponseBuilder |
withBody(byte[] body)
Specifies the response body to use.
|
GenericResponseBuilder |
withBody(java.lang.String body)
Specifies the response body to use.
|
GenericResponseBuilder |
withBody(java.lang.String body,
java.nio.charset.Charset charset)
Specifies the response body to use.
|
GenericResponseBuilder |
withComputedDelay(Function<Response,java.lang.Long> delayProvider)
Allows specification of a
Function to use for computing the delay to use when
responding to the caller. |
GenericResponseBuilder |
withFixedDelay(long fixedDelay)
Allows specification of a fixed delay to use when responding to the caller.
|
GenericResponseBuilder |
withMetaDataEntry(java.lang.String key,
java.lang.String value)
Adds a meta-data mapping.
|
GenericResponseBuilder |
withRandomDelay(long lowerBound,
long upperBound)
Allows specification of a random delay to use when responding to the caller.
|
public static GenericResponseBuilder get()
GenericResponseBuilder
.public GenericResponseBuilder withBody(java.lang.String body)
Charset.defaultCharset()
should be used for converting the string to bytes. If that is incorrect, use withBody(String, Charset)
or withBody(byte[])
instead.body
- string that will be added as body to the responsethis
for additional configurationpublic GenericResponseBuilder withBody(java.lang.String body, java.nio.charset.Charset charset)
body
- string that will be added as body to the responsecharset
- charset of string that will be add as bodythis
for additional configurationpublic GenericResponseBuilder withBody(byte[] body)
body
- response bodythis
for additional configurationpublic GenericResponseBuilder withMetaDataEntry(java.lang.String key, java.lang.String value)
key
- name of the key for metadatavalue
- value of metadatathis
for additional configurationpublic GenericResponseBuilder removeMetaDataEntry(java.lang.String key, java.lang.String value)
key
- name of key in metadatavalue
- value of keythis
for additional configurationpublic GenericResponseBuilder removeMetaDataEntries(java.lang.String key)
key
- name of key in metadatathis
for additional configurationpublic GenericResponseBuilder clearMetaData()
this
for additional configurationpublic GenericResponseBuilder withFixedDelay(long fixedDelay)
fixedDelay
- delay of responsethis
for additional configurationpublic GenericResponseBuilder withRandomDelay(long lowerBound, long upperBound)
Response
object, a different, random delay
will be returned which conforms to the bounds provided here.
The default is a fixed delay of 0.
lowerBound
- The lower bound for the random delay (inclusive).upperBound
- The upper bound for the random delay (exclusive).this
for additional configurationpublic GenericResponseBuilder withComputedDelay(Function<Response,java.lang.Long> delayProvider)
Function
to use for computing the delay to use when
responding to the caller. When this is used, every time the delay is fetched from the Response
object, the function will be called again to re-compute the delay.
The default is a fixed delay of 0.
delayProvider
- functionthis
for additional configurationpublic GenericResponseBuilder disableMagicDates()
this
for additional configurationpublic GenericResponseBuilder enableMagicDates()
disableMagicDates()
.this
for additional configurationpublic GenericResponseBuilder disableMagicStrings()
this
for additional configurationpublic GenericResponseBuilder enableMagicStrings()
disableMagicStrings()
.this
for additional configurationpublic Response build()
ResponseBuilder
Response
object which will be used during playback. However, no harm will result from calling it
elsewhere.
It is important to note that this method may not reset or alter the state of the builder. It must be possible to call this method multiple times in a row and get equivalent (but different) objects.
build
in interface ResponseBuilder