io.codearte.accurest.builder.MockMvcSpockMethodRequestProcessingBodyBuilder.groovy Maven / Gradle / Ivy
package io.codearte.accurest.builder
import groovy.transform.PackageScope
import groovy.transform.TypeChecked
import io.codearte.accurest.dsl.GroovyDsl
import io.codearte.accurest.dsl.internal.ExecutionProperty
import io.codearte.accurest.dsl.internal.Header
import java.util.regex.Pattern
@PackageScope
@TypeChecked
class MockMvcSpockMethodRequestProcessingBodyBuilder extends SpockMethodRequestProcessingBodyBuilder {
MockMvcSpockMethodRequestProcessingBodyBuilder(GroovyDsl stubDefinition) {
super(stubDefinition)
}
@Override
protected void validateResponseCodeBlock(BlockBuilder bb) {
bb.addLine("response.statusCode == $response.status.serverValue")
}
@Override
protected void validateResponseHeadersBlock(BlockBuilder bb) {
response.headers?.collect { Header header ->
processHeaderElement(bb, header.name, header.serverValue)
}
}
@Override
protected String getResponseAsString() {
return 'response.body.asString()'
}
@Override
protected void processHeaderElement(BlockBuilder blockBuilder, String property, ExecutionProperty exec) {
blockBuilder.addLine("${exec.insertValue("response.header(\'$property\')")}")
}
@Override
protected void processHeaderElement(BlockBuilder blockBuilder, String property, String value) {
blockBuilder.addLine("response.header('$property') ${convertHeaderComparison(value)}")
}
@Override
protected void processHeaderElement(BlockBuilder blockBuilder, String property, Pattern value) {
blockBuilder.addLine("response.header('$property') ${convertHeaderComparison(value)}")
}
// #273 - should escape $ for Groovy since it will try to make it a GString
@Override
protected String postProcessJsonPathCall(String jsonPath) {
return jsonPath.replace('$', '\\$')
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy