Migrate query tests to integration-test module #3 27/134027/5
authordanielhanrahan <daniel.hanrahan@est.tech>
Wed, 5 Apr 2023 16:11:24 +0000 (17:11 +0100)
committerSourabh Sourabh <sourabh.sourabh@est.tech>
Wed, 12 Apr 2023 12:15:37 +0000 (12:15 +0000)
Issue-ID: CPS-1597
Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech>
Change-Id: I1d92355f272271424a7014057d251cf88eac0203

cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceQueryDataNodeSpec.groovy
integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsDataServiceIntegrationSpec.groovy
integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsQueryServiceIntegrationSpec.groovy
integration-test/src/test/resources/data/bookstore/bookstoreData.json

index 5f8d1ca..d5a6be4 100644 (file)
@@ -37,24 +37,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'
index d371368..826035a 100644 (file)
@@ -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.'() {
index ce740b3..6197691 100644 (file)
@@ -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.'() {
index f9bac60..48cf4e4 100644 (file)
             "editions": [2006],
             "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": "",