Resolves templated test text regardless of whether there is a response body or not
fixes gh-1163
This commit is contained in:
@@ -220,12 +220,18 @@ abstract class RequestProcessingMethodBodyBuilder extends MethodBodyBuilder {
|
||||
bb.endBlock()
|
||||
bb.addLine(addCommentSignIfRequired('and:')).startBlock()
|
||||
validateResponseBodyBlock(bb, response.bodyMatchers, response.body.serverValue)
|
||||
} else if (this.templateProcessor.containsTemplateEntry(bb.toString())) {
|
||||
updateTemplatedEntries(bb)
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateResponseBodyBlock(BlockBuilder bb, BodyMatchers bodyMatchers, Object responseBody) {
|
||||
super.validateResponseBodyBlock(bb, bodyMatchers, responseBody)
|
||||
updateTemplatedEntries(bb)
|
||||
}
|
||||
|
||||
private void updateTemplatedEntries(BlockBuilder bb) {
|
||||
String newBody = this.templateProcessor.transform(request, bb.toString())
|
||||
bb.updateContents(newBody)
|
||||
}
|
||||
|
||||
@@ -2963,4 +2963,43 @@ DocumentContext parsedJson = JsonPath.parse(json);
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('#1163')
|
||||
def 'should resolve from request evaluation even if there is no response body [#methodBuilderName]'() {
|
||||
given:
|
||||
Contract contractDsl = Contract.make {
|
||||
request {
|
||||
method PUT()
|
||||
url '/frauds/name'
|
||||
body([
|
||||
name: $(anyAlphaUnicode())
|
||||
])
|
||||
headers {
|
||||
contentType("application/json")
|
||||
}
|
||||
}
|
||||
response {
|
||||
status OK()
|
||||
headers {
|
||||
header(contentType(), "${fromRequest().header(contentType())}")
|
||||
}
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
and:
|
||||
builder.appendTo(blockBuilder)
|
||||
String test = blockBuilder.toString()
|
||||
when:
|
||||
SyntaxChecker.tryToRun(methodBuilderName, test.join("\n"))
|
||||
then:
|
||||
!test.contains('''{{{request.headers.Content-Type.[0]}}}''')
|
||||
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) }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user