X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cps-ncmp-service%2Fsrc%2Ftest%2Fgroovy%2Forg%2Fonap%2Fcps%2Fncmp%2Fapi%2Fimpl%2Futils%2FDmiServiceUrlBuilderSpec.groovy;h=c83a540a37e389e0a448e1629b6322bf6ef9ff8a;hb=d8be9ef1d451f3e19c0c73752ad3d947e8baa9bd;hp=01569887ce4edcf87ef905a9ed550b590195f9f4;hpb=377af14ab2664d8a15673e51cba82f1254379e14;p=cps.git diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/DmiServiceUrlBuilderSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/DmiServiceUrlBuilderSpec.groovy index 01569887c..c83a540a3 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/DmiServiceUrlBuilderSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/DmiServiceUrlBuilderSpec.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,19 @@ package org.onap.cps.ncmp.api.impl.utils -import org.onap.cps.spi.utils.CpsValidator - -import static org.onap.cps.ncmp.api.impl.operations.DmiOperations.DataStoreEnum.PASSTHROUGH_RUNNING +import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_RUNNING +import org.onap.cps.ncmp.api.impl.operations.RequiredDmiService +import org.onap.cps.spi.utils.CpsValidator import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle import org.onap.cps.ncmp.api.impl.config.NcmpConfiguration import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle -import spock.lang.Shared import spock.lang.Specification class DmiServiceUrlBuilderSpec extends Specification { - @Shared - YangModelCmHandle yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle('dmiServiceName', - 'dmiDataServiceName', 'dmiModuleServiceName', new NcmpServiceCmHandle(cmHandleId: 'some-cm-handle-id')) + static YangModelCmHandle yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle('dmiServiceName', + 'dmiDataServiceName', 'dmiModuleServiceName', new NcmpServiceCmHandle(cmHandleId: 'some-cm-handle-id'),'my-module-set-tag', 'my-alternate-id') NcmpConfiguration.DmiProperties dmiProperties = new NcmpConfiguration.DmiProperties() @@ -42,14 +40,15 @@ class DmiServiceUrlBuilderSpec extends Specification { def objectUnderTest = new DmiServiceUrlBuilder(dmiProperties, mockCpsValidator) + def setup() { + dmiProperties.dmiBasePath = 'dmi' + } + def 'Create the dmi service url with #scenario.'() { given: 'uri variables' - dmiProperties.dmiBasePath = 'dmi' - def uriVars = objectUnderTest.populateUriVariables(yangModelCmHandle, - "cmHandle", PASSTHROUGH_RUNNING) + def uriVars = objectUnderTest.populateUriVariables(PASSTHROUGH_RUNNING.datastoreName, yangModelCmHandle.resolveDmiServiceName(RequiredDmiService.DATA), 'cmHandle') and: 'query params' - def uriQueries = objectUnderTest.populateQueryParams(resourceId, - 'optionsParamInQuery', topic) + def uriQueries = objectUnderTest.populateQueryParams(resourceId, 'optionsParamInQuery', topic) when: 'a dmi datastore service url is generated' def dmiServiceUrl = objectUnderTest.getDmiDatastoreUrl(uriQueries, uriVars) then: 'service url is generated as expected' @@ -65,11 +64,9 @@ class DmiServiceUrlBuilderSpec extends Specification { def 'Populate dmi data store url #scenario.'() { given: 'uri variables are created' dmiProperties.dmiBasePath = dmiBasePath - def uriVars = objectUnderTest.populateUriVariables(yangModelCmHandle, - "cmHandle", PASSTHROUGH_RUNNING) + def uriVars = objectUnderTest.populateUriVariables(PASSTHROUGH_RUNNING.datastoreName, yangModelCmHandle.resolveDmiServiceName(RequiredDmiService.DATA), 'cmHandle') and: 'null query params' - def uriQueries = objectUnderTest.populateQueryParams(null, - null, null) + def uriQueries = objectUnderTest.populateQueryParams(null, null, null) when: 'a dmi datastore service url is generated' def dmiServiceUrl = objectUnderTest.getDmiDatastoreUrl(uriQueries, uriVars) then: 'the created dmi service url matches the expected' @@ -79,4 +76,20 @@ class DmiServiceUrlBuilderSpec extends Specification { 'with base path / ' | 'Invalid base path as it starts with /' | '/dmi' || 'dmiServiceName//dmi/v1/ch/cmHandle/data/ds/ncmp-datastore:passthrough-running' 'without base path / ' | 'Valid path as it does not starts with /' | 'dmi' || 'dmiServiceName/dmi/v1/ch/cmHandle/data/ds/ncmp-datastore:passthrough-running' } + + def 'Bath request Url creation.'() { + given: 'the required path parameters' + def batchRequestUriVariables = [dmiServiceName: 'some-service', dmiBasePath: 'testBase', cmHandleId: '123'] + and: 'the relevant query parameters' + def batchRequestQueryParams = objectUnderTest.getDataOperationRequestQueryParams('some topic', 'some id') + when: 'a URL is created' + def result = objectUnderTest.getDataOperationRequestUrl(batchRequestQueryParams, batchRequestUriVariables) + then: 'it is formed correctly' + assert result.toString() == 'some-service/testBase/v1/data?topic=some topic&requestId=some id' + } + + def 'Populate batch uri variables.'() { + expect: 'Populate batch uri variables returns a map with given service name and base path from setup' + assert objectUnderTest.populateDataOperationRequestUriVariables('some service') == [dmiServiceName: 'some service', dmiBasePath: 'dmi' ] + } }