Merge "Persisting a list element to a parent list (ep2)"
authorLuke Gleeson <luke.gleeson@est.tech>
Thu, 20 Jul 2023 09:47:48 +0000 (09:47 +0000)
committerGerrit Code Review <gerrit@onap.org>
Thu, 20 Jul 2023 09:47:48 +0000 (09:47 +0000)
1  2 
integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsDataServiceIntegrationSpec.groovy
integration-test/src/test/resources/data/bookstore/bookstoreData.json

@@@ -43,11 -43,13 +43,13 @@@ class CpsDataServiceIntegrationSpec ext
  
      CpsDataService objectUnderTest
      def originalCountBookstoreChildNodes
+     def originalCountBookstoreTopLevelListNodes
      def now = OffsetDateTime.now()
  
      def setup() {
          objectUnderTest = cpsDataService
          originalCountBookstoreChildNodes = countDataNodesInBookstore()
+         originalCountBookstoreTopLevelListNodes = countTopLevelListDataNodesInBookstore()
      }
  
      def 'Read bookstore top-level container(s) using #fetchDescendantsOption.'() {
          where: 'the following option is used'
              fetchDescendantsOption        || expectNumberOfDataNodes
              OMIT_DESCENDANTS              || 1
 -            DIRECT_CHILDREN_ONLY          || 6
 -            INCLUDE_ALL_DESCENDANTS       || 17
 -            new FetchDescendantsOption(2) || 17
 +            DIRECT_CHILDREN_ONLY          || 7
 +            INCLUDE_ALL_DESCENDANTS       || 28
 +            new FetchDescendantsOption(2) || 28
      }
  
      def 'Read bookstore top-level container(s) using "root" path variations.'() {
          when: 'get data nodes for bookstore container'
              def result = objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, root, OMIT_DESCENDANTS)
          then: 'the tree consist ouf of one data node'
-             assert countDataNodesInTree(result) == 1
+             assert countDataNodesInTree(result) == 2
          and: 'the top level data node has the expected attribute and value'
-             assert result.leaves['bookstore-name'] == ['Easons']
+             assert result.leaves.size() == 2
          where: 'the following variations of "root" are used'
              root << [ '/', '' ]
      }
              thrown(DataNodeNotFoundExceptionBatch)
      }
  
+     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}]}'
+         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)
+         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)
+         then: 'the original number of datanodes is restored'
+             assert originalCountBookstoreTopLevelListNodes == countTopLevelListDataNodesInBookstore()
+     }
      def 'Add and Delete list (element) data nodes.'() {
          given: 'two new (categories) data nodes'
              def json = '{"categories": [ {"code":"new1"}, {"code":"new2" } ] }'
      def countDataNodesInBookstore() {
          return countDataNodesInTree(objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', INCLUDE_ALL_DESCENDANTS))
      }
+     def countTopLevelListDataNodesInBookstore() {
+         return countDataNodesInTree(objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/', INCLUDE_ALL_DESCENDANTS))
+     }
  }
@@@ -1,4 -1,12 +1,12 @@@
  {
+   "multiple-data-tree:invoice": [
+     {
+       "ProductID": "1",
+       "ProductName": "Apple",
+       "price": "100",
+       "stock": false
+     }
+   ],
    "bookstore": {
      "bookstore-name": "Easons",
      "premises": {
@@@ -27,7 -35,7 +35,7 @@@
              "lang": "English",
              "authors": ["Roald Dahl"],
              "editions": [1988, 2000],
 -            "price": 10
 +            "price": 20
            },
            {
              "title": "The Gruffalo",
              "price": 11
            }
          ]
 +      },
 +      {
 +        "code": 5,
 +        "name": "Discount books",
 +        "books" : [
 +          {
 +            "title": "Book 1",
 +            "lang": "blah",
 +            "authors": [],
 +            "editions": [],
 +            "price": 1
 +          },
 +          {
 +            "title": "Book 2",
 +            "lang": "blah",
 +            "authors": [],
 +            "editions": [],
 +            "price": 2
 +          },
 +          {
 +            "title": "Book 3",
 +            "lang": "blah",
 +            "authors": [],
 +            "editions": [],
 +            "price": 3
 +          },
 +          {
 +            "title": "Book 4",
 +            "lang": "blah",
 +            "authors": [],
 +            "editions": [],
 +            "price": 4
 +          },
 +          {
 +            "title": "Book 5",
 +            "lang": "blah",
 +            "authors": [],
 +            "editions": [],
 +            "price": 5
 +          },
 +          {
 +            "title": "Book 6",
 +            "lang": "blah",
 +            "authors": [],
 +            "editions": [],
 +            "price": 6
 +          },
 +          {
 +            "title": "Book 7",
 +            "lang": "blah",
 +            "authors": [],
 +            "editions": [],
 +            "price": 7
 +          },
 +          {
 +            "title": "Book 8",
 +            "lang": "blah",
 +            "authors": [],
 +            "editions": [],
 +            "price": 8
 +          },
 +          {
 +            "title": "Book 9",
 +            "lang": "blah",
 +            "authors": [],
 +            "editions": [],
 +            "price": 9
 +          },
 +          {
 +            "title": "Book 10",
 +            "lang": "blah",
 +            "authors": [],
 +            "editions": [],
 +            "price": 10
 +          }
 +        ]
        }
      ]
    }