Added javadocs

This commit is contained in:
Marcin Grzejszczak
2019-01-20 22:42:36 +01:00
parent 0d0d2ea11c
commit d41d79b887
3 changed files with 212 additions and 0 deletions

View File

@@ -107,28 +107,58 @@ class Contract {
// Can't assert messaging part cause Pact doesn't require destinations it seems
}
/**
* You can set the level of priority of this contract. If there are two contracts
* mapped for example to the same endpoint, then the one with greater priority should
* take precedence. A priority of 1 is highest and takes precedence over a priority of 2.
*/
void priority(int priority) {
this.priority = priority
}
/**
* Name of the generated test / stub. If not provided then the file name will be used.
* If you have multiple contracts in a single file and you don't provide this value
* then a prefix will be added to the file with the index number while iterating
* over the collection of contracts.
*
* Remember to have a unique name for every single contract. Otherwise you might
* generate tests that have two identical methods or you will override the stubs.
*/
void name(String name) {
this.name = name
}
/**
* Label used by the messaging contracts to trigger a message on the consumer side
*
* @param label - name of the label of a messaging contract to trigger
*/
void label(String label) {
this.label = label
}
/**
* Description text. Might be used to describe the usage scenario.
*
* @param description - value of the description
*/
void description(String description) {
this.description = description
}
/**
* The HTTP request part of the contract
*/
void request(@DelegatesTo(Request) Closure closure) {
this.request = new Request()
closure.delegate = request
closure()
}
/**
* The HTTP response part of the contract
*/
void response(@DelegatesTo(Response) Closure closure) {
this.response = new Response()
closure.delegate = response
@@ -141,12 +171,18 @@ class Contract {
closure()
}
/**
* The output side of a messaging contract.
*/
void outputMessage(@DelegatesTo(OutputMessage) Closure closure) {
this.outputMessage = new OutputMessage()
closure.delegate = outputMessage
closure()
}
/**
* Whether the contract should be ignored or not.
*/
void ignored() {
this.ignored = true
}

View File

@@ -63,22 +63,37 @@ class Request extends Common {
this.multipart = request.multipart
}
/**
* Name of the HTTP method
*/
void method(String method) {
this.method = toDslProperty(method)
}
/**
* Name of the HTTP method
*/
void method(HttpMethods.HttpMethod httpMethod) {
this.method = toDslProperty(httpMethod.toString())
}
/**
* Name of the HTTP method
*/
void method(DslProperty method) {
this.method = toDslProperty(method)
}
/**
* URL to which the request will be sent
*/
void url(Object url) {
this.url = new Url(url)
}
/**
* URL to which the request will be sent
*/
void url(DslProperty url) {
this.url = new Url(url)
}
@@ -89,66 +104,109 @@ class Request extends Common {
closure()
}
/**
* URL to which the request will be sent. Allows to customize
* additional query parameters if needed
*/
void url(DslProperty url, @DelegatesTo(UrlPath) Closure closure) {
this.url = new Url(url)
closure.delegate = this.url
closure()
}
/**
* URL to which the request will be sent
*/
void urlPath(String path) {
this.urlPath = new UrlPath(path)
}
/**
* URL to which the request will be sent
*/
void urlPath(GString path) {
this.urlPath = new UrlPath(path)
}
/**
* URL to which the request will be sent
*/
void urlPath(DslProperty path) {
this.urlPath = new UrlPath(path)
}
/**
* URL to which the request will be sent. Allows to customize
* additional query parameters if needed
*/
void urlPath(String path, @DelegatesTo(UrlPath) Closure closure) {
this.urlPath = new UrlPath(path)
closure.delegate = urlPath
closure()
}
/**
* URL to which the request will be sent. Allows to customize
* additional query parameters if needed
*/
void urlPath(GString path, @DelegatesTo(UrlPath) Closure closure) {
this.urlPath = new UrlPath(path)
closure.delegate = urlPath
closure()
}
/**
* URL to which the request will be sent. Allows to customize
* additional query parameters if needed
*/
void urlPath(DslProperty path, @DelegatesTo(UrlPath) Closure closure) {
this.urlPath = new UrlPath(path)
closure.delegate = urlPath
closure()
}
/**
* Allows to configure HTTP headers
*/
void headers(@DelegatesTo(RequestHeaders) Closure closure) {
this.headers = new RequestHeaders()
closure.delegate = headers
closure()
}
/**
* Allows to configure HTTP cookies
*/
void cookies(@DelegatesTo(RequestCookies) Closure closure) {
this.cookies = new RequestCookies()
closure.delegate = cookies
closure()
}
/**
* Allows set an HTTP body
*/
void body(Map<String, Object> body) {
this.body = new Body(convertObjectsToDslProperties(body))
}
/**
* Allows set an HTTP body
*/
void body(List body) {
this.body = new Body(convertObjectsToDslProperties(body))
}
/**
* Allows set an HTTP body
*/
void body(DslProperty dslProperty) {
this.body = new Body(dslProperty)
}
/**
* Allows set an HTTP body
*/
void body(Object bodyAsValue) {
this.body = new Body(bodyAsValue)
}
@@ -157,46 +215,79 @@ class Request extends Common {
return body
}
/**
* Allows to set multipart via the map notation
*/
void multipart(Map<String, Object> body) {
this.multipart = new Multipart(convertObjectsToDslProperties(body))
}
/**
* Allows to set multipart via lists
*/
void multipart(List multipartAsList) {
this.multipart = new Multipart(convertObjectsToDslProperties(multipartAsList))
}
/**
* Allows to set multipart value
*/
void multipart(DslProperty dslProperty) {
this.multipart = new Multipart(dslProperty)
}
/**
* Allows to set multipart value
*/
void multipart(Object multipartAsValue) {
this.multipart = new Multipart(multipartAsValue)
}
/**
* Sets the equality check to the given query parameter
*/
MatchingStrategy equalTo(Object value) {
return new MatchingStrategy(value, MatchingStrategy.Type.EQUAL_TO)
}
/**
* Sets the containing check to the given query parameter
*/
MatchingStrategy containing(Object value) {
return new MatchingStrategy(value, MatchingStrategy.Type.CONTAINS)
}
/**
* Sets the matching check to the given query parameter
*/
MatchingStrategy matching(Object value) {
return new MatchingStrategy(value, MatchingStrategy.Type.MATCHING)
}
/**
* Sets the not matching check to the given query parameter
*/
MatchingStrategy notMatching(Object value) {
return new MatchingStrategy(value, MatchingStrategy.Type.NOT_MATCHING)
}
/**
* Sets the XML equality check to the body
*/
MatchingStrategy equalToXml(Object value) {
return new MatchingStrategy(value, MatchingStrategy.Type.EQUAL_TO_XML)
}
/**
* Sets the JSON equality check to the body
*/
MatchingStrategy equalToJson(Object value) {
return new MatchingStrategy(value, MatchingStrategy.Type.EQUAL_TO_JSON)
}
/**
* Sets absence scheck to the given query parameter
*/
MatchingStrategy absent() {
return new MatchingStrategy(true, MatchingStrategy.Type.ABSENT)
}
@@ -205,6 +296,9 @@ class Request extends Common {
throw new IllegalStateException("Optional can be used only for the stub side of the request!")
}
/**
* Allows to set a dynamic value for the given element
*/
DslProperty value(ClientDslProperty client) {
Object concreteValue = client.serverValue
Object dynamicValue = client.clientValue
@@ -216,22 +310,37 @@ class Request extends Common {
return new DslProperty(dynamicValue, concreteValue)
}
/**
* Allows to set a dynamic value for the given regular expression element
*/
DslProperty $(RegexProperty property) {
return value(property)
}
/**
* Allows to set a dynamic value for the given regular expression element
*/
DslProperty value(RegexProperty property) {
return value(client(property))
}
/**
* Allows to set a dynamic value for the given element
*/
DslProperty $(ClientDslProperty client) {
return value(client)
}
/**
* Allows to set a dynamic value for the Pattern element
*/
DslProperty value(Pattern client) {
return value(new RegexProperty(client))
}
/**
* Allows to set a dynamic value for the given Pattern element
*/
DslProperty $(Pattern client) {
return value(client)
}
@@ -250,12 +359,18 @@ class Request extends Common {
bodyMatchers(closure)
}
/**
* Allows to set matchers for the body
*/
void bodyMatchers(@DelegatesTo(BodyMatchers) Closure closure) {
this.bodyMatchers = new BodyMatchers()
closure.delegate = this.bodyMatchers
closure()
}
/**
* Allows to set a dynamic value for client and server side
*/
@Override
DslProperty value(ClientDslProperty client, ServerDslProperty server) {
if (server.clientValue instanceof RegexProperty) {
@@ -264,6 +379,9 @@ class Request extends Common {
return super.value(client, server)
}
/**
* Allows to set a dynamic value for client and server side
*/
@Override
DslProperty value(ServerDslProperty server, ClientDslProperty client) {
if (server.clientValue instanceof RegexProperty) {

View File

@@ -59,34 +59,55 @@ class Response extends Common {
this.body = response.body
}
/**
* Allows to set the HTTP status
*/
void status(int status) {
this.status = toDslProperty(status)
}
/**
* Allows to set the HTTP status
*/
void status(DslProperty status) {
this.status = toDslProperty(status)
}
/**
* Allows to configure HTTP headers
*/
void headers(@DelegatesTo(ResponseHeaders) Closure closure) {
this.headers = new ResponseHeaders()
closure.delegate = headers
closure()
}
/**
* Allows to configure HTTP cookies
*/
void cookies(@DelegatesTo(ResponseCookies) Closure closure) {
this.cookies = new ResponseCookies()
closure.delegate = cookies
closure()
}
/**
* Allows set an HTTP body
*/
void body(Map<String, Object> body) {
this.body = new Body(convertObjectsToDslProperties(body))
}
/**
* Allows set an HTTP body
*/
void body(List body) {
this.body = new Body(convertObjectsToDslProperties(body))
}
/**
* Allows set an HTTP body
*/
void body(Object bodyAsValue) {
if (bodyAsValue instanceof List) {
body(bodyAsValue as List)
@@ -95,10 +116,17 @@ class Response extends Common {
}
}
/**
* Allows to set a fixed delay of the response in milliseconds
*/
void fixedDelayMilliseconds(int timeInMilliseconds) {
this.delay = toDslProperty(timeInMilliseconds)
}
/**
* Turns on the asynchronous mode for this contract. Used with MockMvc and the
* Servlet 3.0 features
*/
void async() {
this.async = true
}
@@ -107,6 +135,9 @@ class Response extends Common {
throw new IllegalStateException("Optional can be used only in the test side of the response!")
}
/**
* Allows to set a dynamic value for the given element
*/
DslProperty value(ServerDslProperty server) {
Object dynamicValue = server.serverValue
Object concreteValue = server.clientValue
@@ -116,22 +147,37 @@ class Response extends Common {
return new DslProperty(concreteValue, dynamicValue)
}
/**
* Allows to set a dynamic value for the given element
*/
DslProperty $(ServerDslProperty server) {
return value(server)
}
/**
* Allows to set a dynamic value for the given element
*/
DslProperty value(Pattern server) {
return value(new RegexProperty(server))
}
/**
* Allows to set a dynamic value for the given element
*/
DslProperty value(RegexProperty server) {
return value(new ServerDslProperty(server))
}
/**
* Allows to set a dynamic value for the given element
*/
DslProperty $(RegexProperty server) {
return value(server)
}
/**
* Allows to set a dynamic value for the given element
*/
DslProperty $(Pattern server) {
return value(new RegexProperty(server))
}
@@ -150,16 +196,25 @@ class Response extends Common {
bodyMatchers(closure)
}
/**
* Allows to set matchers for the body
*/
void bodyMatchers(@DelegatesTo(ResponseBodyMatchers) Closure closure) {
this.bodyMatchers = new ResponseBodyMatchers()
closure.delegate = this.bodyMatchers
closure()
}
/**
* Allows to reference entries from the request
*/
FromRequest fromRequest() {
return new FromRequest()
}
/**
* Allows to set a dynamic value for the given element
*/
@Override
DslProperty value(ClientDslProperty client, ServerDslProperty server) {
if (client.clientValue instanceof RegexProperty) {
@@ -168,6 +223,9 @@ class Response extends Common {
return super.value(client, server)
}
/**
* Allows to set a dynamic value for the given element
*/
@Override
DslProperty value(ServerDslProperty server, ClientDslProperty client) {
if (client.clientValue instanceof RegexProperty) {