1 package org.onap.cps.model
3 import org.onap.cps.TestUtils
4 import org.onap.cps.spi.model.DataNodeBuilder
5 import org.onap.cps.utils.YangUtils
6 import org.onap.cps.yang.YangTextSchemaSourceSetBuilder
7 import spock.lang.Specification
9 class DataNodeBuilderSpec extends Specification {
11 def 'Converting Normalized Node (tree) to a DataNode (tree).'() {
12 given: 'a Yang module'
13 def yangResourceNameToContent = TestUtils.getYangResourcesAsMap('bookstore.yang')
14 def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent)getSchemaContext()
15 and: 'a normalized node for that model'
16 def jsonData = TestUtils.getResourceFileContent('bookstore.json')
17 def normalizedNode = YangUtils.parseJsonData(jsonData, schemaContext)
18 when: 'the normalized node is converted to a DataNode (tree)'
19 def result = new DataNodeBuilder().withNormalizedNodeTree(normalizedNode).build()
20 then: 'the system creates a (root) fragment without a parent and 2 children (categories)'
21 result.childDataNodes.size() == 2
22 and: 'each child (category) has the root fragment (result) as parent and in turn as 1 child (a list of books)'
23 result.childDataNodes.each { it.childDataNodes.size() == 1 }
24 and: 'the fragments have the correct xpaths'
25 assert result.xpath == '/bookstore'
26 assert result.childDataNodes.collect { it.xpath }
27 .containsAll(["/bookstore/categories[@code='01']", "/bookstore/categories[@code='02']"])