Fixed nested lists etc.

This commit is contained in:
Marcin Grzejszczak
2015-02-22 13:58:01 +01:00
parent 3ca2cd35cb
commit dfee248b0f
2 changed files with 76 additions and 0 deletions

View File

@@ -26,4 +26,76 @@ class DslToWiremockClientConverterSpec extends Specification {
new JsonSlurper().parseText(json) == new JsonSlurper().parseText("""
{"request":{"method":"PUT","urlPattern":"/[0-9]{2}"},"response":{"status":200}}""")
}
def "should convert DSL file with a nested list to Wiremock JSON"() {
given:
def converter = new DslToWiremockClientConverter()
and:
String dslBody = """
io.coderate.accurest.dsl.GroovyDsl.make {
request {
method 'PUT'
url '/api/12'
headers {
header 'Content-Type': 'application/vnd.com.ofg.twitter-places-analyzer.v1+json'
}
body '''
[{
"created_at": "Sat Jul 26 09:38:57 +0000 2014",
"id": 492967299297845248,
"id_str": "492967299297845248",
"text": "Gonna see you at Warsaw",
"place":
{
"attributes":{},
"bounding_box":
{
"coordinates":
[[
[-77.119759,38.791645],
[-76.909393,38.791645],
[-76.909393,38.995548],
[-77.119759,38.995548]
]],
"type":"Polygon"
},
"country":"United States",
"country_code":"US",
"full_name":"Washington, DC",
"id":"01fbe706f872cb32",
"name":"Washington",
"place_type":"city",
"url": "http://api.twitter.com/1/geo/id/01fbe706f872cb32.json"
}
}]
'''
}
response {
status 200
}
}
"""
when:
String json = converter.convertContent(dslBody)
then:
new JsonSlurper().parseText(json) == new JsonSlurper().parseText("""{
"request":{
"method":"PUT",
"url":"/api/12",
"body": {
"equalTo": "[{\\"created_at\\":\\"Sat Jul 26 09:38:57 +0000 2014\\",\\"id\\":492967299297845248,\\"id_str\\":\\"492967299297845248\\",\\"place\\":{\\"attributes\\":{},\\"bounding_box\\":{\\"coordinates\\":[[[-77.119759,38.791645],[-76.909393,38.791645],[-76.909393,38.995548],[-77.119759,38.995548]]],\\"type\\":\\"Polygon\\"},\\"country\\":\\"United States\\",\\"country_code\\":\\"US\\",\\"full_name\\":\\"Washington, DC\\",\\"id\\":\\"01fbe706f872cb32\\",\\"name\\":\\"Washington\\",\\"place_type\\":\\"city\\",\\"url\\":\\"http://api.twitter.com/1/geo/id/01fbe706f872cb32.json\\"},\\"text\\":\\"Gonna see you at Warsaw\\"}]"
},
"headers": {
"Content-Type": {
"equalTo": "application/vnd.com.ofg.twitter-places-analyzer.v1+json"
}
}
},
"response":{
"status":200}
}
""")
}
}

View File

@@ -57,6 +57,10 @@ class WiremockRequestStubStrategy extends BaseWiremockStubStrategy {
}
}
private String parseBody(List responseBody) {
return JsonOutput.toJson(responseBody)
}
private String parseBody(Map responseBody) {
return JsonOutput.toJson(responseBody)
}