Interface ContractTemplate
- All Known Implementing Classes:
CompositeContractTemplate,HandlebarsContractTemplate
public interface ContractTemplate
Contract for defining templated responses.
If no implementation is provided then Handlebars will be picked as a default implementation.
- Since:
- 1.1.0
- Author:
- Marcin Grzejszczak
-
Method Summary
Modifier and TypeMethodDescriptionbody()Handlebars is using the Mustache template thus it looks like this {{ Mustache }}.default Stringdefault StringescapedBody(String jsonPath) default StringHandlebars is using the Mustache template thus it looks like this {{{ Mustache }}}.default StringescapedCookie(String key) default StringescapedHeader(String key) default StringescapedHeader(String key, int index) default StringHandlebars is using the Mustache template thus it looks like this {{{ Mustache }}}.default Stringdefault StringescapedPath(int index) default StringescapedQuery(String key) default StringescapedQuery(String key, int index) default StringHandlebars is using the Mustache template thus it looks like this {{ Mustache }}.path()path(int index) default booleandefault booleanstartsWithTemplate(String text) url()
-
Method Details
-
startsWithTemplate
- Parameters:
text- text to assert- Returns:
- asserts whether the given text starts with proper opening template.
-
startsWithEscapedTemplate
- Parameters:
text- text to assert- Returns:
- asserts whether the given text starts with proper opening template for escaped value.
-
openingTemplate
String openingTemplate()Handlebars is using the Mustache template thus it looks like this {{ Mustache }}. In this case the opening template would return {{- Returns:
- opening template for a variable
-
closingTemplate
String closingTemplate()Handlebars is using the Mustache template thus it looks like this {{ Mustache }}. In this case the closing template would return }}- Returns:
- closing template for a variable
-
escapedOpeningTemplate
Handlebars is using the Mustache template thus it looks like this {{{ Mustache }}}. In this case the opening template would return {{{- Returns:
- escaped opening template for a variable
-
escapedClosingTemplate
Handlebars is using the Mustache template thus it looks like this {{{ Mustache }}}. In this case the closing template would return }}}- Returns:
- escaped closing template for a variable
-
url
String url()- Returns:
- returns the template for retrieving a URL path and query from request
-
query
- Parameters:
key- query parameter key- Returns:
- the template for retrieving first value of a query parameter e.g. {{ request.query.search }}
-
query
- Parameters:
key- query parameter keyindex- query parameter index- Returns:
- the template for retrieving nth value of a query parameter (zero indexed) e.g. {{ request.query.search.[5] }}
-
path
String path()- Returns:
- the template for retrieving a URL path
-
path
- Parameters:
index- request path index- Returns:
- the template for retrieving nth value of a URL path (zero indexed) e.g. {{ request.path.[2] }}
-
header
- Parameters:
key- headers key- Returns:
- the template for retrieving the first value of a request header e.g. {{ request.headers.X-Request-Id }}
-
header
- Parameters:
key- headers keyindex- headers index- Returns:
- the template for retrieving the nth value of a request header (zero indexed) e.g. {{ request.headers.X-Request-Id.[5] }}
-
cookie
- Parameters:
key- cookie key- Returns:
- the template for retrieving the first value of a cookie with certain key
-
body
String body()- Returns:
- request body text (avoid for non-text bodies) e.g. {{ request.body }} . The body will not be escaped so you won't be able to directly embed it in a JSON for example.
-
body
- Parameters:
jsonPath- json path value- Returns:
- request body text for the given JsonPath. e.g. {{ jsonPath request.body '$.a.b.c' }}
-
escapedUrl
- Returns:
- the template for retrieving a escaped URL path and query from request
-
escapedQuery
- Parameters:
key- query parameter key- Returns:
- the template for retrieving escaped first value of a query parameter e.g. {{{ request.query.search }}}
-
escapedQuery
- Parameters:
key- query parameter keyindex- query parameter index- Returns:
- the template for retrieving esacped nth value of a query parameter (zero indexed) e.g. {{{ request.query.search.[5] }}}
-
escapedPath
- Returns:
- the template for retrieving a escaped URL path
-
escapedPath
- Parameters:
index- path index- Returns:
- the template for retrieving escaped nth value of a URL path (zero indexed) e.g. {{{ request.path.[2] }}}
-
escapedHeader
- Parameters:
key- headers key- Returns:
- the template for retrieving the escaped first value of a request header e.g. {{{ request.headers.X-Request-Id }}}
-
escapedHeader
- Parameters:
key- headers keyindex- headers index- Returns:
- the template for retrieving the esacaped nth value of a request header (zero indexed) e.g. {{{ request.headers.X-Request-Id.[5] }}}
-
escapedCookie
- Parameters:
key- cookie key- Returns:
- the template for retrieving the escaped first value of a cookie with certain key
-
escapedBody
- Returns:
- request body text (avoid for non-text bodies) e.g. {{{ request.body }}} . The body will not be escaped so you won't be able to directly embed it in a JSON for example.
-
escapedBody
- Parameters:
jsonPath- json path value- Returns:
- request body text for the given JsonPath. e.g. {{{ jsonPath request.body '$.a.b.c' }}}
-