diff options
author | danielhanrahan <daniel.hanrahan@est.tech> | 2023-04-05 17:11:24 +0100 |
---|---|---|
committer | Sourabh Sourabh <sourabh.sourabh@est.tech> | 2023-04-12 12:15:37 +0000 |
commit | b99ae09807a2893e0678d2209b4ee08194f95fe8 (patch) | |
tree | 964c32565e4bbfde6a83ecfe28caaab991c916ce | |
parent | bc05c93a30bf7b11707476d3c277623ee5acc729 (diff) |
Migrate query tests to integration-test module #3
Issue-ID: CPS-1597
Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech>
Change-Id: I1d92355f272271424a7014057d251cf88eac0203
4 files changed, 35 insertions, 24 deletions
diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceQueryDataNodeSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceQueryDataNodeSpec.groovy index 5f8d1caf35..d5a6be4e80 100644 --- a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceQueryDataNodeSpec.groovy +++ b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceQueryDataNodeSpec.groovy @@ -38,24 +38,6 @@ class CpsDataPersistenceQueryDataNodeSpec extends CpsPersistenceSpecBase { static final String SET_DATA = '/data/cps-path-query.sql' @Sql([CLEAR_DATA, SET_DATA]) - def 'Cps Path query using descendant anywhere with #scenario condition(s) for a container element.'() { - when: 'a query is executed to get a data node by the given cps path' - def result = objectUnderTest.queryDataNodes(DATASPACE_NAME, ANCHOR_FOR_SHOP_EXAMPLE, cpsPath, OMIT_DESCENDANTS) - then: 'the correct number of data nodes are retrieved' - result.size() == expectedXPaths.size() - and: 'xpaths of the retrieved data nodes are as expected' - for (int i = 0; i < result.size(); i++) { - assert result[i].getXpath() == expectedXPaths[i] - } - where: 'the following data is used' - scenario | cpsPath || expectedXPaths - 'one leaf' | '//author[@FirstName="Joe"]' || ["/shops/shop[@id='1']/categories[@code='1']/book/author[@FirstName='Joe' and @Surname='Bloggs']", "/shops/shop[@id='1']/categories[@code='2']/book/author[@FirstName='Joe' and @Surname='Smith']"] - 'more than one leaf' | '//author[@FirstName="Joe" and @Surname="Bloggs"]' || ["/shops/shop[@id='1']/categories[@code='1']/book/author[@FirstName='Joe' and @Surname='Bloggs']"] - 'leaves reversed in order' | '//author[@Surname="Bloggs" and @FirstName="Joe"]' || ["/shops/shop[@id='1']/categories[@code='1']/book/author[@FirstName='Joe' and @Surname='Bloggs']"] - 'leaf and text condition' | '//author[@FirstName="Joe"]/Surname[text()="Bloggs"]' || ["/shops/shop[@id='1']/categories[@code='1']/book/author[@FirstName='Joe' and @Surname='Bloggs']"] - } - - @Sql([CLEAR_DATA, SET_DATA]) def 'Cps Path query using descendant anywhere with #scenario condition(s) for a list element.'() { when: 'a query is executed to get a data node by the given cps path' def result = objectUnderTest.queryDataNodes(DATASPACE_NAME, ANCHOR_FOR_SHOP_EXAMPLE, cpsPath, OMIT_DESCENDANTS) diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsDataServiceIntegrationSpec.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsDataServiceIntegrationSpec.groovy index d371368217..826035af57 100644 --- a/integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsDataServiceIntegrationSpec.groovy +++ b/integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsDataServiceIntegrationSpec.groovy @@ -42,8 +42,8 @@ class CpsDataServiceIntegrationSpec extends FunctionalSpecBase { fetchDescendantsOption || expectNumberOfDataNodes FetchDescendantsOption.OMIT_DESCENDANTS || 1 FetchDescendantsOption.DIRECT_CHILDREN_ONLY || 5 - FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS || 12 - new FetchDescendantsOption(2) || 12 + FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS || 14 + new FetchDescendantsOption(2) || 14 } def 'Read bookstore top-level container(s) has correct dataspace and anchor.'() { 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 ce740b3e52..6197691c78 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 @@ -65,7 +65,7 @@ class CpsQueryServiceIntegrationSpec extends FunctionalSpecBase { '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 | 5 - 'no condition and level 2 descendants' | '/bookstore' | new FetchDescendantsOption(2) || 1 | 12 + 'no condition and level 2 descendants' | '/bookstore' | new FetchDescendantsOption(2) || 1 | 14 } def 'Query for attribute by cps path with cps paths that return no data because of #scenario.'() { @@ -96,7 +96,7 @@ class CpsQueryServiceIntegrationSpec extends FunctionalSpecBase { when: 'a query is executed to get all books' def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE, BOOKSTORE_ANCHOR, '//books', OMIT_DESCENDANTS) then: 'the expected number of books are returned' - assert result.size() == 7 + assert result.size() == 9 } def 'Cps Path query using descendant anywhere with #scenario.'() { @@ -111,7 +111,7 @@ class CpsQueryServiceIntegrationSpec extends FunctionalSpecBase { '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 leaf-list' | '//books/authors[text()="Terry Pratchett"]' || ["Good Omens"] + '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"] 'text condition on int leaf-list' | '//books/editions[text()="2000"]' || ["Matilda"] @@ -121,6 +121,21 @@ class CpsQueryServiceIntegrationSpec extends FunctionalSpecBase { 'text condition on key containing /' | '//books/title[text()="Debian GNU/Linux"]' || ["Debian GNU/Linux"] } + def 'Cps Path query using descendant anywhere with #scenario condition for a container element.'() { + when: 'a query is executed to get a data node by the given cps path' + def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE, BOOKSTORE_ANCHOR, cpsPath, OMIT_DESCENDANTS) + then: 'book titles from 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 || expectedBookTitles + 'one leaf' | '//books[@price=14]' || ['The Light Fantastic'] + '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'] + 'leaves reversed in order' | '//books[@lang="English" and @price=12]' || ['The Colour of Magic'] + 'leaf and text' | '//books[@price=14]/authors[text()="Terry Pratchett"]' || ['The Light Fantastic'] + } + 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) @@ -148,7 +163,7 @@ class CpsQueryServiceIntegrationSpec extends FunctionalSpecBase { scenario | fetchDescendantsOption || expectedNumberOfNodes 'no' | OMIT_DESCENDANTS || 1 'direct' | DIRECT_CHILDREN_ONLY || 5 - 'all' | INCLUDE_ALL_DESCENDANTS || 12 + 'all' | INCLUDE_ALL_DESCENDANTS || 14 } def 'Cps Path query with syntax error throws a CPS Path Exception.'() { diff --git a/integration-test/src/test/resources/data/bookstore/bookstoreData.json b/integration-test/src/test/resources/data/bookstore/bookstoreData.json index f9bac6012c..48cf4e4e58 100644 --- a/integration-test/src/test/resources/data/bookstore/bookstoreData.json +++ b/integration-test/src/test/resources/data/bookstore/bookstoreData.json @@ -47,6 +47,20 @@ "price": 13 }, { + "title": "The Colour of Magic", + "lang": "English", + "authors": ["Terry Pratchett"], + "editions": [1983], + "price": 12 + }, + { + "title": "The Light Fantastic", + "lang": "English", + "authors": ["Terry Pratchett"], + "editions": [1986], + "price": 14 + }, + { "title": "A Book with No Language", "lang": "", "authors": ["Joe Bloggs"], |