Merge "Support pagination in query across all anchors(ep4)"
[cps.git] / integration-test / src / test / groovy / org / onap / cps / integration / functional / CpsDataServiceIntegrationSpec.groovy
index 2efbcb2..475d3d2 100644 (file)
@@ -24,7 +24,7 @@ package org.onap.cps.integration.functional
 import org.onap.cps.api.CpsDataService
 import org.onap.cps.integration.base.FunctionalSpecBase
 import org.onap.cps.spi.FetchDescendantsOption
-import org.onap.cps.spi.exceptions.AlreadyDefinedExceptionBatch
+import org.onap.cps.spi.exceptions.AlreadyDefinedException
 import org.onap.cps.spi.exceptions.AnchorNotFoundException
 import org.onap.cps.spi.exceptions.CpsAdminException
 import org.onap.cps.spi.exceptions.CpsPathException
@@ -43,89 +43,119 @@ class CpsDataServiceIntegrationSpec extends FunctionalSpecBase {
 
     CpsDataService objectUnderTest
     def originalCountBookstoreChildNodes
+    def originalCountBookstoreTopLevelListNodes
     def now = OffsetDateTime.now()
 
     def setup() {
         objectUnderTest = cpsDataService
-        originalCountBookstoreChildNodes = countDataNodesInTree(objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', DIRECT_CHILDREN_ONLY))
-}
+        originalCountBookstoreChildNodes = countDataNodesInBookstore()
+        originalCountBookstoreTopLevelListNodes = countTopLevelListDataNodesInBookstore()
+    }
 
-def 'Read bookstore top-level container(s) using #fetchDescendantsOption.'() {
-    when: 'get data nodes for bookstore container'
-        def result = objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', fetchDescendantsOption)
-    then: 'the tree consist ouf of #expectNumberOfDataNodes data nodes'
-        assert countDataNodesInTree(result) == expectNumberOfDataNodes
-    and: 'the top level data node has the expected attribute and value'
-        assert result.leaves['bookstore-name'] == ['Easons']
-    and: 'they are from the correct dataspace'
-        assert result.dataspace == [FUNCTIONAL_TEST_DATASPACE_1]
-    and: 'they are from the correct anchor'
-        assert result.anchorName == [BOOKSTORE_ANCHOR_1]
-    where: 'the following option is used'
-        fetchDescendantsOption        || expectNumberOfDataNodes
-        OMIT_DESCENDANTS              || 1
-        DIRECT_CHILDREN_ONLY          || 6
-        INCLUDE_ALL_DESCENDANTS       || 17
-        new FetchDescendantsOption(2) || 17
-}
+    def 'Read bookstore top-level container(s) using #fetchDescendantsOption.'() {
+        when: 'get data nodes for bookstore container'
+            def result = objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', fetchDescendantsOption)
+        then: 'the tree consist ouf of #expectNumberOfDataNodes data nodes'
+            assert countDataNodesInTree(result) == expectNumberOfDataNodes
+        and: 'the top level data node has the expected attribute and value'
+            assert result.leaves['bookstore-name'] == ['Easons-1']
+        and: 'they are from the correct dataspace'
+            assert result.dataspace == [FUNCTIONAL_TEST_DATASPACE_1]
+        and: 'they are from the correct anchor'
+            assert result.anchorName == [BOOKSTORE_ANCHOR_1]
+        where: 'the following option is used'
+            fetchDescendantsOption        || expectNumberOfDataNodes
+            OMIT_DESCENDANTS              || 1
+            DIRECT_CHILDREN_ONLY          || 7
+            INCLUDE_ALL_DESCENDANTS       || 28
+            new FetchDescendantsOption(2) || 28
+    }
 
-def 'Read bookstore top-level container(s) using "root" path variations.'() {
-    when: 'get data nodes for bookstore container'
-        def result = objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, root, OMIT_DESCENDANTS)
-    then: 'the tree consist ouf of one data node'
-        assert countDataNodesInTree(result) == 1
-    and: 'the top level data node has the expected attribute and value'
-        assert result.leaves['bookstore-name'] == ['Easons']
-    where: 'the following variations of "root" are used'
-        root << [ '/', '' ]
-}
+    def 'Read bookstore top-level container(s) using "root" path variations.'() {
+        when: 'get data nodes for bookstore container'
+            def result = objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, root, OMIT_DESCENDANTS)
+        then: 'the tree consist correct number of data nodes'
+            assert countDataNodesInTree(result) == 2
+        and: 'the top level data node has the expected number of leaves'
+            assert result.leaves.size() == 2
+        where: 'the following variations of "root" are used'
+            root << [ '/', '' ]
+    }
 
-def 'Read data nodes with error: #cpsPath'() {
-    when: 'attempt to get data nodes using invalid path'
-        objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, DIRECT_CHILDREN_ONLY)
-    then: 'a #expectedException is thrown'
-        thrown(expectedException)
-    where:
-        cpsPath              || expectedException
-        'invalid path'       || CpsPathException
-        '/non-existing-path' || DataNodeNotFoundException
-}
+    def 'Read data nodes with error: #cpsPath'() {
+        when: 'attempt to get data nodes using invalid path'
+            objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, DIRECT_CHILDREN_ONLY)
+        then: 'a #expectedException is thrown'
+            thrown(expectedException)
+        where:
+            cpsPath              || expectedException
+            'invalid path'       || CpsPathException
+            '/non-existing-path' || DataNodeNotFoundException
+    }
 
-def 'Read (multiple) data nodes (batch) with #cpsPath'() {
-    when: 'attempt to get data nodes using invalid path'
-        objectUnderTest.getDataNodesForMultipleXpaths(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, [ cpsPath ], DIRECT_CHILDREN_ONLY)
-    then: 'no exception is thrown'
-        noExceptionThrown()
-    where:
-        cpsPath << [ 'invalid path', '/non-existing-path' ]
-}
+    def 'Read (multiple) data nodes (batch) with #cpsPath'() {
+        when: 'attempt to get data nodes using invalid path'
+            objectUnderTest.getDataNodesForMultipleXpaths(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, [ cpsPath ], DIRECT_CHILDREN_ONLY)
+        then: 'no exception is thrown'
+            noExceptionThrown()
+        where:
+            cpsPath << [ 'invalid path', '/non-existing-path' ]
+    }
 
-def 'Delete root data node.'() {
-    when: 'the "root" is deleted'
-        objectUnderTest.deleteDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, [ '/' ], now)
-    and: 'attempt to get the top level data node'
-        objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', DIRECT_CHILDREN_ONLY)
-    then: 'an datanode not found exception is thrown'
-        thrown(DataNodeNotFoundException)
-    cleanup:
-        restoreBookstoreDataAnchor(1)
-}
+    def 'Delete root data node.'() {
+        when: 'the "root" is deleted'
+            objectUnderTest.deleteDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, [ '/' ], now)
+        and: 'attempt to get the top level data node'
+            objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', DIRECT_CHILDREN_ONLY)
+        then: 'an datanode not found exception is thrown'
+            thrown(DataNodeNotFoundException)
+        cleanup:
+            restoreBookstoreDataAnchor(1)
+    }
 
-def 'Add and Delete a (container) data node.'() {
-    given: 'new (webinfo) datanode'
-        def json = '{"webinfo": {"domain-name":"ourbookstore.com" ,"contact-email":"info@ourbookstore.com" }}'
-    when: 'the new datanode is saved'
-        objectUnderTest.saveData(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1 , '/bookstore', json, now)
-    then: 'it can be retrieved by its xpath'
-        def result = objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/webinfo', DIRECT_CHILDREN_ONLY)
-            assert result.size() == 1
-            assert result[0].xpath == '/bookstore/webinfo'
-        and: 'there is now one extra datanode'
-            assert originalCountBookstoreChildNodes + 1 == countDataNodesInTree(objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', DIRECT_CHILDREN_ONLY))
-        when: 'the new datanode is deleted'
-            objectUnderTest.deleteDataNode(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/webinfo', now)
-        then: 'the original number of data nodes is restored'
-            assert originalCountBookstoreChildNodes == countDataNodesInTree(objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', DIRECT_CHILDREN_ONLY))
+    def 'Get whole list data' () {
+            def xpathForWholeList = "/bookstore/categories"
+        when: 'get data nodes for bookstore container'
+            def dataNodes = objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, xpathForWholeList, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS)
+        then: 'the tree consist ouf of #expectNumberOfDataNodes data nodes'
+            assert dataNodes.size() == 5
+        and: 'each datanode contains the list node xpath partially in its xpath'
+            dataNodes.each {dataNode ->
+                assert dataNode.xpath.contains(xpathForWholeList)
+            }
+    }
+
+    def 'Read (multiple) data nodes with #scenario' () {
+        when: 'attempt to get data nodes using multiple valid xpaths'
+            def dataNodes = objectUnderTest.getDataNodesForMultipleXpaths(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, xpath, OMIT_DESCENDANTS)
+        then: 'expected numer of data nodes are returned'
+            dataNodes.size() == expectedNumberOfDataNodes
+        where: 'the following data was used'
+                    scenario                    |                       xpath                                       |   expectedNumberOfDataNodes
+            'container-node xpath'              | ['/bookstore']                                                    |               1
+            'list-item'                         | ['/bookstore/categories[@code=1]']                                |               1
+            'parent-list xpath'                 | ['/bookstore/categories']                                         |               5
+            'child-list xpath'                  | ['/bookstore/categories[@code=1]/books']                          |               2
+            'both parent and child list xpath'  | ['/bookstore/categories', '/bookstore/categories[@code=1]/books'] |               7
+    }
+
+    def 'Add and Delete a (container) data node using #scenario.'() {
+            when: 'the new datanode is saved'
+                objectUnderTest.saveData(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1 , parentXpath, json, now)
+            then: 'it can be retrieved by its normalized xpath'
+                def result = objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, normalizedXpathToNode, DIRECT_CHILDREN_ONLY)
+                assert result.size() == 1
+                assert result[0].xpath == normalizedXpathToNode
+            and: 'there is now one extra datanode'
+                assert originalCountBookstoreChildNodes + 1 == countDataNodesInBookstore()
+            when: 'the new datanode is deleted'
+                objectUnderTest.deleteDataNode(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, normalizedXpathToNode, now)
+            then: 'the original number of data nodes is restored'
+                assert originalCountBookstoreChildNodes == countDataNodesInBookstore()
+            where:
+                scenario                      | parentXpath                         | json                                                                                        || normalizedXpathToNode
+                'normalized parent xpath'     | '/bookstore'                        | '{"webinfo": {"domain-name":"ourbookstore.com", "contact-email":"info@ourbookstore.com" }}' || "/bookstore/webinfo"
+                'non-normalized parent xpath' | '/bookstore/categories[ @code="1"]' | '{"books": {"title":"new" }}'                                                               || "/bookstore/categories[@code='1']/books[@title='new']"
     }
 
     def 'Attempt to create a top level data node using root.'() {
@@ -143,8 +173,8 @@ def 'Add and Delete a (container) data node.'() {
             def json = '{"bookstore": {} }'
             objectUnderTest.saveData(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, json, now)
         then: 'an exception that (one cps paths is)  already defined is thrown '
-            def exceptionThrown = thrown(AlreadyDefinedExceptionBatch)
-            exceptionThrown.alreadyDefinedXpaths == [ '/bookstore' ] as Set
+            def exceptionThrown = thrown(AlreadyDefinedException)
+            exceptionThrown.alreadyDefinedObjectNames == ['/bookstore' ] as Set
         cleanup:
             restoreBookstoreDataAnchor(1)
     }
@@ -177,6 +207,21 @@ def 'Add and Delete a (container) data node.'() {
             thrown(DataNodeNotFoundExceptionBatch)
     }
 
+    def 'Add and Delete top-level list (element) data nodes with root node.'() {
+        given: 'a new (multiple-data-tree:invoice) datanodes'
+            def json = '{"bookstore-address":[{"bookstore-name":"Scholastic","address":"Bangalore,India","postal-code":"560043"}]}'
+        when: 'the new list elements are saved'
+            objectUnderTest.saveListElements(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1 , '/', json, now)
+        then: 'they can be retrieved by their xpaths'
+            objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1 , '/bookstore-address[@bookstore-name="Easons"]', INCLUDE_ALL_DESCENDANTS)
+        and: 'there is one extra datanode'
+            assert originalCountBookstoreTopLevelListNodes + 1 == countTopLevelListDataNodesInBookstore()
+        when: 'the new elements are deleted'
+            objectUnderTest.deleteDataNode(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1 , '/bookstore-address[@bookstore-name="Easons"]', now)
+        then: 'the original number of datanodes is restored'
+            assert originalCountBookstoreTopLevelListNodes == countTopLevelListDataNodesInBookstore()
+    }
+
     def 'Add and Delete list (element) data nodes.'() {
         given: 'two new (categories) data nodes'
             def json = '{"categories": [ {"code":"new1"}, {"code":"new2" } ] }'
@@ -186,12 +231,12 @@ def 'Add and Delete a (container) data node.'() {
             objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="new1"]', DIRECT_CHILDREN_ONLY).size() == 1
             objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="new2"]', DIRECT_CHILDREN_ONLY).size() == 1
         and: 'there are now two extra data nodes'
-            assert originalCountBookstoreChildNodes + 2 == countDataNodesInTree(objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', DIRECT_CHILDREN_ONLY))
+            assert originalCountBookstoreChildNodes + 2 == countDataNodesInBookstore()
         when: 'the new elements are deleted'
             objectUnderTest.deleteDataNode(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="new1"]', now)
             objectUnderTest.deleteDataNode(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="new2"]', now)
         then: 'the original number of data nodes is restored'
-            assert originalCountBookstoreChildNodes == countDataNodesInTree(objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', DIRECT_CHILDREN_ONLY))
+            assert originalCountBookstoreChildNodes == countDataNodesInBookstore()
     }
 
     def 'Add list (element) data nodes that already exist.'() {
@@ -200,10 +245,10 @@ def 'Add and Delete a (container) data node.'() {
         when: 'attempt to save the list element'
             objectUnderTest.saveListElements(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1 , '/bookstore', json, now)
         then: 'an exception that (one cps paths is)  already defined is thrown '
-            def exceptionThrown = thrown(AlreadyDefinedExceptionBatch)
-            exceptionThrown.alreadyDefinedXpaths == [ '/bookstore/categories[@code=\'1\']' ] as Set
+            def exceptionThrown = thrown(AlreadyDefinedException)
+            exceptionThrown.alreadyDefinedObjectNames == ['/bookstore/categories[@code=\'1\']' ] as Set
         and: 'there is now one extra data nodes'
-            assert originalCountBookstoreChildNodes + 1 == countDataNodesInTree(objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', DIRECT_CHILDREN_ONLY))
+            assert originalCountBookstoreChildNodes + 1 == countDataNodesInBookstore()
         cleanup:
             restoreBookstoreDataAnchor(1)
     }
@@ -216,7 +261,7 @@ def 'Add and Delete a (container) data node.'() {
         when: 'the new element is deleted'
             objectUnderTest.deleteListOrListElement(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="new1"]', now)
         then: 'the original number of data nodes is restored'
-            assert originalCountBookstoreChildNodes == countDataNodesInTree(objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', DIRECT_CHILDREN_ONLY))
+            assert originalCountBookstoreChildNodes == countDataNodesInBookstore()
     }
 
     def 'Add and Delete a batch of lists (element) data nodes.'() {
@@ -229,12 +274,12 @@ def 'Add and Delete a (container) data node.'() {
             assert objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="new1"]', DIRECT_CHILDREN_ONLY).size() == 1
             assert objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="new2"]', DIRECT_CHILDREN_ONLY).size() == 1
         and: 'there are now two extra data nodes'
-            assert originalCountBookstoreChildNodes + 2 == countDataNodesInTree(objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', DIRECT_CHILDREN_ONLY))
+            assert originalCountBookstoreChildNodes + 2 == countDataNodesInBookstore()
         when: 'the new elements are deleted'
             objectUnderTest.deleteDataNode(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="new1"]', now)
             objectUnderTest.deleteDataNode(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="new2"]', now)
         then: 'the original number of data nodes is restored'
-            assert originalCountBookstoreChildNodes == countDataNodesInTree(objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', DIRECT_CHILDREN_ONLY))
+            assert originalCountBookstoreChildNodes == countDataNodesInBookstore()
     }
 
     def 'Add and Delete a batch of lists (element) data nodes with partial success.'() {
@@ -244,10 +289,10 @@ def 'Add and Delete a (container) data node.'() {
         when: 'the batches of new list element(s) are saved'
             objectUnderTest.saveListElementsBatch(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1 , '/bookstore', [jsonNewElement, jsonExistingElement], now)
         then: 'an already defined (batch) exception is thrown for the existing path'
-            def exceptionThrown = thrown(AlreadyDefinedExceptionBatch)
-            assert exceptionThrown.alreadyDefinedXpaths ==  [ '/bookstore/categories[@code=\'1\']' ] as Set
+            def exceptionThrown = thrown(AlreadyDefinedException)
+            assert exceptionThrown.alreadyDefinedObjectNames ==  ['/bookstore/categories[@code=\'1\']' ] as Set
         and: 'there is now one extra data node'
-            assert originalCountBookstoreChildNodes + 1 == countDataNodesInTree(objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', DIRECT_CHILDREN_ONLY))
+            assert originalCountBookstoreChildNodes + 1 == countDataNodesInBookstore()
         cleanup:
             restoreBookstoreDataAnchor(1)
     }
@@ -267,7 +312,7 @@ def 'Add and Delete a (container) data node.'() {
         where: 'the following data is used'
             scenario                 | parentXpath                              | json                                || expectedException
             'parent does not exist'  | '/bookstore/categories[@code="unknown"]' | '{"books": [ {"title":"new"} ] } '  || DataNodeNotFoundException
-            'already existing child' | '/bookstore'                             | '{"categories": [ {"code":"1"} ] }' || AlreadyDefinedExceptionBatch
+            'already existing child' | '/bookstore'                             | '{"categories": [ {"code":"1"} ] }' || AlreadyDefinedException
     }
 
     def 'Add multiple child data nodes with partial success.'() {
@@ -276,8 +321,8 @@ def 'Add and Delete a (container) data node.'() {
         when: 'attempt to add the elements'
             objectUnderTest.saveData(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', json, now)
         then: 'an already defined (batch) exception is thrown for the existing path'
-            def thrown  = thrown(AlreadyDefinedExceptionBatch)
-            assert thrown.alreadyDefinedXpaths == [ "/bookstore/categories[@code='1']" ] as Set
+            def thrown  = thrown(AlreadyDefinedException)
+            assert thrown.alreadyDefinedObjectNames == [ "/bookstore/categories[@code='1']" ] as Set
         and: 'the new data node has been added i.e. can be retrieved'
             assert objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="new"]', DIRECT_CHILDREN_ONLY).size() == 1
     }
@@ -305,20 +350,6 @@ def 'Add and Delete a (container) data node.'() {
             'new code, new child'           | 'new'        | ', "books" : [ { "title": "New Book" } ]' || 2
     }
 
-    def 'Update multiple data node leaves.'() {
-        given: 'Updated json for bookstore data'
-            def jsonData =  "{'book-store:books':{'lang':'English/French','price':100,'title':'Matilda'}}"
-        when: 'update is performed for leaves'
-            objectUnderTest.updateNodeLeaves(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_2, "/bookstore/categories[@code='1']", jsonData, now)
-        then: 'the updated data nodes are retrieved'
-            def result = cpsDataService.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_2, "/bookstore/categories[@code=1]/books[@title='Matilda']", INCLUDE_ALL_DESCENDANTS)
-        and: 'the leaf values are updated as expected'
-            assert result.leaves['lang'] == ['English/French']
-            assert result.leaves['price'] == [100]
-        cleanup:
-            restoreBookstoreDataAnchor(2)
-    }
-
     def 'Update data node leaves for node that has no leaves (yet).'() {
         given: 'new (webinfo) datanode without leaves'
             def json = '{"webinfo": {} }'
@@ -362,4 +393,26 @@ def 'Add and Delete a (container) data node.'() {
         cleanup:
             restoreBookstoreDataAnchor(1)
     }
+
+    def 'Update multiple data node leaves.'() {
+        given: 'Updated json for bookstore data'
+            def jsonData =  "{'book-store:books':{'lang':'English/French','price':100,'title':'Matilda'}}"
+        when: 'update is performed for leaves'
+            objectUnderTest.updateNodeLeaves(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_2, "/bookstore/categories[@code='1']", jsonData, now)
+        then: 'the updated data nodes are retrieved'
+            def result = cpsDataService.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_2, "/bookstore/categories[@code=1]/books[@title='Matilda']", INCLUDE_ALL_DESCENDANTS)
+        and: 'the leaf values are updated as expected'
+            assert result.leaves['lang'] == ['English/French']
+            assert result.leaves['price'] == [100]
+        cleanup:
+            restoreBookstoreDataAnchor(2)
+    }
+
+    def countDataNodesInBookstore() {
+        return countDataNodesInTree(objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', INCLUDE_ALL_DESCENDANTS))
+    }
+
+    def countTopLevelListDataNodesInBookstore() {
+        return countDataNodesInTree(objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/', INCLUDE_ALL_DESCENDANTS))
+    }
 }