Merge "Fix: Make bookstore data consistent"
authorToine Siebelink <toine.siebelink@est.tech>
Tue, 1 Aug 2023 12:20:51 +0000 (12:20 +0000)
committerGerrit Code Review <gerrit@onap.org>
Tue, 1 Aug 2023 12:20:51 +0000 (12:20 +0000)
cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy
cps-service/src/test/resources/bookstore.json
cps-service/src/test/resources/bookstore.yang
integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsDataServiceIntegrationSpec.groovy
integration-test/src/test/resources/data/bookstore/bookstore.yang
integration-test/src/test/resources/data/bookstore/bookstoreData.json

index cb95fb6..b4ac7a6 100644 (file)
@@ -118,7 +118,7 @@ class CpsDataServiceImplSpec extends Specification {
         given: 'schema set for given anchor and dataspace references bookstore model'
             setupSchemaSetMocks('bookstore.yang')
         when: 'save data method is invoked with list element json data'
-            def jsonData = '{"multiple-data-tree:invoice": [{"ProductID": "2","ProductName": "Banana","price": "100","stock": True}]}'
+            def jsonData = '{"bookstore-address":[{"bookstore-name":"Easons","address":"Dublin,Ireland","postal-code":"D02HA21"}]}'
             objectUnderTest.saveListElements(dataspaceName, anchorName, '/', jsonData, observedTimestamp)
         then: 'the persistence service method is invoked with correct parameters'
             1 * mockCpsDataPersistenceService.storeDataNodes(dataspaceName, anchorName,
@@ -126,7 +126,7 @@ class CpsDataServiceImplSpec extends Specification {
                     {
                         assert dataNodeCollection.size() == 1
                         assert dataNodeCollection.collect { it.getXpath() }
-                            .containsAll(['/invoice[@ProductID=\'2\']'])
+                            .containsAll(['/bookstore-address[@bookstore-name=\'Easons\']'])
                     }
                 }
             )
index 4b8ed3d..c5fd0ff 100644 (file)
@@ -1,10 +1,9 @@
 {
-   "multiple-data-tree:invoice": [
+   "bookstore-address": [
       {
-         "ProductID": "1",
-         "ProductName": "Apple",
-         "price": "100",
-         "stock": false
+         "bookstore-name": "Easons",
+         "address": "Dublin,Ireland",
+         "postal-code": "D02HA21"
       }
    ],
    "test:bookstore":{
index b7a52e2..2033fc7 100644 (file)
@@ -15,31 +15,22 @@ module stores {
         }
     }
 
-    list invoice {
-        key "ProductID";
-        leaf ProductID {
-            type uint64;
-            mandatory "true";
-            description
-            "Unique product ID. Example: 001";
-        }
-        leaf ProductName {
+    list bookstore-address {
+        key "bookstore-name";
+        leaf bookstore-name {
             type string;
-            mandatory "true";
             description
-            "Name of the Product";
+            "Name of bookstore. Example: My Bookstore";
         }
-        leaf price {
-            type uint64;
-            mandatory "true";
+        leaf address {
+            type string;
             description
-            "Price of book";
+            "Address of store";
         }
-        leaf stock {
-            type boolean;
-            default "false";
+        leaf postal-code {
+            type string;
             description
-            "Book in stock or not. Example value: true";
+            "Postal code of store";
         }
     }
 
index 6b556d3..678aa64 100644 (file)
@@ -209,15 +209,15 @@ class CpsDataServiceIntegrationSpec extends FunctionalSpecBase {
 
     def 'Add and Delete top-level list (element) data nodes with root node.'() {
         given: 'a new (multiple-data-tree:invoice) datanodes'
-            def json = '{"multiple-data-tree:invoice": [{"ProductID": "2","ProductName": "Mango","price": "150","stock": true}]}'
+            def json = '{"bookstore-address":[{"bookstore-name":"Scholastic","address":"Bangalore,India","postal-code":"560043"}]}'
         when: 'the new list elements are saved'
             objectUnderTest.saveListElements(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1 , '/', json, now)
         then: 'they can be retrieved by their xpaths'
-            objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1 , '/invoice[@ProductID ="2"]', INCLUDE_ALL_DESCENDANTS)
+            objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1 , '/bookstore-address[@bookstore-name="Easons"]', INCLUDE_ALL_DESCENDANTS)
         and: 'there is one extra datanode'
             assert originalCountBookstoreTopLevelListNodes + 1 == countTopLevelListDataNodesInBookstore()
         when: 'the new elements are deleted'
-            objectUnderTest.deleteDataNode(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1 , '/invoice[@ProductID ="2"]', now)
+            objectUnderTest.deleteDataNode(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1 , '/bookstore-address[@bookstore-name="Easons"]', now)
         then: 'the original number of datanodes is restored'
             assert originalCountBookstoreTopLevelListNodes == countTopLevelListDataNodesInBookstore()
     }
index ab384de..6f60f19 100644 (file)
@@ -15,31 +15,22 @@ module stores {
         }
     }
 
-    list invoice {
-        key "ProductID";
-        leaf ProductID {
-            type uint64;
-            mandatory "true";
-            description
-            "Unique product ID. Example: 001";
-        }
-        leaf ProductName {
+    list bookstore-address {
+        key "bookstore-name";
+        leaf bookstore-name {
             type string;
-            mandatory "true";
             description
-            "Name of the Product";
+            "Name of bookstore. Example: My Bookstore";
         }
-        leaf price {
-            type uint64;
-            mandatory "true";
+        leaf address {
+            type string;
             description
-            "Price of book";
+            "Address of store";
         }
-        leaf stock {
-            type boolean;
-            default "false";
+        leaf postal-code {
+            type string;
             description
-            "Book in stock or not. Example value: true";
+            "Postal code of store";
         }
     }
 
index 5f66a1d..418acf8 100644 (file)
@@ -1,10 +1,9 @@
 {
-  "multiple-data-tree:invoice": [
+  "bookstore-address": [
     {
-      "ProductID": "1",
-      "ProductName": "Apple",
-      "price": "100",
-      "stock": false
+      "bookstore-name": "Easons",
+      "address": "Dublin,Ireland",
+      "postal-code": "D02HA21"
     }
   ],
   "bookstore": {