Merge branch '2.1.x'
This commit is contained in:
@@ -44,6 +44,7 @@ import org.springframework.cloud.contract.verifier.util.ContentUtils
|
||||
import org.springframework.cloud.contract.verifier.util.MapConverter
|
||||
import org.springframework.util.StringUtils
|
||||
|
||||
import static org.springframework.cloud.contract.verifier.util.ContentType.DEFINED
|
||||
import static org.springframework.cloud.contract.verifier.util.ContentType.FORM
|
||||
import static org.springframework.cloud.contract.verifier.util.ContentType.JSON
|
||||
import static org.springframework.cloud.contract.verifier.util.ContentType.TEXT
|
||||
@@ -421,7 +422,7 @@ abstract class MethodBodyBuilder implements ClassVerifier {
|
||||
convertedResponseBody =
|
||||
extractValue(convertedResponseBody as GString, contentType, { Object o -> o instanceof DslProperty ? o.serverValue : o })
|
||||
}
|
||||
if (TEXT != contentType && FORM != contentType) {
|
||||
if (TEXT != contentType && FORM != contentType && DEFINED != contentType) {
|
||||
boolean dontParseStrings = contentType == JSON && convertedResponseBody instanceof Map
|
||||
Closure parsingClosure = dontParseStrings ? Closure.IDENTITY : MapConverter.JSON_PARSING_CLOSURE
|
||||
convertedResponseBody = MapConverter.
|
||||
|
||||
@@ -26,6 +26,8 @@ enum ContentType {
|
||||
XML("application/xml"),
|
||||
TEXT("text/plain"),
|
||||
FORM("application/x-www-form-urlencoded"),
|
||||
// the content-type was defined and we don't want to override it
|
||||
DEFINED(""),
|
||||
UNKNOWN("application/octet-stream")
|
||||
|
||||
final String mimeType
|
||||
|
||||
@@ -41,6 +41,7 @@ import static org.apache.commons.text.StringEscapeUtils.escapeJava
|
||||
import static org.apache.commons.text.StringEscapeUtils.escapeJson
|
||||
import static org.apache.commons.text.StringEscapeUtils.escapeXml11
|
||||
import static org.apache.commons.text.StringEscapeUtils.unescapeXml
|
||||
import static org.springframework.cloud.contract.verifier.util.ContentType.DEFINED
|
||||
import static org.springframework.cloud.contract.verifier.util.ContentType.JSON
|
||||
import static org.springframework.cloud.contract.verifier.util.ContentType.UNKNOWN
|
||||
|
||||
@@ -392,6 +393,12 @@ class ContentUtils {
|
||||
if (content?.contains("form-urlencoded")) {
|
||||
return ContentType.FORM
|
||||
}
|
||||
if (content?.contains("octet-stream")) {
|
||||
return UNKNOWN
|
||||
}
|
||||
if (content) {
|
||||
return DEFINED
|
||||
}
|
||||
return UNKNOWN
|
||||
}
|
||||
|
||||
|
||||
@@ -1407,4 +1407,37 @@ response:
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, classDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue("#1049")
|
||||
def "should work with body having new lines [#methodBuilderName]"() {
|
||||
given:
|
||||
Contract contractDsl = Contract.make {
|
||||
request {
|
||||
method GET()
|
||||
url "/foo"
|
||||
}
|
||||
response {
|
||||
status OK()
|
||||
headers {
|
||||
contentType('application/x-research-info-systems;charset=UTF-8')
|
||||
}
|
||||
body("1\n2\n3\n")
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
then:
|
||||
String test = blockBuilder.toString()
|
||||
SyntaxChecker.tryToCompileWithoutCompileStatic(methodBuilderName, test)
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, classDataForMethod) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, classDataForMethod) }
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, classDataForMethod) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, classDataForMethod) }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user