Fixed issues with Pact conversion after upgrade (#1323)
This commit is contained in:
@@ -81,22 +81,10 @@ class BodyConverter {
|
||||
}
|
||||
DslPart p = isRoot ? createRootDslPart(v) : parent
|
||||
if (v instanceof Map) {
|
||||
if (!isRoot) {
|
||||
p = p.object()
|
||||
}
|
||||
processMap(v as Map, p as PactDslJsonBody, dslPropertyValueExtractor)
|
||||
if (!isRoot) {
|
||||
p = p.closeObject()
|
||||
}
|
||||
}
|
||||
else if (v instanceof Collection) {
|
||||
if (!isRoot) {
|
||||
p = p.array()
|
||||
}
|
||||
processCollection(v as Collection, p as PactDslJsonArray, dslPropertyValueExtractor)
|
||||
if (!isRoot) {
|
||||
p = p.closeArray()
|
||||
}
|
||||
}
|
||||
return p
|
||||
}
|
||||
@@ -123,8 +111,15 @@ class BodyConverter {
|
||||
else if (v instanceof Number) {
|
||||
jsonArray.number(v)
|
||||
}
|
||||
else {
|
||||
traverse(it, jsonArray, dslPropertyValueExtractor)
|
||||
else if (v instanceof Map) {
|
||||
PactDslJsonBody current = jsonArray.object()
|
||||
traverse(v, current, dslPropertyValueExtractor)
|
||||
current.closeObject()
|
||||
}
|
||||
else if (v instanceof Collection) {
|
||||
PactDslJsonArray current = jsonArray.array()
|
||||
traverse(v, current, dslPropertyValueExtractor)
|
||||
current.closeArray()
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -146,11 +141,16 @@ class BodyConverter {
|
||||
else if (v instanceof Number) {
|
||||
jsonObject.numberValue(k, v)
|
||||
}
|
||||
else {
|
||||
else if (v instanceof Map) {
|
||||
PactDslJsonBody current = jsonObject.object(k)
|
||||
traverse(v, current, dslPropertyValueExtractor)
|
||||
current.closeObject()
|
||||
}
|
||||
else if (v instanceof Collection) {
|
||||
PactDslJsonArray current = jsonObject.array(k)
|
||||
traverse(v, current, dslPropertyValueExtractor)
|
||||
current.closeArray()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -800,6 +800,42 @@ class PactContractConverterSpec extends Specification {
|
||||
then:
|
||||
contracts == expectedContracts
|
||||
}
|
||||
|
||||
@Issue("1277")
|
||||
def "should work properly with json body"() {
|
||||
when:
|
||||
converter.convertTo([
|
||||
Contract.make {
|
||||
request {
|
||||
method 'PUT'
|
||||
url '/api/admins/1'
|
||||
body('''{
|
||||
"username" : "username",
|
||||
"password" : "password",
|
||||
"roles" : [ "ADMIN" ]
|
||||
}''')
|
||||
headers {
|
||||
header('''Content-Type''', '''application/json;charset=UTF-8''')
|
||||
}
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body('''{
|
||||
"admin" : {
|
||||
"adminId" : 1,
|
||||
"username" : "username",
|
||||
"roles" : [ "ADMIN" ]
|
||||
}
|
||||
}''')
|
||||
headers {
|
||||
header('''Content-Type''', '''application/json;charset=UTF-8''')
|
||||
}
|
||||
}
|
||||
}
|
||||
])
|
||||
then:
|
||||
noExceptionThrown()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user