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:
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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}
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user