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 java.time.OffsetDateTime
25 import org.onap.cps.api.CpsQueryService
26 import org.onap.cps.integration.base.FunctionalSpecBase
27 import org.onap.cps.spi.FetchDescendantsOption
28 import org.onap.cps.spi.exceptions.CpsPathException
30 import static org.onap.cps.spi.FetchDescendantsOption.DIRECT_CHILD_ONLY
31 import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
32 import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS
34 class CpsQueryServiceIntegrationSpec extends FunctionalSpecBase {
36 CpsQueryService objectUnderTest
38 def setup() { objectUnderTest = cpsQueryService }
40 def 'Query bookstore using CPS path where #scenario.'() {
41 when: 'query data nodes for bookstore container'
42 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, INCLUDE_ALL_DESCENDANTS)
43 then: 'the result contains expected number of nodes'
44 assert result.size() == expectedResultSize
45 and: 'the result contains the expected leaf values'
46 result.leaves.forEach( dataNodeLeaves -> {
47 expectedLeaves.forEach( (expectedLeafKey,expectedLeafValue) -> {
48 assert dataNodeLeaves[expectedLeafKey] == expectedLeafValue
52 scenario | cpsPath || expectedResultSize | expectedLeaves
53 'the AND condition is used' | '//books[@lang="English" and @price=15]' || 2 | [lang:"English", price:15]
54 'the AND is used where result does not exist' | '//books[@lang="English" and @price=1000]' || 0 | []
57 def 'Cps Path query using comparative and boolean operators.'() {
58 given: 'a cps path query in the discount category'
59 def cpsPath = "/bookstore/categories[@code='5']/books" + leafCondition
60 when: 'a query is executed to get response by the given cps path'
61 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1,
62 cpsPath, OMIT_DESCENDANTS)
63 then: 'the cps-path of queryDataNodes has the expectedLeaves'
64 def bookPrices = result.collect { it.getLeaves().get('price') }
65 assert bookPrices.sort() == expectedBookPrices.sort()
66 where: 'the following data is used'
67 leafCondition || expectedBookPrices
69 '[@price < 5]' || [1, 2, 3, 4]
70 '[@price > 5]' || [6, 7, 8, 9, 10]
71 '[@price <= 5]' || [1, 2, 3, 4, 5]
72 '[@price >= 5]' || [5, 6, 7, 8, 9, 10]
74 '[@price = 3 or @price = 7]' || [3, 7]
75 '[@price = 3 and @price = 7]' || []
76 '[@price > 3 and @price <= 6]' || [4, 5, 6]
77 '[@price < 3 or @price > 8]' || [1, 2, 9, 10]
78 '[@price = 1 or @price = 3 or @price = 5]' || [1, 3, 5]
79 '[@price = 1 or @price >= 8 and @price < 10]' || [1, 8, 9]
80 '[@price >= 3 and @price <= 5 or @price > 9]' || [3, 4, 5, 10]
83 def 'Cps Path query for leaf value(s) with #scenario.'() {
84 when: 'a query is executed to get a data node by the given cps path'
85 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, fetchDescendantsOption)
86 then: 'the correct number of parent nodes are returned'
87 assert result.size() == expectedNumberOfParentNodes
88 and: 'the correct total number of data nodes are returned'
89 assert countDataNodesInTree(result) == expectedTotalNumberOfNodes
90 where: 'the following data is used'
91 scenario | cpsPath | fetchDescendantsOption || expectedNumberOfParentNodes | expectedTotalNumberOfNodes
92 'string and no descendants' | '/bookstore/categories[@code="1"]/books[@title="Matilda"]' | OMIT_DESCENDANTS || 1 | 1
93 'integer and descendants' | '/bookstore/categories[@code="1"]/books[@price=15]' | INCLUDE_ALL_DESCENDANTS || 1 | 1
94 'no condition and no descendants' | '/bookstore/categories' | OMIT_DESCENDANTS || 5 | 5
95 'no condition and level 1 descendants' | '/bookstore' | new FetchDescendantsOption(1) || 1 | 7
96 'no condition and level 2 descendants' | '/bookstore' | new FetchDescendantsOption(2) || 1 | 28
99 def 'Query for attribute by cps path with cps paths that return no data because of #scenario.'() {
100 when: 'a query is executed to get data nodes for the given cps path'
101 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, OMIT_DESCENDANTS)
102 then: 'no data is returned'
103 assert result.isEmpty()
104 where: 'following cps queries are performed'
106 'cps path is incomplete' | '/bookstore[@title="Matilda"]'
107 'leaf value does not exist' | '/bookstore/categories[@code="1"]/books[@title=\'does not exist\']'
108 'incomplete end of xpath prefix' | '/bookstore/categories/books[@price=15]'
111 def 'Cps Path query using descendant anywhere and #type (further) descendants.'() {
112 when: 'a query is executed to get a data node by the given cps path'
113 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="1"]', fetchDescendantsOption)
114 then: 'the data node has the correct number of children'
115 assert result[0].childDataNodes.xpath.sort() == expectedChildNodes.sort()
116 where: 'the following data is used'
117 type | fetchDescendantsOption || expectedChildNodes
118 'omit' | OMIT_DESCENDANTS || []
119 'include' | INCLUDE_ALL_DESCENDANTS || ["/bookstore/categories[@code='1']/books[@title='Matilda']",
120 "/bookstore/categories[@code='1']/books[@title='The Gruffalo']"]
123 def 'Cps Path query for all books.'() {
124 when: 'a query is executed to get all books'
125 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '//books', OMIT_DESCENDANTS)
126 then: 'the expected number of books are returned'
127 assert result.size() == 19
130 def 'Cps Path query using descendant anywhere with #scenario.'() {
131 when: 'a query is executed to get a data node by the given cps path'
132 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, OMIT_DESCENDANTS)
133 then: 'xpaths of the retrieved data nodes are as expected'
134 def bookTitles = result.collect { it.getLeaves().get('title') }
135 assert bookTitles.sort() == expectedBookTitles.sort()
136 where: 'the following data is used'
137 scenario | cpsPath || expectedBookTitles
138 'string leaf condition' | '//books[@title="Matilda"]' || ["Matilda"]
139 'text condition on leaf' | '//books/title[text()="Matilda"]' || ["Matilda"]
140 'text condition case mismatch' | '//books/title[text()="matilda"]' || []
141 'text condition on int leaf' | '//books/price[text()="20"]' || ["A Book with No Language", "Matilda"]
142 'text condition on leaf-list' | '//books/authors[text()="Terry Pratchett"]' || ["Good Omens", "The Colour of Magic", "The Light Fantastic"]
143 'text condition partial match' | '//books/authors[text()="Terry"]' || []
144 'text condition (existing) empty string' | '//books/lang[text()=""]' || ["A Book with No Language"]
145 'text condition on int leaf-list' | '//books/editions[text()="2000"]' || ["Matilda"]
146 'match of leaf containing /' | '//books[@lang="N/A"]' || ["Logarithm tables"]
147 'text condition on leaf containing /' | '//books/lang[text()="N/A"]' || ["Logarithm tables"]
148 'match of key containing /' | '//books[@title="Debian GNU/Linux"]' || ["Debian GNU/Linux"]
149 'text condition on key containing /' | '//books/title[text()="Debian GNU/Linux"]' || ["Debian GNU/Linux"]
152 def 'Query for attribute by cps path using contains condition #scenario.'() {
153 when: 'a query is executed to get response by the given cps path'
154 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, INCLUDE_ALL_DESCENDANTS)
155 then: 'xpaths of the retrieved data nodes are as expected'
156 def bookTitles = result.collect { it.getLeaves().get('title') }
157 assert bookTitles.sort() == expectedBookTitles.sort()
158 where: 'the following data is used'
159 scenario | cpsPath || expectedBookTitles
160 'contains condition with leaf' | '//books[contains(@title,"Mat")]' || ["Matilda"]
161 'contains condition with case-sensitive' | '//books[contains(@title,"Ti")]' || []
162 'contains condition with Integer Value' | '//books[contains(@price,"15")]' || ["Annihilation", "The Gruffalo"]
165 def 'Query for attribute by cps path using contains condition with no value.'() {
166 when: 'a query is executed to get response by the given cps path'
167 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '//books[contains(@title,"")]', OMIT_DESCENDANTS)
168 then: 'all books are returned'
169 assert result.size() == 19
172 def 'Cps Path query using descendant anywhere with #scenario condition for a container element.'() {
173 when: 'a query is executed to get a data node by the given cps path'
174 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, OMIT_DESCENDANTS)
175 then: 'book titles from the retrieved data nodes are as expected'
176 def bookTitles = result.collect { it.getLeaves().get('title') }
177 assert bookTitles.sort() == expectedBookTitles.sort()
178 where: 'the following data is used'
179 scenario | cpsPath || expectedBookTitles
180 'one leaf' | '//books[@price=14]' || ['The Light Fantastic']
181 'one leaf with ">" condition' | '//books[@price>14]' || ['A Book with No Language', 'Annihilation', 'Debian GNU/Linux', 'Matilda', 'The Gruffalo']
182 'one text' | '//books/authors[text()="Terry Pratchett"]' || ['Good Omens', 'The Colour of Magic', 'The Light Fantastic']
183 'more than one leaf' | '//books[@price=12 and @lang="English"]' || ['The Colour of Magic']
184 'more than one leaf has "OR" condition' | '//books[@lang="English" or @price=15]' || ['Annihilation', 'Good Omens', 'Matilda', 'The Colour of Magic', 'The Gruffalo', 'The Light Fantastic']
185 'more than one leaf has "OR" condition with non-json data' | '//books[@title="xyz" or @price=13]' || ['Good Omens']
186 'more than one leaf has multiple AND' | '//books[@lang="English" and @price=13 and @edition=1983]' || []
187 'more than one leaf has multiple OR' | '//books[ @title="Matilda" or @price=15 or @edition=2006]' || ['Annihilation', 'Matilda', 'The Gruffalo']
188 'leaves reversed in order' | '//books[@lang="English" and @price=12]' || ['The Colour of Magic']
189 'more than one leaf has combination of AND/OR' | '//books[@edition=1983 and @price=13 or @title="Good Omens"]' || ['Good Omens']
190 'more than one leaf has OR/AND' | '//books[@title="The Light Fantastic" or @price=11 and @edition=1983]' || ['The Light Fantastic']
191 'leaf and text' | '//books[@price=14]/authors[text()="Terry Pratchett"]' || ['The Light Fantastic']
192 'leaf and contains' | '//books[contains(@price,"13")]' || ['Good Omens']
195 def 'Cps Path query using descendant anywhere with #scenario condition(s) for a list element.'() {
196 when: 'a query is executed to get a data node by the given cps path'
197 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, INCLUDE_ALL_DESCENDANTS)
198 then: 'xpaths of the retrieved data nodes are as expected'
199 result.xpath.toList() == ["/bookstore/premises/addresses[@house-number='2' and @street='Main Street']"]
200 where: 'the following data is used'
202 'full composite key' | '//addresses[@house-number=2 and @street="Main Street"]'
203 'one partial key leaf' | '//addresses[@house-number=2]'
204 'one non key leaf' | '//addresses[@county="Kildare"]'
205 'mix of partial key and non key leaf' | '//addresses[@street="Main Street" and @county="Kildare"]'
208 def 'Query for attribute by cps path of type ancestor with #scenario.'() {
209 when: 'the given cps path is parsed'
210 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, OMIT_DESCENDANTS)
211 then: 'the xpaths of the retrieved data nodes are as expected'
212 assert result.xpath.sort() == expectedXPaths.sort()
213 where: 'the following data is used'
214 scenario | cpsPath || expectedXPaths
215 'multiple list-ancestors' | '//books/ancestor::categories' || ["/bookstore/categories[@code='1']", "/bookstore/categories[@code='2']", "/bookstore/categories[@code='3']", "/bookstore/categories[@code='4']", "/bookstore/categories[@code='5']"]
216 'one ancestor with list value' | '//books/ancestor::categories[@code="1"]' || ["/bookstore/categories[@code='1']"]
217 'top ancestor' | '//books/ancestor::bookstore' || ["/bookstore"]
218 'list with index value in the xpath prefix' | '//categories[@code="1"]/books/ancestor::bookstore' || ["/bookstore"]
219 'ancestor with parent list' | '//books/ancestor::bookstore/categories' || ["/bookstore/categories[@code='1']", "/bookstore/categories[@code='2']", "/bookstore/categories[@code='3']", "/bookstore/categories[@code='4']", "/bookstore/categories[@code='5']"]
220 'ancestor with parent' | '//books/ancestor::bookstore/categories[@code="2"]' || ["/bookstore/categories[@code='2']"]
221 'ancestor combined with text condition' | '//books/title[text()="Matilda"]/ancestor::bookstore' || ["/bookstore"]
222 'ancestor with parent that does not exist' | '//books/ancestor::parentDoesNoExist/categories' || []
223 'ancestor does not exist' | '//books/ancestor::ancestorDoesNotExist' || []
224 'ancestor combined with contains condition' | '//books[contains(@title,"Mat")]/ancestor::bookstore' || ["/bookstore"]
227 def 'Query for attribute by cps path of type ancestor with #scenario descendants.'() {
228 when: 'the given cps path is parsed'
229 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '//books/ancestor::bookstore', fetchDescendantsOption)
230 then: 'the xpaths of the retrieved data nodes are as expected'
231 assert countDataNodesInTree(result) == expectedNumberOfNodes
232 where: 'the following data is used'
233 scenario | fetchDescendantsOption || expectedNumberOfNodes
234 'no' | OMIT_DESCENDANTS || 1
235 'direct' | DIRECT_CHILD_ONLY || 7
236 'all' | INCLUDE_ALL_DESCENDANTS || 28
239 def 'Cps Path query with #scenario throws a CPS Path Exception.'() {
240 when: 'trying to execute a query with a syntax (parsing) error'
241 objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, OMIT_DESCENDANTS)
242 then: 'a cps path exception is thrown'
243 thrown(CpsPathException)
244 where: 'the following data is used'
246 'cpsPath that cannot be parsed' | 'cpsPath that cannot be parsed'
247 'String with comparative operator' | '//books[@lang>"German" and @price>10]'
250 def 'Cps Path query across anchors with #scenario.'() {
251 when: 'a query is executed to get a data nodes across anchors by the given CpsPath'
252 def result = objectUnderTest.queryDataNodesAcrossAnchors(FUNCTIONAL_TEST_DATASPACE_1, cpsPath, OMIT_DESCENDANTS)
253 then: 'the correct dataspace is queried'
254 assert result.dataspace.toSet() == [FUNCTIONAL_TEST_DATASPACE_1].toSet()
255 and: 'correct anchors are queried'
256 assert result.anchorName.toSet() == [BOOKSTORE_ANCHOR_1, BOOKSTORE_ANCHOR_2].toSet()
257 and: 'the correct number of nodes is returned'
258 assert result.size() == expectedXpathsPerAnchor.size() * NUMBER_OF_ANCHORS_PER_DATASPACE_WITH_BOOKSTORE_DATA
259 and: 'the queried nodes have expected xpaths'
260 assert result.xpath.toSet() == expectedXpathsPerAnchor.toSet()
261 where: 'the following data is used'
262 scenario | cpsPath || expectedXpathsPerAnchor
263 'container node' | '/bookstore' || ["/bookstore"]
264 'list node' | '/bookstore/categories' || ["/bookstore/categories[@code='1']", "/bookstore/categories[@code='2']", "/bookstore/categories[@code='3']", "/bookstore/categories[@code='4']", "/bookstore/categories[@code='5']"]
265 'string leaf-condition' | '/bookstore[@bookstore-name="Easons"]' || ["/bookstore"]
266 'integer leaf-condition' | '/bookstore/categories[@code="1"]/books[@price=15]' || ["/bookstore/categories[@code='1']/books[@title='The Gruffalo']"]
267 'multiple list-ancestors' | '//books/ancestor::categories' || ["/bookstore/categories[@code='1']", "/bookstore/categories[@code='2']", "/bookstore/categories[@code='3']", "/bookstore/categories[@code='4']", "/bookstore/categories[@code='5']"]
268 'one ancestor with list value' | '//books/ancestor::categories[@code="1"]' || ["/bookstore/categories[@code='1']"]
269 'list with index value in the xpath prefix' | '//categories[@code="1"]/books/ancestor::bookstore' || ["/bookstore"]
270 'ancestor with parent list' | '//books/ancestor::bookstore/categories' || ["/bookstore/categories[@code='1']", "/bookstore/categories[@code='2']", "/bookstore/categories[@code='3']", "/bookstore/categories[@code='4']", "/bookstore/categories[@code='5']"]
271 'ancestor with parent list element' | '//books/ancestor::bookstore/categories[@code="2"]' || ["/bookstore/categories[@code='2']"]
272 'ancestor combined with text condition' | '//books/title[text()="Matilda"]/ancestor::bookstore' || ["/bookstore"]
275 def 'Cps Path query across anchors with #scenario descendants.'() {
276 when: 'a query is executed to get a data node by the given cps path'
277 def result = objectUnderTest.queryDataNodesAcrossAnchors(FUNCTIONAL_TEST_DATASPACE_1, '/bookstore', fetchDescendantsOption)
278 then: 'the correct dataspace was queried'
279 assert result.dataspace.toSet() == [FUNCTIONAL_TEST_DATASPACE_1].toSet()
280 and: 'correct number of datanodes are returned'
281 assert countDataNodesInTree(result) == expectedNumberOfNodesPerAnchor * NUMBER_OF_ANCHORS_PER_DATASPACE_WITH_BOOKSTORE_DATA
282 where: 'the following data is used'
283 scenario | fetchDescendantsOption || expectedNumberOfNodesPerAnchor
284 'no' | OMIT_DESCENDANTS || 1
285 'direct' | DIRECT_CHILD_ONLY || 7
286 'all' | INCLUDE_ALL_DESCENDANTS || 28
289 def 'Cps Path query across anchors with ancestors and #scenario descendants.'() {
290 when: 'a query is executed to get a data node by the given cps path'
291 def result = objectUnderTest.queryDataNodesAcrossAnchors(FUNCTIONAL_TEST_DATASPACE_1, '//books/ancestor::bookstore', fetchDescendantsOption)
292 then: 'the correct dataspace was queried'
293 assert result.dataspace.toSet() == [FUNCTIONAL_TEST_DATASPACE_1].toSet()
294 and: 'correct number of datanodes are returned'
295 assert countDataNodesInTree(result) == expectedNumberOfNodesPerAnchor * NUMBER_OF_ANCHORS_PER_DATASPACE_WITH_BOOKSTORE_DATA
296 where: 'the following data is used'
297 scenario | fetchDescendantsOption || expectedNumberOfNodesPerAnchor
298 'no' | OMIT_DESCENDANTS || 1
299 'direct' | DIRECT_CHILD_ONLY || 7
300 'all' | INCLUDE_ALL_DESCENDANTS || 28
303 def 'Cps Path query across anchors with syntax error throws a CPS Path Exception.'() {
304 when: 'trying to execute a query with a syntax (parsing) error'
305 objectUnderTest.queryDataNodesAcrossAnchors(FUNCTIONAL_TEST_DATASPACE_1, 'cpsPath that cannot be parsed' , OMIT_DESCENDANTS)
306 then: 'a cps path exception is thrown'
307 thrown(CpsPathException)
310 def 'Cps Path querys with all descendants including descendants that are list entries: #scenario.'() {
311 when: 'a query is executed to get a data node by the given cps path'
312 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, INCLUDE_ALL_DESCENDANTS)
313 then: 'correct number of datanodes are returned'
314 assert countDataNodesInTree(result) == expectedNumberOfDataNodes
316 scenario | cpsPath || expectedNumberOfDataNodes
317 'absolute path all list entries' | '/bookstore/categories' || 24
318 'absolute path 1 list entry by key' | '/bookstore/categories[@code="3"]' || 5
319 'absolute path 1 list entry by name' | '/bookstore/categories[@name="Comedy"]' || 5
320 'relative path all list entries' | '//categories' || 24
321 'relative path 1 list entry by key' | '//categories[@code="3"]' || 5
322 'relative path 1 list entry by leaf' | '//categories[@name="Comedy"]' || 5
323 'incomplete absolute path' | '/categories' || 0
324 'incomplete absolute 1 list entry' | '/categories[@code="3"]' || 0
327 def 'Cps Path query contains #wildcard.'() {
328 when: 'a query is executed with a wildcard in the given cps path'
329 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, INCLUDE_ALL_DESCENDANTS)
330 then: 'no results are returned, as Cps Path query does not interpret wildcard characters'
331 assert result.isEmpty()
334 ' sql wildcard in parent path list index' | '/bookstore/categories[@code="%"]/books'
335 'regex wildcard in parent path list index' | '/bookstore/categories[@code=".*"]/books'
336 ' sql wildcard in leaf-condition' | '/bookstore/categories[@code="1"]/books[@title="%"]'
337 'regex wildcard in leaf-condition' | '/bookstore/categories[@code="1"]/books[@title=".*"]'
338 ' sql wildcard in text-condition' | '/bookstore/categories[@code="1"]/books/title[text()="%"]'
339 'regex wildcard in text-condition' | '/bookstore/categories[@code="1"]/books/title[text()=".*"]'
340 ' sql wildcard in contains-condition' | '/bookstore/categories[@code="1"]/books[contains(@title, "%")]'
341 'regex wildcard in contains-condition' | '/bookstore/categories[@code="1"]/books[contains(@title, ".*")]'
344 def 'Cps Path query can return a data node containing [@ in xpath #scenario.'() {
345 given: 'a book with special characters [@ and ] in title'
346 cpsDataService.saveData(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, "/bookstore/categories[@code='1']", '{"books": [ {"title":"[@hello=world]"} ] }', OffsetDateTime.now())
347 when: 'a query is executed'
348 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, OMIT_DESCENDANTS)
349 then: 'the node is returned'
350 assert result.size() == 1
351 cleanup: 'the new datanode'
352 cpsDataService.deleteDataNode(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, "/bookstore/categories[@code='1']/books[@title='[@hello=world]']", OffsetDateTime.now())
355 'leaf-condition' || "/bookstore/categories[@code='1']/books[@title='[@hello=world]']"
356 'text-condition' || "/bookstore/categories[@code='1']/books/title[text()='[@hello=world]']"
357 'contains-condition' || "/bookstore/categories[@code='1']/books[contains(@title, '[@hello=world]')]"
360 def 'Cps Path get and query can handle apostrophe inside #quotes.'() {
361 given: 'a book with special characters in title'
362 cpsDataService.saveData(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, "/bookstore/categories[@code='1']",
363 '{"books": [ {"title":"I\'m escaping"} ] }', OffsetDateTime.now())
364 when: 'a query is executed'
365 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, OMIT_DESCENDANTS)
366 then: 'the node is returned'
367 assert result.size() == 1
368 assert result[0].xpath == "/bookstore/categories[@code='1']/books[@title='I''m escaping']"
369 cleanup: 'the new datanode'
370 cpsDataService.deleteDataNode(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, "/bookstore/categories[@code='1']/books[@title='I''m escaping']", OffsetDateTime.now())
373 'single quotes' || "/bookstore/categories[@code='1']/books[@title='I''m escaping']"
374 'double quotes' || '/bookstore/categories[@code="1"]/books[@title="I\'m escaping"]'
375 'text-condition' || "/bookstore/categories[@code='1']/books/title[text()='I''m escaping']"
376 'contains-condition' || "/bookstore/categories[@code='1']/books[contains(@title, 'I''m escaping')]"