2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2023 Nordix Foundation
4 * Modifications Copyright (C) 2023 TechMahindra Ltd.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the 'License');
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an 'AS IS' BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.cps.integration.functional
24 import org.onap.cps.api.CpsDataService
25 import org.onap.cps.integration.base.FunctionalSpecBase
26 import org.onap.cps.spi.FetchDescendantsOption
27 import org.onap.cps.spi.exceptions.AlreadyDefinedException
28 import org.onap.cps.spi.exceptions.AnchorNotFoundException
29 import org.onap.cps.spi.exceptions.CpsAdminException
30 import org.onap.cps.spi.exceptions.CpsPathException
31 import org.onap.cps.spi.exceptions.DataNodeNotFoundException
32 import org.onap.cps.spi.exceptions.DataNodeNotFoundExceptionBatch
33 import org.onap.cps.spi.exceptions.DataValidationException
34 import org.onap.cps.spi.exceptions.DataspaceNotFoundException
36 import java.time.OffsetDateTime
38 import static org.onap.cps.spi.FetchDescendantsOption.DIRECT_CHILDREN_ONLY
39 import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
40 import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS
42 class CpsDataServiceIntegrationSpec extends FunctionalSpecBase {
44 CpsDataService objectUnderTest
45 def originalCountBookstoreChildNodes
46 def originalCountBookstoreTopLevelListNodes
47 def now = OffsetDateTime.now()
50 objectUnderTest = cpsDataService
51 originalCountBookstoreChildNodes = countDataNodesInBookstore()
52 originalCountBookstoreTopLevelListNodes = countTopLevelListDataNodesInBookstore()
55 def 'Read bookstore top-level container(s) using #fetchDescendantsOption.'() {
56 when: 'get data nodes for bookstore container'
57 def result = objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', fetchDescendantsOption)
58 then: 'the tree consist ouf of #expectNumberOfDataNodes data nodes'
59 assert countDataNodesInTree(result) == expectNumberOfDataNodes
60 and: 'the top level data node has the expected attribute and value'
61 assert result.leaves['bookstore-name'] == ['Easons-1']
62 and: 'they are from the correct dataspace'
63 assert result.dataspace == [FUNCTIONAL_TEST_DATASPACE_1]
64 and: 'they are from the correct anchor'
65 assert result.anchorName == [BOOKSTORE_ANCHOR_1]
66 where: 'the following option is used'
67 fetchDescendantsOption || expectNumberOfDataNodes
69 DIRECT_CHILDREN_ONLY || 7
70 INCLUDE_ALL_DESCENDANTS || 28
71 new FetchDescendantsOption(2) || 28
74 def 'Read bookstore top-level container(s) using "root" path variations.'() {
75 when: 'get data nodes for bookstore container'
76 def result = objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, root, OMIT_DESCENDANTS)
77 then: 'the tree consist correct number of data nodes'
78 assert countDataNodesInTree(result) == 2
79 and: 'the top level data node has the expected number of leaves'
80 assert result.leaves.size() == 2
81 where: 'the following variations of "root" are used'
85 def 'Read data nodes with error: #cpsPath'() {
86 when: 'attempt to get data nodes using invalid path'
87 objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, DIRECT_CHILDREN_ONLY)
88 then: 'a #expectedException is thrown'
89 thrown(expectedException)
91 cpsPath || expectedException
92 'invalid path' || CpsPathException
93 '/non-existing-path' || DataNodeNotFoundException
96 def 'Read (multiple) data nodes (batch) with #cpsPath'() {
97 when: 'attempt to get data nodes using invalid path'
98 objectUnderTest.getDataNodesForMultipleXpaths(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, [ cpsPath ], DIRECT_CHILDREN_ONLY)
99 then: 'no exception is thrown'
102 cpsPath << [ 'invalid path', '/non-existing-path' ]
105 def 'Get data nodes error scenario #scenario'() {
106 when: 'attempt to retrieve data nodes'
107 objectUnderTest.getDataNodes(dataspaceName, anchorName, xpath, OMIT_DESCENDANTS)
108 then: 'expected exception is thrown'
109 thrown(expectedException)
110 where: 'following data is used'
111 scenario | dataspaceName | anchorName | xpath || expectedException
112 'non existent dataspace' | 'non-existent' | 'not-relevant' | '/not-relevant' || DataspaceNotFoundException
113 'non existent anchor' | FUNCTIONAL_TEST_DATASPACE_1 | 'non-existent' | '/not-relevant' || AnchorNotFoundException
114 'non-existent xpath' | FUNCTIONAL_TEST_DATASPACE_1 | BOOKSTORE_ANCHOR_1| '/non-existing' || DataNodeNotFoundException
115 'invalid-dataspace' | 'Invalid dataspace' | 'not-relevant' | '/not-relevant' || DataValidationException
116 'invalid-dataspace' | FUNCTIONAL_TEST_DATASPACE_1 | 'Invalid Anchor' | '/not-relevant' || DataValidationException
119 def 'Delete root data node.'() {
120 when: 'the "root" is deleted'
121 objectUnderTest.deleteDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, [ '/' ], now)
122 and: 'attempt to get the top level data node'
123 objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', DIRECT_CHILDREN_ONLY)
124 then: 'an datanode not found exception is thrown'
125 thrown(DataNodeNotFoundException)
127 restoreBookstoreDataAnchor(1)
130 def 'Get whole list data' () {
131 def xpathForWholeList = "/bookstore/categories"
132 when: 'get data nodes for bookstore container'
133 def dataNodes = objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, xpathForWholeList, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS)
134 then: 'the tree consist ouf of #expectNumberOfDataNodes data nodes'
135 assert dataNodes.size() == 5
136 and: 'each datanode contains the list node xpath partially in its xpath'
137 dataNodes.each {dataNode ->
138 assert dataNode.xpath.contains(xpathForWholeList)
142 def 'Read (multiple) data nodes with #scenario' () {
143 when: 'attempt to get data nodes using multiple valid xpaths'
144 def dataNodes = objectUnderTest.getDataNodesForMultipleXpaths(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, xpath, OMIT_DESCENDANTS)
145 then: 'expected numer of data nodes are returned'
146 dataNodes.size() == expectedNumberOfDataNodes
147 where: 'the following data was used'
148 scenario | xpath | expectedNumberOfDataNodes
149 'container-node xpath' | ['/bookstore'] | 1
150 'list-item' | ['/bookstore/categories[@code=1]'] | 1
151 'parent-list xpath' | ['/bookstore/categories'] | 5
152 'child-list xpath' | ['/bookstore/categories[@code=1]/books'] | 2
153 'both parent and child list xpath' | ['/bookstore/categories', '/bookstore/categories[@code=1]/books'] | 7
156 def 'Add and Delete a (container) data node using #scenario.'() {
157 when: 'the new datanode is saved'
158 objectUnderTest.saveData(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1 , parentXpath, json, now)
159 then: 'it can be retrieved by its normalized xpath'
160 def result = objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, normalizedXpathToNode, DIRECT_CHILDREN_ONLY)
161 assert result.size() == 1
162 assert result[0].xpath == normalizedXpathToNode
163 and: 'there is now one extra datanode'
164 assert originalCountBookstoreChildNodes + 1 == countDataNodesInBookstore()
165 when: 'the new datanode is deleted'
166 objectUnderTest.deleteDataNode(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, normalizedXpathToNode, now)
167 then: 'the original number of data nodes is restored'
168 assert originalCountBookstoreChildNodes == countDataNodesInBookstore()
170 scenario | parentXpath | json || normalizedXpathToNode
171 'normalized parent xpath' | '/bookstore' | '{"webinfo": {"domain-name":"ourbookstore.com", "contact-email":"info@ourbookstore.com" }}' || "/bookstore/webinfo"
172 'non-normalized parent xpath' | '/bookstore/categories[ @code="1"]' | '{"books": {"title":"new" }}' || "/bookstore/categories[@code='1']/books[@title='new']"
175 def 'Attempt to create a top level data node using root.'() {
176 given: 'a new anchor'
177 cpsAdminService.createAnchor(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_SCHEMA_SET, 'newAnchor1');
178 when: 'attempt to save new top level datanode'
179 def json = '{"bookstore": {"bookstore-name": "New Store"} }'
180 objectUnderTest.saveData(FUNCTIONAL_TEST_DATASPACE_1, 'newAnchor1' , '/', json, now)
181 then: 'since there is no data a data node not found exception is thrown'
182 thrown(DataNodeNotFoundException)
185 def 'Attempt to save top level data node that already exist'() {
186 when: 'attempt to save already existing top level node'
187 def json = '{"bookstore": {} }'
188 objectUnderTest.saveData(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, json, now)
189 then: 'an exception that (one cps paths is) already defined is thrown '
190 def exceptionThrown = thrown(AlreadyDefinedException)
191 exceptionThrown.alreadyDefinedObjectNames == ['/bookstore' ] as Set
193 restoreBookstoreDataAnchor(1)
196 def 'Delete a single datanode with invalid path.'() {
197 when: 'attempt to delete a single datanode with invalid path'
198 objectUnderTest.deleteDataNode(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/invalid path', now)
199 then: 'a cps path parser exception is thrown'
200 thrown(CpsPathException)
203 def 'Delete multiple data nodes with invalid path.'() {
204 when: 'attempt to delete datanode collection with invalid path'
205 objectUnderTest.deleteDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, ['/invalid path'], now)
206 then: 'the error is silently ignored'
210 def 'Delete single data node with non-existing path.'() {
211 when: 'attempt to delete a single datanode non-existing invalid path'
212 objectUnderTest.deleteDataNode(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/does/not/exist', now)
213 then: 'a datanode not found exception is thrown'
214 thrown(DataNodeNotFoundException)
217 def 'Delete multiple data nodes with non-existing path(s).'() {
218 when: 'attempt to delete a single datanode non-existing invalid path'
219 objectUnderTest.deleteDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, ['/does/not/exist'], now)
220 then: 'a datanode not found (batch) exception is thrown'
221 thrown(DataNodeNotFoundExceptionBatch)
224 def 'Add and Delete top-level list (element) data nodes with root node.'() {
225 given: 'a new (multiple-data-tree:invoice) datanodes'
226 def json = '{"bookstore-address":[{"bookstore-name":"Easons","address":"Bangalore,India","postal-code":"560043"}]}'
227 when: 'the new list elements are saved'
228 objectUnderTest.saveListElements(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1 , '/', json, now)
229 then: 'they can be retrieved by their xpaths'
230 objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1 , '/bookstore-address[@bookstore-name="Easons"]', INCLUDE_ALL_DESCENDANTS)
231 and: 'there is one extra datanode'
232 assert originalCountBookstoreTopLevelListNodes + 1 == countTopLevelListDataNodesInBookstore()
233 when: 'the new elements are deleted'
234 objectUnderTest.deleteDataNode(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1 , '/bookstore-address[@bookstore-name="Easons"]', now)
235 then: 'the original number of datanodes is restored'
236 assert originalCountBookstoreTopLevelListNodes == countTopLevelListDataNodesInBookstore()
239 def 'Add and Delete list (element) data nodes.'() {
240 given: 'two new (categories) data nodes'
241 def json = '{"categories": [ {"code":"new1"}, {"code":"new2" } ] }'
242 when: 'the new list elements are saved'
243 objectUnderTest.saveListElements(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1 , '/bookstore', json, now)
244 then: 'they can be retrieved by their xpaths'
245 objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="new1"]', DIRECT_CHILDREN_ONLY).size() == 1
246 objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="new2"]', DIRECT_CHILDREN_ONLY).size() == 1
247 and: 'there are now two extra data nodes'
248 assert originalCountBookstoreChildNodes + 2 == countDataNodesInBookstore()
249 when: 'the new elements are deleted'
250 objectUnderTest.deleteDataNode(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="new1"]', now)
251 objectUnderTest.deleteDataNode(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="new2"]', now)
252 then: 'the original number of data nodes is restored'
253 assert originalCountBookstoreChildNodes == countDataNodesInBookstore()
256 def 'Add list (element) data nodes that already exist.'() {
257 given: 'two (categories) data nodes, one new and one existing'
258 def json = '{"categories": [ {"code":"1"}, {"code":"new1"} ] }'
259 when: 'attempt to save the list element'
260 objectUnderTest.saveListElements(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1 , '/bookstore', json, now)
261 then: 'an exception that (one cps paths is) already defined is thrown '
262 def exceptionThrown = thrown(AlreadyDefinedException)
263 exceptionThrown.alreadyDefinedObjectNames == ['/bookstore/categories[@code=\'1\']' ] as Set
264 and: 'there is now one extra data nodes'
265 assert originalCountBookstoreChildNodes + 1 == countDataNodesInBookstore()
267 restoreBookstoreDataAnchor(1)
270 def 'Add and Delete list (element) data nodes using lists specific method.'() {
271 given: 'a new (categories) data nodes'
272 def json = '{"categories": [ {"code":"new1"} ] }'
273 and: 'the new list element is saved'
274 objectUnderTest.saveListElements(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1 , '/bookstore', json, now)
275 when: 'the new element is deleted'
276 objectUnderTest.deleteListOrListElement(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="new1"]', now)
277 then: 'the original number of data nodes is restored'
278 assert originalCountBookstoreChildNodes == countDataNodesInBookstore()
281 def 'Add and Delete a batch of lists (element) data nodes.'() {
282 given: 'two new (categories) data nodes in two separate batches'
283 def json1 = '{"categories": [ {"code":"new1"} ] }'
284 def json2 = '{"categories": [ {"code":"new2"} ] } '
285 when: 'the batches of new list element(s) are saved'
286 objectUnderTest.saveListElementsBatch(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1 , '/bookstore', [json1, json2], now)
287 then: 'they can be retrieved by their xpaths'
288 assert objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="new1"]', DIRECT_CHILDREN_ONLY).size() == 1
289 assert objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="new2"]', DIRECT_CHILDREN_ONLY).size() == 1
290 and: 'there are now two extra data nodes'
291 assert originalCountBookstoreChildNodes + 2 == countDataNodesInBookstore()
292 when: 'the new elements are deleted'
293 objectUnderTest.deleteDataNode(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="new1"]', now)
294 objectUnderTest.deleteDataNode(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="new2"]', now)
295 then: 'the original number of data nodes is restored'
296 assert originalCountBookstoreChildNodes == countDataNodesInBookstore()
299 def 'Add and Delete a batch of lists (element) data nodes with partial success.'() {
300 given: 'two new (categories) data nodes in two separate batches'
301 def jsonNewElement = '{"categories": [ {"code":"new1"} ] }'
302 def jsonExistingElement = '{"categories": [ {"code":"1"} ] } '
303 when: 'the batches of new list element(s) are saved'
304 objectUnderTest.saveListElementsBatch(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1 , '/bookstore', [jsonNewElement, jsonExistingElement], now)
305 then: 'an already defined (batch) exception is thrown for the existing path'
306 def exceptionThrown = thrown(AlreadyDefinedException)
307 assert exceptionThrown.alreadyDefinedObjectNames == ['/bookstore/categories[@code=\'1\']' ] as Set
308 and: 'there is now one extra data node'
309 assert originalCountBookstoreChildNodes + 1 == countDataNodesInBookstore()
311 restoreBookstoreDataAnchor(1)
314 def 'Attempt to add empty lists.'() {
315 when: 'the batches of new list element(s) are saved'
316 objectUnderTest.replaceListContent(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1 , '/bookstore', [ ], now)
317 then: 'an admin exception is thrown'
318 thrown(CpsAdminException)
321 def 'Add child error scenario: #scenario.'() {
322 when: 'attempt to add a child data node with #scenario'
323 objectUnderTest.saveData(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, parentXpath, json, now)
324 then: 'a #expectedException is thrown'
325 thrown(expectedException)
326 where: 'the following data is used'
327 scenario | parentXpath | json || expectedException
328 'parent does not exist' | '/bookstore/categories[@code="unknown"]' | '{"books": [ {"title":"new"} ] } ' || DataNodeNotFoundException
329 'already existing child' | '/bookstore' | '{"categories": [ {"code":"1"} ] }' || AlreadyDefinedException
332 def 'Add multiple child data nodes with partial success.'() {
333 given: 'one existing and one new list element'
334 def json = '{"categories": [ {"code":"1"}, {"code":"new"} ] }'
335 when: 'attempt to add the elements'
336 objectUnderTest.saveData(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', json, now)
337 then: 'an already defined (batch) exception is thrown for the existing path'
338 def thrown = thrown(AlreadyDefinedException)
339 assert thrown.alreadyDefinedObjectNames == [ "/bookstore/categories[@code='1']" ] as Set
340 and: 'the new data node has been added i.e. can be retrieved'
341 assert objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="new"]', DIRECT_CHILDREN_ONLY).size() == 1
344 def 'Replace list content #scenario.'() {
345 given: 'the bookstore categories 1 and 2 exist and have at least 1 child each '
346 assert countDataNodesInTree(objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="1"]', DIRECT_CHILDREN_ONLY)) > 1
347 assert countDataNodesInTree(objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="2"]', DIRECT_CHILDREN_ONLY)) > 1
348 when: 'the categories list is replaced with just category "1" and without child nodes (books)'
349 def json = '{"categories": [ {"code":"' +categoryCode + '"' + childJson + '} ] }'
350 objectUnderTest.replaceListContent(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', json, now)
351 then: 'the new replaced category can be retrieved but has no children anymore'
352 assert expectedNumberOfDataNodes == countDataNodesInTree(objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="' +categoryCode + '"]', DIRECT_CHILDREN_ONLY))
353 when: 'attempt to retrieve a category (code) not in the new list'
354 objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="2"]', DIRECT_CHILDREN_ONLY)
355 then: 'a datanode not found exception occurs'
356 thrown(DataNodeNotFoundException)
358 restoreBookstoreDataAnchor(1)
359 where: 'the following data is used'
360 scenario | categoryCode | childJson || expectedNumberOfDataNodes
361 'existing code, no children' | '1' | '' || 1
362 'existing code, new child' | '1' | ', "books" : [ { "title": "New Book" } ]' || 2
363 'existing code, existing child' | '1' | ', "books" : [ { "title": "Matilda" } ]' || 2
364 'new code, new child' | 'new' | ', "books" : [ { "title": "New Book" } ]' || 2
367 def 'Update data node leaves for node that has no leaves (yet).'() {
368 given: 'new (webinfo) datanode without leaves'
369 def json = '{"webinfo": {} }'
370 objectUnderTest.saveData(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1 , '/bookstore', json, now)
371 when: 'update is performed to add a leaf'
372 def updatedJson = '{"webinfo": {"domain-name":"new leaf data"}}'
373 objectUnderTest.updateNodeLeaves(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, "/bookstore", updatedJson, now)
374 then: 'the updated data nodes are retrieved'
375 def result = cpsDataService.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, "/bookstore/webinfo", INCLUDE_ALL_DESCENDANTS)
376 and: 'the leaf value is updated as expected'
377 assert result.leaves['domain-name'] == ['new leaf data']
379 restoreBookstoreDataAnchor(1)
382 def 'Update multiple data leaves error scenario: #scenario.'() {
383 when: 'attempt to update data node for #scenario'
384 objectUnderTest.updateNodeLeaves(dataspaceName, anchorName, xpath, 'irrelevant json data', now)
385 then: 'a #expectedException is thrown'
386 thrown(expectedException)
387 where: 'the following data is used'
388 scenario | dataspaceName | anchorName | xpath || expectedException
389 'invalid dataspace name' | 'Invalid Dataspace' | 'not-relevant' | '/not relevant' || DataValidationException
390 'invalid anchor name' | FUNCTIONAL_TEST_DATASPACE_1 | 'INVALID ANCHOR' | '/not relevant' || DataValidationException
391 'non-existing dataspace' | 'non-existing-dataspace' | 'not-relevant' | '/not relevant' || DataspaceNotFoundException
392 'non-existing anchor' | FUNCTIONAL_TEST_DATASPACE_1 | 'non-existing-anchor' | '/not relevant' || AnchorNotFoundException
393 'non-existing-xpath' | FUNCTIONAL_TEST_DATASPACE_1 | BOOKSTORE_ANCHOR_1 | '/non-existing' || DataValidationException
396 def 'Update data nodes and descendants.'() {
397 given: 'some web info for the bookstore'
398 def json = '{"webinfo": {"domain-name":"ourbookstore.com" ,"contact-email":"info@ourbookstore.com" }}'
399 objectUnderTest.saveData(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1 , '/bookstore', json, now)
400 when: 'the webinfo (container) is updated'
401 json = '{"webinfo": {"domain-name":"newdomain.com" ,"contact-email":"info@newdomain.com" }}'
402 objectUnderTest.updateDataNodeAndDescendants(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', json, now)
403 then: 'webinfo has been updated with teh new details'
404 def result = objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/webinfo', DIRECT_CHILDREN_ONLY)
405 result.leaves.'domain-name'[0] == 'newdomain.com'
406 result.leaves.'contact-email'[0] == 'info@newdomain.com'
408 restoreBookstoreDataAnchor(1)
411 def 'Update bookstore top-level container data node.'() {
412 when: 'the bookstore top-level container is updated'
413 def json = '{ "bookstore": { "bookstore-name": "new bookstore" }}'
414 objectUnderTest.updateDataNodeAndDescendants(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/', json, now)
415 then: 'bookstore name has been updated'
416 def result = objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', DIRECT_CHILDREN_ONLY)
417 result.leaves.'bookstore-name'[0] == 'new bookstore'
419 restoreBookstoreDataAnchor(1)
422 def 'Update multiple data node leaves.'() {
423 given: 'Updated json for bookstore data'
424 def jsonData = "{'book-store:books':{'lang':'English/French','price':100,'title':'Matilda'}}"
425 when: 'update is performed for leaves'
426 objectUnderTest.updateNodeLeaves(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_2, "/bookstore/categories[@code='1']", jsonData, now)
427 then: 'the updated data nodes are retrieved'
428 def result = cpsDataService.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_2, "/bookstore/categories[@code=1]/books[@title='Matilda']", INCLUDE_ALL_DESCENDANTS)
429 and: 'the leaf values are updated as expected'
430 assert result.leaves['lang'] == ['English/French']
431 assert result.leaves['price'] == [100]
433 restoreBookstoreDataAnchor(2)
436 def countDataNodesInBookstore() {
437 return countDataNodesInTree(objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', INCLUDE_ALL_DESCENDANTS))
440 def countTopLevelListDataNodesInBookstore() {
441 return countDataNodesInTree(objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/', INCLUDE_ALL_DESCENDANTS))