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
CpsDataService objectUnderTest
def originalCountBookstoreChildNodes
+ def originalCountBookstoreTopLevelListNodes
def now = OffsetDateTime.now()
def setup() {
objectUnderTest = cpsDataService
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, root, OMIT_DESCENDANTS)
then: 'the tree consist ouf of one data node'
- assert countDataNodesInTree(result) == 1
+ assert countDataNodesInTree(result) == 2
and: 'the top level data node has the expected attribute and value'
- assert result.leaves['bookstore-name'] == ['Easons']
+ assert result.leaves.size() == 2
where: 'the following variations of "root" are used'
root << [ '/', '' ]
}
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)
}
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 = '{"multiple-data-tree:invoice": [{"ProductID": "2","ProductName": "Mango","price": "150","stock": true}]}'
+ 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 , '/invoice[@ProductID ="2"]', 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 , '/invoice[@ProductID ="2"]', 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" } ] }'
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:
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:
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.'() {
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
}
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))
+ }
}