Merge branch '2.0.x'

This commit is contained in:
Marcin Grzejszczak
2019-01-20 13:06:15 +01:00
4 changed files with 16 additions and 2 deletions

View File

@@ -189,7 +189,8 @@ abstract class JUnitMethodBodyBuilder extends RequestProcessingMethodBodyBuilder
readBytesFromFileString(fileProperty, CommunicationType.REQUEST) :
readStringFromFileString(fileProperty, CommunicationType.REQUEST)
} else {
value = "\"$body\""
String escaped = escapeRequestSpecialChars(body.toString())
value = "\"$escaped\""
}
return ".body($value)"
}

View File

@@ -125,6 +125,10 @@ abstract class MethodBodyBuilder implements ClassVerifier {
return new HandlebarsTemplateProcessor()
}
protected ContentType getRequestContentType() {
return ContentType.UNKNOWN
}
/**
* Builds the response body validation code block
*/

View File

@@ -65,6 +65,14 @@ abstract class RequestProcessingMethodBodyBuilder extends MethodBodyBuilder {
this.response = stubDefinition.response
}
protected String escapeRequestSpecialChars(String string) {
if (getRequestContentType() == ContentType.JSON) {
return string
.replaceAll('\\\\n', '\\\\\\\\n')
}
return string
}
/**
* Returns code used to retrieve a response for the given {@link Request}
*/

View File

@@ -164,7 +164,8 @@ abstract class SpockMethodRequestProcessingBodyBuilder extends RequestProcessing
readBytesFromFileString(fileProperty, CommunicationType.REQUEST) :
readStringFromFileString(fileProperty, CommunicationType.REQUEST)
} else {
value = "'''$body'''"
String escaped = escapeRequestSpecialChars(body.toString())
value = "'''$escaped'''"
}
return ".body($value)"
}