From 00d347f812d78105f34c0e2570a5659f578cc3d8 Mon Sep 17 00:00:00 2001 From: mchmielarz Date: Wed, 16 Dec 2015 23:34:17 +0100 Subject: [PATCH] Conversion of a map with integer as keys added. --- .../util/JsonToJsonPathsConverter.groovy | 2 +- .../MockMvcSpockMethodBuilderSpec.groovy | 29 +++++++++++++++++++ .../util/JsonToJsonPathsConverterSpec.groovy | 15 ++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/util/JsonToJsonPathsConverter.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/util/JsonToJsonPathsConverter.groovy index 319e7ab660..0bf9cc2ff5 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/util/JsonToJsonPathsConverter.groovy +++ b/accurest-core/src/main/groovy/io/codearte/accurest/util/JsonToJsonPathsConverter.groovy @@ -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)] } } diff --git a/accurest-core/src/test/groovy/io/codearte/accurest/builder/MockMvcSpockMethodBuilderSpec.groovy b/accurest-core/src/test/groovy/io/codearte/accurest/builder/MockMvcSpockMethodBuilderSpec.groovy index f5217c6266..efdb49fbc0 100644 --- a/accurest-core/src/test/groovy/io/codearte/accurest/builder/MockMvcSpockMethodBuilderSpec.groovy +++ b/accurest-core/src/test/groovy/io/codearte/accurest/builder/MockMvcSpockMethodBuilderSpec.groovy @@ -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 { diff --git a/accurest-core/src/test/groovy/io/codearte/accurest/util/JsonToJsonPathsConverterSpec.groovy b/accurest-core/src/test/groovy/io/codearte/accurest/util/JsonToJsonPathsConverterSpec.groovy index 5348c77fd5..90b0c0d2da 100644 --- a/accurest-core/src/test/groovy/io/codearte/accurest/util/JsonToJsonPathsConverterSpec.groovy +++ b/accurest-core/src/test/groovy/io/codearte/accurest/util/JsonToJsonPathsConverterSpec.groovy @@ -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: