Additional functionality

This commit is contained in:
Tim Ysewyn
2019-08-08 00:17:12 +02:00
parent 981463dbf7
commit 8a2a1a3251
3 changed files with 65 additions and 4 deletions

View File

@@ -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<Any>, value: DslProperty<Any>) = NamedProperty(name, value)
fun named(name: DslProperty<Any>, value: DslProperty<Any>,
contentType: DslProperty<Any>) = NamedProperty(name, value, contentType)
fun named(namedMap: Map<String, DslProperty<Any>>) = NamedProperty(namedMap)
/* REGEX */
fun regexProperty(value: Any) = RegexProperty(value)

View File

@@ -83,6 +83,54 @@ open class RequestDsl : CommonDsl(), RegexCreatingProperty<ClientDslProperty> {
/* 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)

View File

@@ -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())
}