X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cps-ncmp-rest%2Fsrc%2Ftest%2Fgroovy%2Forg%2Fonap%2Fcps%2Fncmp%2Frest%2Fcontroller%2FNetworkCmProxyControllerSpec.groovy;h=436f22b327bc612bb01d02f8600f3a14d6506f37;hb=20b4f9cf0b662de4a7665b2a82593ef0205f5e06;hp=d62ae93b098d05b58d3f694310f89a3e8a89c3a6;hpb=f3798ee9857edb45243d540606ceac21df1215ab;p=cps.git diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy index d62ae93b0..436f22b32 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy @@ -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 @@ -30,10 +31,10 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put +import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.CREATE +import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.UPDATE -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 +55,6 @@ class NetworkCmProxyControllerSpec extends Specification { @SpringBean NetworkCmProxyDataService mockNetworkCmProxyDataService = Mock() - @SpringBean - ObjectMapper objectMapper = new ObjectMapper() - @Value('${rest.api.ncmp-base-path}/v1') def ncmpBasePathV1 @@ -175,25 +173,10 @@ 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.' () { + def 'Get Resource Data from passthrough operational.' () { given: 'resource data url' def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-operational" + - "?resourceIdentifier=parent/child&fields=testFields&depth=5" + "?resourceIdentifier=parent/child&options=(a=1,b=2)" when: 'get data resource request is performed' def response = mvc.perform( get(getUrl) @@ -204,22 +187,20 @@ class NetworkCmProxyControllerSpec extends Specification { 1 * mockNetworkCmProxyDataService.getResourceDataOperationalForCmHandle('testCmHandle', 'parent/child', 'application/json', - 'testFields', - 5) + '(a=1,b=2)') and: 'response status is Ok' response.status == HttpStatus.OK.value() } - def 'Get Resource Data from pass-through running with #scenario value in resource identifier param.' () { + def 'Get Resource Data from passthrough running with #scenario value in resource identifier param.' () { given: 'resource data url' def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-running" + - "?resourceIdentifier=" + resourceIdentifier + "&fields=testFields&depth=5" + "?resourceIdentifier=" + resourceIdentifier + "&options=(a=1,b=2)" and: 'ncmp service returns json object' mockNetworkCmProxyDataService.getResourceDataPassThroughRunningForCmHandle('testCmHandle', resourceIdentifier, 'application/json', - 'testFields', - 5) >> '{valid-json}' + '(a=1,b=2)') >> '{valid-json}' when: 'get data resource request is performed' def response = mvc.perform( get(getUrl) @@ -240,19 +221,36 @@ class NetworkCmProxyControllerSpec extends Specification { '? needs to be encoded as %3F' | 'idWith%3F' } - def 'Create Resource Data from pass-through running with #scenario.' () { + def 'Update resource data from passthrough running.' () { + 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: 'ncmp service method to update resource is called' + 1 * mockNetworkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle('testCmHandle', + 'parent/child', UPDATE,'some-request-body', 'application/json;charset=UTF-8') + and: 'the response status is OK' + response.status == HttpStatus.OK.value() + } + + def 'Create Resource Data from passthrough running with #scenario.' () { given: 'resource data url' - def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-running" + + def url = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-running" + "?resourceIdentifier=parent/child" - when: 'get data resource request is performed' + when: 'create resource request is performed' def response = mvc.perform( - post(getUrl) + post(url) .contentType(MediaType.APPLICATION_JSON_VALUE) .accept(MediaType.APPLICATION_JSON_VALUE).content(requestBody) ).andReturn().response then: 'ncmp service method to create resource called' - 1 * mockNetworkCmProxyDataService.createResourceDataPassThroughRunningForCmHandle('testCmHandle', - 'parent/child', requestBody, 'application/json;charset=UTF-8') + 1 * mockNetworkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle('testCmHandle', + 'parent/child', CREATE, requestBody, 'application/json;charset=UTF-8') and: 'resource is created' response.status == HttpStatus.CREATED.value() where: 'given request body' @@ -274,5 +272,34 @@ 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":[]}' + } + }