+ @Sql([CLEAR_DATA, SET_DATA])
+ def 'Delete list scenario: #scenario.'() {
+ when: 'deleting list is executed for: #scenario.'
+ objectUnderTest.deleteListDataNode(DATASPACE_NAME, ANCHOR_NAME3, targetXpaths)
+ then: 'only the expected children remain'
+ def parentFragment = fragmentRepository.getById(parentFragmentId)
+ def remainingChildXpaths = parentFragment.getChildFragments().collect { it.getXpath() }
+ assert remainingChildXpaths.size() == expectedRemainingChildXpaths.size()
+ assert remainingChildXpaths.containsAll(expectedRemainingChildXpaths)
+ where: 'following parameters were used'
+ scenario | targetXpaths | parentFragmentId || expectedRemainingChildXpaths
+ 'list element with key' | '/parent-203/child-204[@key="A"]' | LIST_DATA_NODE_PARENT203_FRAGMENT_ID || ['/parent-203/child-203', '/parent-203/child-204[@key="X"]']
+ 'list element with combined keys' | '/parent-202/child-205[@key="A" and @key2="B"]' | LIST_DATA_NODE_PARENT202_FRAGMENT_ID || ['/parent-202/child-206[@key="A"]']
+ 'whole list' | '/parent-203/child-204' | LIST_DATA_NODE_PARENT203_FRAGMENT_ID || ['/parent-203/child-203']
+ 'list element under list element' | '/parent-203/child-204[@key="X"]/grand-child-204[@key2="Y"]' | LIST_DATA_NODE_PARENT203_FRAGMENT_ID || ['/parent-203/child-203', '/parent-203/child-204[@key="X"]', '/parent-203/child-204[@key="A"]']
+ }
+
+ @Sql([CLEAR_DATA, SET_DATA])
+ def 'Delete list error scenario: #scenario.'() {
+ when: 'attempting to delete scenario: #scenario.'
+ objectUnderTest.deleteListDataNode(DATASPACE_NAME, ANCHOR_NAME3, targetXpaths)
+ then: 'a DataNodeNotFoundException is thrown'
+ thrown(DataNodeNotFoundException)
+ where: 'following parameters were used'
+ scenario | targetXpaths
+ 'whole list, parent node does not exist' | '/unknown/some-child'
+ 'list element, parent node does not exist' | '/unknown/child-204[@key="A"]'
+ 'whole list does not exist' | '/parent-200/unknown'
+ 'list element, list does not exist' | '/parent-200/unknown[@key="C"]'
+ 'list element, element does not exist' | '/parent-203/child-204[@key="C"]'
+ 'valid datanode but not a list' | '/parent-200/child-202'
+ }
+
+ @Sql([CLEAR_DATA, SET_DATA])
+ def 'Confirm deletion of #scenario.'() {
+ given: 'a valid data node'
+ def dataNode
+ def dataNodeXpath
+ when: 'data nodes are deleted'
+ objectUnderTest.deleteDataNode(DATASPACE_NAME, ANCHOR_NAME3, xpathForDeletion)
+ then: 'verify data nodes are removed'
+ try {
+ dataNode = objectUnderTest.getDataNode(DATASPACE_NAME, ANCHOR_NAME3, getDataNodesXpaths, INCLUDE_ALL_DESCENDANTS)
+ dataNodeXpath = dataNode.getXpath()
+ assert dataNodeXpath == expectedXpaths
+ } catch (DataNodeNotFoundException) {
+ assert dataNodeXpath == expectedXpaths
+ }
+ where: 'following parameters were used'
+ scenario | xpathForDeletion | getDataNodesXpaths || expectedXpaths
+ 'child of target' | '/parent-206/child-206' | '/parent-206/child-206' || null
+ 'child data node, parent still exists' | '/parent-206/child-206' | '/parent-206' || '/parent-206'
+ 'list element' | '/parent-206/child-206/grand-child-206[@key="A"]' | '/parent-206/child-206/grand-child-206[@key="A"]' || null
+ 'list element, sibling still exists' | '/parent-206/child-206/grand-child-206[@key="A"]' | '/parent-206/child-206/grand-child-206[@key="X"]' || '/parent-206/child-206/grand-child-206[@key="X"]'
+ }
+
+ @Sql([CLEAR_DATA, SET_DATA])
+ def 'Delete data node with #scenario.'() {
+ when: 'data node is deleted'
+ objectUnderTest.deleteDataNode(DATASPACE_NAME, ANCHOR_NAME3, datanodeXpath)
+ then: 'a #expectedException is thrown'
+ thrown(DataNodeNotFoundException)
+ where: 'the following parameters were used'
+ scenario | datanodeXpath
+ 'valid data node, non existent child node' | '/parent-203/child-non-existent'
+ 'invalid list element' | '/parent-206/child-206/grand-child-206@key="A"]'