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.CpsQueryService
25 import org.onap.cps.integration.base.FunctionalSpecBase
26 import org.onap.cps.spi.FetchDescendantsOption
27 import org.onap.cps.spi.exceptions.CpsPathException
29 import static org.onap.cps.spi.FetchDescendantsOption.DIRECT_CHILDREN_ONLY
30 import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
31 import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS
33 class CpsQueryServiceIntegrationSpec extends FunctionalSpecBase {
35 CpsQueryService objectUnderTest
37 def setup() { objectUnderTest = cpsQueryService }
39 def 'Query bookstore using CPS path where #scenario.'() {
40 when: 'query data nodes for bookstore container'
41 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, INCLUDE_ALL_DESCENDANTS)
42 then: 'the result contains expected number of nodes'
43 assert result.size() == expectedResultSize
44 and: 'the result contains the expected leaf values'
45 result.leaves.forEach( dataNodeLeaves -> {
46 expectedLeaves.forEach( (expectedLeafKey,expectedLeafValue) -> {
47 assert dataNodeLeaves[expectedLeafKey] == expectedLeafValue
51 scenario | cpsPath || expectedResultSize | expectedLeaves
52 'the AND condition is used' | '//books[@lang="English" and @price=15]' || 2 | [lang:"English", price:15]
53 'the AND is used where result does not exist' | '//books[@lang="English" and @price=1000]' || 0 | []
56 def 'Cps Path query using combinations of OR operator #scenario.'() {
57 when: 'a query is executed to get response by the given cps path'
58 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, OMIT_DESCENDANTS)
59 then: 'the result contains expected number of nodes'
60 assert result.size() == expectedResultSize
61 and: 'the cps-path of queryDataNodes has the expectedLeaves'
62 assert result.leaves.sort() == expectedLeaves.sort()
63 where: 'the following data is used'
64 scenario | cpsPath || expectedResultSize | expectedLeaves
65 'the "OR" condition' | '//books[@lang="English" or @price=15]' || 6 | [[lang: "English", price: 15, title: "Annihilation", authors: ["Jeff VanderMeer"], editions: [2014]],
66 [lang: "English", price: 15, title: "The Gruffalo", authors: ["Julia Donaldson"], editions: [1999]],
67 [lang: "English", price: 14, title: "The Light Fantastic", authors: ["Terry Pratchett"], editions: [1986]],
68 [lang: "English", price: 13, title: "Good Omens", authors: ["Terry Pratchett", "Neil Gaiman"], editions: [2006]],
69 [lang: "English", price: 12, title: "The Colour of Magic", authors: ["Terry Pratchett"], editions: [1983]],
70 [lang: "English", price: 10, title: "Matilda", authors: ["Roald Dahl"], editions: [1988, 2000]]]
71 'the "OR" condition with non-json data' | '//books[@title="xyz" or @price=15]' || 2 | [[lang: "English", price: 15, title: "Annihilation", authors: ["Jeff VanderMeer"], editions: [2014]],
72 [lang: "English", price: 15, title: "The Gruffalo", authors: ["Julia Donaldson"], editions: [1999]]]
73 'combination of multiple AND' | '//books[@lang="English" and @price=15 and @edition=1983]' || 0 | []
74 'combination of multiple OR' | '//books[ @title="Matilda" or @price=15 or @edition=1983]' || 3 | [[lang: "English", price: 15, title: "Annihilation", authors: ["Jeff VanderMeer"], editions: [2014]],
75 [lang: "English", price: 10, title: "Matilda", authors: ["Roald Dahl"], editions: [1988, 2000]],
76 [lang: "English", price: 15, title: "The Gruffalo", authors: ["Julia Donaldson"], editions: [1999]]]
77 'combination of AND/OR' | '//books[@edition=1983 and @price=15 or @title="Good Omens"]' || 1 | [[lang: "English", price: 13, title: "Good Omens", authors: ["Terry Pratchett", "Neil Gaiman"], editions: [2006]]]
78 'combination of OR/AND' | '//books[@title="Annihilation" or @price=39 and @lang="arabic"]' || 1 | [[lang: "English", price: 15, title: "Annihilation", authors: ["Jeff VanderMeer"], editions: [2014]]]
81 def 'cps-path query using combinations of Comparative Operators #scenario.'() {
82 when: 'a query is executed to get response by the given cpsPath'
83 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, OMIT_DESCENDANTS)
84 then: 'the result contains expected number of nodes'
85 assert result.size() == expectedResultSize
86 and: 'xpaths of the retrieved data nodes are as expected'
87 def bookTitles = result.collect { it.getLeaves().get('title') }
88 assert bookTitles.sort() == expectedBookTitles.sort()
89 where: 'the following data is used'
90 scenario | cpsPath || expectedResultSize | expectedBookTitles
91 'the ">" condition' | '//books[@price>13 ]' || 5 | ['A Book with No Language', 'Annihilation', 'Debian GNU/Linux', 'The Gruffalo', 'The Light Fantastic']
92 'the "<" condition ' | '//books[@price<15]' || 5 | ['Good Omens', 'Logarithm tables', 'Matilda', 'The Colour of Magic', 'The Light Fantastic']
93 'the "<=" condition' | '//books[@price<=15]' || 7 | ['Annihilation', 'Good Omens', 'Logarithm tables', 'Matilda', 'The Colour of Magic', 'The Gruffalo', 'The Light Fantastic']
94 'the ">=" condition' | '//books[@price>=20]' || 2 | ['A Book with No Language', 'Debian GNU/Linux']
95 'the "<" condition where result does not exist' | '//books[@price<5]' || 0 | []
96 'the ">" condition where result does not exist' | '//books[@price>1000]' || 0 | []
97 'the ">" condition with AND condition' | '//books[@price>13 and @title="A Book with No Language"]' || 1 | ['A Book with No Language']
98 'the "<" condition with OR condition' | '//books[@price<10 or @lang="German"]' || 1 | ['Debian GNU/Linux']
99 'the "<=" condition with AND/OR condition' | '//books[@price<=15 and @title="Annihilation" or @lang="Spanish"]' || 1 | ['Annihilation']
100 'the ">=" condition with OR/AND condition' | '//books[@price>=13 or @lang="Spanish" and @title="Good Omens"]' || 6 | ['A Book with No Language', 'Annihilation', 'Good Omens', 'Debian GNU/Linux', 'The Gruffalo', 'The Light Fantastic']
101 'Mix of integer and string condition ' | '//books[@lang="German" and @price>38]' || 1 | ['Debian GNU/Linux']
104 def 'Cps Path query for leaf value(s) with #scenario.'() {
105 when: 'a query is executed to get a data node by the given cps path'
106 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, fetchDescendantsOption)
107 then: 'the correct number of parent nodes are returned'
108 assert result.size() == expectedNumberOfParentNodes
109 and: 'the correct total number of data nodes are returned'
110 assert countDataNodesInTree(result) == expectedTotalNumberOfNodes
111 where: 'the following data is used'
112 scenario | cpsPath | fetchDescendantsOption || expectedNumberOfParentNodes | expectedTotalNumberOfNodes
113 'string and no descendants' | '/bookstore/categories[@code="1"]/books[@title="Matilda"]' | OMIT_DESCENDANTS || 1 | 1
114 'integer and descendants' | '/bookstore/categories[@code="1"]/books[@price=15]' | INCLUDE_ALL_DESCENDANTS || 1 | 1
115 'no condition and no descendants' | '/bookstore/categories' | OMIT_DESCENDANTS || 4 | 4
116 'no condition and level 1 descendants' | '/bookstore' | new FetchDescendantsOption(1) || 1 | 6
117 'no condition and level 2 descendants' | '/bookstore' | new FetchDescendantsOption(2) || 1 | 17
120 def 'Query for attribute by cps path with cps paths that return no data because of #scenario.'() {
121 when: 'a query is executed to get data nodes for the given cps path'
122 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, OMIT_DESCENDANTS)
123 then: 'no data is returned'
124 assert result.isEmpty()
125 where: 'following cps queries are performed'
127 'cps path is incomplete' | '/bookstore[@title="Matilda"]'
128 'leaf value does not exist' | '/bookstore/categories[@code="1"]/books[@title=\'does not exist\']'
129 'incomplete end of xpath prefix' | '/bookstore/categories/books[@price=15]'
132 def 'Cps Path query using descendant anywhere and #type (further) descendants.'() {
133 when: 'a query is executed to get a data node by the given cps path'
134 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="1"]', fetchDescendantsOption)
135 then: 'the data node has the correct number of children'
136 assert result[0].childDataNodes.xpath.sort() == expectedChildNodes.sort()
137 where: 'the following data is used'
138 type | fetchDescendantsOption || expectedChildNodes
139 'omit' | OMIT_DESCENDANTS || []
140 'include' | INCLUDE_ALL_DESCENDANTS || ["/bookstore/categories[@code='1']/books[@title='Matilda']",
141 "/bookstore/categories[@code='1']/books[@title='The Gruffalo']"]
144 def 'Cps Path query for all books.'() {
145 when: 'a query is executed to get all books'
146 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '//books', OMIT_DESCENDANTS)
147 then: 'the expected number of books are returned'
148 assert result.size() == 9
151 def 'Cps Path query using descendant anywhere with #scenario.'() {
152 when: 'a query is executed to get a data node by the given cps path'
153 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, OMIT_DESCENDANTS)
154 then: 'xpaths of the retrieved data nodes are as expected'
155 def bookTitles = result.collect { it.getLeaves().get('title') }
156 assert bookTitles.sort() == expectedBookTitles.sort()
157 where: 'the following data is used'
158 scenario | cpsPath || expectedBookTitles
159 'string leaf condition' | '//books[@title="Matilda"]' || ["Matilda"]
160 'text condition on leaf' | '//books/title[text()="Matilda"]' || ["Matilda"]
161 'text condition case mismatch' | '//books/title[text()="matilda"]' || []
162 'text condition on int leaf' | '//books/price[text()="10"]' || ["Matilda"]
163 'text condition on leaf-list' | '//books/authors[text()="Terry Pratchett"]' || ["Good Omens", "The Colour of Magic", "The Light Fantastic"]
164 'text condition partial match' | '//books/authors[text()="Terry"]' || []
165 'text condition (existing) empty string' | '//books/lang[text()=""]' || ["A Book with No Language"]
166 'text condition on int leaf-list' | '//books/editions[text()="2000"]' || ["Matilda"]
167 'match of leaf containing /' | '//books[@lang="N/A"]' || ["Logarithm tables"]
168 'text condition on leaf containing /' | '//books/lang[text()="N/A"]' || ["Logarithm tables"]
169 'match of key containing /' | '//books[@title="Debian GNU/Linux"]' || ["Debian GNU/Linux"]
170 'text condition on key containing /' | '//books/title[text()="Debian GNU/Linux"]' || ["Debian GNU/Linux"]
173 def 'Query for attribute by cps path using contains condition #scenario.'() {
174 when: 'a query is executed to get response by the given cps path'
175 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, INCLUDE_ALL_DESCENDANTS)
176 then: 'xpaths of the retrieved data nodes are as expected'
177 def bookTitles = result.collect { it.getLeaves().get('title') }
178 assert bookTitles.sort() == expectedBookTitles.sort()
179 where: 'the following data is used'
180 scenario | cpsPath || expectedBookTitles
181 'contains condition with leaf' | '//books[contains(@title,"Mat")]' || ["Matilda"]
182 'contains condition with case-sensitive' | '//books[contains(@title,"Ti")]' || []
183 'contains condition with Integer Value' | '//books[contains(@price,"15")]' || ["Annihilation", "The Gruffalo"]
184 'contains condition with No-value' | '//books[contains(@title,"")]' || ["A Book with No Language", "Annihilation", "Debian GNU/Linux", "Good Omens", "Logarithm tables", "Matilda", "The Colour of Magic", "The Gruffalo", "The Light Fantastic"]
187 def 'Cps Path query using descendant anywhere with #scenario condition for a container element.'() {
188 when: 'a query is executed to get a data node by the given cps path'
189 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, OMIT_DESCENDANTS)
190 then: 'book titles from the retrieved data nodes are as expected'
191 def bookTitles = result.collect { it.getLeaves().get('title') }
192 assert bookTitles.sort() == expectedBookTitles.sort()
193 where: 'the following data is used'
194 scenario | cpsPath || expectedBookTitles
195 'one leaf' | '//books[@price=14]' || ['The Light Fantastic']
196 'one leaf with ">" condition' | '//books[@price>14]' || ['A Book with No Language', 'Annihilation', 'Debian GNU/Linux', 'The Gruffalo']
197 'one text' | '//books/authors[text()="Terry Pratchett"]' || ['Good Omens', 'The Colour of Magic', 'The Light Fantastic']
198 'more than one leaf' | '//books[@price=12 and @lang="English"]' || ['The Colour of Magic']
199 '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']
200 'more than one leaf has "OR" condition with non-json data' | '//books[@title="xyz" or @price=13]' || ['Good Omens']
201 'more than one leaf has multiple AND' | '//books[@lang="English" and @price=13 and @edition=1983]' || []
202 'more than one leaf has multiple OR' | '//books[ @title="Matilda" or @price=15 or @edition=2006]' || ['Annihilation', 'Matilda', 'The Gruffalo']
203 'leaves reversed in order' | '//books[@lang="English" and @price=12]' || ['The Colour of Magic']
204 'more than one leaf has combination of AND/OR' | '//books[@edition=1983 and @price=13 or @title="Good Omens"]' || ['Good Omens']
205 'more than one leaf has OR/AND' | '//books[@title="The Light Fantastic" or @price=11 and @edition=1983]' || ['The Light Fantastic']
206 'leaf and text' | '//books[@price=14]/authors[text()="Terry Pratchett"]' || ['The Light Fantastic']
207 'leaf and contains' | '//books[contains(@price,"13")]' || ['Good Omens']
210 def 'Cps Path query using descendant anywhere with #scenario condition(s) for a list element.'() {
211 when: 'a query is executed to get a data node by the given cps path'
212 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, INCLUDE_ALL_DESCENDANTS)
213 then: 'xpaths of the retrieved data nodes are as expected'
214 result.xpath.toList() == ["/bookstore/premises/addresses[@house-number='2' and @street='Main Street']"]
215 where: 'the following data is used'
217 'full composite key' | '//addresses[@house-number=2 and @street="Main Street"]'
218 'one partial key leaf' | '//addresses[@house-number=2]'
219 'one non key leaf' | '//addresses[@county="Kildare"]'
220 'mix of partial key and non key leaf' | '//addresses[@street="Main Street" and @county="Kildare"]'
223 def 'Query for attribute by cps path of type ancestor with #scenario.'() {
224 when: 'the given cps path is parsed'
225 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, OMIT_DESCENDANTS)
226 then: 'the xpaths of the retrieved data nodes are as expected'
227 assert result.xpath.sort() == expectedXPaths.sort()
228 where: 'the following data is used'
229 scenario | cpsPath || expectedXPaths
230 'multiple list-ancestors' | '//books/ancestor::categories' || ["/bookstore/categories[@code='1']", "/bookstore/categories[@code='2']", "/bookstore/categories[@code='3']", "/bookstore/categories[@code='4']"]
231 'one ancestor with list value' | '//books/ancestor::categories[@code="1"]' || ["/bookstore/categories[@code='1']"]
232 'top ancestor' | '//books/ancestor::bookstore' || ["/bookstore"]
233 'list with index value in the xpath prefix' | '//categories[@code="1"]/books/ancestor::bookstore' || ["/bookstore"]
234 'ancestor with parent list' | '//books/ancestor::bookstore/categories' || ["/bookstore/categories[@code='1']", "/bookstore/categories[@code='2']", "/bookstore/categories[@code='3']", "/bookstore/categories[@code='4']"]
235 'ancestor with parent' | '//books/ancestor::bookstore/categories[@code="2"]' || ["/bookstore/categories[@code='2']"]
236 'ancestor combined with text condition' | '//books/title[text()="Matilda"]/ancestor::bookstore' || ["/bookstore"]
237 'ancestor with parent that does not exist' | '//books/ancestor::parentDoesNoExist/categories' || []
238 'ancestor does not exist' | '//books/ancestor::ancestorDoesNotExist' || []
239 'ancestor combined with contains condition' | '//books[contains(@title,"Mat")]/ancestor::bookstore' || ["/bookstore"]
242 def 'Query for attribute by cps path of type ancestor with #scenario descendants.'() {
243 when: 'the given cps path is parsed'
244 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '//books/ancestor::bookstore', fetchDescendantsOption)
245 then: 'the xpaths of the retrieved data nodes are as expected'
246 assert countDataNodesInTree(result) == expectedNumberOfNodes
247 where: 'the following data is used'
248 scenario | fetchDescendantsOption || expectedNumberOfNodes
249 'no' | OMIT_DESCENDANTS || 1
250 'direct' | DIRECT_CHILDREN_ONLY || 6
251 'all' | INCLUDE_ALL_DESCENDANTS || 17
254 def 'Cps Path query with #scenario throws a CPS Path Exception.'() {
255 when: 'trying to execute a query with a syntax (parsing) error'
256 objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, OMIT_DESCENDANTS)
257 then: 'a cps path exception is thrown'
258 thrown(CpsPathException)
259 where: 'the following data is used'
261 'cpsPath that cannot be parsed' | 'cpsPath that cannot be parsed'
262 'String with comparative operator' | '//books[@lang>"German" and @price>10]'
265 def 'Cps Path query across anchors with #scenario.'() {
266 when: 'a query is executed to get a data nodes across anchors by the given CpsPath'
267 def result = objectUnderTest.queryDataNodesAcrossAnchors(FUNCTIONAL_TEST_DATASPACE_1, cpsPath, OMIT_DESCENDANTS)
268 then: 'the correct dataspace is queried'
269 assert result.dataspace.toSet() == [FUNCTIONAL_TEST_DATASPACE_1].toSet()
270 and: 'correct anchors are queried'
271 assert result.anchorName.toSet() == [BOOKSTORE_ANCHOR_1, BOOKSTORE_ANCHOR_2].toSet()
272 and: 'the correct number of nodes is returned'
273 assert result.size() == expectedXpathsPerAnchor.size() * NUMBER_OF_ANCHORS_PER_DATASPACE_WITH_BOOKSTORE_DATA
274 and: 'the queried nodes have expected xpaths'
275 assert result.xpath.toSet() == expectedXpathsPerAnchor.toSet()
276 where: 'the following data is used'
277 scenario | cpsPath || expectedXpathsPerAnchor
278 'container node' | '/bookstore' || ["/bookstore"]
279 'list node' | '/bookstore/categories' || ["/bookstore/categories[@code='1']", "/bookstore/categories[@code='2']", "/bookstore/categories[@code='3']", "/bookstore/categories[@code='4']"]
280 'string leaf-condition' | '/bookstore[@bookstore-name="Easons"]' || ["/bookstore"]
281 'integer leaf-condition' | '/bookstore/categories[@code="1"]/books[@price=15]' || ["/bookstore/categories[@code='1']/books[@title='The Gruffalo']"]
282 'multiple list-ancestors' | '//books/ancestor::categories' || ["/bookstore/categories[@code='1']", "/bookstore/categories[@code='2']", "/bookstore/categories[@code='3']", "/bookstore/categories[@code='4']"]
283 'one ancestor with list value' | '//books/ancestor::categories[@code="1"]' || ["/bookstore/categories[@code='1']"]
284 'list with index value in the xpath prefix' | '//categories[@code="1"]/books/ancestor::bookstore' || ["/bookstore"]
285 'ancestor with parent list' | '//books/ancestor::bookstore/categories' || ["/bookstore/categories[@code='1']", "/bookstore/categories[@code='2']", "/bookstore/categories[@code='3']", "/bookstore/categories[@code='4']"]
286 'ancestor with parent list element' | '//books/ancestor::bookstore/categories[@code="2"]' || ["/bookstore/categories[@code='2']"]
287 'ancestor combined with text condition' | '//books/title[text()="Matilda"]/ancestor::bookstore' || ["/bookstore"]
290 def 'Cps Path query across anchors with #scenario descendants.'() {
291 when: 'a query is executed to get a data node by the given cps path'
292 def result = objectUnderTest.queryDataNodesAcrossAnchors(FUNCTIONAL_TEST_DATASPACE_1, '/bookstore', fetchDescendantsOption)
293 then: 'the correct dataspace was queried'
294 assert result.dataspace.toSet() == [FUNCTIONAL_TEST_DATASPACE_1].toSet()
295 and: 'correct number of datanodes are returned'
296 assert countDataNodesInTree(result) == expectedNumberOfNodesPerAnchor * NUMBER_OF_ANCHORS_PER_DATASPACE_WITH_BOOKSTORE_DATA
297 where: 'the following data is used'
298 scenario | fetchDescendantsOption || expectedNumberOfNodesPerAnchor
299 'no' | OMIT_DESCENDANTS || 1
300 'direct' | DIRECT_CHILDREN_ONLY || 6
301 'all' | INCLUDE_ALL_DESCENDANTS || 17
304 def 'Cps Path query across anchors with ancestors and #scenario descendants.'() {
305 when: 'a query is executed to get a data node by the given cps path'
306 def result = objectUnderTest.queryDataNodesAcrossAnchors(FUNCTIONAL_TEST_DATASPACE_1, '//books/ancestor::bookstore', fetchDescendantsOption)
307 then: 'the correct dataspace was queried'
308 assert result.dataspace.toSet() == [FUNCTIONAL_TEST_DATASPACE_1].toSet()
309 and: 'correct number of datanodes are returned'
310 assert countDataNodesInTree(result) == expectedNumberOfNodesPerAnchor * NUMBER_OF_ANCHORS_PER_DATASPACE_WITH_BOOKSTORE_DATA
311 where: 'the following data is used'
312 scenario | fetchDescendantsOption || expectedNumberOfNodesPerAnchor
313 'no' | OMIT_DESCENDANTS || 1
314 'direct' | DIRECT_CHILDREN_ONLY || 6
315 'all' | INCLUDE_ALL_DESCENDANTS || 17
318 def 'Cps Path query across anchors with syntax error throws a CPS Path Exception.'() {
319 when: 'trying to execute a query with a syntax (parsing) error'
320 objectUnderTest.queryDataNodesAcrossAnchors(FUNCTIONAL_TEST_DATASPACE_1, 'cpsPath that cannot be parsed' , OMIT_DESCENDANTS)
321 then: 'a cps path exception is thrown'
322 thrown(CpsPathException)
325 def 'Cps Path querys with all descendants including descendants that are list entries: #scenario.'() {
326 when: 'a query is executed to get a data node by the given cps path'
327 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, INCLUDE_ALL_DESCENDANTS)
328 then: 'correct number of datanodes are returned'
329 assert countDataNodesInTree(result) == expectedNumberOfDataNodes
331 scenario | cpsPath || expectedNumberOfDataNodes
332 'absolute path all list entries' | '/bookstore/categories' || 13
333 'absolute path 1 list entry by key' | '/bookstore/categories[@code="3"]' || 5
334 'absolute path 1 list entry by name' | '/bookstore/categories[@name="Comedy"]' || 5
335 'relative path all list entries' | '//categories' || 13
336 'relative path 1 list entry by key' | '//categories[@code="3"]' || 5
337 'relative path 1 list entry by leaf' | '//categories[@name="Comedy"]' || 5
338 'incomplete absolute path' | '/categories' || 0
339 'incomplete absolute 1 list entry' | '/categories[@code="3"]' || 0
342 def 'Cps Path query should ignore special characters: #scenario.'() {
343 when: 'a query is executed to get data nodes by the given cps path'
344 def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, INCLUDE_ALL_DESCENDANTS)
345 then: 'no data nodes are returned'
346 assert result.isEmpty()
349 ' sql wildcard in contains-condition' | '/bookstore/categories[@code="1"]/books[contains(@title, "%")]'
350 'regex wildcard in contains-condition' | '/bookstore/categories[@code="1"]/books[contains(@title, ".*")]'