Create list-node elements (part3): NCMP REST and service layers
[cps.git] / cps-ncmp-service / src / test / groovy / org / onap / cps / api / impl / NetworkCmProxyDataServiceImplSpec.groovy
index 49028be..e67d4ad 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2021 Nordix Foundation
+ *  Modifications Copyright (C) 2021 Pantheon.tech
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -49,6 +50,39 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
             fetchDescendantsOption << FetchDescendantsOption.values()
     }
 
+    def 'Create full data node: #scenario.'() {
+        given: 'a cm handle and root xpath'
+            def jsonData = 'some json'
+        when: 'createDataNode is invoked'
+            objectUnderTest.createDataNode(cmHandle, xpath, jsonData)
+        then: 'the CPS service method is invoked once with the expected parameters'
+            1 * mockcpsDataService.saveData(expectedDataspaceName, cmHandle, jsonData)
+        where: 'following parameters were used'
+            scenario           | xpath
+            'no xpath'         | ''
+            'root level xpath' | '/'
+    }
+
+    def 'Create child data node.'() {
+        given: 'a cm handle and parent node xpath'
+            def jsonData = 'some json'
+            def xpath = '/test-node'
+        when: 'createDataNode is invoked'
+            objectUnderTest.createDataNode(cmHandle, xpath, jsonData)
+        then: 'the CPS service method is invoked once with the expected parameters'
+            1 * mockcpsDataService.saveData(expectedDataspaceName, cmHandle, xpath, jsonData)
+    }
+
+    def 'Add list-node elements.'() {
+        given: 'a cm handle and parent node xpath'
+            def jsonData = 'some json'
+            def xpath = '/test-node'
+        when: 'addListNodeElements is invoked'
+            objectUnderTest.addListNodeElements(cmHandle, xpath, jsonData)
+        then: 'the CPS service method is invoked once with the expected parameters'
+            1 * mockcpsDataService.saveListNodeData(expectedDataspaceName, cmHandle, xpath, jsonData)
+    }
+
     def 'Update data node leaves.'() {
         given: 'a cm Handle and a cps path'
             def xpath = '/xpath'