Fixed issue with content is not allowed in prolog for body from the xml file (#1107)

* Created test 'should create stub with body from the file' - failed

* Fixed 'Content is not allowed in prolog' for body from the xml file; 

fixes issue #1105
This commit is contained in:
Artem Ptushkin
2019-06-14 16:55:13 +03:00
committed by Marcin Grzejszczak
parent e566d02180
commit 31f43648ac
3 changed files with 57 additions and 0 deletions

View File

@@ -66,4 +66,8 @@ class FromFileProperty implements Serializable {
return this.file.bytes
}
@Override
String toString() {
return asString()
}
}

View File

@@ -606,6 +606,54 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
stubMappingIsValidWireMockStub(json)
}
def 'should create stub with body from the file'() {
given:
org.springframework.cloud.contract.spec.Contract groovyDsl = org.springframework.cloud.contract.spec.Contract.make {
request {
method 'GET'
headers {
header 'Content-Type': 'application/xml'
}
url "/users"
body file('classpath/request.xml')
}
response {
status OK()
}
}
when:
String json = toWireMockClientJsonStub(groovyDsl)
then:
AssertionUtil.assertThatJsonsAreEqual(('''
{
"request": {
"method": "GET",
"url": "/users",
"bodyPatterns": [
{
"matchesXPath": {
"expression": "/foo/name/text()",
"equalTo": "Jozo"
}
},
{
"matchesXPath": {
"expression": "/foo/jobId/text()",
"equalTo": "123"
}
}
]
},
"response": {
"status": 200,
"transformers" : [ "response-template", "foo-transformer" ]
}
}
'''), json)
and:
stubMappingIsValidWireMockStub(json)
}
def 'should convert groovy dsl stub with regexp Body as String to wireMock stub for the client side'() {
given:
org.springframework.cloud.contract.spec.Contract groovyDsl = org.springframework.cloud.contract.spec.Contract.make {

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<foo>
<name>Jozo</name>
<jobId>123</jobId>
</foo>