Migrate query tests to integration-test module #2 26/134026/5
authordanielhanrahan <daniel.hanrahan@est.tech>
Tue, 4 Apr 2023 18:00:44 +0000 (19:00 +0100)
committerdanielhanrahan <daniel.hanrahan@est.tech>
Tue, 11 Apr 2023 16:52:05 +0000 (17:52 +0100)
- Migrate some query tests to integration-test
- Edit bookstore model to add integer leaf-list 'editions'
- Lower cps-ri code coverage

Issue-ID: CPS-1597
Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech>
Change-Id: If50bf15ad7d7f147448f6b60d464efc1cdc91005

cps-ri/pom.xml
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/bookstore.yang
integration-test/src/test/resources/data/bookstore/bookstoreData.json
integration-test/src/test/resources/data/bookstore/largeModelData.json

index f282069..3cb4130 100644 (file)
 \r
     <artifactId>cps-ri</artifactId>\r
 \r
+    <properties>\r
+        <minimum-coverage>0.96</minimum-coverage>\r
+    </properties>\r
+\r
     <dependencies>\r
         <dependency>\r
             <groupId>${project.groupId}</groupId>\r
index 8e50017..5f8d1ca 100644 (file)
@@ -37,32 +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 '() {
-        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
-            'fully unique descendant name'                           | '//categories[@code=2]'                                || ["/shops/shop[@id='1']/categories[@code='2']", "/shops/shop[@id='2']/categories[@code='1']", "/shops/shop[@id='2']/categories[@code='2']"]
-            'descendant name match end of other node'                | '//book'                                               || ["/shops/shop[@id='1']/categories[@code='1']/book", "/shops/shop[@id='1']/categories[@code='2']/book"]
-            'descendant with text condition on leaf'                 | '//book/title[text()="Chapters"]'                      || ["/shops/shop[@id='1']/categories[@code='2']/book"]
-            'descendant with text condition case mismatch'           | '//book/title[text()="chapters"]'                      || []
-            'descendant with text condition on int leaf'             | '//book/price[text()="5"]'                             || ["/shops/shop[@id='1']/categories[@code='1']/book"]
-            'descendant with text condition on leaf-list'            | '//book/labels[text()="special offer"]'                || ["/shops/shop[@id='1']/categories[@code='1']/book"]
-            'descendant with text condition partial match'           | '//book/labels[text()="special"]'                      || []
-            'descendant with text condition (existing) empty string' | '//book/labels[text()=""]'                             || ["/shops/shop[@id='1']/categories[@code='1']/book"]
-            'descendant with text condition on int leaf-list'        | '//book/editions[text()="2000"]'                       || ["/shops/shop[@id='1']/categories[@code='2']/book"]
-            'descendant name match of leaf containing /'             | '//categories/type[text()="text/with/slash"]'          || ["/shops/shop[@id='1']/categories[@code='string/with/slash/']"]
-            'descendant with text condition on leaf containing /'    | '//categories[@code=\'string/with/slash\']'            || ["/shops/shop[@id='1']/categories[@code='string/with/slash/']"]
-            'descendant with text condition on leaf containing ['    | '//book/author[@Address="String[with]square[bracket]"]'|| []
-    }
-
     @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'
index ddf8dcf..d371368 100644 (file)
@@ -41,9 +41,9 @@ class CpsDataServiceIntegrationSpec extends FunctionalSpecBase {
         where: 'the following option is used'
             fetchDescendantsOption                         || expectNumberOfDataNodes
             FetchDescendantsOption.OMIT_DESCENDANTS        || 1
-            FetchDescendantsOption.DIRECT_CHILDREN_ONLY    || 4
-            FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS || 8
-            new FetchDescendantsOption(2)                  || 8
+            FetchDescendantsOption.DIRECT_CHILDREN_ONLY    || 5
+            FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS || 12
+            new FetchDescendantsOption(2)                  || 12
     }
 
     def 'Read bookstore top-level container(s) has correct dataspace and anchor.'() {
index 1f3a76d..ce740b3 100644 (file)
@@ -63,9 +63,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               || 3                           | 3
-            'no condition and level 1 descendants' | '/bookstore'                                               | new FetchDescendantsOption(1)  || 1                           | 4
-            'no condition and level 2 descendants' | '/bookstore'                                               | new FetchDescendantsOption(2)  || 1                           | 8
+            '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
     }
 
     def 'Query for attribute by cps path with cps paths that return no data because of #scenario.'() {
@@ -92,6 +92,35 @@ class CpsQueryServiceIntegrationSpec extends FunctionalSpecBase {
                                                      "/bookstore/categories[@code='1']/books[@title='The Gruffalo']"]
     }
 
+    def 'Cps Path query for all books.'() {
+        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
+    }
+
+    def 'Cps Path query using descendant anywhere with #scenario.'() {
+        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: '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                                     || expectedBookTitles
+            '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 leaf-list'            | '//books/authors[text()="Terry Pratchett"]' || ["Good Omens"]
+            '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"]
+            'match of leaf containing /'             | '//books[@lang="N/A"]'                      || ["Logarithm tables"]
+            'text condition on leaf containing /'    | '//books/lang[text()="N/A"]'                || ["Logarithm tables"]
+            'match of key containing /'              | '//books[@title="Debian GNU/Linux"]'        || ["Debian GNU/Linux"]
+            'text condition on key containing /'     | '//books/title[text()="Debian GNU/Linux"]'  || ["Debian GNU/Linux"]
+    }
+
     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)
@@ -99,11 +128,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']"]
+            'multiple list-ancestors'                   | '//books/ancestor::categories'                        || ["/bookstore/categories[@code='1']", "/bookstore/categories[@code='2']", "/bookstore/categories[@code='3']", "/bookstore/categories[@code='4']"]
             '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 list'                 | '//books/ancestor::bookstore/categories'              || ["/bookstore/categories[@code='1']", "/bookstore/categories[@code='2']", "/bookstore/categories[@code='3']", "/bookstore/categories[@code='4']"]
             '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'      || []
@@ -118,8 +147,8 @@ class CpsQueryServiceIntegrationSpec extends FunctionalSpecBase {
         where: 'the following data is used'
             scenario | fetchDescendantsOption  || expectedNumberOfNodes
             'no'     | OMIT_DESCENDANTS        || 1
-            'direct' | DIRECT_CHILDREN_ONLY    || 4
-            'all'    | INCLUDE_ALL_DESCENDANTS || 8
+            'direct' | DIRECT_CHILDREN_ONLY    || 5
+            'all'    | INCLUDE_ALL_DESCENDANTS || 12
     }
 
     def 'Cps Path query with syntax error throws a CPS Path Exception.'() {
index 2179fb9..c3bfc50 100644 (file)
@@ -21,37 +21,37 @@ module stores {
             type string;
         }
 
-    list categories {
+        list categories {
 
-        key "code";
+            key "code";
 
-        leaf code {
-            type string;
-        }
-
-        leaf name {
-            type string;
-        }
-
-        list books {
-            key title;
-
-            leaf title {
+            leaf code {
                 type string;
             }
-            leaf lang {
-                type string;
-            }
-            leaf-list authors {
+
+            leaf name {
                 type string;
             }
-            leaf pub_year {
-                type year;
-            }
-            leaf price {
-                type uint64;
+
+            list books {
+                key title;
+
+                leaf title {
+                    type string;
+                }
+                leaf lang {
+                    type string;
+                }
+                leaf-list authors {
+                    type string;
+                }
+                leaf-list editions {
+                    type year;
+                }
+                leaf price {
+                    type uint64;
+                }
             }
         }
     }
-    }
 }
index 1c6cb88..f9bac60 100644 (file)
             "title": "Matilda",
             "lang": "English",
             "authors": ["Roald Dahl"],
-            "pub_year": 1988,
+            "editions": [1988, 2000],
             "price": 10
           },
           {
             "title": "The Gruffalo",
             "lang": "English",
             "authors": ["Julia Donaldson"],
-            "pub_year": 1999,
+            "editions": [1999],
             "price": 15
           }
         ]
@@ -30,7 +30,7 @@
             "title": "Annihilation",
             "lang": "English",
             "authors": ["Jeff VanderMeer"],
-            "pub_year": 2014,
+            "editions": [2014],
             "price": 15
           }
         ]
             "title": "Good Omens",
             "lang": "English",
             "authors": ["Neil Gaiman", "Terry Pratchett"],
-            "pub_year": 2006,
+            "editions": [2006],
             "price": 13
+          },
+          {
+            "title": "A Book with No Language",
+            "lang": "",
+            "authors": ["Joe Bloggs"],
+            "editions": [2023],
+            "price": 20
+          }
+        ]
+      },
+      {
+        "code": 4,
+        "name": "Computing",
+        "books" : [
+          {
+            "title": "Debian GNU/Linux",
+            "lang": "German",
+            "authors": ["Peter H. Ganten", "Wulf Alex"],
+            "editions": [2007, 2013, 2021],
+            "price": 39
+          },
+          {
+            "title": "Logarithm tables",
+            "lang": "N/A",
+            "authors": ["Joe Bloggs"],
+            "editions": [2009],
+            "price": 11
           }
         ]
       }
-
     ]
   }
-}
\ No newline at end of file
+}
index bdc22a7..4a92a1d 100644 (file)
             "title": "Matilda",
             "lang": "English",
             "authors": ["Roald Dahl"],
-            "pub_year": 1988,
+            "editions": [1988, 2000],
             "price": 10
           },
           {
             "title": "The Gruffalo",
             "lang": "English",
             "authors": ["Julia Donaldson"],
-            "pub_year": 1999,
+            "editions": [1999],
             "price": 15
           }
         ]
@@ -30,7 +30,7 @@
             "title": "Annihilation",
             "lang": "English",
             "authors": ["Jeff VanderMeer"],
-            "pub_year": 2014,
+            "editions": [2014],
             "price": 15
           }
         ]
@@ -43,7 +43,7 @@
             "title": "Good Omens",
             "lang": "English",
             "authors": ["Neil Gaiman", "Terry Pratchett"],
-            "pub_year": 2006,
+            "editions": [2006],
             "price": 13
           }
         ]
             "title": "Matilda",
             "lang": "English",
             "authors": ["Roald Dahl"],
-            "pub_year": 1988,
+            "editions": [1988, 2000],
             "price": 10
           },
           {
             "title": "The Gruffalo",
             "lang": "English",
             "authors": ["Julia Donaldson"],
-            "pub_year": 1999,
+            "editions": [1999],
             "price": 15
           }
         ]
@@ -76,7 +76,7 @@
             "title": "Annihilation",
             "lang": "English",
             "authors": ["Jeff VanderMeer"],
-            "pub_year": 2014,
+            "editions": [2014],
             "price": 15
           }
         ]
@@ -89,7 +89,7 @@
             "title": "Good Omens",
             "lang": "English",
             "authors": ["Neil Gaiman", "Terry Pratchett"],
-            "pub_year": 2006,
+            "editions": [2006],
             "price": 13
           }
         ]
             "title": "Matilda",
             "lang": "English",
             "authors": ["Roald Dahl"],
-            "pub_year": 1988,
+            "editions": [1988, 2000],
             "price": 10
           },
           {
             "title": "The Gruffalo",
             "lang": "English",
             "authors": ["Julia Donaldson"],
-            "pub_year": 1999,
+            "editions": [1999],
             "price": 15
           }
         ]
             "title": "Annihilation",
             "lang": "English",
             "authors": ["Jeff VanderMeer"],
-            "pub_year": 2014,
+            "editions": [2014],
             "price": 15
           }
         ]
             "title": "Good Omens",
             "lang": "English",
             "authors": ["Neil Gaiman", "Terry Pratchett"],
-            "pub_year": 2006,
+            "editions": [2006],
             "price": 13
           }
         ]
             "title": "Matilda",
             "lang": "English",
             "authors": ["Roald Dahl"],
-            "pub_year": 1988,
+            "editions": [1988, 2000],
             "price": 10
           },
           {
             "title": "The Gruffalo",
             "lang": "English",
             "authors": ["Julia Donaldson"],
-            "pub_year": 1999,
+            "editions": [1999],
             "price": 15
           }
         ]
             "title": "Annihilation",
             "lang": "English",
             "authors": ["Jeff VanderMeer"],
-            "pub_year": 2014,
+            "editions": [2014],
             "price": 15
           }
         ]
             "title": "Good Omens",
             "lang": "English",
             "authors": ["Neil Gaiman", "Terry Pratchett"],
-            "pub_year": 2006,
+            "editions": [2006],
             "price": 13
           }
         ]
             "title": "Matilda",
             "lang": "English",
             "authors": ["Roald Dahl"],
-            "pub_year": 1988,
+            "editions": [1988, 2000],
             "price": 10
           },
           {
             "title": "The Gruffalo",
             "lang": "English",
             "authors": ["Julia Donaldson"],
-            "pub_year": 1999,
+            "editions": [1999],
             "price": 15
           }
         ]
             "title": "Annihilation",
             "lang": "English",
             "authors": ["Jeff VanderMeer"],
-            "pub_year": 2014,
+            "editions": [2014],
             "price": 15
           }
         ]
             "title": "Good Omens",
             "lang": "English",
             "authors": ["Neil Gaiman", "Terry Pratchett"],
-            "pub_year": 2006,
+            "editions": [2006],
             "price": 13
           }
         ]
             "title": "Matilda",
             "lang": "English",
             "authors": ["Roald Dahl"],
-            "pub_year": 1988,
+            "editions": [1988, 2000],
             "price": 10
           },
           {
             "title": "The Gruffalo",
             "lang": "English",
             "authors": ["Julia Donaldson"],
-            "pub_year": 1999,
+            "editions": [1999],
             "price": 15
           }
         ]
             "title": "Annihilation",
             "lang": "English",
             "authors": ["Jeff VanderMeer"],
-            "pub_year": 2014,
+            "editions": [2014],
             "price": 15
           }
         ]
             "title": "Good Omens",
             "lang": "English",
             "authors": ["Neil Gaiman", "Terry Pratchett"],
-            "pub_year": 2006,
+            "editions": [2006],
             "price": 13
           }
         ]
             "title": "Matilda",
             "lang": "English",
             "authors": ["Roald Dahl"],
-            "pub_year": 1988,
+            "editions": [1988, 2000],
             "price": 10
           },
           {
             "title": "The Gruffalo",
             "lang": "English",
             "authors": ["Julia Donaldson"],
-            "pub_year": 1999,
+            "editions": [1999],
             "price": 15
           }
         ]
             "title": "Annihilation",
             "lang": "English",
             "authors": ["Jeff VanderMeer"],
-            "pub_year": 2014,
+            "editions": [2014],
             "price": 15
           }
         ]
             "title": "Good Omens",
             "lang": "English",
             "authors": ["Neil Gaiman", "Terry Pratchett"],
-            "pub_year": 2006,
+            "editions": [2006],
             "price": 13
           }
         ]
             "title": "Matilda",
             "lang": "English",
             "authors": ["Roald Dahl"],
-            "pub_year": 1988,
+            "editions": [1988, 2000],
             "price": 10
           },
           {
             "title": "The Gruffalo",
             "lang": "English",
             "authors": ["Julia Donaldson"],
-            "pub_year": 1999,
+            "editions": [1999],
             "price": 15
           }
         ]
             "title": "Annihilation",
             "lang": "English",
             "authors": ["Jeff VanderMeer"],
-            "pub_year": 2014,
+            "editions": [2014],
             "price": 15
           }
         ]
             "title": "Good Omens",
             "lang": "English",
             "authors": ["Neil Gaiman", "Terry Pratchett"],
-            "pub_year": 2006,
+            "editions": [2006],
             "price": 13
           }
         ]
             "title": "Matilda",
             "lang": "English",
             "authors": ["Roald Dahl"],
-            "pub_year": 1988,
+            "editions": [1988, 2000],
             "price": 10
           },
           {
             "title": "The Gruffalo",
             "lang": "English",
             "authors": ["Julia Donaldson"],
-            "pub_year": 1999,
+            "editions": [1999],
             "price": 15
           }
         ]
             "title": "Annihilation",
             "lang": "English",
             "authors": ["Jeff VanderMeer"],
-            "pub_year": 2014,
+            "editions": [2014],
             "price": 15
           }
         ]
             "title": "Good Omens",
             "lang": "English",
             "authors": ["Neil Gaiman", "Terry Pratchett"],
-            "pub_year": 2006,
+            "editions": [2006],
             "price": 13
           }
         ]
             "title": "Matilda",
             "lang": "English",
             "authors": ["Roald Dahl"],
-            "pub_year": 1988,
+            "editions": [1988, 2000],
             "price": 10
           },
           {
             "title": "The Gruffalo",
             "lang": "English",
             "authors": ["Julia Donaldson"],
-            "pub_year": 1999,
+            "editions": [1999],
             "price": 15
           }
         ]
             "title": "Annihilation",
             "lang": "English",
             "authors": ["Jeff VanderMeer"],
-            "pub_year": 2014,
+            "editions": [2014],
             "price": 15
           }
         ]
             "title": "Good Omens",
             "lang": "English",
             "authors": ["Neil Gaiman", "Terry Pratchett"],
-            "pub_year": 2006,
+            "editions": [2006],
             "price": 13
           }
         ]
             "title": "Matilda",
             "lang": "English",
             "authors": ["Roald Dahl"],
-            "pub_year": 1988,
+            "editions": [1988, 2000],
             "price": 10
           },
           {
             "title": "The Gruffalo",
             "lang": "English",
             "authors": ["Julia Donaldson"],
-            "pub_year": 1999,
+            "editions": [1999],
             "price": 15
           }
         ]
             "title": "Annihilation",
             "lang": "English",
             "authors": ["Jeff VanderMeer"],
-            "pub_year": 2014,
+            "editions": [2014],
             "price": 15
           }
         ]
             "title": "Good Omens",
             "lang": "English",
             "authors": ["Neil Gaiman", "Terry Pratchett"],
-            "pub_year": 2006,
+            "editions": [2006],
             "price": 13
           }
         ]