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=530ce4e3a1b33dc9c927961a66c389944609ef09;hb=eeef2ae7d17fcff7fbd33614972ad42f495e7998;hp=cca62b9ec06e4b84e30242c82b522b972e9fcd7d;hpb=9e09fe868b39fd5f13092a923da3474deb0f75b9;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 cca62b9ec..530ce4e3a 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 @@ -25,12 +25,17 @@ package org.onap.cps.ncmp.rest.controller import org.onap.cps.TestUtils import org.onap.cps.spi.model.ModuleReference +import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.PATCH 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.delete import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get 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 static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.DELETE import com.google.gson.Gson import org.onap.cps.ncmp.api.NetworkCmProxyDataService @@ -219,19 +224,36 @@ class NetworkCmProxyControllerSpec extends Specification { '? needs to be encoded as %3F' | 'idWith%3F' } + def 'Update resource data from pass-through 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 pass-through 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' @@ -282,18 +304,36 @@ class NetworkCmProxyControllerSpec extends Specification { 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" + + def 'Patch resource data in pass-through running datastore.' () { + given: 'patch resource data url' + def url = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-running" + "?resourceIdentifier=parent/child" - when: 'update data resource request is performed' + when: 'patch 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') + patch(url) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON).content('{"some-key" : "some-value"}') ).andReturn().response - then: 'the response status is not implemented' - response.status == HttpStatus.NOT_IMPLEMENTED.value() + then: 'ncmp service method to update resource is called' + 1 * mockNetworkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle('testCmHandle', + 'parent/child', PATCH, '{some-key=some-value}', 'application/json;charset=UTF-8') + and: 'the response status is OK' + response.status == HttpStatus.OK.value() + } + + def 'Delete resource data in pass-through running datastore.' () { + given: 'delete resource data url' + def url = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-running" + + "?resourceIdentifier=parent/child" + when: 'delete data resource request is performed' + def response = mvc.perform( + delete(url).contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON) + .content('{"some-key" : "some-value"}')).andReturn().response + then: 'the ncmp service method to delete resource is called' + 1 * mockNetworkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle('testCmHandle', + 'parent/child', DELETE, '{"some-key" : "some-value"}', 'application/json;charset=UTF-8') + and: 'the response is No Content' + response.status == HttpStatus.NO_CONTENT.value() } }