Merge pull request #160 from dstepanov/fix-unicode-escape
Don't generate UTF8 escaping "\u041C\u043E\u0441\u043A\u0432\u0430" in tests
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package io.codearte.accurest.builder
|
||||
|
||||
import groovy.json.JsonOutput
|
||||
import groovy.json.StringEscapeUtils
|
||||
import groovy.transform.PackageScope
|
||||
import groovy.transform.TypeChecked
|
||||
import io.codearte.accurest.dsl.GroovyDsl
|
||||
@@ -117,7 +119,13 @@ abstract class SpockMethodBodyBuilder {
|
||||
|
||||
protected String getBodyAsString() {
|
||||
Object bodyValue = extractServerValueFromBody(request.body.serverValue)
|
||||
return trimRepeatedQuotes(new JsonOutput().toJson(bodyValue))
|
||||
String json = new JsonOutput().toJson(bodyValue)
|
||||
json = convertUnicodeEscapes(json)
|
||||
return trimRepeatedQuotes(json)
|
||||
}
|
||||
|
||||
protected String convertUnicodeEscapes(String json) {
|
||||
return StringEscapeUtils.unescapeJavaScript(json)
|
||||
}
|
||||
|
||||
protected String trimRepeatedQuotes(String toTrim) {
|
||||
|
||||
@@ -735,4 +735,39 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
!spockTest.contains("cursor")
|
||||
}
|
||||
|
||||
|
||||
def "shouldn't generate unicode escape characters"() {
|
||||
given:
|
||||
Pattern ONLY_ALPHA_UNICODE = Pattern.compile(/[\p{L}]*/)
|
||||
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
method "PUT"
|
||||
url "/v1/payments/e86df6f693de4b35ae648464c5b0dc09/енев"
|
||||
headers {
|
||||
header('Content-Type': 'application/json')
|
||||
}
|
||||
body(
|
||||
client: [
|
||||
first_name: $(stub(ONLY_ALPHA_UNICODE), test('Пенева')),
|
||||
last_name : $(stub(ONLY_ALPHA_UNICODE), test('Пенева'))
|
||||
]
|
||||
)
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
headers {
|
||||
header('Content-Type': 'application/json')
|
||||
}
|
||||
}
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def spockTest = blockBuilder.toString()
|
||||
then:
|
||||
!spockTest.contains("\\u041f")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user