X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=integration-test%2Fsrc%2Ftest%2Fgroovy%2Forg%2Fonap%2Fcps%2Fintegration%2Ffunctional%2FCpsQueryServiceIntegrationSpec.groovy;h=146ea95e8b514bc117f177f6f62f973a8c7159a1;hb=a1ab76467ce2d096e3d51eaf144cfe043ef1c241;hp=a04302fa63a86a58a9f837b9030b78b9bff3e160;hpb=5f964d1910e309502530631bff4d21e5d59f4dc8;p=cps.git diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsQueryServiceIntegrationSpec.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsQueryServiceIntegrationSpec.groovy index a04302fa6..146ea95e8 100644 --- a/integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsQueryServiceIntegrationSpec.groovy +++ b/integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsQueryServiceIntegrationSpec.groovy @@ -21,15 +21,17 @@ package org.onap.cps.integration.functional +import java.time.OffsetDateTime import org.onap.cps.api.CpsQueryService import org.onap.cps.integration.base.FunctionalSpecBase import org.onap.cps.spi.FetchDescendantsOption +import org.onap.cps.spi.PaginationOption import org.onap.cps.spi.exceptions.CpsPathException -import spock.lang.Ignore import static org.onap.cps.spi.FetchDescendantsOption.DIRECT_CHILDREN_ONLY import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS +import static org.onap.cps.spi.PaginationOption.NO_PAGINATION class CpsQueryServiceIntegrationSpec extends FunctionalSpecBase { @@ -54,29 +56,30 @@ class CpsQueryServiceIntegrationSpec extends FunctionalSpecBase { 'the AND is used where result does not exist' | '//books[@lang="English" and @price=1000]' || 0 | [] } - def 'Cps Path query using combinations of OR operator #scenario.'() { + def 'Cps Path query using comparative and boolean operators.'() { + given: 'a cps path query in the discount category' + def cpsPath = "/bookstore/categories[@code='5']/books" + leafCondition when: 'a query is executed to get response by the given cps path' - def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpspath, OMIT_DESCENDANTS) - then: 'the result contains expected number of nodes' - assert result.size() == expectedResultSize - and: 'the cps-path of queryDataNodes has the expectedLeaves' - assert result.leaves.sort() == expectedLeaves.sort() + def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, + cpsPath, OMIT_DESCENDANTS) + then: 'the cps-path of queryDataNodes has the expectedLeaves' + def bookPrices = result.collect { it.getLeaves().get('price') } + assert bookPrices.sort() == expectedBookPrices.sort() where: 'the following data is used' - scenario | cpspath || expectedResultSize | expectedLeaves - 'the "OR" condition' | '//books[@lang="English" or @price=15]' || 6 | [[lang: "English", price: 15, title: "Annihilation", authors: ["Jeff VanderMeer"], editions: [2014]], - [lang: "English", price: 15, title: "The Gruffalo", authors: ["Julia Donaldson"], editions: [1999]], - [lang: "English", price: 14, title: "The Light Fantastic", authors: ["Terry Pratchett"], editions: [1986]], - [lang: "English", price: 13, title: "Good Omens", authors: ["Terry Pratchett", "Neil Gaiman"], editions: [2006]], - [lang: "English", price: 12, title: "The Colour of Magic", authors: ["Terry Pratchett"], editions: [1983]], - [lang: "English", price: 10, title: "Matilda", authors: ["Roald Dahl"], editions: [1988, 2000]]] - '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]], - [lang: "English", price: 15, title: "The Gruffalo", authors: ["Julia Donaldson"], editions: [1999]]] - 'combination of multiple AND' | '//books[@lang="English" and @price=15 and @edition=1983]' || 0 | [] - '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]], - [lang: "English", price: 10, title: "Matilda", authors: ["Roald Dahl"], editions: [1988, 2000]], - [lang: "English", price: 15, title: "The Gruffalo", authors: ["Julia Donaldson"], editions: [1999]]] - '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]]] - '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]]] + leafCondition || expectedBookPrices + '[@price = 5]' || [5] + '[@price < 5]' || [1, 2, 3, 4] + '[@price > 5]' || [6, 7, 8, 9, 10] + '[@price <= 5]' || [1, 2, 3, 4, 5] + '[@price >= 5]' || [5, 6, 7, 8, 9, 10] + '[@price > 10]' || [] + '[@price = 3 or @price = 7]' || [3, 7] + '[@price = 3 and @price = 7]' || [] + '[@price > 3 and @price <= 6]' || [4, 5, 6] + '[@price < 3 or @price > 8]' || [1, 2, 9, 10] + '[@price = 1 or @price = 3 or @price = 5]' || [1, 3, 5] + '[@price = 1 or @price >= 8 and @price < 10]' || [1, 8, 9] + '[@price >= 3 and @price <= 5 or @price > 9]' || [3, 4, 5, 10] } def 'Cps Path query for leaf value(s) with #scenario.'() { @@ -90,9 +93,9 @@ class CpsQueryServiceIntegrationSpec extends FunctionalSpecBase { scenario | cpsPath | fetchDescendantsOption || expectedNumberOfParentNodes | expectedTotalNumberOfNodes 'string and no descendants' | '/bookstore/categories[@code="1"]/books[@title="Matilda"]' | OMIT_DESCENDANTS || 1 | 1 'integer and descendants' | '/bookstore/categories[@code="1"]/books[@price=15]' | INCLUDE_ALL_DESCENDANTS || 1 | 1 - 'no condition and no descendants' | '/bookstore/categories' | OMIT_DESCENDANTS || 4 | 4 - 'no condition and level 1 descendants' | '/bookstore' | new FetchDescendantsOption(1) || 1 | 6 - 'no condition and level 2 descendants' | '/bookstore' | new FetchDescendantsOption(2) || 1 | 17 + 'no condition and no descendants' | '/bookstore/categories' | OMIT_DESCENDANTS || 5 | 5 + 'no condition and level 1 descendants' | '/bookstore' | new FetchDescendantsOption(1) || 1 | 7 + 'no condition and level 2 descendants' | '/bookstore' | new FetchDescendantsOption(2) || 1 | 28 } def 'Query for attribute by cps path with cps paths that return no data because of #scenario.'() { @@ -123,7 +126,7 @@ class CpsQueryServiceIntegrationSpec extends FunctionalSpecBase { when: 'a query is executed to get all books' def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '//books', OMIT_DESCENDANTS) then: 'the expected number of books are returned' - assert result.size() == 9 + assert result.size() == 19 } def 'Cps Path query using descendant anywhere with #scenario.'() { @@ -137,7 +140,7 @@ class CpsQueryServiceIntegrationSpec extends FunctionalSpecBase { 'string leaf condition' | '//books[@title="Matilda"]' || ["Matilda"] 'text condition on leaf' | '//books/title[text()="Matilda"]' || ["Matilda"] 'text condition case mismatch' | '//books/title[text()="matilda"]' || [] - 'text condition on int leaf' | '//books/price[text()="10"]' || ["Matilda"] + 'text condition on int leaf' | '//books/price[text()="20"]' || ["A Book with No Language", "Matilda"] 'text condition on leaf-list' | '//books/authors[text()="Terry Pratchett"]' || ["Good Omens", "The Colour of Magic", "The Light Fantastic"] 'text condition partial match' | '//books/authors[text()="Terry"]' || [] 'text condition (existing) empty string' | '//books/lang[text()=""]' || ["A Book with No Language"] @@ -150,18 +153,22 @@ class CpsQueryServiceIntegrationSpec extends FunctionalSpecBase { def 'Query for attribute by cps path using contains condition #scenario.'() { when: 'a query is executed to get response by the given cps path' - def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, OMIT_DESCENDANTS) - then: 'the cps-path of queryDataNodes has expected number of nodes' - assert result.size() == expectedResultsize - and: 'xpaths of the retrieved data nodes are as expected' + def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, INCLUDE_ALL_DESCENDANTS) + then: 'xpaths of the retrieved data nodes are as expected' def bookTitles = result.collect { it.getLeaves().get('title') } assert bookTitles.sort() == expectedBookTitles.sort() where: 'the following data is used' - scenario | cpsPath | expectedResultsize || expectedBookTitles - 'contains condition with leaf' | '//books[contains(@title,"Mat")]' | 1 || ["Matilda"] - 'contains condition with case-sensitive' | '//books[contains(@title,"Ti")]' | 0 || [] - 'contains condition with Integer Value' | '//books[contains(@price,"15")]' | 2 || ["Annihilation", "The Gruffalo"] - 'contains condition with No-value' | '//books[contains(@title,"")]' | 9 || ["A Book with No Language", "Annihilation", "Debian GNU/Linux", "Good Omens", "Logarithm tables", "Matilda", "The Colour of Magic", "The Gruffalo", "The Light Fantastic"] + scenario | cpsPath || expectedBookTitles + 'contains condition with leaf' | '//books[contains(@title,"Mat")]' || ["Matilda"] + 'contains condition with case-sensitive' | '//books[contains(@title,"Ti")]' || [] + 'contains condition with Integer Value' | '//books[contains(@price,"15")]' || ["Annihilation", "The Gruffalo"] + } + + def 'Query for attribute by cps path using contains condition with no value.'() { + when: 'a query is executed to get response by the given cps path' + def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '//books[contains(@title,"")]', OMIT_DESCENDANTS) + then: 'all books are returned' + assert result.size() == 19 } def 'Cps Path query using descendant anywhere with #scenario condition for a container element.'() { @@ -173,6 +180,7 @@ class CpsQueryServiceIntegrationSpec extends FunctionalSpecBase { where: 'the following data is used' scenario | cpsPath || expectedBookTitles 'one leaf' | '//books[@price=14]' || ['The Light Fantastic'] + 'one leaf with ">" condition' | '//books[@price>14]' || ['A Book with No Language', 'Annihilation', 'Debian GNU/Linux', 'Matilda', 'The Gruffalo'] 'one text' | '//books/authors[text()="Terry Pratchett"]' || ['Good Omens', 'The Colour of Magic', 'The Light Fantastic'] 'more than one leaf' | '//books[@price=12 and @lang="English"]' || ['The Colour of Magic'] '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'] @@ -206,11 +214,11 @@ class CpsQueryServiceIntegrationSpec extends FunctionalSpecBase { 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']", "/bookstore/categories[@code='4']"] + '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']"] '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']", "/bookstore/categories[@code='4']"] + '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']"] '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' || [] @@ -226,21 +234,24 @@ class CpsQueryServiceIntegrationSpec extends FunctionalSpecBase { where: 'the following data is used' scenario | fetchDescendantsOption || expectedNumberOfNodes 'no' | OMIT_DESCENDANTS || 1 - 'direct' | DIRECT_CHILDREN_ONLY || 6 - 'all' | INCLUDE_ALL_DESCENDANTS || 17 + 'direct' | DIRECT_CHILDREN_ONLY || 7 + 'all' | INCLUDE_ALL_DESCENDANTS || 28 } - def 'Cps Path query with syntax error throws a CPS Path Exception.'() { + def 'Cps Path query with #scenario throws a CPS Path Exception.'() { when: 'trying to execute a query with a syntax (parsing) error' - objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, 'cpsPath that cannot be parsed' , OMIT_DESCENDANTS) + objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, OMIT_DESCENDANTS) then: 'a cps path exception is thrown' thrown(CpsPathException) + where: 'the following data is used' + scenario | cpsPath + 'cpsPath that cannot be parsed' | 'cpsPath that cannot be parsed' + 'String with comparative operator' | '//books[@lang>"German" and @price>10]' } - @Ignore def 'Cps Path query across anchors with #scenario.'() { when: 'a query is executed to get a data nodes across anchors by the given CpsPath' - def result = objectUnderTest.queryDataNodesAcrossAnchors(FUNCTIONAL_TEST_DATASPACE_1, cpsPath, OMIT_DESCENDANTS) + def result = objectUnderTest.queryDataNodesAcrossAnchors(FUNCTIONAL_TEST_DATASPACE_1, cpsPath, OMIT_DESCENDANTS, NO_PAGINATION) then: 'the correct dataspace is queried' assert result.dataspace.toSet() == [FUNCTIONAL_TEST_DATASPACE_1].toSet() and: 'correct anchors are queried' @@ -252,21 +263,19 @@ class CpsQueryServiceIntegrationSpec extends FunctionalSpecBase { where: 'the following data is used' scenario | cpsPath || expectedXpathsPerAnchor 'container node' | '/bookstore' || ["/bookstore"] - 'list node' | '/bookstore/categories' || ["/bookstore/categories[@code='1']", "/bookstore/categories[@code='2']", "/bookstore/categories[@code='3']", "/bookstore/categories[@code='4']"] - 'string leaf-condition' | '/bookstore[@bookstore-name="Easons"]' || ["/bookstore"] + 'list node' | '/bookstore/categories' || ["/bookstore/categories[@code='1']", "/bookstore/categories[@code='2']", "/bookstore/categories[@code='3']", "/bookstore/categories[@code='4']", "/bookstore/categories[@code='5']"] 'integer leaf-condition' | '/bookstore/categories[@code="1"]/books[@price=15]' || ["/bookstore/categories[@code='1']/books[@title='The Gruffalo']"] - 'multiple list-ancestors' | '//books/ancestor::categories' || ["/bookstore/categories[@code='1']", "/bookstore/categories[@code='2']", "/bookstore/categories[@code='3']", "/bookstore/categories[@code='4']"] + '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']"] 'one ancestor with list value' | '//books/ancestor::categories[@code="1"]' || ["/bookstore/categories[@code='1']"] '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']", "/bookstore/categories[@code='4']"] + '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']"] 'ancestor with parent list element' | '//books/ancestor::bookstore/categories[@code="2"]' || ["/bookstore/categories[@code='2']"] 'ancestor combined with text condition' | '//books/title[text()="Matilda"]/ancestor::bookstore' || ["/bookstore"] } - @Ignore def 'Cps Path query across anchors with #scenario descendants.'() { when: 'a query is executed to get a data node by the given cps path' - def result = objectUnderTest.queryDataNodesAcrossAnchors(FUNCTIONAL_TEST_DATASPACE_1, '/bookstore', fetchDescendantsOption) + def result = objectUnderTest.queryDataNodesAcrossAnchors(FUNCTIONAL_TEST_DATASPACE_1, '/bookstore', fetchDescendantsOption, NO_PAGINATION) then: 'the correct dataspace was queried' assert result.dataspace.toSet() == [FUNCTIONAL_TEST_DATASPACE_1].toSet() and: 'correct number of datanodes are returned' @@ -274,14 +283,13 @@ class CpsQueryServiceIntegrationSpec extends FunctionalSpecBase { where: 'the following data is used' scenario | fetchDescendantsOption || expectedNumberOfNodesPerAnchor 'no' | OMIT_DESCENDANTS || 1 - 'direct' | DIRECT_CHILDREN_ONLY || 6 - 'all' | INCLUDE_ALL_DESCENDANTS || 17 + 'direct' | DIRECT_CHILDREN_ONLY || 7 + 'all' | INCLUDE_ALL_DESCENDANTS || 28 } - @Ignore def 'Cps Path query across anchors with ancestors and #scenario descendants.'() { when: 'a query is executed to get a data node by the given cps path' - def result = objectUnderTest.queryDataNodesAcrossAnchors(FUNCTIONAL_TEST_DATASPACE_1, '//books/ancestor::bookstore', fetchDescendantsOption) + def result = objectUnderTest.queryDataNodesAcrossAnchors(FUNCTIONAL_TEST_DATASPACE_1, '//books/ancestor::bookstore', fetchDescendantsOption, NO_PAGINATION) then: 'the correct dataspace was queried' assert result.dataspace.toSet() == [FUNCTIONAL_TEST_DATASPACE_1].toSet() and: 'correct number of datanodes are returned' @@ -289,15 +297,128 @@ class CpsQueryServiceIntegrationSpec extends FunctionalSpecBase { where: 'the following data is used' scenario | fetchDescendantsOption || expectedNumberOfNodesPerAnchor 'no' | OMIT_DESCENDANTS || 1 - 'direct' | DIRECT_CHILDREN_ONLY || 6 - 'all' | INCLUDE_ALL_DESCENDANTS || 17 + 'direct' | DIRECT_CHILDREN_ONLY || 7 + 'all' | INCLUDE_ALL_DESCENDANTS || 28 } def 'Cps Path query across anchors with syntax error throws a CPS Path Exception.'() { when: 'trying to execute a query with a syntax (parsing) error' - objectUnderTest.queryDataNodesAcrossAnchors(FUNCTIONAL_TEST_DATASPACE_1, 'cpsPath that cannot be parsed' , OMIT_DESCENDANTS) + objectUnderTest.queryDataNodesAcrossAnchors(FUNCTIONAL_TEST_DATASPACE_1, 'cpsPath that cannot be parsed' , OMIT_DESCENDANTS, NO_PAGINATION) then: 'a cps path exception is thrown' thrown(CpsPathException) } + def 'Cps Path querys with all descendants including descendants that are list entries: #scenario.'() { + when: 'a query is executed to get a data node by the given cps path' + def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, INCLUDE_ALL_DESCENDANTS) + then: 'correct number of datanodes are returned' + assert countDataNodesInTree(result) == expectedNumberOfDataNodes + where: + scenario | cpsPath || expectedNumberOfDataNodes + 'absolute path all list entries' | '/bookstore/categories' || 24 + 'absolute path 1 list entry by key' | '/bookstore/categories[@code="3"]' || 5 + 'absolute path 1 list entry by name' | '/bookstore/categories[@name="Comedy"]' || 5 + 'relative path all list entries' | '//categories' || 24 + 'relative path 1 list entry by key' | '//categories[@code="3"]' || 5 + 'relative path 1 list entry by leaf' | '//categories[@name="Comedy"]' || 5 + 'incomplete absolute path' | '/categories' || 0 + 'incomplete absolute 1 list entry' | '/categories[@code="3"]' || 0 + } + + def 'Cps Path query contains #wildcard.'() { + when: 'a query is executed with a wildcard in the given cps path' + def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, INCLUDE_ALL_DESCENDANTS) + then: 'no results are returned, as Cps Path query does not interpret wildcard characters' + assert result.isEmpty() + where: + wildcard | cpsPath + ' sql wildcard in parent path list index' | '/bookstore/categories[@code="%"]/books' + 'regex wildcard in parent path list index' | '/bookstore/categories[@code=".*"]/books' + ' sql wildcard in leaf-condition' | '/bookstore/categories[@code="1"]/books[@title="%"]' + 'regex wildcard in leaf-condition' | '/bookstore/categories[@code="1"]/books[@title=".*"]' + ' sql wildcard in text-condition' | '/bookstore/categories[@code="1"]/books/title[text()="%"]' + 'regex wildcard in text-condition' | '/bookstore/categories[@code="1"]/books/title[text()=".*"]' + ' sql wildcard in contains-condition' | '/bookstore/categories[@code="1"]/books[contains(@title, "%")]' + 'regex wildcard in contains-condition' | '/bookstore/categories[@code="1"]/books[contains(@title, ".*")]' + } + + def 'Cps Path query can return a data node containing [@ in xpath #scenario.'() { + given: 'a book with special characters [@ and ] in title' + cpsDataService.saveData(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, "/bookstore/categories[@code='1']", '{"books": [ {"title":"[@hello=world]"} ] }', OffsetDateTime.now()) + when: 'a query is executed' + def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, OMIT_DESCENDANTS) + then: 'the node is returned' + assert result.size() == 1 + cleanup: 'the new datanode' + cpsDataService.deleteDataNode(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, "/bookstore/categories[@code='1']/books[@title='[@hello=world]']", OffsetDateTime.now()) + where: + scenario || cpsPath + 'leaf-condition' || "/bookstore/categories[@code='1']/books[@title='[@hello=world]']" + 'text-condition' || "/bookstore/categories[@code='1']/books/title[text()='[@hello=world]']" + 'contains-condition' || "/bookstore/categories[@code='1']/books[contains(@title, '[@hello=world]')]" + } + + def 'Cps Path get and query can handle apostrophe inside #quotes.'() { + given: 'a book with special characters in title' + cpsDataService.saveData(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, "/bookstore/categories[@code='1']", + '{"books": [ {"title":"I\'m escaping"} ] }', OffsetDateTime.now()) + when: 'a query is executed' + def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, cpsPath, OMIT_DESCENDANTS) + then: 'the node is returned' + assert result.size() == 1 + assert result[0].xpath == "/bookstore/categories[@code='1']/books[@title='I''m escaping']" + cleanup: 'the new datanode' + cpsDataService.deleteDataNode(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, "/bookstore/categories[@code='1']/books[@title='I''m escaping']", OffsetDateTime.now()) + where: + quotes || cpsPath + 'single quotes' || "/bookstore/categories[@code='1']/books[@title='I''m escaping']" + 'double quotes' || '/bookstore/categories[@code="1"]/books[@title="I\'m escaping"]' + 'text-condition' || "/bookstore/categories[@code='1']/books/title[text()='I''m escaping']" + 'contains-condition' || "/bookstore/categories[@code='1']/books[contains(@title, 'I''m escaping')]" + } + + def 'Cps Path query across anchors using pagination option with #scenario.'() { + when: 'a query is executed to get a data nodes across anchors by the given CpsPath and pagination option' + def result = objectUnderTest.queryDataNodesAcrossAnchors(FUNCTIONAL_TEST_DATASPACE_1, '/bookstore', OMIT_DESCENDANTS, new PaginationOption(pageIndex, pageSize)) + then: 'correct bookstore names are queried' + def bookstoreNames = result.collect { it.getLeaves().get('bookstore-name') } + assert bookstoreNames.toList() == expectedBookstoreNames + and: 'the correct number of page size is returned' + assert result.size() == expectedPageSize + and: 'the queried nodes have expected anchor names' + assert result.anchorName.toSet() == expectedAnchors.toSet() + where: 'the following data is used' + scenario | pageIndex | pageSize || expectedPageSize || expectedAnchors || expectedBookstoreNames + '1st page with one anchor' | 1 | 1 || 1 || [BOOKSTORE_ANCHOR_1] || ['Easons-1'] + '1st page with two anchor' | 1 | 2 || 2 || [BOOKSTORE_ANCHOR_1, BOOKSTORE_ANCHOR_2] || ['Easons-1', 'Easons-2'] + '2nd page' | 2 | 1 || 1 || [BOOKSTORE_ANCHOR_2] || ['Easons-2'] + 'no 2nd page due to page size' | 2 | 2 || 0 || [] || [] + } + + def 'Cps Path query across anchors using pagination option for ancestor axis.'() { + when: 'a query is executed to get a data nodes across anchors by the given CpsPath and pagination option' + def result = objectUnderTest.queryDataNodesAcrossAnchors(FUNCTIONAL_TEST_DATASPACE_1, '//books/ancestor::categories', INCLUDE_ALL_DESCENDANTS, new PaginationOption(1, 2)) + then: 'correct category codes are queried' + def categoryNames = result.collect { it.getLeaves().get('name') } + assert categoryNames.toSet() == ['Discount books', 'Computing', 'Comedy', 'Thriller', 'Children'].toSet() + and: 'the queried nodes have expected anchors' + assert result.anchorName.toSet() == [BOOKSTORE_ANCHOR_1, BOOKSTORE_ANCHOR_2].toSet() + } + + def 'Count number of anchors for given dataspace name and cps path'() { + expect: '/bookstore is present in two anchors' + assert objectUnderTest.countAnchorsForDataspaceAndCpsPath(FUNCTIONAL_TEST_DATASPACE_1, '/bookstore') == 2 + } + + def 'Cps Path query across anchors using no pagination'() { + when: 'a query is executed to get a data nodes across anchors by the given CpsPath and pagination option' + def result = objectUnderTest.queryDataNodesAcrossAnchors(FUNCTIONAL_TEST_DATASPACE_1, '/bookstore', OMIT_DESCENDANTS, NO_PAGINATION) + then: 'all bookstore names are queried' + def bookstoreNames = result.collect { it.getLeaves().get('bookstore-name') } + assert bookstoreNames.toSet() == ['Easons-1', 'Easons-2'].toSet() + and: 'the correct number of page size is returned' + assert result.size() == 2 + and: 'the queried nodes have expected bookstore names' + assert result.anchorName.toSet() == [BOOKSTORE_ANCHOR_1, BOOKSTORE_ANCHOR_2].toSet() + } }