Fixed the generation of values for regexs
This commit is contained in:
@@ -20,6 +20,9 @@ import groovy.transform.CompileStatic
|
||||
import groovy.transform.EqualsAndHashCode
|
||||
import groovy.transform.ToString
|
||||
import groovy.transform.TypeChecked
|
||||
import repackaged.nl.flotsam.xeger.Xeger
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
/**
|
||||
* Represents an input for messaging. The input can be a message or some
|
||||
@@ -77,6 +80,14 @@ class Input extends Common {
|
||||
closure()
|
||||
}
|
||||
|
||||
DslProperty value(ClientDslProperty client) {
|
||||
Object clientValue = client.clientValue
|
||||
if (client.clientValue instanceof Pattern) {
|
||||
clientValue = new Xeger(((Pattern)client.clientValue).pattern()).generate()
|
||||
}
|
||||
return new DslProperty(client.clientValue, clientValue)
|
||||
}
|
||||
|
||||
static class BodyType extends DslProperty {
|
||||
|
||||
BodyType(Object clientValue, Object serverValue) {
|
||||
|
||||
@@ -20,6 +20,9 @@ import groovy.transform.CompileStatic
|
||||
import groovy.transform.EqualsAndHashCode
|
||||
import groovy.transform.ToString
|
||||
import groovy.transform.TypeChecked
|
||||
import repackaged.nl.flotsam.xeger.Xeger
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
@TypeChecked
|
||||
@EqualsAndHashCode
|
||||
@@ -47,14 +50,6 @@ class OutputMessage extends Common {
|
||||
this.sentTo = sentTo
|
||||
}
|
||||
|
||||
ServerDslProperty producer(Object clientValue) {
|
||||
return new ServerDslProperty(clientValue)
|
||||
}
|
||||
|
||||
ClientDslProperty consumer(Object clientValue) {
|
||||
return new ClientDslProperty(clientValue)
|
||||
}
|
||||
|
||||
void body(Object bodyAsValue) {
|
||||
this.body = new DslProperty(bodyAsValue)
|
||||
}
|
||||
@@ -72,6 +67,14 @@ class OutputMessage extends Common {
|
||||
void assertThat(String assertThat) {
|
||||
this.assertThat = new ExecutionProperty(assertThat)
|
||||
}
|
||||
|
||||
DslProperty value(ServerDslProperty server) {
|
||||
Object value = server.clientValue
|
||||
if (server.clientValue instanceof Pattern) {
|
||||
value = new Xeger(((Pattern)server.clientValue).pattern()).generate()
|
||||
}
|
||||
return new DslProperty(value, server.serverValue)
|
||||
}
|
||||
}
|
||||
|
||||
@CompileStatic
|
||||
|
||||
@@ -92,7 +92,7 @@ class Response extends Common {
|
||||
if (server.clientValue instanceof Pattern) {
|
||||
value = new Xeger(((Pattern)server.clientValue).pattern()).generate()
|
||||
}
|
||||
return new DslProperty(server.clientValue, value)
|
||||
return new DslProperty(value, server.serverValue)
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package org.springframework.cloud.contract.spec.internal
|
||||
|
||||
import spock.lang.Specification
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@@ -32,6 +35,7 @@ class ResponseSpec extends Specification {
|
||||
property = value(producer(regex("[0-9]{5}")))
|
||||
}
|
||||
then:
|
||||
(property.serverValue as String).matches(/[0-9]{5}/)
|
||||
(property.clientValue as String).matches(/[0-9]{5}/)
|
||||
(property.serverValue as Pattern).pattern() == '[0-9]{5}'
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user