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 5f4f7eb7dd..2d9a34d62e 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 @@ -101,14 +101,20 @@ open class CommonDsl { * @param charset to use for converting the bytes to String * @return String file contents */ - fun file(relativePath: String, charset: Charset) = Body(FromFileProperty(fileLocation(relativePath), String::class.java, charset)) + fun file(relativePath: String, charset: Charset) = FromFileProperty(fileLocation(relativePath), String::class.java, charset) /** * Read file contents as bytes[]. * @param relativePath of the file to read * @return String file contents */ - fun fileAsBytes(relativePath: String) = Body(FromFileProperty(fileLocation(relativePath), ByteArray::class.java)) + fun fileAsBytes(relativePath: String) = FromFileProperty(fileLocation(relativePath), ByteArray::class.java) + + fun bodyFromFile(relativePath: String) = bodyFromFile(relativePath, Charset.defaultCharset()) + + fun bodyFromFile(relativePath: String, charset: Charset) = Body(FromFileProperty(fileLocation(relativePath), String::class.java, charset)) + + fun bodyFromFileAsBytes(relativePath: String) = Body(FromFileProperty(fileLocation(relativePath), ByteArray::class.java)) /** * Read file contents as array of bytes. @@ -125,6 +131,13 @@ open class CommonDsl { } } + fun named(name: DslProperty, value: DslProperty) = NamedProperty(name, value) + + fun named(name: DslProperty, value: DslProperty, + contentType: DslProperty) = NamedProperty(name, value, contentType) + + fun named(namedMap: Map>) = NamedProperty(namedMap) + /* REGEX */ fun regexProperty(value: Any) = RegexProperty(value) 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 cbaaab54f4..4c0b7b103b 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 @@ -83,6 +83,54 @@ open class RequestDsl : CommonDsl(), RegexCreatingProperty { /* HELPER FUNCTIONS */ + /** + * Sets the equality check to the given query parameter. + * @param value value to check against + * @return matching strategy + */ + fun equalTo(value: Any) = MatchingStrategy(value, MatchingStrategy.Type.EQUAL_TO) + + /** + * Sets the containing check to the given query parameter. + * @param value value to check against + * @return matching strategy + */ + fun containing(value: Any) = MatchingStrategy(value, MatchingStrategy.Type.CONTAINS) + + /** + * Sets the matching check to the given query parameter. + * @param value value to check against + * @return matching strategy + */ + fun matching(value: Any) = MatchingStrategy(value, MatchingStrategy.Type.MATCHING) + + /** + * Sets the not matching check to the given query parameter. + * @param value value to check against + * @return matching strategy + */ + fun notMatching(value: Any) = MatchingStrategy(value, MatchingStrategy.Type.NOT_MATCHING) + + /** + * Sets the XML equality check to the body. + * @param value value to check against + * @return matching strategy + */ + fun equalToXml(value: Any) = MatchingStrategy(value, MatchingStrategy.Type.EQUAL_TO_XML) + + /** + * Sets the JSON equality check to the body. + * @param value value to check against + * @return matching strategy + */ + fun equalToJson(value: Any) = MatchingStrategy(value, MatchingStrategy.Type.EQUAL_TO_JSON) + + /** + * Sets absence check to the given query parameter. + * @return matching strategy + */ + fun absent() = MatchingStrategy(true, MatchingStrategy.Type.ABSENT) + fun value(value: ClientDslProperty) = delegate.value(value) fun v(value: ClientDslProperty) = delegate.value(value) diff --git a/specs/spring-cloud-contract-spec-kotlin/src/test/resources/contracts/shouldWorkWithBinaryPayload.kts b/specs/spring-cloud-contract-spec-kotlin/src/test/resources/contracts/shouldWorkWithBinaryPayload.kts index 19664fd291..3ba4406cb9 100644 --- a/specs/spring-cloud-contract-spec-kotlin/src/test/resources/contracts/shouldWorkWithBinaryPayload.kts +++ b/specs/spring-cloud-contract-spec-kotlin/src/test/resources/contracts/shouldWorkWithBinaryPayload.kts @@ -26,11 +26,11 @@ contract { headers { contentType(applicationOctetStream()) } - body = fileAsBytes("contracts/request.pdf") + body = bodyFromFileAsBytes("contracts/request.pdf") } response { status = code(200) - body = fileAsBytes("contracts/response.pdf") + body = bodyFromFileAsBytes("contracts/response.pdf") headers { contentType(applicationOctetStream()) }