Merge pull request #186 from mchmielarz/master

#185 Conversion of a map with integers as keys added.
This commit is contained in:
Marcin Grzejszczak
2015-12-16 23:48:56 +01:00
3 changed files with 45 additions and 1 deletions

View File

@@ -93,7 +93,7 @@ class JsonToJsonPathsConverter {
private static Map convertWithKey(Class parentType, String parentKey, Map map, Closure closureToExecute) {
return map.collectEntries {
String entrykey, value ->
Object entrykey, value ->
[entrykey, traverseRecursively(parentType, "${parentKey}.${entrykey}", value, closureToExecute)]
}
}

View File

@@ -121,6 +121,35 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub())
}
@Issue("185")
def "should generate assertions for a response body containing map with integers as keys"() {
given:
GroovyDsl contractDsl = GroovyDsl.make {
request {
method "GET"
url "test"
}
response {
status 200
body(
property: [
14: 0.0,
7 : 0.0
]
)
}
}
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
builder.appendTo(blockBuilder)
then:
blockBuilder.toString().contains("\$.property[?(@.7 == 0.0)]")
blockBuilder.toString().contains("\$.property[?(@.14 == 0.0)]")
and:
stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub())
}
def "should generate assertions for array in response body"() {
given:
GroovyDsl contractDsl = GroovyDsl.make {

View File

@@ -119,6 +119,21 @@ class JsonToJsonPathsConverterSpec extends Specification {
assertThatJsonPathsInMapAreValid(json, pathAndValues)
}
def "should convert numbers map"() {
given:
String json = ''' {
"extensions": {"7":28.00,"14":41.00,"30":60.00}
}
'''
when:
JsonPaths pathAndValues = JsonToJsonPathsConverter.transformToJsonPathWithTestsSideValues(new JsonSlurper().parseText(json))
then:
pathAndValues['''$.extensions[?(@.7 == 28)]'''] == 28.0
pathAndValues['''$.extensions[?(@.14 == 41)]'''] == 41.0
pathAndValues['''$.extensions[?(@.30 == 60)]'''] == 60.0
and:
assertThatJsonPathsInMapAreValid(json, pathAndValues)
}
def 'should convert a json with a list of errors'() {
given: