2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2022 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.cps.ncmp.api.utils
23 import static org.onap.cps.ncmp.api.impl.operations.DmiOperations.DataStoreEnum.PASSTHROUGH_RUNNING
25 import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
26 import org.onap.cps.ncmp.api.impl.config.NcmpConfiguration
27 import org.onap.cps.ncmp.api.impl.utils.DmiServiceUrlBuilder
28 import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle
29 import spock.lang.Shared
30 import spock.lang.Specification
32 class DmiServiceUrlBuilderSpec extends Specification {
35 YangModelCmHandle yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle("dmiServiceName",
36 "dmiDataServiceName", "dmiModuleServiceName", new NcmpServiceCmHandle())
38 NcmpConfiguration.DmiProperties dmiProperties = new NcmpConfiguration.DmiProperties();
40 def objectUnderTest = new DmiServiceUrlBuilder(dmiProperties)
42 def 'Create the dmi service url with #scenario.'() {
43 given: 'uri variables'
44 dmiProperties.dmiBasePath = 'dmi';
45 def uriVars = objectUnderTest.populateUriVariables(yangModelCmHandle,
46 "cmHandle", PASSTHROUGH_RUNNING);
48 def uriQueries = objectUnderTest.populateQueryParams(resourceId,
49 'optionsParamInQuery', topicParamInQuery);
50 when: 'a dmi datastore service url is generated'
51 def dmiServiceUrl = objectUnderTest.getDmiDatastoreUrl(uriQueries, uriVars)
52 then: 'service url is generated as expected'
53 assert dmiServiceUrl == expectedDmiServiceUrl
54 where: 'the following parameters are used'
55 scenario | topicParamInQuery | resourceId || expectedDmiServiceUrl
56 'With valid resourceId' | 'topicParamInQuery' | 'resourceId' || 'dmiServiceName/dmi/v1/ch/cmHandle/data/ds/ncmp-datastore:passthrough-running?resourceIdentifier=resourceId&options=optionsParamInQuery&topic=topicParamInQuery'
57 'With Empty resourceId' | 'topicParamInQuery' | '' || 'dmiServiceName/dmi/v1/ch/cmHandle/data/ds/ncmp-datastore:passthrough-running?options=optionsParamInQuery&topic=topicParamInQuery'
58 'With Empty dmi base path' | 'topicParamInQuery' | 'resourceId' || 'dmiServiceName/dmi/v1/ch/cmHandle/data/ds/ncmp-datastore:passthrough-running?resourceIdentifier=resourceId&options=optionsParamInQuery&topic=topicParamInQuery'
59 'With Empty topicParamInQuery' | '' | 'resourceId' || 'dmiServiceName/dmi/v1/ch/cmHandle/data/ds/ncmp-datastore:passthrough-running?resourceIdentifier=resourceId&options=optionsParamInQuery'
62 def 'Populate dmi data store url #scenario.'() {
63 given: 'uri variables are created'
64 dmiProperties.dmiBasePath = dmiBasePath;
65 def uriVars = objectUnderTest.populateUriVariables(yangModelCmHandle,
66 "cmHandle", PASSTHROUGH_RUNNING);
67 and: 'null query params'
68 def uriQueries = objectUnderTest.populateQueryParams(null,
70 when: 'a dmi datastore service url is generated'
71 def dmiServiceUrl = objectUnderTest.getDmiDatastoreUrl(uriQueries, uriVars)
72 then: 'the created dmi service url matches the expected'
73 assert dmiServiceUrl == expectedDmiServiceUrl
74 where: 'the following parameters are used'
75 scenario | decription | dmiBasePath || expectedDmiServiceUrl
76 'with base path / ' | 'Invalid base path as it starts with /' | '/dmi' || 'dmiServiceName//dmi/v1/ch/cmHandle/data/ds/ncmp-datastore:passthrough-running'
77 'without base path / ' | 'Valid path as it does not starts with /' | 'dmi' || 'dmiServiceName/dmi/v1/ch/cmHandle/data/ds/ncmp-datastore:passthrough-running'