Fix #262 - support maps in list
This commit is contained in:
@@ -171,6 +171,42 @@ class DslToWireMockClientConverterSpec extends Specification {
|
||||
}
|
||||
''', json, false)
|
||||
}
|
||||
|
||||
|
||||
@Issue("262")
|
||||
def "should create stub with map inside list"() {
|
||||
given:
|
||||
def converter = new DslToWireMockClientConverter()
|
||||
and:
|
||||
File file = tmpFolder.newFile("dsl-mapinlist.groovy")
|
||||
file.write("""
|
||||
io.codearte.accurest.dsl.GroovyDsl.make {
|
||||
request {
|
||||
method 'GET'
|
||||
urlPath '/foos'
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body([[id: value(
|
||||
client('123'),
|
||||
server(regex('[0-9]+'))
|
||||
)], [id: value(
|
||||
client('567'),
|
||||
server(regex('[0-9]+'))
|
||||
)]])
|
||||
headers {
|
||||
header 'Content-Type': 'application/json'
|
||||
}
|
||||
}
|
||||
}
|
||||
""")
|
||||
when:
|
||||
String json = converter.convertContent("test", new Contract(file.toPath(), false, 0, null))
|
||||
then:
|
||||
JSONAssert.assertEquals('''
|
||||
{"request":{"urlPath":"/foos","method":"GET"},"response":{"body":"[{\\"id\\":\\"123\\"},{\\"id\\":\\"567\\"}]"}}
|
||||
''', json, false)
|
||||
}
|
||||
|
||||
def 'should convert dsl to wiremock to show it in the docs'() {
|
||||
given:
|
||||
|
||||
@@ -69,7 +69,15 @@ abstract class BaseWireMockStubStrategy {
|
||||
}
|
||||
|
||||
public String parseBody(List list, ContentType contentType) {
|
||||
return parseBody(toJson(list), contentType)
|
||||
List result = []
|
||||
list.each {
|
||||
if (it instanceof Map) {
|
||||
result += MapConverter.getStubSideValues(it)
|
||||
} else {
|
||||
result += parseBody(it, contentType)
|
||||
}
|
||||
}
|
||||
return parseBody(toJson(result), contentType)
|
||||
}
|
||||
|
||||
public String parseBody(GString value, ContentType contentType) {
|
||||
|
||||
@@ -1168,6 +1168,38 @@ World.'''"""
|
||||
"MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
}
|
||||
|
||||
@Issue('262')
|
||||
def "should generate proper test code with map inside list"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
method 'GET'
|
||||
urlPath '/foos'
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body([[id: value(
|
||||
client('123'),
|
||||
server(regex('[0-9]+'))
|
||||
)], [id: value(
|
||||
client('567'),
|
||||
server(regex('[0-9]+'))
|
||||
)]])
|
||||
headers {
|
||||
header('Content-Type': 'application/json;charset=UTF-8')
|
||||
}
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new MockMvcSpockMethodRequestProcessingBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.then(blockBuilder)
|
||||
def test = blockBuilder.toString()
|
||||
then:
|
||||
test.contains('assertThatJson(parsedJson).array().contains("id").matches("[0-9]+")')
|
||||
}
|
||||
|
||||
|
||||
GroovyDsl dslForDocs =
|
||||
// tag::dsl_example[]
|
||||
io.codearte.accurest.dsl.GroovyDsl.make {
|
||||
|
||||
Reference in New Issue
Block a user