From 13998987c57a8ace243725a49d7ce55bcaf34f16 Mon Sep 17 00:00:00 2001 From: sourabh_sourabh Date: Tue, 16 Jul 2024 17:21:45 +0100 Subject: Integration test to validate DMI service URL - New groovy test is written to validate if dmi service url is encoded correctly. Issue-ID: CPS-2317 Change-Id: I048bf37dd3ba4f37df7dace927f55bf8dd899922 Signed-off-by: sourabh_sourabh --- .../org/onap/cps/utils/JsonObjectMapperSpec.groovy | 2 +- .../onap/cps/integration/base/DmiDispatcher.groovy | 2 + .../ncmp/CmHandleResourceDataSpec.groovy | 53 ++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/CmHandleResourceDataSpec.groovy diff --git a/cps-service/src/test/groovy/org/onap/cps/utils/JsonObjectMapperSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/utils/JsonObjectMapperSpec.groovy index 8cbd493550..09d45b92c0 100644 --- a/cps-service/src/test/groovy/org/onap/cps/utils/JsonObjectMapperSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/utils/JsonObjectMapperSpec.groovy @@ -42,7 +42,7 @@ class JsonObjectMapperSpec extends Specification { def contentMap = new JsonSlurper().parseText(new String(content)) and: 'the parsed content is as expected' assert contentMap.'test:bookstore'.'bookstore-name' == 'Chapters/Easons' - where: 'the following data stores are used' + where: 'the following content types are used' type << ['String', 'bytes'] } diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/base/DmiDispatcher.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/base/DmiDispatcher.groovy index e77815f5ec..50ff93cebb 100644 --- a/integration-test/src/test/groovy/org/onap/cps/integration/base/DmiDispatcher.groovy +++ b/integration-test/src/test/groovy/org/onap/cps/integration/base/DmiDispatcher.groovy @@ -55,6 +55,7 @@ class DmiDispatcher extends Dispatcher { def isAvailable = true Map> moduleNamesPerCmHandleId = [:] def lastAuthHeaderReceived + def dmiResourceDataUrl @Override MockResponse dispatch(RecordedRequest request) { @@ -79,6 +80,7 @@ class DmiDispatcher extends Dispatcher { // pass-through data operation for a CM-handle case ~'^/dmi/v1/ch/(.*)/data/ds/(.*)$': + dmiResourceDataUrl = request.path return mockResponseWithBody(HttpStatus.OK, '{}') // legacy pass-through batch data operation diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/CmHandleResourceDataSpec.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/CmHandleResourceDataSpec.groovy new file mode 100644 index 0000000000..8dfa118da6 --- /dev/null +++ b/integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/CmHandleResourceDataSpec.groovy @@ -0,0 +1,53 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2024 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.integration.functional.ncmp + +import org.onap.cps.integration.base.CpsIntegrationSpecBase +import org.onap.cps.ncmp.api.data.models.CmResourceAddress +import org.onap.cps.ncmp.impl.data.NetworkCmProxyFacade +import spock.util.concurrent.PollingConditions + +import static org.onap.cps.ncmp.api.data.models.DatastoreType.PASSTHROUGH_OPERATIONAL + +class CmHandleResourceDataSpec extends CpsIntegrationSpecBase { + + NetworkCmProxyFacade objectUnderTest + + def setup() { + dmiDispatcher.moduleNamesPerCmHandleId['ch-1'] = ['M1', 'M2'] + registerCmHandle(DMI_URL, 'ch-1', NO_MODULE_SET_TAG) + objectUnderTest = networkCmProxyFacade + } + + def cleanup() { + deregisterCmHandle(DMI_URL, 'ch-1') + } + + def 'Get resource data having special chars into path & query param value.'() { + when: 'getting the resource data' + def cmResourceAddress = new CmResourceAddress(PASSTHROUGH_OPERATIONAL.datastoreName, 'ch-1', 'parent/child') + objectUnderTest.getResourceDataForCmHandle(cmResourceAddress, '(a=1,b=2)', 'my-client-topic', false, null) + then: 'dmi resource data url is encoded correctly' + new PollingConditions().within(5, () -> { + assert dmiDispatcher.dmiResourceDataUrl == '/dmi/v1/ch/ch-1/data/ds/ncmp-datastore%3Apassthrough-operational?resourceIdentifier=parent%2Fchild&options=%28a%3D1%2Cb%3D2%29&topic=my-client-topic' + }) + } +} -- cgit 1.2.3-korg