aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ncmp-rest/src/test
diff options
context:
space:
mode:
authorlukegleeson <luke.gleeson@est.tech>2022-10-20 10:14:00 +0100
committerlukegleeson <luke.gleeson@est.tech>2022-11-15 17:18:39 +0000
commit20e7a733d8a3657fd9932eaf8144f47777965533 (patch)
tree0776eaf8cb4de6689bdeae4ea7a1f688b29d56c8 /cps-ncmp-rest/src/test
parentb99f0f00cb964af7b88a85c09bbb11f6c0b1f04d (diff)
Query data NCMP-Operational with CPSpath
New GET Endpoint: /v1/ch/{cm-handle}/data/ds/{ncmp-datastore-name}/query?cps-path={CPSPath} Implemented error for {ncmp-datastore-name} other than operational - (Toine) Refactored and renamed (abstract) handler for better re-use Mainly by introducing a separate handler for OperationalQuery Reviewers Toine, Sourabh, Priyank Issue-ID: CPS-1002 Signed-off-by: lukegleeson <luke.gleeson@est.tech> Change-Id: Iaca018869d95d4ce800072431baa190050a6dad0
Diffstat (limited to 'cps-ncmp-rest/src/test')
-rw-r--r--cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy45
-rw-r--r--cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandlerFactorySpec.groovy40
-rw-r--r--cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreResourceRequestHandlerFactorySpec.groovy20
3 files changed, 85 insertions, 20 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 b6194bc79..d67804e12 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
@@ -27,20 +27,24 @@ import com.fasterxml.jackson.databind.ObjectMapper
import org.mapstruct.factory.Mappers
import org.onap.cps.TestUtils
import org.onap.cps.ncmp.api.NetworkCmProxyDataService
+import org.onap.cps.ncmp.api.NetworkCmProxyQueryService
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.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.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
@@ -84,6 +88,9 @@ class NetworkCmProxyControllerSpec extends Specification {
NetworkCmProxyDataService mockNetworkCmProxyDataService = Mock()
@SpringBean
+ NetworkCmProxyQueryService mockNetworkCmProxyQueryService = Mock()
+
+ @SpringBean
ObjectMapper objectMapper = new ObjectMapper()
@SpringBean
@@ -131,6 +138,10 @@ class NetworkCmProxyControllerSpec extends Specification {
DatastoreType.PASSTHROUGH_RUNNING) >>
new NcmpDatastorePassthroughRunningResourceRequestHandler(
mockNetworkCmProxyDataService, spiedCpsTaskExecutor, TIMEOUT_IN_MS, NOTIFICATION_ENABLED)
+
+ stubbedNcmpDatastoreResourceRequestHandlerFactory.getNcmpDatastoreResourceQueryHandler() >>
+ new NcmpDatastoreOperationalQueryHandler(mockNetworkCmProxyQueryService, spiedCpsTaskExecutor,
+ TIMEOUT_IN_MS, NOTIFICATION_ENABLED);
}
def 'Get Resource Data from pass-through operational.'() {
@@ -194,6 +205,40 @@ class NetworkCmProxyControllerSpec extends Specification {
'invalid non-empty topic value in url' | 'passthrough-running' | '&topic=1_5_*_#'
}
+ def 'Query Resource Data from operational.'() {
+ given: 'the query resource data url'
+ def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:operational/query" +
+ "?cps-path=/cps/path"
+ when: 'the query data resource request is performed'
+ def response = mvc.perform(
+ get(getUrl)
+ .contentType(MediaType.APPLICATION_JSON)
+ ).andReturn().response
+ then: 'the NCMP query service is called with queryResourceDataOperationalForCmHandle'
+ 1 * mockNetworkCmProxyQueryService.queryResourceDataOperational('testCmHandle',
+ '/cps/path',
+ FetchDescendantsOption.OMIT_DESCENDANTS)
+ and: 'response status is Ok'
+ response.status == HttpStatus.OK.value()
+ }
+
+ def 'Query Resource Data using datastore of #datastore'() {
+ given: 'the query resource data url'
+ def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:${datastore}/query" +
+ "?cps-path=/cps/path"
+ when: 'the query data resource request is performed'
+ def response = mvc.perform(
+ get(getUrl)
+ .contentType(MediaType.APPLICATION_JSON)
+ ).andReturn().response
+ then: 'a 400 BAD_REQUEST is returned for the unsupported datastore'
+ response.status == 400
+ and: 'the error message is that datastore #datastore is not supported'
+ response.contentAsString.contains("ncmp-datastore:${datastore} is not supported")
+ where: 'the following datastore is used'
+ datastore << ["passthrough-running", "passthrough-operational"]
+ }
+
def 'Get Resource Data from pass-through running with #scenario value in resource identifier param.'() {
given: 'resource data url'
def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-running" +
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
new file mode 100644
index 000000000..7c504981e
--- /dev/null
+++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandlerFactorySpec.groovy
@@ -0,0 +1,40 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.ncmp.rest.controller.handlers
+
+import spock.lang.Specification
+
+class NcmpDatastoreRequestHandlerFactorySpec extends Specification {
+
+ def objectUnderTest = new NcmpDatastoreResourceRequestHandlerFactory(null, null, null)
+
+ def 'Creating ncmp datastore request handlers.'() {
+ when: 'a ncmp datastore request handler is created for #datastoreType'
+ def result = objectUnderTest.getNcmpDatastoreResourceRequestHandler(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
+ }
+}
diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreResourceRequestHandlerFactorySpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreResourceRequestHandlerFactorySpec.groovy
deleted file mode 100644
index 3f7a8a5ce..000000000
--- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreResourceRequestHandlerFactorySpec.groovy
+++ /dev/null
@@ -1,20 +0,0 @@
-package org.onap.cps.ncmp.rest.controller.handlers
-
-import spock.lang.Specification
-
-class NcmpDatastoreResourceRequestHandlerFactorySpec extends Specification {
-
- def objectUnderTest = new NcmpDatastoreResourceRequestHandlerFactory(null, null)
-
- def 'Creating ncmp datastore request handlers.'() {
- when: 'a ncmp datastore request handler is created for #datastoreType'
- def result = objectUnderTest.getNcmpDatastoreResourceRequestHandler(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
- }
-} \ No newline at end of file