summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/test/groovy
diff options
context:
space:
mode:
authorsourabh_sourabh <sourabh.sourabh@est.tech>2023-02-02 11:22:20 +0000
committerSourabh Sourabh <sourabh.sourabh@est.tech>2023-02-08 17:09:23 +0000
commitd3eff8e28514075ab30a1013ae29194eab35958c (patch)
tree577ad9e26f5810812822b2391b39f152ec4ed76c /cps-ncmp-service/src/test/groovy
parentfd43dbe8705c489bb9c62b1b1cd8c7f905a7c5a9 (diff)
Use getDataNodes (plural version) into NCMP to get CM handles
- Use plural getYangModelCmHandles get YangModelCmHandles by CmHandles in batches. Issue-ID: CPS-1426 Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech> Change-Id: Ie175b471bd98b02b572ca4a3ff699d721b5b782a Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/test/groovy')
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/YangDataConverterSpec.groovy14
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImplSpec.groovy27
2 files changed, 40 insertions, 1 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/YangDataConverterSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/YangDataConverterSpec.groovy
index 3ef3df5ef..dd673eb8f 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/YangDataConverterSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/YangDataConverterSpec.groovy
@@ -38,4 +38,18 @@ class YangDataConverterSpec extends Specification{
assert yangModelCmHandle.dmiProperties[0].name == 'dmiProp1'
assert yangModelCmHandle.dmiProperties[0].value == 'dmiValue1'
}
+
+ def 'Convert multiple cm handle data nodes'(){
+ given: 'two data nodes in a collection one with private properties'
+ def dataNodeAdditionalProperties = new DataNode(xpath:'/additional-properties[@name="dmiProp1"]',
+ leaves: ['name': 'dmiProp1', 'value': 'dmiValue1'])
+ def dataNodes = [new DataNode(xpath:'/dmi-registry/cm-handles[@id=\'some-cm-handle\']'),
+ new DataNode(xpath:'/dmi-registry/cm-handles[@id=\'another-cm-handle\']', childDataNodes:[dataNodeAdditionalProperties])]
+ when: 'the data nodes are converted'
+ def yangModelCmHandles = YangDataConverter.convertDataNodesToYangModelCmHandles(dataNodes)
+ then: 'verify both have returned and cmhandleIds are correct'
+ assert yangModelCmHandles.size() == 2
+ assert yangModelCmHandles.id.containsAll(['some-cm-handle', 'another-cm-handle'])
+ }
+
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImplSpec.groovy
index 2ca0e9964..93e79f682 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImplSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImplSpec.groovy
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation
+ * Copyright (C) 2022-2023 Nordix Foundation
* Modifications Copyright (C) 2022 Bell Canada
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,6 +28,7 @@ import org.onap.cps.api.CpsModuleService
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
import org.onap.cps.spi.CascadeDeleteAllowed
import org.onap.cps.spi.FetchDescendantsOption
+import org.onap.cps.spi.exceptions.DataValidationException
import org.onap.cps.spi.model.DataNode
import org.onap.cps.spi.model.ModuleDefinition
import org.onap.cps.spi.model.ModuleReference
@@ -38,6 +39,7 @@ import spock.lang.Specification
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter
+import java.util.stream.Collectors
import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NO_TIMESTAMP
import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
@@ -64,6 +66,9 @@ class InventoryPersistenceImplSpec extends Specification {
def leaves = ["dmi-service-name":"common service name","dmi-data-service-name":"data service name","dmi-model-service-name":"model service name"]
def xpath = "/dmi-registry/cm-handles[@id='some-cm-handle']"
+ def cmHandleId2 = 'another-cm-handle'
+ def xpath2 = "/dmi-registry/cm-handles[@id='another-cm-handle']"
+
@Shared
def childDataNodesForCmHandleWithAllProperties = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='some cm handle']/additional-properties[@name='name1']", leaves: ["name":"name1", "value":"value1"]),
new DataNode(xpath: "/dmi-registry/cm-handles[@id='some cm handle']/public-properties[@name='name2']", leaves: ["name":"name2","value":"value2"])]
@@ -118,6 +123,26 @@ class InventoryPersistenceImplSpec extends Specification {
1 * mockCpsValidator.validateNameCharacters(cmHandleId)
}
+ def "Retrieve multiple YangModelCmHandles"() {
+ given: 'the cps data service returns 2 data nodes from the DMI registry'
+ def dataNodes = [new DataNode(xpath: xpath), new DataNode(xpath: xpath2)]
+ mockCpsDataService.getDataNodes('NCMP-Admin', 'ncmp-dmi-registry', [xpath, xpath2] , INCLUDE_ALL_DESCENDANTS) >> dataNodes
+ when: 'retrieving the yang modelled cm handle'
+ def results = objectUnderTest.getYangModelCmHandles([cmHandleId, cmHandleId2])
+ then: 'verify both have returned and cmhandleIds are correct'
+ assert results.size() == 2
+ assert results.id.containsAll([cmHandleId, cmHandleId2])
+ }
+
+ def "Handling name validation errors in getYangModelCmHandles."() {
+ given: 'the cps data service returns one of two data nodes from the DMI registry with empty leaf attributes'
+ mockCpsValidator.validateNameCharacters(cmHandleId) >> {throw new DataValidationException('some message', 'some detail')}
+ when:
+ objectUnderTest.getYangModelCmHandle(cmHandleId)
+ then: 'exception is thrown'
+ thrown(DataValidationException)
+ }
+
def 'Get a Cm Handle Composite State'() {
given: 'a valid cm handle id'
def cmHandleId = 'Some-Cm-Handle'