Merge branch '1.1.x'
This commit is contained in:
@@ -177,8 +177,8 @@ abstract class JUnitMethodBodyBuilder extends RequestProcessingMethodBodyBuilder
|
||||
return buildEscapedMatchesMethod(headerValue) + ";"
|
||||
}
|
||||
|
||||
private String buildEscapedMatchesMethod(Pattern headerValue) {
|
||||
String escapedHeader = convertUnicodeEscapesIfRequired("$headerValue")
|
||||
private String buildEscapedMatchesMethod(Pattern escapedValue) {
|
||||
String escapedHeader = convertUnicodeEscapesIfRequired("$escapedValue")
|
||||
return createMatchesMethod(escapedHeader)
|
||||
}
|
||||
|
||||
|
||||
@@ -324,12 +324,16 @@ abstract class MethodBodyBuilder {
|
||||
addColonIfRequired(bb)
|
||||
// TODO xml validation
|
||||
} else {
|
||||
bb.addLine(getSimpleResponseBodyString(getResponseAsString()))
|
||||
processText(bb, "", convertedResponseBody)
|
||||
addColonIfRequired(bb)
|
||||
simpleTextResponseBodyCheck(bb, convertedResponseBody)
|
||||
}
|
||||
}
|
||||
|
||||
private void simpleTextResponseBodyCheck(BlockBuilder bb, convertedResponseBody) {
|
||||
bb.addLine(getSimpleResponseBodyString(getResponseAsString()))
|
||||
processText(bb, "", convertedResponseBody)
|
||||
addColonIfRequired(bb)
|
||||
}
|
||||
|
||||
private void addJsonResponseBodyCheck(BlockBuilder bb, convertedResponseBody, BodyMatchers bodyMatchers) {
|
||||
appendJsonPath(bb, getResponseAsString())
|
||||
Object copiedBody = cloneBody(convertedResponseBody)
|
||||
@@ -363,6 +367,9 @@ abstract class MethodBodyBuilder {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!(convertedResponseBody instanceof Map || convertedResponseBody instanceof List)) {
|
||||
simpleTextResponseBodyCheck(bb, convertedResponseBody)
|
||||
}
|
||||
processBodyElement(bb, "", "", convertedResponseBody)
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ class RestAssuredJUnitMethodBodyBuilder extends JUnitMethodBodyBuilder {
|
||||
|
||||
@Override
|
||||
protected String getResponseBodyPropertyComparisonString(String property, Pattern value) {
|
||||
return null
|
||||
return """assertThat(responseBody).${createHeaderComparison(value)}"""
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -283,10 +283,10 @@ class ContentUtils {
|
||||
|
||||
static ContentType recognizeContentTypeFromHeader(Headers headers) {
|
||||
String content = headers?.entries.find { it.name == "Content-Type" } ?.clientValue?.toString()
|
||||
if (content?.endsWith("json")) {
|
||||
if (content?.contains("json")) {
|
||||
return ContentType.JSON
|
||||
}
|
||||
if (content?.endsWith("xml")) {
|
||||
if (content?.contains("xml")) {
|
||||
return ContentType.XML
|
||||
}
|
||||
if (content?.contains("text")) {
|
||||
|
||||
@@ -2096,7 +2096,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
|
||||
}
|
||||
|
||||
@Issue('#172')
|
||||
def "should resolve plain text properly via headers"() {
|
||||
def "should resolve plain text properly via headers"() {
|
||||
given:
|
||||
Contract contractDsl = Contract.make {
|
||||
request {
|
||||
@@ -2128,6 +2128,41 @@ DocumentContext parsedJson = JsonPath.parse(json);
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | '''assertThat(responseBody).isEqualTo("{\\"a\\":1}\\n{\\"a\\":2}'''
|
||||
}
|
||||
|
||||
@Issue('#443')
|
||||
def "should resolve plain text that happens to be a valid json for [#methodBuilderName]"() {
|
||||
given:
|
||||
Contract contractDsl = Contract.make {
|
||||
request {
|
||||
method 'GET'
|
||||
url '/foo'
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
headers {
|
||||
contentType(applicationJsonUtf8())
|
||||
}
|
||||
body(
|
||||
value(client('true'), server(regex("true|false")))
|
||||
)
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def test = blockBuilder.toString()
|
||||
then:
|
||||
testAssertion(test)
|
||||
and:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | testAssertion
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | { String testContents -> testContents.contains("""responseBody ==~ java.util.regex.Pattern.compile('true|false')""") }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | { String testContents -> testContents.contains("""assertThat(responseBody).matches("true|false");""") }
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | { String testContents -> testContents.contains("""responseBody ==~ java.util.regex.Pattern.compile('true|false')""") }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | { String testContents -> testContents.contains("""assertThat(responseBody).matches("true|false");""") }
|
||||
}
|
||||
|
||||
@Issue('#169')
|
||||
def "should escape quotes properly using [#methodBuilderName]"() {
|
||||
given:
|
||||
|
||||
Reference in New Issue
Block a user