- def 'Converting NormalizedNode to a DataNode collection -- edge cases: #scenario.'() {
- when: 'the normalized node is #node'
- def result = new DataNodeBuilder().withNormalizedNodeTree(normalizedNode).buildCollection()
- then: 'the resulting collection contains data nodes for expected list elements'
- assert result.size() == expectedSize
- assert result.containsAll(expectedNodes)
- where: 'following parameters are used'
- scenario | node | normalizedNode | expectedSize | expectedNodes
- 'NormalizedNode is null' | 'null' | null | 1 | [ new DataNode() ]
- 'NormalizedNode is an unsupported type' | 'not supported' | Mock(NormalizedNode) | 0 | [ ]
+ def 'Converting ContainerNode to a Collection with #scenario.'() {
+ expect: 'converting null to a collection returns an empty collection'
+ assert objectUnderTest.withContainerNode(containerNode).buildCollection().isEmpty()
+ where: 'the following container node is used'
+ scenario | containerNode
+ 'null object' | null
+ 'object without body' | Mock(ContainerNode)
+ }
+
+ def 'Converting ContainerNode to a DataNode with unsupported Normalized Node.'() {
+ given: 'a container node of an unsupported type'
+ def mockContainerNode = Mock(ContainerNode)
+ mockContainerNode.body() >> [ Mock(ForeignDataNode) ]
+ when: 'attempt to convert it'
+ objectUnderTest.withContainerNode(mockContainerNode).build()
+ then: 'a data validation exception is thrown'
+ thrown(DataValidationException)
+ }
+
+ def 'Build datanode from attributes.'() {
+ when: 'data node is built'
+ def result = new DataNodeBuilder()
+ .withDataspace('my dataspace')
+ .withAnchor('my anchor')
+ .withModuleNamePrefix('my prefix')
+ .withXpath('some xpath')
+ .withLeaves([leaf1: 'value1'])
+ .withChildDataNodes([Mock(DataNode)])
+ .build()
+ then: 'the datanode has all the defined attributes'
+ assert result.dataspace == 'my dataspace'
+ assert result.anchorName == 'my anchor'
+ assert result.moduleNamePrefix == 'my prefix'
+ assert result.moduleNamePrefix == 'my prefix'
+ assert result.xpath == 'some xpath'
+ assert result.leaves == [leaf1: 'value1']
+ assert result.childDataNodes.size() == 1