Fix for get cm handle identifiers response body
[cps.git] / cps-ncmp-rest / src / test / groovy / org / onap / cps / ncmp / rest / controller / NetworkCmProxyControllerSpec.groovy
index b8c68d9..cca62b9 100644 (file)
@@ -22,6 +22,7 @@
 
 package org.onap.cps.ncmp.rest.controller
 
+import org.onap.cps.TestUtils
 import org.onap.cps.spi.model.ModuleReference
 
 import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
@@ -31,9 +32,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put
 
-import com.fasterxml.jackson.databind.ObjectMapper
 import com.google.gson.Gson
-import org.onap.cps.TestUtils
 import org.onap.cps.ncmp.api.NetworkCmProxyDataService
 import org.onap.cps.spi.model.DataNodeBuilder
 import org.spockframework.spring.SpringBean
@@ -54,9 +53,6 @@ class NetworkCmProxyControllerSpec extends Specification {
     @SpringBean
     NetworkCmProxyDataService mockNetworkCmProxyDataService = Mock()
 
-    @SpringBean
-    ObjectMapper objectMapper = new ObjectMapper()
-
     @Value('${rest.api.ncmp-base-path}/v1')
     def ncmpBasePathV1
 
@@ -175,21 +171,6 @@ class NetworkCmProxyControllerSpec extends Specification {
             response.contentAsString.contains('"leaf":"value"')
     }
 
-    def 'Register CM Handle Event' () {
-        given: 'jsonData'
-            def jsonData = TestUtils.getResourceFileContent('dmi-registration.json')
-        when: 'post request is performed'
-            def response = mvc.perform(
-                post("$ncmpBasePathV1/ch")
-                .contentType(MediaType.APPLICATION_JSON)
-                .content(jsonData)
-            ).andReturn().response
-        then: 'the cm handles are registered with the service'
-            1 * mockNetworkCmProxyDataService.updateDmiRegistrationAndSyncModule(_)
-        and: 'response status is created'
-            response.status == HttpStatus.CREATED.value()
-    }
-
     def 'Get Resource Data from pass-through operational.' () {
         given: 'resource data url'
             def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-operational" +
@@ -272,5 +253,47 @@ class NetworkCmProxyControllerSpec extends Specification {
         and: 'response returns an OK http code'
             response.status == HttpStatus.OK.value()
     }
+
+    def 'Retrieve cm handles.'() {
+        given: 'an endpoint and json data'
+            def searchesEndpoint = "$ncmpBasePathV1/ch/searches"
+            String jsonData = TestUtils.getResourceFileContent('cmhandle-search.json')
+        and: 'the service method is invoked with module names and returns two cm handle ids'
+            mockNetworkCmProxyDataService.executeCmHandleHasAllModulesSearch(['module1', 'module2']) >> ['some-cmhandle-id1', 'some-cmhandle-id2']
+        when: 'the searches api is invoked'
+            def response = mvc.perform(post(searchesEndpoint)
+                    .contentType(MediaType.APPLICATION_JSON)
+                    .content(jsonData)).andReturn().response
+        then: 'response status returns OK'
+            response.status == HttpStatus.OK.value()
+        and: 'the expected response content is returned'
+            response.contentAsString == '{"cmHandles":[{"cmHandleId":"some-cmhandle-id1"},{"cmHandleId":"some-cmhandle-id2"}]}'
+    }
+
+    def 'Call execute cm handle searches with unrecognized condition name.'() {
+        given: 'an endpoint and json data'
+            def searchesEndpoint = "$ncmpBasePathV1/ch/searches"
+            String jsonData = TestUtils.getResourceFileContent('invalid-cmhandle-search.json')
+        when: 'the searches api is invoked'
+            def response = mvc.perform(post(searchesEndpoint)
+                    .contentType(MediaType.APPLICATION_JSON)
+                    .content(jsonData)).andReturn().response
+        then: 'an empty cm handle identifier is returned'
+            response.contentAsString == '{"cmHandles":[]}'
+    }
+
+    def 'Update resource data in passthrough-running datastore.' () {
+        given: 'update resource data url'
+            def updateUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-running" +
+                    "?resourceIdentifier=parent/child"
+        when: 'update data resource request is performed'
+            def response = mvc.perform(
+                    put(updateUrl)
+                            .contentType(MediaType.APPLICATION_JSON_VALUE)
+                            .accept(MediaType.APPLICATION_JSON_VALUE).content('some-request-body')
+            ).andReturn().response
+        then: 'the response status is not implemented'
+            response.status == HttpStatus.NOT_IMPLEMENTED.value()
+    }
 }