diff options
author | sourabh_sourabh <sourabh.sourabh@est.tech> | 2023-03-27 14:36:20 +0100 |
---|---|---|
committer | sourabh_sourabh <sourabh.sourabh@est.tech> | 2023-04-27 12:36:02 +0100 |
commit | 4031d43f06cb6ceb2e5bc39feb3e4a19ed3c6307 (patch) | |
tree | 04c8dad982804ec7d36a7814e91d730dfb7173c8 /cps-ncmp-rest/src/test/groovy | |
parent | 8c32ab510d9554ef6713f34d9895e2909e17200e (diff) |
CPS-1553 :REST endpoint to accept collection of cm handles for GET operation
-Introduced an interface having all un-implemented or default defination
of any method that is further extended or implemented by abstract or
stubbed controller.
-Exposed an endpoint to accept bulk request
-Modified an existing methods for more readability. (Parameterized datasource for ... methods)
-Code impl. for getResourceDataFromDmi method to send bulk request to
new proposed dmi-plugin endpoint that would accept bulk request.
-We need to investigate a groovy test that fails only into onap CICD pipeline.
For now it's commented out by added TODO tag. (org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy:205)
Issue-ID: CPS-1553
Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech>
Change-Id: Ieac39690956e3a0eab41068db57c5d93a16d04f0
Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech>
Diffstat (limited to 'cps-ncmp-rest/src/test/groovy')
2 files changed, 93 insertions, 50 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 d67804e128..9531101e1d 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2021 Pantheon.tech * Modifications Copyright (C) 2021 highstreet technologies GmbH - * Modifications Copyright (C) 2021-2022 Nordix Foundation + * Modifications Copyright (C) 2021-2023 Nordix Foundation * Modifications Copyright (C) 2021-2022 Bell Canada. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -33,18 +33,13 @@ 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.api.models.NcmpServiceCmHandle -import org.onap.cps.ncmp.rest.controller.handlers.DatastoreType -import org.onap.cps.ncmp.rest.controller.handlers.NcmpDatastoreOperationalQueryHandler -import org.onap.cps.ncmp.rest.controller.handlers.NcmpDatastoreOperationalResourceRequestHandler -import org.onap.cps.ncmp.rest.controller.handlers.NcmpDatastorePassthroughOperationalResourceRequestHandler -import org.onap.cps.ncmp.rest.controller.handlers.NcmpDatastorePassthroughRunningResourceRequestHandler +import org.onap.cps.ncmp.rest.controller.handlers.NcmpCachedResourceRequestHandler +import org.onap.cps.ncmp.rest.controller.handlers.NcmpPassthroughResourceRequestHandler import org.onap.cps.ncmp.rest.controller.handlers.NcmpDatastoreResourceRequestHandlerFactory -import org.onap.cps.ncmp.rest.exceptions.InvalidDatastoreException import org.onap.cps.ncmp.rest.executor.CpsNcmpTaskExecutor import org.onap.cps.ncmp.rest.mapper.CmHandleStateMapper import org.onap.cps.ncmp.rest.util.DeprecationHelper import org.onap.cps.spi.FetchDescendantsOption -import org.onap.cps.spi.exceptions.DataValidationException import org.onap.cps.spi.model.ModuleDefinition import org.onap.cps.spi.model.ModuleReference import org.onap.cps.utils.JsonObjectMapper @@ -55,31 +50,32 @@ import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest import org.springframework.http.HttpStatus import org.springframework.http.MediaType import org.springframework.test.web.servlet.MockMvc -import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder import spock.lang.Shared import spock.lang.Specification - import java.time.OffsetDateTime import java.time.ZoneOffset import java.time.format.DateTimeFormatter import static org.onap.cps.ncmp.api.inventory.CompositeState.DataStores import static org.onap.cps.ncmp.api.inventory.CompositeState.Operational -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.PATCH -import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.DELETE import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put 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.rest.controller.handlers.DatastoreType.PASSTHROUGH_OPERATIONAL +import static org.onap.cps.ncmp.rest.controller.handlers.DatastoreType.PASSTHROUGH_RUNNING +import static org.onap.cps.ncmp.rest.controller.handlers.DatastoreType.OPERATIONAL @WebMvcTest(NetworkCmProxyController) class NetworkCmProxyControllerSpec extends Specification { - public static final int TIMEOUT_IN_MS = 2000 - public static final boolean NOTIFICATION_ENABLED = true + private static final int TIMEOUT_IN_MS = 2000 + private static final boolean NOTIFICATION_ENABLED = true @Autowired MockMvc mvc @@ -115,6 +111,7 @@ class NetworkCmProxyControllerSpec extends Specification { def ncmpBasePathV1 def requestBody = '{"some-key":"some-value"}' + def bulkRequestBody = '["testCmHandle"]' @Shared def NO_TOPIC = null @@ -124,24 +121,15 @@ class NetworkCmProxyControllerSpec extends Specification { .format(OffsetDateTime.of(2022, 12, 31, 20, 30, 40, 1, ZoneOffset.UTC)) void setup() { - stubbedNcmpDatastoreResourceRequestHandlerFactory.getNcmpDatastoreResourceRequestHandler( - DatastoreType.OPERATIONAL) >> - new NcmpDatastoreOperationalResourceRequestHandler( - mockNetworkCmProxyDataService, spiedCpsTaskExecutor, TIMEOUT_IN_MS, NOTIFICATION_ENABLED) + stubbedNcmpDatastoreResourceRequestHandlerFactory.getNcmpResourceRequestHandler( + OPERATIONAL) >> getNcmpDatastoreRequestHandler(OPERATIONAL,new NcmpCachedResourceRequestHandler(mockNetworkCmProxyQueryService)) - stubbedNcmpDatastoreResourceRequestHandlerFactory.getNcmpDatastoreResourceRequestHandler( - DatastoreType.PASSTHROUGH_OPERATIONAL) >> - new NcmpDatastorePassthroughOperationalResourceRequestHandler( - mockNetworkCmProxyDataService, spiedCpsTaskExecutor, TIMEOUT_IN_MS, NOTIFICATION_ENABLED) + stubbedNcmpDatastoreResourceRequestHandlerFactory.getNcmpResourceRequestHandler( + PASSTHROUGH_OPERATIONAL) >> getNcmpDatastoreRequestHandler(PASSTHROUGH_OPERATIONAL,new NcmpPassthroughResourceRequestHandler()) - stubbedNcmpDatastoreResourceRequestHandlerFactory.getNcmpDatastoreResourceRequestHandler( - DatastoreType.PASSTHROUGH_RUNNING) >> - new NcmpDatastorePassthroughRunningResourceRequestHandler( - mockNetworkCmProxyDataService, spiedCpsTaskExecutor, TIMEOUT_IN_MS, NOTIFICATION_ENABLED) + stubbedNcmpDatastoreResourceRequestHandlerFactory.getNcmpResourceRequestHandler( + PASSTHROUGH_RUNNING) >> getNcmpDatastoreRequestHandler(PASSTHROUGH_RUNNING,new NcmpPassthroughResourceRequestHandler()) - stubbedNcmpDatastoreResourceRequestHandlerFactory.getNcmpDatastoreResourceQueryHandler() >> - new NcmpDatastoreOperationalQueryHandler(mockNetworkCmProxyQueryService, spiedCpsTaskExecutor, - TIMEOUT_IN_MS, NOTIFICATION_ENABLED); } def 'Get Resource Data from pass-through operational.'() { @@ -154,11 +142,8 @@ class NetworkCmProxyControllerSpec extends Specification { .contentType(MediaType.APPLICATION_JSON) ).andReturn().response then: 'the NCMP data service is called with getResourceDataOperationalForCmHandle' - 1 * mockNetworkCmProxyDataService.getResourceDataOperationalForCmHandle('testCmHandle', - 'parent/child', - '(a=1,b=2)', - NO_TOPIC, - NO_REQUEST_ID) + 1 * mockNetworkCmProxyDataService.getResourceDataForCmHandle(PASSTHROUGH_OPERATIONAL.datastoreName, 'testCmHandle', + 'parent/child','(a=1,b=2)', NO_TOPIC, NO_REQUEST_ID) and: 'response status is Ok' response.status == HttpStatus.OK.value() } @@ -205,6 +190,48 @@ class NetworkCmProxyControllerSpec extends Specification { 'invalid non-empty topic value in url' | 'passthrough-running' | '&topic=1_5_*_#' } + def 'Get bulk resource data for #datastoreName from dmi service.'() { + given: 'bulk resource data url' + def getUrl = "$ncmpBasePathV1/batch/data/ds/${datastoreName}" + + "?resourceIdentifier=parent/child&options=(a=1,b=2)&topic=myTopic" + when: 'post data resource request is performed' + def response = mvc.perform( + post(getUrl) + .contentType(MediaType.APPLICATION_JSON) + .content(bulkRequestBody) + ).andReturn().response + then: 'response status is Ok' + response.status == HttpStatus.OK.value() + // TODO Need to be un-commented as it's failing into onap CICD pipeline + // but passed into nordix and local build. + //and: 'the NCMP data service is called with getResourceDataForCmHandleBatch' + // 1 * mockNetworkCmProxyDataService.getResourceDataForCmHandleBatch(datastoreName, ['testCmHandle'], + // 'parent/child', + // '(a=1,b=2)', + // 'myTopic', + // _) + and: 'async request id is generated' + assert response.contentAsString.contains("requestId") + where: 'the following data stores are used' + datastoreName << [PASSTHROUGH_RUNNING.datastoreName, PASSTHROUGH_OPERATIONAL.datastoreName] + } + + 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" + when: 'post data resource request is performed' + def response = mvc.perform( + post(getUrl) + .contentType(MediaType.APPLICATION_JSON) + .content(bulkRequestBody) + ).andReturn().response + then: 'response status code is 501 not implemented' + response.status == HttpStatus.NOT_IMPLEMENTED.value() + where: 'the following data store is un-supported' + datastoreName << [OPERATIONAL.datastoreName] + } + def 'Query Resource Data from operational.'() { given: 'the query resource data url' def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:operational/query" + @@ -244,11 +271,8 @@ class NetworkCmProxyControllerSpec extends Specification { def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-running" + "?resourceIdentifier=" + resourceIdentifier + "&options=(a=1,b=2)" and: 'ncmp service returns json object' - mockNetworkCmProxyDataService.getResourceDataPassThroughRunningForCmHandle('testCmHandle', - resourceIdentifier, - '(a=1,b=2)', - NO_TOPIC, - NO_REQUEST_ID) >> '{valid-json}' + mockNetworkCmProxyDataService.getResourceDataForCmHandle(PASSTHROUGH_RUNNING.datastoreName, 'testCmHandle', + resourceIdentifier,'(a=1,b=2)', NO_TOPIC, NO_REQUEST_ID) >> '{valid-json}' when: 'get data resource request is performed' def response = mvc.perform( get(getUrl) @@ -531,9 +555,7 @@ class NetworkCmProxyControllerSpec extends Specification { .contentType(MediaType.APPLICATION_JSON) ).andReturn().response then: 'the NCMP data service is called with getResourceDataOperational with #descendantsOption' - 1 * mockNetworkCmProxyDataService.getResourceDataOperational('testCmHandle', - 'parent/child', - descendantsOption) + 1 * mockNetworkCmProxyDataService.getResourceDataForCmHandle(OPERATIONAL.datastoreName, 'testCmHandle', 'parent/child', descendantsOption) and: 'response status is Ok' response.status == HttpStatus.OK.value() where: 'the following parameters are used' @@ -626,5 +648,19 @@ class NetworkCmProxyControllerSpec extends Specification { return assertContainsAll(response, expectedContent) } + def getNcmpDatastoreRequestHandler(dataStoreType, ncmpDatastoreRequestHandler) { + if (ncmpDatastoreRequestHandler instanceof NcmpCachedResourceRequestHandler) { + NcmpCachedResourceRequestHandler ncmpCachedResourceRequestHandler = (NcmpCachedResourceRequestHandler) ncmpDatastoreRequestHandler + ncmpCachedResourceRequestHandler.dataStoreName = dataStoreType.datastoreName + } else { + NcmpPassthroughResourceRequestHandler ncmpPassthroughResourceRequestHandler = (NcmpPassthroughResourceRequestHandler) ncmpDatastoreRequestHandler + ncmpPassthroughResourceRequestHandler.dataStoreName = dataStoreType.datastoreName + } + ncmpDatastoreRequestHandler.networkCmProxyDataService = mockNetworkCmProxyDataService + ncmpDatastoreRequestHandler.cpsNcmpTaskExecutor = spiedCpsTaskExecutor + ncmpDatastoreRequestHandler.notificationFeatureEnabled = NOTIFICATION_ENABLED + ncmpDatastoreRequestHandler.timeOutInMilliSeconds = TIMEOUT_IN_MS + return ncmpDatastoreRequestHandler + } } diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandlerFactorySpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandlerFactorySpec.groovy index 7c504981e2..15b3ee6c1e 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandlerFactorySpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandlerFactorySpec.groovy @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation + * Copyright (C) 2022-2023 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,21 +20,28 @@ package org.onap.cps.ncmp.rest.controller.handlers +import org.spockframework.spring.SpringBean import spock.lang.Specification class NcmpDatastoreRequestHandlerFactorySpec extends Specification { - def objectUnderTest = new NcmpDatastoreResourceRequestHandlerFactory(null, null, null) + @SpringBean + NcmpCachedResourceRequestHandler mockNcmpCachedResourceRequestHandler = new NcmpCachedResourceRequestHandler(null) + + @SpringBean + NcmpPassthroughResourceRequestHandler mockNcmpPassthroughResourceRequestHandler = new NcmpPassthroughResourceRequestHandler() + + def objectUnderTest = new NcmpDatastoreResourceRequestHandlerFactory(mockNcmpCachedResourceRequestHandler, mockNcmpPassthroughResourceRequestHandler) def 'Creating ncmp datastore request handlers.'() { when: 'a ncmp datastore request handler is created for #datastoreType' - def result = objectUnderTest.getNcmpDatastoreResourceRequestHandler(datastoreType) + def result = objectUnderTest.getNcmpResourceRequestHandler(datastoreType) then: 'the result is of the expected class' result.class == expectedClass where: 'the following type of datastore is used' datastoreType || expectedClass - DatastoreType.OPERATIONAL || NcmpDatastoreOperationalResourceRequestHandler - DatastoreType.PASSTHROUGH_OPERATIONAL || NcmpDatastorePassthroughOperationalResourceRequestHandler - DatastoreType.PASSTHROUGH_RUNNING || NcmpDatastorePassthroughRunningResourceRequestHandler + DatastoreType.OPERATIONAL || NcmpCachedResourceRequestHandler + DatastoreType.PASSTHROUGH_OPERATIONAL || NcmpPassthroughResourceRequestHandler + DatastoreType.PASSTHROUGH_RUNNING || NcmpPassthroughResourceRequestHandler } } |