Should not fail when matchers don't have dots
fixes gh-894
This commit is contained in:
@@ -154,7 +154,11 @@ class JsonToJsonPathsConverter {
|
||||
removeTrailingContainers(pathToDelete, context)
|
||||
}
|
||||
else {
|
||||
String lastParent = matcherPath.substring(0, matcherPath.lastIndexOf("."))
|
||||
int lastIndexOfDot = matcherPath.lastIndexOf(".")
|
||||
if (lastIndexOfDot == -1) {
|
||||
return false
|
||||
}
|
||||
String lastParent = matcherPath.substring(0, lastIndexOfDot)
|
||||
def lastParentObject = context.read(lastParent)
|
||||
if (isIterable(lastParentObject)
|
||||
&&
|
||||
@@ -229,9 +233,9 @@ class JsonToJsonPathsConverter {
|
||||
return path
|
||||
}
|
||||
int lastIndexOfDot = lastIndexOfDot(path)
|
||||
String toLastDot = path.substring(0, lastIndexOfDot)
|
||||
String fromLastDot = path.substring(lastIndexOfDot + 1)
|
||||
String propertyName = "@.${fromLastDot}"
|
||||
String toLastDot = lastIndexOfDot == -1 ? '$' : path.substring(0, lastIndexOfDot)
|
||||
String propertyName = lastIndexOfDot == -1 ? '@' : "@.${fromLastDot}"
|
||||
String comparison = createComparison(propertyName, bodyMatcher, value, body)
|
||||
return "${toLastDot}[?(${comparison})]"
|
||||
}
|
||||
|
||||
@@ -2669,6 +2669,32 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
|
||||
}
|
||||
|
||||
@Issue("#894")
|
||||
def "should not fail when matchers don't have dots"() {
|
||||
given:
|
||||
Contract contractDsl = Contract.make {
|
||||
request {
|
||||
method 'POST'
|
||||
url "/example"
|
||||
body([ "123", "234"])
|
||||
bodyMatchers {
|
||||
jsonPath('$[*]', byRegex(nonEmpty()))
|
||||
}
|
||||
}
|
||||
response {
|
||||
status 201
|
||||
}
|
||||
}
|
||||
when:
|
||||
String wireMockStub = new WireMockStubStrategy("Test",
|
||||
new ContractMetadata(null, false, 0, null, contractDsl), contractDsl)
|
||||
.toWireMockClientStub()
|
||||
|
||||
then:
|
||||
stubMappingIsValidWireMockStub(wireMockStub)
|
||||
|
||||
}
|
||||
|
||||
WireMockConfiguration config() {
|
||||
return new WireMockConfiguration().extensions(responseTemplateTransformer())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user