X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cps-service%2Fsrc%2Ftest%2Fgroovy%2Forg%2Fonap%2Fcps%2Futils%2FYangUtilsSpec.groovy;h=25b90d702f0bef192f3694d42e95bd1d788e30ea;hb=c9275522f95f6cd94f28286f5e86f86dd451a19b;hp=cca2ac6217e77144a04b87d686832bddb0476169;hpb=15b93e7ad7db7372d51c4c1ad45f95d463aaaffc;p=cps.git diff --git a/cps-service/src/test/groovy/org/onap/cps/utils/YangUtilsSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/utils/YangUtilsSpec.groovy index cca2ac621..25b90d702 100644 --- a/cps-service/src/test/groovy/org/onap/cps/utils/YangUtilsSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/utils/YangUtilsSpec.groovy @@ -88,4 +88,31 @@ class YangUtilsSpec extends Specification { 'another invalid parent path' | '/test-tree/branch[@name=\'Branch\']/nest/name/last-name' 'fragment does not belong to parent' | '/test-tree/' } + + def 'Parsing json data with invalid json string: #description.'() { + given: 'schema context' + def yangResourcesMap = TestUtils.getYangResourcesAsMap('bookstore.yang') + def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesMap).getSchemaContext() + when: 'malformed json string is parsed' + YangUtils.parseJsonData(invalidJson, schemaContext) + then: 'an exception is thrown' + thrown(DataValidationException) + where: 'the following malformed json is provided' + description | invalidJson + 'malformed json string with unterminated array data' | '{bookstore={categories=[{books=[{authors=[Iain M. Banks]}]}]}}' + 'incorrect json' | '{" }' + } + + def 'Parsing json data with space.'() { + given: 'schema context' + def yangResourcesMap = TestUtils.getYangResourcesAsMap('bookstore.yang') + def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesMap).getSchemaContext() + and: 'some json data with space in the array elements' + def jsonDataWithSpacesInArrayElement = TestUtils.getResourceFileContent('bookstore.json') + when: 'that json data is parsed' + YangUtils.parseJsonData(jsonDataWithSpacesInArrayElement, schemaContext) + then: 'no exception thrown' + noExceptionThrown() + } + }