Fixed missing concrete value generation from a regex for messaging

fixes gh-650
This commit is contained in:
Marcin Grzejszczak
2018-05-11 14:29:51 +02:00
parent 077e18aa25
commit 45b566111a
4 changed files with 72 additions and 7 deletions

View File

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

View File

@@ -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) {