diff options
Diffstat (limited to 'cps-ncmp-rest/src/test/groovy/org')
2 files changed, 75 insertions, 23 deletions
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 fb411c054..31e83aa7a 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 @@ -32,11 +32,14 @@ import org.onap.cps.ncmp.api.inventory.CmHandleState import org.onap.cps.ncmp.api.inventory.CompositeState import org.onap.cps.ncmp.api.inventory.DataStoreSyncState import org.onap.cps.ncmp.api.inventory.LockReasonCategory +import org.onap.cps.ncmp.rest.model.BatchOperationDefinition import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle import org.onap.cps.ncmp.rest.controller.handlers.NcmpCachedResourceRequestHandler import org.onap.cps.ncmp.rest.controller.handlers.NcmpPassthroughResourceRequestHandler import org.onap.cps.ncmp.rest.executor.CpsNcmpTaskExecutor import org.onap.cps.ncmp.rest.mapper.CmHandleStateMapper +import org.onap.cps.ncmp.rest.mapper.ResourceDataBatchRequestMapper +import org.onap.cps.ncmp.rest.model.ResourceDataBatchRequest import org.onap.cps.ncmp.rest.util.DeprecationHelper import org.onap.cps.spi.FetchDescendantsOption import org.onap.cps.spi.model.ModuleDefinition @@ -62,10 +65,10 @@ 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.patch import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete -import static org.onap.cps.ncmp.api.impl.operations.OperationEnum.CREATE -import static org.onap.cps.ncmp.api.impl.operations.OperationEnum.UPDATE -import static org.onap.cps.ncmp.api.impl.operations.OperationEnum.PATCH -import static org.onap.cps.ncmp.api.impl.operations.OperationEnum.DELETE +import static org.onap.cps.ncmp.api.impl.operations.OperationType.CREATE +import static org.onap.cps.ncmp.api.impl.operations.OperationType.UPDATE +import static org.onap.cps.ncmp.api.impl.operations.OperationType.PATCH +import static org.onap.cps.ncmp.api.impl.operations.OperationType.DELETE import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_OPERATIONAL import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_RUNNING import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.OPERATIONAL @@ -98,6 +101,9 @@ class NetworkCmProxyControllerSpec extends Specification { CmHandleStateMapper cmHandleStateMapper = Mappers.getMapper(CmHandleStateMapper) @SpringBean + ResourceDataBatchRequestMapper resourceDataBatchRequestMapper = Mappers.getMapper(ResourceDataBatchRequestMapper) + + @SpringBean CpsNcmpTaskExecutor spiedCpsTaskExecutor = Spy() @SpringBean @@ -113,7 +119,6 @@ class NetworkCmProxyControllerSpec extends Specification { def ncmpBasePathV1 def requestBody = '{"some-key":"some-value"}' - def bulkRequestBody = '["testCmHandle"]' def formattedDateAndTime = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(OffsetDateTime.of(2022, 12, 31, 20, 30, 40, 1, ZoneOffset.UTC)) @@ -200,44 +205,69 @@ class NetworkCmProxyControllerSpec extends Specification { 'invalid non-empty topic value in url' | 'passthrough-operational' | '&topic=1_5_*_#' } - def 'Get (async) bulk resource data from dmi service.'() { - given: 'bulk resource data url' - def getUrl = "$ncmpBasePathV1/batch/data/ds/${datastore.datastoreName}" + - "?resourceIdentifier=parent/child&options=(a=1,b=2)&topic=myTopic" + def 'Get (async) batch resource data from dmi service.'() { + given: 'batch resource data url' + def getUrl = "$ncmpBasePathV1/data?topic=my-topic-name" + def resourceDataBatchRequestJsonData = jsonObjectMapper.asJsonString( + getResourceDataBatchRequest("read", datastore.datastoreName)) + def expectedDmiResourceDataBatchRequest + = jsonObjectMapper.convertJsonString(resourceDataBatchRequestJsonData, org.onap.cps.ncmp.api.models.ResourceDataBatchRequest.class) when: 'post data resource request is performed' def response = mvc.perform( post(getUrl) .contentType(MediaType.APPLICATION_JSON) - .content(bulkRequestBody) + .content(resourceDataBatchRequestJsonData) ).andReturn().response then: 'response status is Ok' response.status == HttpStatus.OK.value() and: 'async request id is generated' assert response.contentAsString.contains("requestId") then: 'wait a little to allow execution of service method by task executor (on separate thread)' - Thread.sleep(100); + Thread.sleep(100) then: 'the service has been invoked with the correct parameters ' - 1 * mockNetworkCmProxyDataService.getResourceDataForCmHandleBatch(datastore.datastoreName, ['testCmHandle'], - 'parent/child', - '(a=1,b=2)', - 'myTopic', - _) + 1 * mockNetworkCmProxyDataService.requestResourceDataForCmHandleBatch('my-topic-name', expectedDmiResourceDataBatchRequest, _) where: 'the following data stores are used' datastore << [PASSTHROUGH_RUNNING, PASSTHROUGH_OPERATIONAL] } - def 'Get bulk resource data for non-supported #datastoreName from dmi service.'() { - given: 'bulk resource data url' - def getUrl = "$ncmpBasePathV1/batch/data/ds/ncmp-datastore:operational" + - "?resourceIdentifier=parent/child&options=(a=1,b=2)&topic=myTopic" + def 'Get batch resource data for #scenario from dmi service.'() { + given: 'batch resource data url' + def getUrl = "$ncmpBasePathV1/data?topic=my-topic-name" + def resourceDataBatchRequestJsonData = jsonObjectMapper.asJsonString( + getResourceDataBatchRequest(operation, datastore)) + when: 'post data resource request is performed' + def response = mvc.perform( + post(getUrl) + .contentType(MediaType.APPLICATION_JSON) + .content(resourceDataBatchRequestJsonData) + ).andReturn().response + then: 'response status is BAD_REQUEST' + response.status == HttpStatus.BAD_REQUEST.value() + where: 'the following parameters are used' + scenario | datastore | operation + 'non-supported datastoreName' | OPERATIONAL.datastoreName | 'read' + 'non-supported operation (passthrough-running)' | PASSTHROUGH_RUNNING.datastoreName | 'create' + 'non-supported operation (passthrough-operational)' | PASSTHROUGH_OPERATIONAL.datastoreName | 'create' + } + + def 'Get batch resource data when notification feature is disabled for datastore: #datastore.'() { + given: 'batch resource data url' + def getUrl = "$ncmpBasePathV1/data?topic=my-topic-name" + def resourceDataBatchRequestJsonData = jsonObjectMapper.asJsonString( + getResourceDataBatchRequest("read", datastore.datastoreName)) + ncmpPassthroughResourceRequestHandler.notificationFeatureEnabled = false when: 'post data resource request is performed' def response = mvc.perform( post(getUrl) .contentType(MediaType.APPLICATION_JSON) - .content(bulkRequestBody) + .content(resourceDataBatchRequestJsonData) ).andReturn().response - then: 'response status code is 501 not implemented' - response.status == HttpStatus.NOT_IMPLEMENTED.value() + then: 'response status is Ok' + response.status == HttpStatus.OK.value() + and: 'async request id is unavailable' + assert response.contentAsString == '{"status":"Asynchronous request is unavailable as notification feature is currently disabled."}' + where: 'the following data stores are used' + datastore << [PASSTHROUGH_RUNNING, PASSTHROUGH_OPERATIONAL] } def 'Query Resource Data from operational.'() { @@ -656,5 +686,23 @@ class NetworkCmProxyControllerSpec extends Specification { return assertContainsAll(response, expectedContent) } + def getResourceDataBatchRequest(operation, datastore) { + def resourceDataBatchRequest = new ResourceDataBatchRequest() + def batchOperationDefinitions = new ArrayList() + batchOperationDefinitions.add(getBatchOperationDefinition(operation, datastore)) + resourceDataBatchRequest.addOperationsItem(batchOperationDefinitions) + } + + def getBatchOperationDefinition(operation, datastore) { + def batchOperationDefinition = new BatchOperationDefinition() + batchOperationDefinition.setOperation(operation) + batchOperationDefinition.setOperationId("operational-12") + batchOperationDefinition.setDatastore(datastore) + batchOperationDefinition.setOptions("some option") + batchOperationDefinition.setResourceIdentifier("some resource identifier") + batchOperationDefinition.addTargetIdsItem("some-cm-handle") + return batchOperationDefinition + } + } diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy index f44d6c990..a3afc5546 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy @@ -33,6 +33,7 @@ import org.onap.cps.ncmp.rest.controller.handlers.NcmpCachedResourceRequestHandl import org.onap.cps.ncmp.rest.controller.handlers.NcmpPassthroughResourceRequestHandler import org.onap.cps.ncmp.rest.executor.CpsNcmpTaskExecutor import org.onap.cps.ncmp.rest.mapper.CmHandleStateMapper +import org.onap.cps.ncmp.rest.mapper.ResourceDataBatchRequestMapper import org.onap.cps.ncmp.rest.util.DeprecationHelper import org.onap.cps.spi.exceptions.AlreadyDefinedException import org.onap.cps.spi.exceptions.AlreadyDefinedExceptionBatch @@ -75,6 +76,9 @@ class NetworkCmProxyRestExceptionHandlerSpec extends Specification { CmHandleStateMapper cmHandleStateMapper = Mappers.getMapper(CmHandleStateMapper) @SpringBean + ResourceDataBatchRequestMapper resourceDataBatchRequestMapper = Mappers.getMapper(ResourceDataBatchRequestMapper) + + @SpringBean CpsNcmpTaskExecutor stubbedCpsTaskExecutor = Stub() @SpringBean |