Remove the dependency-cycle between beans
[cps.git] / integration-test / src / test / groovy / org / onap / cps / integration / functional / CpsDataServiceIntegrationSpec.groovy
index 5c9ced3..b107a87 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
@@ -32,8 +32,7 @@ import org.onap.cps.spi.exceptions.DataNodeNotFoundException
 import org.onap.cps.spi.exceptions.DataNodeNotFoundExceptionBatch
 import org.onap.cps.spi.exceptions.DataValidationException
 import org.onap.cps.spi.exceptions.DataspaceNotFoundException
-
-import java.time.OffsetDateTime
+import org.onap.cps.spi.model.DeltaReport
 
 import static org.onap.cps.spi.FetchDescendantsOption.DIRECT_CHILDREN_ONLY
 import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
@@ -43,11 +42,12 @@ class CpsDataServiceIntegrationSpec extends FunctionalSpecBase {
 
     CpsDataService objectUnderTest
     def originalCountBookstoreChildNodes
-    def now = OffsetDateTime.now()
+    def originalCountBookstoreTopLevelListNodes
 
     def setup() {
         objectUnderTest = cpsDataService
         originalCountBookstoreChildNodes = countDataNodesInBookstore()
+        originalCountBookstoreTopLevelListNodes = countTopLevelListDataNodesInBookstore()
     }
 
     def 'Read bookstore top-level container(s) using #fetchDescendantsOption.'() {
@@ -56,7 +56,7 @@ class CpsDataServiceIntegrationSpec extends FunctionalSpecBase {
         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']
+            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'
@@ -64,18 +64,18 @@ class CpsDataServiceIntegrationSpec extends FunctionalSpecBase {
         where: 'the following option is used'
             fetchDescendantsOption        || expectNumberOfDataNodes
             OMIT_DESCENDANTS              || 1
-            DIRECT_CHILDREN_ONLY          || 6
-            INCLUDE_ALL_DESCENDANTS       || 17
-            new FetchDescendantsOption(2) || 17
+            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']
+        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 << [ '/', '' ]
     }
@@ -100,6 +100,20 @@ class CpsDataServiceIntegrationSpec extends FunctionalSpecBase {
             cpsPath << [ 'invalid path', '/non-existing-path' ]
     }
 
+    def 'Get data nodes error scenario #scenario'() {
+        when: 'attempt to retrieve data nodes'
+            objectUnderTest.getDataNodes(dataspaceName, anchorName, xpath, OMIT_DESCENDANTS)
+        then: 'expected exception is thrown'
+            thrown(expectedException)
+        where: 'following data is used'
+            scenario                 | dataspaceName                | anchorName        | xpath           || expectedException
+            'non existent dataspace' | 'non-existent'               | 'not-relevant'    | '/not-relevant' || DataspaceNotFoundException
+            'non existent anchor'    | FUNCTIONAL_TEST_DATASPACE_1  | 'non-existent'    | '/not-relevant' || AnchorNotFoundException
+            'non-existent xpath'     | FUNCTIONAL_TEST_DATASPACE_1  | BOOKSTORE_ANCHOR_1| '/non-existing' || DataNodeNotFoundException
+            'invalid-dataspace'      | 'Invalid dataspace'          | 'not-relevant'    | '/not-relevant' || DataValidationException
+            'invalid-dataspace'      | FUNCTIONAL_TEST_DATASPACE_1  | 'Invalid Anchor'  | '/not-relevant' || DataValidationException
+    }
+
     def 'Delete root data node.'() {
         when: 'the "root" is deleted'
             objectUnderTest.deleteDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, [ '/' ], now)
@@ -111,28 +125,54 @@ class CpsDataServiceIntegrationSpec extends FunctionalSpecBase {
             restoreBookstoreDataAnchor(1)
     }
 
+    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']"
+            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.'() {
         given: 'a new anchor'
-            cpsAdminService.createAnchor(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_SCHEMA_SET, 'newAnchor1');
+            cpsAnchorService.createAnchor(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_SCHEMA_SET, 'newAnchor1');
         when: 'attempt to save new top level datanode'
             def json = '{"bookstore": {"bookstore-name": "New Store"} }'
             objectUnderTest.saveData(FUNCTIONAL_TEST_DATASPACE_1, 'newAnchor1' , '/', json, now)
@@ -145,8 +185,8 @@ class CpsDataServiceIntegrationSpec extends FunctionalSpecBase {
             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)
     }
@@ -179,6 +219,21 @@ class CpsDataServiceIntegrationSpec extends FunctionalSpecBase {
             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":"Easons","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" } ] }'
@@ -202,8 +257,8 @@ class CpsDataServiceIntegrationSpec extends FunctionalSpecBase {
         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 == countDataNodesInBookstore()
         cleanup:
@@ -246,8 +301,8 @@ class CpsDataServiceIntegrationSpec extends FunctionalSpecBase {
         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 == countDataNodesInBookstore()
         cleanup:
@@ -269,7 +324,7 @@ class CpsDataServiceIntegrationSpec extends FunctionalSpecBase {
         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.'() {
@@ -278,8 +333,8 @@ class CpsDataServiceIntegrationSpec extends FunctionalSpecBase {
         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
     }
@@ -307,20 +362,6 @@ class CpsDataServiceIntegrationSpec extends FunctionalSpecBase {
             '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": {} }'
@@ -365,7 +406,132 @@ class CpsDataServiceIntegrationSpec extends FunctionalSpecBase {
             restoreBookstoreDataAnchor(1)
     }
 
+    def 'Update bookstore top-level container data node.'() {
+        when: 'the bookstore top-level container is updated'
+            def json = '{ "bookstore": { "bookstore-name": "new bookstore" }}'
+            objectUnderTest.updateDataNodeAndDescendants(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/', json, now)
+        then: 'bookstore name has been updated'
+            def result = objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', DIRECT_CHILDREN_ONLY)
+            result.leaves.'bookstore-name'[0] == 'new bookstore'
+        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 'Get delta between 2 anchors for when #scenario'() {
+        when: 'attempt to get delta report between anchors'
+            def result = objectUnderTest.getDeltaByDataspaceAndAnchors(FUNCTIONAL_TEST_DATASPACE_3, BOOKSTORE_ANCHOR_3, BOOKSTORE_ANCHOR_5, xpath, fetchDescendantOption)
+        then: 'delta report contains expected number of changes'
+            result.size() == 2
+        and: 'delta report contains expected action'
+            assert result.get(index).getAction() == expectedActions
+        and: 'delta report contains expected xpath'
+            assert result.get(index).getXpath() == expectedXpath
+        where: 'following data was used'
+            scenario            | index | xpath || expectedActions || expectedXpath                                                | fetchDescendantOption
+            'a node is removed' |   0   | '/'   ||    'remove'     || "/bookstore-address[@bookstore-name='Easons-1']"             | OMIT_DESCENDANTS
+            'a node is added'   |   1   | '/'   ||     'add'       || "/bookstore-address[@bookstore-name='Crossword Bookstores']" | OMIT_DESCENDANTS
+    }
+
+    def 'Get delta between 2 anchors where child nodes are added/removed but parent node remains unchanged'() {
+        def parentNodeXpath = "/bookstore"
+        when: 'attempt to get delta report between anchors'
+            def result = objectUnderTest.getDeltaByDataspaceAndAnchors(FUNCTIONAL_TEST_DATASPACE_3, BOOKSTORE_ANCHOR_3, BOOKSTORE_ANCHOR_5, parentNodeXpath, INCLUDE_ALL_DESCENDANTS)
+        then: 'delta report contains expected number of changes'
+            result.size() == 11
+        and: 'the delta report does not contain parent node xpath'
+            def xpaths = getDeltaReportEntities(result).get('xpaths')
+            assert !(xpaths.contains(parentNodeXpath))
+    }
+
+    def 'Get delta between 2 anchors returns empty response when #scenario'() {
+        when: 'attempt to get delta report between anchors'
+            def result = objectUnderTest.getDeltaByDataspaceAndAnchors(FUNCTIONAL_TEST_DATASPACE_3, sourceAnchor, targetAnchor, xpath, INCLUDE_ALL_DESCENDANTS)
+        then: 'delta report is empty'
+            assert result.isEmpty()
+        where: 'following data was used'
+            scenario                              | sourceAnchor       | targetAnchor       | xpath
+        'anchors with identical data are queried' | BOOKSTORE_ANCHOR_3 | BOOKSTORE_ANCHOR_4 | '/'
+        'same anchor name is passed as parameter' | BOOKSTORE_ANCHOR_3 | BOOKSTORE_ANCHOR_3 | '/'
+        'non existing xpath'                      | BOOKSTORE_ANCHOR_3 | BOOKSTORE_ANCHOR_5 | '/non-existing-xpath'
+    }
+
+    def 'Get delta between anchors error scenario: #scenario'() {
+        when: 'attempt to get delta between anchors'
+            objectUnderTest.getDeltaByDataspaceAndAnchors(dataspaceName, sourceAnchor, targetAnchor, '/some-xpath', INCLUDE_ALL_DESCENDANTS)
+        then: 'expected exception is thrown'
+            thrown(expectedException)
+        where: 'following data was used'
+                    scenario                               | dataspaceName               | sourceAnchor          | targetAnchor          || expectedException
+            'invalid dataspace name'                       | 'Invalid dataspace'         | 'not-relevant'        | 'not-relevant'        || DataValidationException
+            'invalid anchor 1 name'                        | FUNCTIONAL_TEST_DATASPACE_3 | 'invalid anchor'      | 'not-relevant'        || DataValidationException
+            'invalid anchor 2 name'                        | FUNCTIONAL_TEST_DATASPACE_3 | BOOKSTORE_ANCHOR_3    | 'invalid anchor'      || DataValidationException
+            'non-existing dataspace'                       | 'non-existing'              | 'not-relevant1'       | 'not-relevant2'       || DataspaceNotFoundException
+            'non-existing dataspace with same anchor name' | 'non-existing'              | 'not-relevant'        | 'not-relevant'        || DataspaceNotFoundException
+            'non-existing anchor 1'                        | FUNCTIONAL_TEST_DATASPACE_3 | 'non-existing-anchor' | 'not-relevant'        || AnchorNotFoundException
+            'non-existing anchor 2'                        | FUNCTIONAL_TEST_DATASPACE_3 | BOOKSTORE_ANCHOR_3    | 'non-existing-anchor' || AnchorNotFoundException
+    }
+
+    def 'Get delta between anchors for remove action, where source data node #scenario'() {
+        when: 'attempt to get delta between leaves of data nodes present in 2 anchors'
+            def result = objectUnderTest.getDeltaByDataspaceAndAnchors(FUNCTIONAL_TEST_DATASPACE_3, BOOKSTORE_ANCHOR_5, BOOKSTORE_ANCHOR_3, parentNodeXpath, INCLUDE_ALL_DESCENDANTS)
+        then: 'expected action is present in delta report'
+            assert result.get(0).getAction() == 'remove'
+        where: 'following data was used'
+            scenario                     | parentNodeXpath
+            'has leaves and child nodes' | "/bookstore/categories[@code='6']"
+            'has leaves only'            | "/bookstore/categories[@code='5']/books[@title='Book 11']"
+            'has child data node only'   | "/bookstore/support-info/contact-emails"
+            'is empty'                   | "/bookstore/container-without-leaves"
+    }
+
+    def 'Get delta between anchors for add action, where target data node #scenario'() {
+        when: 'attempt to get delta between leaves of data nodes present in 2 anchors'
+            def result = objectUnderTest.getDeltaByDataspaceAndAnchors(FUNCTIONAL_TEST_DATASPACE_3, BOOKSTORE_ANCHOR_3, BOOKSTORE_ANCHOR_5, parentNodeXpath, INCLUDE_ALL_DESCENDANTS)
+        then: 'the expected action is present in delta report'
+            result.get(0).getAction() == 'add'
+        and: 'the expected xapth is present in delta report'
+            result.get(0).getXpath() == parentNodeXpath
+        where: 'following data was used'
+            scenario                     | parentNodeXpath
+            'has leaves and child nodes' | "/bookstore/categories[@code='6']"
+            'has leaves only'            | "/bookstore/categories[@code='5']/books[@title='Book 11']"
+            'has child data node only'   | "/bookstore/support-info/contact-emails"
+            'is empty'                   | "/bookstore/container-without-leaves"
+    }
+
+    def getDeltaReportEntities(List<DeltaReport> deltaReport) {
+        def xpaths = []
+        def action = []
+        def sourcePayload = []
+        def targetPayload = []
+        deltaReport.each {
+            delta -> xpaths.add(delta.getXpath())
+                action.add(delta.getAction())
+                sourcePayload.add(delta.getSourceData())
+                targetPayload.add(delta.getTargetData())
+        }
+        return ['xpaths':xpaths, 'action':action, 'sourcePayload':sourcePayload, 'targetPayload':targetPayload]
+    }
+
     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))
+    }
 }