Added tests for an example with complex body inside the c() or p()
added a small fix for duplicate when().async() fixes gh-1263
This commit is contained in:
@@ -456,7 +456,7 @@ abstract class MethodBodyBuilder implements ClassVerifier {
|
||||
Object convertedResponseBody = jsonBodyVerificationBuilder
|
||||
.addJsonResponseBodyCheck(bb, responseBody,
|
||||
bodyMatchers, getResponseAsString(), shouldCommentOutBDDBlocks())
|
||||
if (!(convertedResponseBody instanceof Map || convertedResponseBody instanceof List)) {
|
||||
if (!(convertedResponseBody instanceof Map || convertedResponseBody instanceof List) && !(convertedResponseBody instanceof ExecutionProperty)) {
|
||||
simpleTextResponseBodyCheck(bb, convertedResponseBody)
|
||||
}
|
||||
processBodyElement(bb, "", "", convertedResponseBody)
|
||||
|
||||
@@ -171,7 +171,7 @@ abstract class RequestProcessingMethodBodyBuilder extends MethodBodyBuilder {
|
||||
}
|
||||
|
||||
private void addAsyncIfRequired(BlockBuilder bb) {
|
||||
if (response.async) {
|
||||
if (response.async && !response.delay) {
|
||||
bb.addLine('.when().async()')
|
||||
}
|
||||
if (response.delay) {
|
||||
|
||||
@@ -3071,4 +3071,49 @@ DocumentContext parsedJson = JsonPath.parse(json);
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('#1263')
|
||||
def 'should allow using execute in the request body [#methodBuilderName]'() {
|
||||
given:
|
||||
Contract contractDsl = Contract.make {
|
||||
description "should migrate spaceship"
|
||||
request {
|
||||
method POST()
|
||||
url('/api/migration')
|
||||
headers {
|
||||
accept('application/json')
|
||||
contentType(applicationJson())
|
||||
}
|
||||
body(
|
||||
$(c([id: 4, foo:5, whatever:"hello"]), p(execute('hashCode()')))
|
||||
)
|
||||
}
|
||||
response {
|
||||
status OK()
|
||||
headers {
|
||||
contentType(applicationJson())
|
||||
}
|
||||
body(
|
||||
$(c([id: 4, foo:5, whatever:"hello"]), p(execute('hashCode()')))
|
||||
)
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
and:
|
||||
builder.appendTo(blockBuilder)
|
||||
String test = blockBuilder.toString()
|
||||
when:
|
||||
SyntaxChecker.tryToRun(methodBuilderName, test.join("\n"))
|
||||
then:
|
||||
// 1 in the request and 1 in the response
|
||||
test.findAll("hashCode()").size() == 2
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2713,6 +2713,46 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
|
||||
}
|
||||
|
||||
@Issue("#1263")
|
||||
def "should work with complex objects in the body"() {
|
||||
given:
|
||||
Contract contractDsl = Contract.make {
|
||||
description "should migrate spaceship"
|
||||
request {
|
||||
method POST()
|
||||
url('/api/migration')
|
||||
headers {
|
||||
accept('application/json')
|
||||
contentType(applicationJson())
|
||||
}
|
||||
body(
|
||||
$(c([id: 4, foo:5, whatever:"hello"]), p(execute('hashCode()')))
|
||||
)
|
||||
}
|
||||
response {
|
||||
status OK()
|
||||
headers {
|
||||
contentType(applicationJson())
|
||||
}
|
||||
body(
|
||||
$(c([id: 4, foo:5, whatever:"hello"]), p(execute('hashCode()')))
|
||||
)
|
||||
}
|
||||
}
|
||||
when:
|
||||
String wireMockStub = new WireMockStubStrategy("Test",
|
||||
new ContractMetadata(null, false, 0, null, contractDsl), contractDsl)
|
||||
.toWireMockClientStub()
|
||||
|
||||
then:
|
||||
wireMockStub.contains('''$[?(@.['whatever'] == 'hello')]''')
|
||||
wireMockStub.contains('''$[?(@.['id'] == 4)]''')
|
||||
wireMockStub.contains('''$[?(@.['foo'] == 5)]''')
|
||||
wireMockStub.contains('''"{\\"id\\":4,\\"foo\\":5,\\"whatever\\":\\"hello\\"}"''')
|
||||
stubMappingIsValidWireMockStub(wireMockStub)
|
||||
|
||||
}
|
||||
|
||||
@Issue("#1257")
|
||||
def "should work with null request element on the client side and optional stub entry"() {
|
||||
given:
|
||||
|
||||
Reference in New Issue
Block a user