Async: NCMP Rest impl. including Request ID generation
[cps.git] / cps-service / src / test / groovy / org / onap / cps / utils / YangUtilsSpec.groovy
index 0b00cbb..25b90d7 100644 (file)
@@ -8,6 +8,7 @@
  *  You may obtain a copy of the License at
  *
  *        http://www.apache.org/licenses/LICENSE-2.0
+
  *  Unless required by applicable law or agreed to in writing, software
  *  distributed under the License is distributed on an "AS IS" BASIS,
  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -26,7 +27,6 @@ import org.onap.cps.yang.YangTextSchemaSourceSetBuilder
 import org.opendaylight.yangtools.yang.common.QName
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode
 import spock.lang.Specification
-import spock.lang.Unroll
 
 class YangUtilsSpec extends Specification {
     def 'Parsing a valid Json String.'() {
@@ -41,7 +41,6 @@ class YangUtilsSpec extends Specification {
             result.nodeType == QName.create('org:onap:ccsdk:sample', '2020-09-15', 'bookstore')
     }
 
-    @Unroll
     def 'Parsing invalid data: #description.'() {
         given: 'a yang model (file)'
             def yangResourceNameToContent = TestUtils.getYangResourcesAsMap('bookstore.yang')
@@ -57,7 +56,6 @@ class YangUtilsSpec extends Specification {
             '{" }'                                            | 'json with syntax exception'
     }
 
-    @Unroll
     def 'Parsing json data fragment by xpath for #scenario.'() {
         given: 'schema context'
             def yangResourcesMap = TestUtils.getYangResourcesAsMap('test-tree.yang')
@@ -73,7 +71,6 @@ class YangUtilsSpec extends Specification {
             'container element'         | '{ "nest": { "name": "N", "birds": ["bird"] } }'                              | '/test-tree/branch[@name=\'Branch\']' || 'nest'
     }
 
-    @Unroll
     def 'Parsing json data fragment by xpath error scenario: #scenario.'() {
         given: 'schema context'
             def yangResourcesMap = TestUtils.getYangResourcesAsMap('test-tree.yang')
@@ -91,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()
+    }
+
 }