summaryrefslogtreecommitdiffstats
path: root/cps-service/src/test
diff options
context:
space:
mode:
authorsourabh_sourabh <sourabh.sourabh@est.tech>2022-01-05 23:50:20 +0530
committerSourabh Sourabh <sourabh.sourabh@est.tech>2022-01-07 10:29:38 +0000
commit6f494f46266e8709d6b61530aa48fe76adacf965 (patch)
tree7f4becbba1e5c649ceb2157afddddd488fde6c0b /cps-service/src/test
parentb3c526ff9704bb8613dc25b2ceb43f1a20b01ed4 (diff)
CPS-Core: Unable to parse JSON input with space for POST endpoint
Issue-ID: CPS-831 Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech> Change-Id: If2f5f7034f05763990001c9dd8ccd9d8dc0099cf
Diffstat (limited to 'cps-service/src/test')
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/utils/YangUtilsSpec.groovy27
1 files changed, 27 insertions, 0 deletions
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 cca2ac6217..25b90d702f 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()
+ }
+
}