Problem with auto-generated values from regex inside the respose body

added missing `$()` method for consumer and producer side only

fixes #94
This commit is contained in:
Marcin Grzejszczak
2016-10-04 15:12:55 +02:00
parent 09cf63a600
commit 8e68dcedd4
4 changed files with 40 additions and 1 deletions

View File

@@ -182,6 +182,10 @@ class Request extends Common {
return new DslProperty(client.clientValue, clientValue)
}
DslProperty $(ClientDslProperty client) {
return value(client)
}
@Override
DslProperty value(ClientDslProperty client, ServerDslProperty server) {
if (server.clientValue instanceof Pattern) {

View File

@@ -95,6 +95,10 @@ class Response extends Common {
return new DslProperty(value, server.serverValue)
}
DslProperty $(ServerDslProperty server) {
return value(server)
}
@Override
DslProperty value(ClientDslProperty client, ServerDslProperty server) {
if (client.clientValue instanceof Pattern) {

View File

@@ -16,6 +16,7 @@
package org.springframework.cloud.contract.verifier.wiremock
import com.github.tomakehurst.wiremock.stubbing.StubMapping
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import org.skyscreamer.jsonassert.JSONAssert
@@ -223,6 +224,37 @@ class DslToWireMockClientConverterSpec extends Specification {
''', json, false)
}
@Issue("94")
def "should create stub when response has only one side of the dynamic value"() {
given:
def converter = new DslToWireMockClientConverter()
and:
File file = tmpFolder.newFile("dsl-dynamic.groovy")
file.write("""
org.springframework.cloud.contract.spec.Contract.make {
request {
method 'GET'
urlPath '/foos'
}
response {
status 200
body(
digit: \$(producer(regex('[0-9]{1}'))),
id: \$(producer(regex(number())))
)
}
}
""")
when:
String json = converter.convertContent("test", new ContractMetadata(file.toPath(), false, 0, null))
StubMapping.buildFrom(json)
then:
noExceptionThrown()
and:
!json.contains('cursor')
}
def 'should convert dsl to wiremock to show it in the docs'() {
given:
def converter = new DslToWireMockClientConverter()

View File

@@ -29,7 +29,6 @@ import org.springframework.cloud.contract.verifier.util.ContentType
import static org.springframework.cloud.contract.verifier.util.ContentUtils.recognizeContentTypeFromContent
import static org.springframework.cloud.contract.verifier.util.ContentUtils.recognizeContentTypeFromHeader
/**
* Converts a {@link Request} into {@link ResponseDefinition}
*