Fixed missing concrete value generation from a regex for messaging
fixes gh-650
This commit is contained in:
@@ -16,7 +16,10 @@
|
||||
|
||||
package org.springframework.cloud.contract.spec.internal
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
import groovy.transform.CompileStatic
|
||||
import groovy.transform.PackageScope
|
||||
import groovy.transform.ToString
|
||||
|
||||
/**
|
||||
@@ -41,6 +44,10 @@ class OptionalProperty implements Serializable {
|
||||
return "($value)?"
|
||||
}
|
||||
|
||||
protected Pattern optionalPatternValue() {
|
||||
return Pattern.compile(optionalPattern())
|
||||
}
|
||||
|
||||
@Override
|
||||
String toString() {
|
||||
return optionalPattern()
|
||||
|
||||
@@ -88,16 +88,26 @@ class OutputMessage extends Common {
|
||||
this.assertThat = new ExecutionProperty(assertThat)
|
||||
}
|
||||
|
||||
DslProperty value(ServerDslProperty server) {
|
||||
Object value = server.clientValue
|
||||
if (server.clientValue instanceof Pattern) {
|
||||
value = StringEscapeUtils.escapeJava(new Xeger(((Pattern)server.clientValue).pattern()).generate())
|
||||
DslProperty value(ClientDslProperty clientDslProperty) {
|
||||
Object clientValue = clientDslProperty.clientValue
|
||||
// for the output messages ran via stub runner,
|
||||
// entries have to have fixed values
|
||||
if (clientDslProperty.clientValue instanceof Pattern) {
|
||||
clientValue = StringEscapeUtils.escapeJava(new Xeger(((Pattern)clientDslProperty.clientValue).pattern()).generate())
|
||||
}
|
||||
return new DslProperty(value, server.serverValue)
|
||||
return new DslProperty(clientValue, clientDslProperty.clientValue)
|
||||
}
|
||||
|
||||
DslProperty $(ServerDslProperty server) {
|
||||
return value(server)
|
||||
DslProperty $(ClientDslProperty client) {
|
||||
return value(client)
|
||||
}
|
||||
|
||||
DslProperty $(Pattern pattern) {
|
||||
return value(client(pattern))
|
||||
}
|
||||
|
||||
DslProperty $(OptionalProperty property) {
|
||||
return value(client(property.optionalPatternValue()))
|
||||
}
|
||||
|
||||
void testMatchers(@DelegatesTo(ResponseBodyMatchers) Closure closure) {
|
||||
|
||||
Reference in New Issue
Block a user