Support pattern properties in messaging contracts (#564)

This commit is contained in:
mfeygelson
2018-03-05 03:22:31 -06:00
committed by Marcin Grzejszczak
parent 1862f6674a
commit c4ab64757f
3 changed files with 56 additions and 0 deletions

View File

@@ -35,6 +35,8 @@ import java.util.regex.Pattern
@ToString(includePackage = false, includeNames = true)
class Input extends Common {
@Delegate ClientPatternValueDslProperty property = new ClientPatternValueDslProperty()
DslProperty<String> messageFrom
ExecutionProperty triggeredBy
Headers messageHeaders = new Headers()
@@ -111,6 +113,17 @@ class Input extends Common {
closure.delegate = this.matchers
closure()
}
@CompileStatic
@EqualsAndHashCode(includeFields = true)
@ToString(includePackage = false)
private class ClientPatternValueDslProperty extends PatternValueDslProperty<ClientDslProperty> {
@Override
protected ClientDslProperty createProperty(Pattern pattern, Object generatedValue) {
return new ClientDslProperty(pattern, generatedValue)
}
}
}

View File

@@ -29,6 +29,8 @@ import java.util.regex.Pattern
@ToString(includePackage = false, includeNames = true)
class OutputMessage extends Common {
@Delegate ServerPatternValueDslProperty property = new ServerPatternValueDslProperty()
DslProperty<String> sentTo
Headers headers
DslProperty body
@@ -82,6 +84,17 @@ class OutputMessage extends Common {
closure.delegate = this.matchers
closure()
}
@CompileStatic
@EqualsAndHashCode(includeFields = true)
@ToString(includePackage = false)
private class ServerPatternValueDslProperty extends PatternValueDslProperty<ServerDslProperty> {
@Override
protected ServerDslProperty createProperty(Pattern pattern, Object generatedValue) {
return new ServerDslProperty(pattern, generatedValue)
}
}
}
@CompileStatic

View File

@@ -66,6 +66,36 @@ class ContractSpec extends Specification {
noExceptionThrown()
}
def 'should work for messaging with pattern properties'() {
when:
Contract.make {
input {
messageFrom('input')
messageBody([
foo: anyNonBlankString()
])
messageHeaders {
header([
foo: anyNumber()
])
}
}
outputMessage {
sentTo('output')
body([
foo2: anyNonEmptyString()
])
headers {
header([
foo2: anyIpAddress()
])
}
}
}
then:
noExceptionThrown()
}
def 'should generate a value if only regex is passed for client'() {
given:
Request request = new Request()