+
+ def 'Query for attribute by cps path of type ancestor with #scenario.'() {
+ when: 'the given cps path is parsed'
+ def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE, BOOKSTORE_ANCHOR, cpsPath, OMIT_DESCENDANTS)
+ then: 'the xpaths of the retrieved data nodes are as expected'
+ assert result.xpath.sort() == expectedXPaths.sort()
+ where: 'the following data is used'
+ scenario | cpsPath || expectedXPaths
+ 'multiple list-ancestors' | '//books/ancestor::categories' || ["/bookstore/categories[@code='1']", "/bookstore/categories[@code='2']", "/bookstore/categories[@code='3']"]
+ 'one ancestor with list value' | '//books/ancestor::categories[@code="1"]' || ["/bookstore/categories[@code='1']"]
+ 'top ancestor' | '//books/ancestor::bookstore' || ["/bookstore"]
+ 'list with index value in the xpath prefix' | '//categories[@code="1"]/books/ancestor::bookstore' || ["/bookstore"]
+ 'ancestor with parent list' | '//books/ancestor::bookstore/categories' || ["/bookstore/categories[@code='1']", "/bookstore/categories[@code='2']", "/bookstore/categories[@code='3']"]
+ 'ancestor with parent' | '//books/ancestor::bookstore/categories[@code="2"]' || ["/bookstore/categories[@code='2']"]
+ 'ancestor combined with text condition' | '//books/title[text()="Matilda"]/ancestor::bookstore' || ["/bookstore"]
+ 'ancestor with parent that does not exist' | '//books/ancestor::parentDoesNoExist/categories' || []
+ 'ancestor does not exist' | '//books/ancestor::ancestorDoesNotExist' || []
+ }
+
+ def 'Query for attribute by cps path of type ancestor with #scenario descendants.'() {
+ when: 'the given cps path is parsed'
+ def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE, BOOKSTORE_ANCHOR, '//books/ancestor::bookstore', fetchDescendantsOption)
+ then: 'the xpaths of the retrieved data nodes are as expected'
+ assert countDataNodesInTree(result) == expectedNumberOfNodes
+ where: 'the following data is used'
+ scenario | fetchDescendantsOption || expectedNumberOfNodes
+ 'no' | OMIT_DESCENDANTS || 1
+ 'direct' | DIRECT_CHILDREN_ONLY || 4
+ 'all' | INCLUDE_ALL_DESCENDANTS || 8
+ }
+
+ def 'Cps Path query with syntax error throws a CPS Path Exception.'() {
+ when: 'trying to execute a query with a syntax (parsing) error'
+ objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE, BOOKSTORE_ANCHOR, 'cpsPath that cannot be parsed' , OMIT_DESCENDANTS)
+ then: 'a cps path exception is thrown'
+ thrown(CpsPathException)
+ }
+