diff --git a/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/ContractDsl.kt b/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/ContractDsl.kt index 2410010d57..de74819ee7 100644 --- a/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/ContractDsl.kt +++ b/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/ContractDsl.kt @@ -28,6 +28,7 @@ import org.springframework.cloud.contract.spec.internal.ResponseDsl /** * @author Tim Ysewyn + * @since 2.2.0 */ @ContractDslMarker class ContractDsl { @@ -36,31 +37,96 @@ class ContractDsl { fun contract(dsl: ContractDsl.() -> Unit): Contract = ContractDsl().apply(dsl).get() } + /** + * 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. + */ var priority: Int? = null + + /** + * The label by which you'll reference the contract on the message consumer side. + */ var label: String? = null + + /** + * Description of a contract. May be used in the documentation generation. + */ var description: String? = null + + /** + * 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. + */ var name: String? = null + + /** + * Whether the contract should be ignored or not. + */ var ignored: Boolean = false + + /** + * Whether the contract is in progress. It's not ignored, but the feature is not yet + * finished. Used together with the {@code generateStubs} option. + */ var inProgress: Boolean = false + + /** + * The HTTP request part of the contract. + */ var request: Request? = null + + /** + * The HTTP response part of the contract. + */ var response: Response? = null + + /** + * The input side of a messaging contract. + */ var input: Input? = null + + /** + * The output side of a messaging contract. + */ var outputMessage: OutputMessage? = null - fun request(request: RequestDsl.() -> Unit) { - this.request = RequestDsl().apply(request).get() + /** + * The HTTP request part of the contract. + * @param configurer lambda to configure the HTTP request + */ + fun request(configurer: RequestDsl.() -> Unit) { + request = RequestDsl().apply(configurer).get() } - fun response(response: ResponseDsl.() -> Unit) { - this.response = ResponseDsl().apply(response).get() + /** + * The HTTP response part of the contract. + * @param configurer lambda to configure the HTTP response + */ + fun response(configurer: ResponseDsl.() -> Unit) { + response = ResponseDsl().apply(configurer).get() } - fun input(input: InputDsl.() -> Unit) { - this.input = InputDsl().apply(input).get() + /** + * The input part of the contract. + * @param configurer lambda to configure the input message + */ + fun input(configurer: InputDsl.() -> Unit) { + input = InputDsl().apply(configurer).get() } - fun outputMessage(outputMessage: OutputMessageDsl.() -> Unit) { - this.outputMessage = OutputMessageDsl().apply(outputMessage).get() + /** + * The output part of the contract. + * @param configurer lambda to configure the output message + */ + fun outputMessage(configurer: OutputMessageDsl.() -> Unit) { + outputMessage = OutputMessageDsl().apply(configurer).get() } private fun get(): Contract { diff --git a/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/ContractDslExtensions.kt b/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/ContractDslExtensions.kt index cbfb6601fe..9bf3327bf8 100644 --- a/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/ContractDslExtensions.kt +++ b/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/ContractDslExtensions.kt @@ -24,7 +24,9 @@ import java.lang.IllegalStateException import java.util.stream.Collectors /** + * Class extension functions which make our lives easier. * @author Tim Ysewyn + * @since 2.2.0 */ infix fun Url.withQueryParameters(parameters: QueryParameters.() -> Unit) = apply { queryParameters = QueryParameters().apply(parameters) diff --git a/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/BodyMatchersDsl.kt b/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/BodyMatchersDsl.kt index d2cfac0495..f37b13ce72 100644 --- a/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/BodyMatchersDsl.kt +++ b/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/BodyMatchersDsl.kt @@ -19,7 +19,10 @@ package org.springframework.cloud.contract.spec.internal import java.util.regex.Pattern /** + * Matching strategy of dynamic parts of the body. + * * @author Tim Ysewyn + * @since 2.2.0 */ open class BodyMatchersDsl { diff --git a/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/CommonDsl.kt b/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/CommonDsl.kt index 1084126b0a..8ac97ded10 100644 --- a/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/CommonDsl.kt +++ b/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/CommonDsl.kt @@ -22,7 +22,10 @@ import java.nio.charset.Charset import java.util.regex.Pattern /** + * Composed out of common variables and funtions. + * * @author Tim Ysewyn + * @since 2.2.0 */ open class CommonDsl { @@ -145,8 +148,18 @@ open class CommonDsl { */ fun test(serverValue: Any?) = ServerDslProperty(serverValue) + /** + * Helper method to indicate an optional property. + * @param value the optional property value + * @return optional dsl property + */ fun optional(value: Any?) = OptionalProperty(value) + /** + * Helper method to indicate that a method needs to be executed during testing. + * @param commandToExecute the name of the method to execute + * @return execution dsl property + */ fun execute(commandToExecute: String) = ExecutionProperty(commandToExecute) /** @@ -165,16 +178,33 @@ open class CommonDsl { fun file(relativePath: String, charset: Charset) = FromFileProperty(fileLocation(relativePath), String::class.java, charset) /** - * Read file contents as bytes[]. + * Read file contents as String with the given Charset. * @param relativePath of the file to read + * @param charset to use for converting the bytes to String * @return String file contents */ fun fileAsBytes(relativePath: String) = FromFileProperty(fileLocation(relativePath), ByteArray::class.java) + /** + * Read file contents as String using a default charset (mostly UTF-8). + * @param relativePath of the file to read + * @return Body DSL property with the content of the file as String + */ fun bodyFromFile(relativePath: String) = bodyFromFile(relativePath, Charset.defaultCharset()) + /** + * Read file contents as String using the provided file encoding. + * @param relativePath of the file to read + * @param charset of the file's encoding + * @return Body the body with the String as its content + */ fun bodyFromFile(relativePath: String, charset: Charset) = Body(FromFileProperty(fileLocation(relativePath), String::class.java, charset)) + /** + * Read file contents as bytes[]. + * @param relativePath of the file to read + * @return Body the body with the byte array as its content + */ fun bodyFromFileAsBytes(relativePath: String) = Body(FromFileProperty(fileLocation(relativePath), ByteArray::class.java)) /** diff --git a/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/CookiesDsl.kt b/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/CookiesDsl.kt index b987bc5a71..24d9aceb49 100644 --- a/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/CookiesDsl.kt +++ b/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/CookiesDsl.kt @@ -17,7 +17,10 @@ package org.springframework.cloud.contract.spec.internal /** + * Represents the cookies when sending/receiving HTTP traffic. + * * @author Tim Ysewyn + * @since 2.2.0 */ open class CookiesDsl : CommonDsl() { diff --git a/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/FromRequestDsl.kt b/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/FromRequestDsl.kt index 7ca6498f9e..e109f2ebd3 100644 --- a/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/FromRequestDsl.kt +++ b/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/FromRequestDsl.kt @@ -19,7 +19,10 @@ package org.springframework.cloud.contract.spec.internal import org.springframework.cloud.contract.spec.ContractTemplate /** + * Helper class to reference the request body parameters. + * * @author Tim Ysewyn + * @since 2.2.0 */ class FromRequestDsl { @@ -52,7 +55,7 @@ class FromRequestDsl { fun path() = FromRequestDslProperty(template.escapedPath()) /** - * nth value of a URL path (zero indexed) e.g. {{{ request.path.[2] }}}*. + * nth value of a URL path (zero indexed) e.g. {{{ request.path.[2] }}}. * @param index path index * @return dsl property */ @@ -74,7 +77,7 @@ class FromRequestDsl { fun header(key: String, index: Int) = FromRequestDslProperty(template.escapedHeader(key, index)) /** - * Retruns the tempalte for retrieving the first value of a cookie with certain key. + * Returns the template for retrieving the first value of a cookie with certain key. * @param key cookie key * @return dsl property */ @@ -100,7 +103,7 @@ class FromRequestDsl { fun rawUrl() = FromRequestDslProperty(template.url()) /** - * Unescaped First value of a query parameter e.g. request.query.search. + * Unescaped first value of a query parameter e.g. request.query.search. * @param key query key * @return dsl property */ @@ -122,14 +125,14 @@ class FromRequestDsl { fun rawPath() = FromRequestDslProperty(template.path()) /** - * Unescaped nth value of a URL path (zero indexed) e.g. {{{ request.path.[2]. }}}* + * Unescaped nth value of a URL path (zero indexed) e.g. {{{ request.path.[2]. }}}. * @param index path index * @return dsl property */ fun rawPath(index: Int) = FromRequestDslProperty(template.path(index)) /** - * Unescaped First value of a request header e.g. request.headers.X-Request-Id. + * Unescaped first value of a request header e.g. request.headers.X-Request-Id. * @param key header key * @return dsl property */ diff --git a/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/HeadersDsl.kt b/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/HeadersDsl.kt index 492fe6aa32..591081f5d9 100644 --- a/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/HeadersDsl.kt +++ b/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/HeadersDsl.kt @@ -17,7 +17,10 @@ package org.springframework.cloud.contract.spec.internal /** + * Represents the headers when sending/receiving HTTP traffic. + * * @author Tim Ysewyn + * @since 2.2.0 */ open class HeadersDsl: CommonDsl() { diff --git a/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/InputDsl.kt b/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/InputDsl.kt index b893a179b5..03d24bdad7 100644 --- a/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/InputDsl.kt +++ b/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/InputDsl.kt @@ -19,18 +19,46 @@ package org.springframework.cloud.contract.spec.internal import org.springframework.cloud.contract.spec.toDslProperty /** + * Represents an input for messaging. + * The input can be a message or some action inside the application. + * * @author Tim Ysewyn + * @since 2.2.0 */ @ContractDslMarker class InputDsl : CommonDsl() { private val delegate = Input() + /** + * Name of a destination from which message would come to trigger action in the + * system. + */ var messageFrom: DslProperty? = null + + /** + * Function that needs to be executed to trigger action in the system. + */ var triggeredBy: String? = null + + /** + * The message headers part of the contract. + */ var headers: Headers? = null + + /** + * The contents of the incoming message. + */ var messageBody: Input.BodyType? = null + + /** + * Function that needs to be executed after the message has been received/processed by the system. + */ var assertThat: String? = null + + /** + * The body matchers part of the contract. + */ var bodyMatchers: BodyMatchers? = null fun messageFrom(messageFrom: String) = messageFrom.toDslProperty() diff --git a/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/KotlinContractConverter.kt b/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/KotlinContractConverter.kt index ee63ced2ce..55786d3692 100644 --- a/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/KotlinContractConverter.kt +++ b/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/KotlinContractConverter.kt @@ -23,7 +23,10 @@ import java.net.URLClassLoader.newInstance import javax.script.ScriptEngineManager /** + * Converter that will convert the Kotlin DSL to Java DSL. + * * @author Tim Ysewyn + * @since 2.2.0 */ class KotlinContractConverter: ContractConverter> { diff --git a/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/MultipartDsl.kt b/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/MultipartDsl.kt index f1c4f3d486..d17950c54b 100644 --- a/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/MultipartDsl.kt +++ b/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/MultipartDsl.kt @@ -19,7 +19,10 @@ package org.springframework.cloud.contract.spec.internal import org.springframework.cloud.contract.spec.toDslProperty /** + * Represents the content when sending multipart HTTP requests. + * * @author Tim Ysewyn + * @since 2.2.0 */ class MultipartDsl { diff --git a/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/OutputMessageDsl.kt b/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/OutputMessageDsl.kt index 77c7799689..f2babfb262 100644 --- a/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/OutputMessageDsl.kt +++ b/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/OutputMessageDsl.kt @@ -19,17 +19,41 @@ package org.springframework.cloud.contract.spec.internal import org.springframework.cloud.contract.spec.toDslProperty /** + * Represents an output for messaging. + * Used for verifying the body and headers that are sent. + * * @author Tim Ysewyn + * @since 2.2.0 */ @ContractDslMarker class OutputMessageDsl : CommonDsl() { private val delegate = OutputMessage() + /** + * Name of a destination to which a message should be sent. + */ var sentTo: DslProperty? = null + + /** + * The message headers part of the contract. + */ var headers: Headers? = null + + /** + * Name of a destination from which message would come to trigger action in the + * system. + */ var body: DslProperty? = null + + /** + * Function that needs to be executed after the message has been sent out of the system. + */ var assertThat: String? = null + + /** + * The body matchers part of the contract. + */ var bodyMatchers: ResponseBodyMatchers? = null fun sentTo(sentTo: String) = sentTo.toDslProperty() diff --git a/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/RequestDsl.kt b/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/RequestDsl.kt index c410462b86..2a05fe498b 100644 --- a/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/RequestDsl.kt +++ b/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/RequestDsl.kt @@ -22,20 +22,54 @@ import org.springframework.cloud.contract.spec.util.RegexpUtils import java.util.regex.Pattern /** + * Represents the request side of the HTTP communication. + * * @author Tim Ysewyn + * @since 2.2.0 */ @ContractDslMarker open class RequestDsl : CommonDsl() { private val delegate = Request() + /** + * The HTTP method. + */ var method: DslProperty<*>? = null + + /** + * The URL to which the request will be sent. + */ var url: Url? = null + + /** + * The URL to which the request will be sent. + */ var urlPath: UrlPath? = null + + /** + * The HTTP headers which should be sent with the request. + */ var headers: Headers? = null + + /** + * The HTTP cookies which should be sent with the request. + */ var cookies: Cookies? = null + + /** + * The HTTP request body which should be sent. + */ var body: Body? = null + + /** + * The content that needs to be sent with a multipart HTTP request. + */ var multipart: Multipart? = null + + /** + * The HTTP request body matchers. + */ var bodyMatchers: BodyMatchers? = null fun method(method: String) = method.toDslProperty() diff --git a/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/ResponseBodyMatchersDsl.kt b/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/ResponseBodyMatchersDsl.kt index ccdfb9600f..1bef19c4da 100644 --- a/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/ResponseBodyMatchersDsl.kt +++ b/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/ResponseBodyMatchersDsl.kt @@ -17,7 +17,10 @@ package org.springframework.cloud.contract.spec.internal /** + * Additional matchers for the response or output message part. + * * @author Tim Ysewyn + * @since 2.2.0 */ class ResponseBodyMatchersDsl: BodyMatchersDsl() { diff --git a/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/ResponseDsl.kt b/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/ResponseDsl.kt index e2866a4e4f..7094d30a86 100644 --- a/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/ResponseDsl.kt +++ b/specs/spring-cloud-contract-spec-kotlin/src/main/kotlin/org/springframework/cloud/contract/spec/internal/ResponseDsl.kt @@ -22,20 +22,50 @@ import org.springframework.cloud.contract.spec.util.RegexpUtils import java.util.regex.Pattern /** + * Represents the response side of the HTTP communication. + * * @author Tim Ysewyn + * @since 2.2.0 */ @ContractDslMarker class ResponseDsl : CommonDsl() { private val delegate = Response() - var status: DslProperty? = null - var delay: DslProperty? = null - var headers: Headers? = null - var cookies: Cookies? = null - var body: Body? = null - var async: Boolean = false - var bodyMatchers: ResponseBodyMatchers? = null + /** + * The HTTP response status. + */ + var status: DslProperty? = null + + /** + * The HTTP response delay in milliseconds. + */ + var delay: DslProperty? = null + + /** + * The HTTP response headers. + */ + var headers: Headers? = null + + /** + * The HTTP response cookies. + */ + var cookies: Cookies? = null + + /** + * The HTTP response body. + */ + var body: Body? = null + + /** + * Indicates asynchronous communication. + */ + var async: Boolean = false + + /** + * The HTTP response body matchers. + */ + var bodyMatchers: ResponseBodyMatchers? = null fun code(code: Int): DslProperty = code.toDslProperty()