From 977f7c395cee52cdecd0b01cb0412ebfeb9db048 Mon Sep 17 00:00:00 2001 From: "raviteja.karumuri" Date: Tue, 20 Jun 2023 19:10:21 +0100 Subject: NCMP : Replacing the word 'Batch' as 'DataOperation'. Issue-ID: CPS-1754 Signed-off-by: raviteja.karumuri Change-Id: Ie9f56effb160582ba7177331fb6260b2bde2342b --- .../impl/NetworkCmProxyDataServiceImplSpec.groovy | 41 +++++------ .../impl/operations/DmiDataOperationsSpec.groovy | 16 ++--- .../utils/DataOperationRequestUtilsSpec.groovy | 80 ++++++++++++++++++++++ .../utils/ResourceDataBatchRequestUtilsSpec.groovy | 80 ---------------------- .../src/test/resources/dataOperationRequest.json | 36 ++++++++++ .../test/resources/resourceDataBatchRequest.json | 36 ---------- 6 files changed, 145 insertions(+), 144 deletions(-) create mode 100644 cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/DataOperationRequestUtilsSpec.groovy delete mode 100644 cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/ResourceDataBatchRequestUtilsSpec.groovy create mode 100644 cps-ncmp-service/src/test/resources/dataOperationRequest.json delete mode 100644 cps-ncmp-service/src/test/resources/resourceDataBatchRequest.json (limited to 'cps-ncmp-service/src/test') diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy index 79f7e50e76..af2b80f755 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy @@ -33,13 +33,13 @@ import org.onap.cps.ncmp.api.inventory.CompositeState import org.onap.cps.ncmp.api.inventory.InventoryPersistence import org.onap.cps.ncmp.api.inventory.LockReasonCategory import org.onap.cps.ncmp.api.inventory.DataStoreSyncState -import org.onap.cps.ncmp.api.models.BatchOperationDefinition +import org.onap.cps.ncmp.api.models.DataOperationDefinition import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters import org.onap.cps.ncmp.api.models.ConditionApiProperties import org.onap.cps.ncmp.api.models.DmiPluginRegistration import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle -import org.onap.cps.ncmp.api.models.ResourceDataBatchRequest +import org.onap.cps.ncmp.api.models.DataOperationRequest import org.onap.cps.spi.exceptions.CpsException import org.onap.cps.spi.model.ConditionProperties import spock.lang.Shared @@ -135,13 +135,13 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { response == '{dmi-response}' } - def 'Get batch resource data for #datastoreName from DMI.'() { + def 'Execute (async) data operation for #datastoreName from DMI.'() { given: 'cpsDataService returns valid data node' - def resourceDataBatchRequest = getResourceDataBatchRequest(datastoreName) - when: 'get batch resource data is called' - objectUnderTest.requestResourceDataForCmHandleBatch('some topic', resourceDataBatchRequest, 'requestId') - then: 'get batch resource data returns expected response' - 1 * mockDmiDataOperations.requestResourceDataFromDmi('some topic', resourceDataBatchRequest, 'requestId') + def dataOperationRequest = getDataOperationRequest(datastoreName) + when: 'request resource data for data operation is called' + objectUnderTest.executeDataOperationForCmHandles('some topic', dataOperationRequest, 'requestId') + then: 'request resource data for data operation returns expected response' + 1 * mockDmiDataOperations.requestResourceDataFromDmi('some topic', dataOperationRequest, 'requestId') where: 'the following data stores are used' datastoreName << [PASSTHROUGH_RUNNING.datastoreName, PASSTHROUGH_OPERATIONAL.datastoreName] } @@ -368,21 +368,22 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode } - def getResourceDataBatchRequest(datastore) { - def resourceDataBatchRequest = new ResourceDataBatchRequest() - def batchOperationDefinitions = new ArrayList() - batchOperationDefinitions.add(getBatchOperationDefinition(datastore)) - resourceDataBatchRequest.setBatchOperationDefinitions(batchOperationDefinitions) + def getDataOperationRequest(datastore) { + def dataOperationRequest = new DataOperationRequest() + def dataOperationDefinitions = new ArrayList() + dataOperationDefinitions.add(getDataOperationDefinition(datastore)) + dataOperationRequest.setDataOperationDefinitions(dataOperationDefinitions) + return dataOperationRequest } - def getBatchOperationDefinition(datastore) { - def batchOperationDefinition = new BatchOperationDefinition() - batchOperationDefinition.setOperation("read") - batchOperationDefinition.setOperationId("operational-12") - batchOperationDefinition.setDatastore(datastore) + def getDataOperationDefinition(datastore) { + def dataOperationDefinition = new DataOperationDefinition() + dataOperationDefinition.setOperation("read") + dataOperationDefinition.setOperationId("operational-12") + dataOperationDefinition.setDatastore(datastore) def targetIds = new ArrayList() targetIds.add("some-cm-handle") - batchOperationDefinition.setCmHandleIds(targetIds) - return batchOperationDefinition + dataOperationDefinition.setCmHandleIds(targetIds) + return dataOperationDefinition } } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiDataOperationsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiDataOperationsSpec.groovy index 9343666260..be178e1276 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiDataOperationsSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiDataOperationsSpec.groovy @@ -24,7 +24,7 @@ package org.onap.cps.ncmp.api.impl.operations import com.fasterxml.jackson.databind.ObjectMapper import org.onap.cps.ncmp.api.impl.config.NcmpConfiguration import org.onap.cps.ncmp.api.impl.utils.DmiServiceUrlBuilder -import org.onap.cps.ncmp.api.models.ResourceDataBatchRequest +import org.onap.cps.ncmp.api.models.DataOperationRequest import org.onap.cps.ncmp.utils.TestUtils import org.onap.cps.utils.JsonObjectMapper import org.spockframework.spring.SpringBean @@ -82,12 +82,12 @@ class DmiDataOperationsSpec extends DmiOperationsBaseSpec { 'datastore running with properties' | [yangModelCmHandleProperty] | PASSTHROUGH_RUNNING | OPTIONS_PARAM || '{"operation":"read","cmHandleProperties":{"prop1":"val1"}}' | 'passthrough-running' | '&options=(a=1,b=2)' } - def 'call get batch resource data from DMI service #scenario.'() { - given: 'collection of yang model cm Handles and resource data batch request' + def 'Execute (async) data operation from DMI service.'() { + given: 'collection of yang model cm Handles and data operation request' mockYangModelCmHandleCollectionRetrieval([yangModelCmHandleProperty]) - def resourceDataBatchRequestJsonData = TestUtils.getResourceFileContent('resourceDataBatchRequest.json') - def resourceDataBatchRequest = spiedJsonObjectMapper.convertJsonString(resourceDataBatchRequestJsonData, ResourceDataBatchRequest.class) - resourceDataBatchRequest.batchOperationDefinitions[0].cmHandleIds = [cmHandleId] + def dataOperationBatchRequestJsonData = TestUtils.getResourceFileContent('dataOperationRequest.json') + def dataOperationRequest = spiedJsonObjectMapper.convertJsonString(dataOperationBatchRequestJsonData, DataOperationRequest.class) + dataOperationRequest.dataOperationDefinitions[0].cmHandleIds = [cmHandleId] def requestBodyAsJsonStringArg = null and: 'a positive response from DMI service when it is called with valid request parameters' def responseFromDmi = new ResponseEntity(HttpStatus.ACCEPTED) @@ -95,8 +95,8 @@ class DmiDataOperationsSpec extends DmiOperationsBaseSpec { def expectedBatchRequestAsJson = '[{"operation":"read","operationId":"operational-14","datastore":"ncmp-datastore:passthrough-operational","options":"some option","resourceIdentifier":"some resource identifier","cmHandles":[{"id":"some-cm-handle","cmHandleProperties":{"prop1":"val1"}}]}]' mockDmiRestClient.postOperationWithJsonData(expectedDmiBatchResourceDataUrl, _, READ.operationName) >> responseFromDmi dmiServiceUrlBuilder.getBatchRequestUrl(_, _) >> expectedDmiBatchResourceDataUrl - when: 'get resource data for batch of cm handles are invoked' - objectUnderTest.requestResourceDataFromDmi('my-topic-name', resourceDataBatchRequest, 'requestId') + when: 'get resource data for group of cm handles are invoked' + objectUnderTest.requestResourceDataFromDmi('my-topic-name', dataOperationRequest, 'requestId') then: 'wait a little to allow execution of service method by task executor (on separate thread)' Thread.sleep(100) then: 'validate ncmp generated dmi request body json args' diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/DataOperationRequestUtilsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/DataOperationRequestUtilsSpec.groovy new file mode 100644 index 0000000000..af3841a40b --- /dev/null +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/DataOperationRequestUtilsSpec.groovy @@ -0,0 +1,80 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 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. + * 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.api.impl.utils + +import com.fasterxml.jackson.databind.ObjectMapper +import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle +import org.onap.cps.ncmp.api.inventory.CmHandleState +import org.onap.cps.ncmp.api.inventory.CompositeStateBuilder +import org.onap.cps.ncmp.api.models.DataOperationRequest +import org.onap.cps.ncmp.utils.TestUtils +import org.onap.cps.utils.JsonObjectMapper +import org.spockframework.spring.SpringBean +import spock.lang.Specification + +class DataOperationRequestUtilsSpec extends Specification { + + @SpringBean + JsonObjectMapper jsonObjectMapper = new JsonObjectMapper(new ObjectMapper()) + + def 'Process per data operation request with #serviceName.'() { + given: 'data operation request with 3 operations' + def dataOperationRequestJsonData = TestUtils.getResourceFileContent('dataOperationRequest.json') + def dataOperationRequest = jsonObjectMapper.convertJsonString(dataOperationRequestJsonData, DataOperationRequest.class) + and: '4 known cm handles: ch1-dmi1, ch2-dmi1, ch3-dmi2, ch4-dmi2' + def yangModelCmHandles = getYangModelCmHandles() + when: 'data operation request is processed' + def operationsOutPerDmiServiceName = ResourceDataBatchRequestUtils.processPerOperationInBatchRequest(dataOperationRequest, yangModelCmHandles) + and: 'converted to a json node' + def dmiDataOperationRequestBody = jsonObjectMapper.asJsonString(operationsOutPerDmiServiceName.get(serviceName)) + def dmiDataOperationRequestBodyAsJsonNode = jsonObjectMapper.convertToJsonNode(dmiDataOperationRequestBody).get(operationIndex) + then: 'it contains the correct operation details' + assert dmiDataOperationRequestBodyAsJsonNode.get('operation').asText() == 'read' + assert dmiDataOperationRequestBodyAsJsonNode.get('operationId').asText() == expectedOperationId + assert dmiDataOperationRequestBodyAsJsonNode.get('datastore').asText() == expectedDatastore + and: 'the correct cm handles (just for #serviceName)' + assert dmiDataOperationRequestBodyAsJsonNode.get('cmHandles').size() == expectedCmHandleIds.size() + expectedCmHandleIds.each { + dmiDataOperationRequestBodyAsJsonNode.get('cmHandles').toString().contains(it) + } + where: 'the following dmi service and operations are checked' + serviceName | operationIndex || expectedOperationId | expectedDatastore | expectedCmHandleIds + 'dmi1' | 0 || 'operational-14' | 'ncmp-datastore:passthrough-operational' | ['ch6-dmi1'] + 'dmi1' | 1 || 'running-12' | 'ncmp-datastore:passthrough-running' | ['ch1-dmi1', 'ch2-dmi1'] + 'dmi1' | 2 || 'operational-15' | 'ncmp-datastore:passthrough-operational' | ['ch6-dmi1'] + 'dmi2' | 0 || 'operational-14' | 'ncmp-datastore:passthrough-operational' | ['ch3-dmi2'] + 'dmi2' | 1 || 'running-12' | 'ncmp-datastore:passthrough-running' | ['ch7-dmi2'] + 'dmi2' | 2 || 'operational-15' | 'ncmp-datastore:passthrough-operational' | ['ch4-dmi2'] + } + + static def getYangModelCmHandles() { + def dmiProperties = [new YangModelCmHandle.Property('prop', 'some DMI property')] + def readyState = new CompositeStateBuilder().withCmHandleState(CmHandleState.READY).withLastUpdatedTimeNow().build() + return [new YangModelCmHandle(id: 'ch1-dmi1', dmiServiceName: 'dmi1', dmiProperties: dmiProperties, compositeState: readyState), + new YangModelCmHandle(id: 'ch2-dmi1', dmiServiceName: 'dmi1', dmiProperties: dmiProperties, compositeState: readyState), + new YangModelCmHandle(id: 'ch6-dmi1', dmiServiceName: 'dmi1', dmiProperties: dmiProperties, compositeState: readyState), + new YangModelCmHandle(id: 'ch8-dmi1', dmiServiceName: 'dmi1', dmiProperties: dmiProperties, compositeState: readyState), + new YangModelCmHandle(id: 'ch3-dmi2', dmiServiceName: 'dmi2', dmiProperties: dmiProperties, compositeState: readyState), + new YangModelCmHandle(id: 'ch4-dmi2', dmiServiceName: 'dmi2', dmiProperties: dmiProperties, compositeState: readyState), + new YangModelCmHandle(id: 'ch7-dmi2', dmiServiceName: 'dmi2', dmiProperties: dmiProperties, compositeState: readyState), + ] + } +} diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/ResourceDataBatchRequestUtilsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/ResourceDataBatchRequestUtilsSpec.groovy deleted file mode 100644 index e65874930b..0000000000 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/ResourceDataBatchRequestUtilsSpec.groovy +++ /dev/null @@ -1,80 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 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. - * 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.api.impl.utils - -import com.fasterxml.jackson.databind.ObjectMapper -import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle -import org.onap.cps.ncmp.api.inventory.CmHandleState -import org.onap.cps.ncmp.api.inventory.CompositeStateBuilder -import org.onap.cps.ncmp.api.models.ResourceDataBatchRequest -import org.onap.cps.ncmp.utils.TestUtils -import org.onap.cps.utils.JsonObjectMapper -import org.spockframework.spring.SpringBean -import spock.lang.Specification - -class ResourceDataBatchRequestUtilsSpec extends Specification { - - @SpringBean - JsonObjectMapper jsonObjectMapper = new JsonObjectMapper(new ObjectMapper()) - - def 'Process per operation in batch request with #serviceName.'() { - given: 'batch request with 3 operations' - def resourceDataBatchRequestJsonData = TestUtils.getResourceFileContent('resourceDataBatchRequest.json') - def resourceDataBatchRequest = jsonObjectMapper.convertJsonString(resourceDataBatchRequestJsonData, ResourceDataBatchRequest.class) - and: '4 known cm handles: ch1-dmi1, ch2-dmi1, ch3-dmi2, ch4-dmi2' - def yangModelCmHandles = getYangModelCmHandles() - when: 'Operation in batch request is processed' - def operationsOutPerDmiServiceName = ResourceDataBatchRequestUtils.processPerOperationInBatchRequest(resourceDataBatchRequest, yangModelCmHandles) - and: 'converted to a json node' - def dmiBatchRequestBody = jsonObjectMapper.asJsonString(operationsOutPerDmiServiceName.get(serviceName)) - def dmiBatchRequestBodyAsJsonNode = jsonObjectMapper.convertToJsonNode(dmiBatchRequestBody).get(operationIndex) - then: 'it contains the correct operation details' - assert dmiBatchRequestBodyAsJsonNode.get('operation').asText() == 'read' - assert dmiBatchRequestBodyAsJsonNode.get('operationId').asText() == expectedOperationId - assert dmiBatchRequestBodyAsJsonNode.get('datastore').asText() == expectedDatastore - and: 'the correct cm handles (just for #serviceName)' - assert dmiBatchRequestBodyAsJsonNode.get('cmHandles').size() == expectedCmHandleIds.size() - expectedCmHandleIds.each { - dmiBatchRequestBodyAsJsonNode.get('cmHandles').toString().contains(it) - } - where: 'the following dmi service and operations are checked' - serviceName | operationIndex || expectedOperationId | expectedDatastore | expectedCmHandleIds - 'dmi1' | 0 || 'operational-14' | 'ncmp-datastore:passthrough-operational' | ['ch6-dmi1'] - 'dmi1' | 1 || 'running-12' | 'ncmp-datastore:passthrough-running' | ['ch1-dmi1', 'ch2-dmi1'] - 'dmi1' | 2 || 'operational-15' | 'ncmp-datastore:passthrough-operational' | ['ch6-dmi1'] - 'dmi2' | 0 || 'operational-14' | 'ncmp-datastore:passthrough-operational' | ['ch3-dmi2'] - 'dmi2' | 1 || 'running-12' | 'ncmp-datastore:passthrough-running' | ['ch7-dmi2'] - 'dmi2' | 2 || 'operational-15' | 'ncmp-datastore:passthrough-operational' | ['ch4-dmi2'] - } - - static def getYangModelCmHandles() { - def dmiProperties = [new YangModelCmHandle.Property('prop', 'some DMI property')] - def readyState = new CompositeStateBuilder().withCmHandleState(CmHandleState.READY).withLastUpdatedTimeNow().build() - return [new YangModelCmHandle(id: 'ch1-dmi1', dmiServiceName: 'dmi1', dmiProperties: dmiProperties, compositeState: readyState), - new YangModelCmHandle(id: 'ch2-dmi1', dmiServiceName: 'dmi1', dmiProperties: dmiProperties, compositeState: readyState), - new YangModelCmHandle(id: 'ch6-dmi1', dmiServiceName: 'dmi1', dmiProperties: dmiProperties, compositeState: readyState), - new YangModelCmHandle(id: 'ch8-dmi1', dmiServiceName: 'dmi1', dmiProperties: dmiProperties, compositeState: readyState), - new YangModelCmHandle(id: 'ch3-dmi2', dmiServiceName: 'dmi2', dmiProperties: dmiProperties, compositeState: readyState), - new YangModelCmHandle(id: 'ch4-dmi2', dmiServiceName: 'dmi2', dmiProperties: dmiProperties, compositeState: readyState), - new YangModelCmHandle(id: 'ch7-dmi2', dmiServiceName: 'dmi2', dmiProperties: dmiProperties, compositeState: readyState), - ] - } -} diff --git a/cps-ncmp-service/src/test/resources/dataOperationRequest.json b/cps-ncmp-service/src/test/resources/dataOperationRequest.json new file mode 100644 index 0000000000..98ed39b9ae --- /dev/null +++ b/cps-ncmp-service/src/test/resources/dataOperationRequest.json @@ -0,0 +1,36 @@ +{ + "operations": [ + { + "operation": "read", + "operationId": "operational-14", + "datastore": "ncmp-datastore:passthrough-operational", + "options": "some option", + "resourceIdentifier": "some resource identifier", + "targetIds": [ + "ch3-dmi2", + "unknown-cm-handle", + "ch6-dmi1" + ] + }, + { + "operation": "read", + "operationId": "running-12", + "datastore": "ncmp-datastore:passthrough-running", + "targetIds": [ + "ch1-dmi1", + "ch7-dmi2", + "ch2-dmi1" + ] + }, + { + "operation": "read", + "operationId": "operational-15", + "datastore": "ncmp-datastore:passthrough-operational", + "options": "some option", + "targetIds": [ + "ch4-dmi2", + "ch6-dmi1" + ] + } + ] +} diff --git a/cps-ncmp-service/src/test/resources/resourceDataBatchRequest.json b/cps-ncmp-service/src/test/resources/resourceDataBatchRequest.json deleted file mode 100644 index 98ed39b9ae..0000000000 --- a/cps-ncmp-service/src/test/resources/resourceDataBatchRequest.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "operations": [ - { - "operation": "read", - "operationId": "operational-14", - "datastore": "ncmp-datastore:passthrough-operational", - "options": "some option", - "resourceIdentifier": "some resource identifier", - "targetIds": [ - "ch3-dmi2", - "unknown-cm-handle", - "ch6-dmi1" - ] - }, - { - "operation": "read", - "operationId": "running-12", - "datastore": "ncmp-datastore:passthrough-running", - "targetIds": [ - "ch1-dmi1", - "ch7-dmi2", - "ch2-dmi1" - ] - }, - { - "operation": "read", - "operationId": "operational-15", - "datastore": "ncmp-datastore:passthrough-operational", - "options": "some option", - "targetIds": [ - "ch4-dmi2", - "ch6-dmi1" - ] - } - ] -} -- cgit