CPS-505 Retrieving modules for new CM handle
[cps.git] / cps-ncmp-rest / src / test / groovy / org / onap / cps / ncmp / rest / controller / NetworkCmProxyControllerSpec.groovy
index b2a060c..65946a9 100644 (file)
@@ -191,7 +191,7 @@ class NetworkCmProxyControllerSpec extends Specification {
                 .content(jsonData)
             ).andReturn().response
         then: 'the cm handles are registered with the service'
-            1 * mockNetworkCmProxyDataService.updateDmiPluginRegistration(_)
+            1 * mockNetworkCmProxyDataService.updateDmiRegistrationAndSyncModule(_)
         and: 'response status is created'
             response.status == HttpStatus.CREATED.value()
     }
@@ -206,8 +206,8 @@ class NetworkCmProxyControllerSpec extends Specification {
                             .contentType(MediaType.APPLICATION_JSON)
                     .accept(MediaType.APPLICATION_JSON_VALUE)
             ).andReturn().response
-        then: 'the NCMP data service is called with getResourceDataOperationalFoCmHandle'
-            1 * mockNetworkCmProxyDataService.getResourceDataOperationalFoCmHandle('testCmHandle',
+        then: 'the NCMP data service is called with getResourceDataOperationalForCmHandle'
+            1 * mockNetworkCmProxyDataService.getResourceDataOperationalForCmHandle('testCmHandle',
                     'testResourceIdentifier',
                     'application/json',
                     'testFields',
@@ -216,5 +216,43 @@ class NetworkCmProxyControllerSpec extends Specification {
             response.status == HttpStatus.OK.value()
     }
 
+    def 'Get Resource Data from pass-through running.' () {
+        given: 'resource data url'
+            def getUrl = "$basePath/v1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-running" +
+                    "/testResourceIdentifier?fields=testFields&depth=5"
+        and: 'ncmp service returns json object'
+            mockNetworkCmProxyDataService.getResourceDataPassThroughRunningForCmHandle('testCmHandle',
+                'testResourceIdentifier',
+                'application/json',
+                'testFields',
+                5) >> '{valid-json}'
+        when: 'get data resource request is performed'
+            def response = mvc.perform(
+                    get(getUrl)
+                            .contentType(MediaType.APPLICATION_JSON)
+                            .accept(MediaType.APPLICATION_JSON_VALUE)
+            ).andReturn().response
+        then: 'response status is Ok'
+            response.status == HttpStatus.OK.value()
+        and: 'response contains valid object body'
+            response.getContentAsString() == '{valid-json}'
+    }
+
+    def 'Create Resource Data from pass-through running using POST.' () {
+        given: 'resource data url'
+            def getUrl = "$basePath/v1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-running" +
+                    "/testResourceIdentifier"
+        when: 'get data resource request is performed'
+            def response = mvc.perform(
+                    post(getUrl)
+                            .contentType(MediaType.APPLICATION_JSON_VALUE)
+                            .accept(MediaType.APPLICATION_JSON_VALUE).content('{"some-json":"value"}')
+            ).andReturn().response
+        then: 'ncmp service method to create resource called'
+            1 * mockNetworkCmProxyDataService.createResourceDataPassThroughRunningForCmHandle('testCmHandle',
+                    'testResourceIdentifier', ['some-json':'value'], 'application/json;charset=UTF-8')
+        and: 'resource is created'
+            response.status == HttpStatus.CREATED.value()
+    }
 }