Additional functionality
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user