Merge "fix data from object to string"
[cps.git] / cps-ncmp-rest / src / test / groovy / org / onap / cps / ncmp / rest / controller / NetworkCmProxyControllerSpec.groovy
index 4ff0ca4..9f2b4e1 100644 (file)
@@ -22,6 +22,8 @@
 
 package org.onap.cps.ncmp.rest.controller
 
+import org.onap.cps.spi.model.ModuleReference
+
 import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
 import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS
 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
@@ -183,7 +185,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()
     }
@@ -230,7 +232,7 @@ class NetworkCmProxyControllerSpec extends Specification {
             response.getContentAsString() == '{valid-json}'
     }
 
-    def 'Create Resource Data from pass-through running using POST.' () {
+    def 'Create Resource Data from pass-through running with #scenario.' () {
         given: 'resource data url'
             def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-running" +
                     "/testResourceIdentifier"
@@ -238,13 +240,31 @@ class NetworkCmProxyControllerSpec extends Specification {
             def response = mvc.perform(
                     post(getUrl)
                             .contentType(MediaType.APPLICATION_JSON_VALUE)
-                            .accept(MediaType.APPLICATION_JSON_VALUE).content('{"some-json":"value"}')
+                            .accept(MediaType.APPLICATION_JSON_VALUE).content(requestBody)
             ).andReturn().response
         then: 'ncmp service method to create resource called'
             1 * mockNetworkCmProxyDataService.createResourceDataPassThroughRunningForCmHandle('testCmHandle',
-                    'testResourceIdentifier', ['some-json':'value'], 'application/json;charset=UTF-8')
+                    'testResourceIdentifier', requestBody, 'application/json;charset=UTF-8')
         and: 'resource is created'
             response.status == HttpStatus.CREATED.value()
+        where: 'given request body'
+            scenario                        |  requestBody
+            'body contains " and new line'  |  'body with " quote and \n new line'
+            'body contains normal string'   |  'normal request body'
+    }
+
+    def 'Get module references for the given dataspace and cm handle.' () {
+        given: 'get module references url'
+            def getUrl = "$ncmpBasePathV1/ch/some-cmhandle/modules"
+        when: 'get module resource request is performed'
+            def response =mvc.perform(get(getUrl)).andReturn().response
+        then: 'ncmp service method to get yang resource module references is called'
+            mockNetworkCmProxyDataService.getYangResourcesModuleReferences('some-cmhandle')
+                    >> [new ModuleReference(moduleName: 'some-name1',revision: 'some-revision1')]
+        and: 'response contains an array with the module name and revision'
+            response.getContentAsString() == '[{"moduleName":"some-name1","revision":"some-revision1"}]'
+        and: 'response returns an OK http code'
+            response.status == HttpStatus.OK.value()
     }
 }