aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/test
diff options
context:
space:
mode:
authorseanbeirne <sean.beirne@est.tech>2024-10-21 16:18:27 +0100
committerseanbeirne <sean.beirne@est.tech>2024-11-05 13:44:45 +0000
commita1a71f782f2db1b50a41f095d49c981f5095b4fb (patch)
treef915a69c83d74ce7ecf2f0735cff5951a4f4368c /cps-ncmp-service/src/test
parentc475188530572efedbcb606239da0cdcee48c05b (diff)
Support Alternate-Id for CPS-E05 data batch interface
Issue-ID: CPS-2274 Change-Id: I75163bc7943fca5cbbe8c24601a2dfc184a9e6cc Signed-off-by: seanbeirne <sean.beirne@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/test')
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/DmiDataOperationsSpec.groovy6
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/NcmpDatastoreRequestHandlerSpec.groovy4
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/utils/DmiDataOperationsHelperSpec.groovy23
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/dmi/DmiOperationsBaseSpec.groovy2
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImplSpec.groovy38
-rw-r--r--cps-ncmp-service/src/test/resources/dataOperationRequest.json11
6 files changed, 55 insertions, 29 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/DmiDataOperationsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/DmiDataOperationsSpec.groovy
index fd76abb581..b046c12387 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/DmiDataOperationsSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/DmiDataOperationsSpec.groovy
@@ -112,7 +112,7 @@ class DmiDataOperationsSpec extends DmiOperationsBaseSpec {
mockYangModelCmHandleCollectionRetrieval([yangModelCmHandleProperty])
def dataOperationBatchRequestJsonData = TestUtils.getResourceFileContent('dataOperationRequest.json')
def dataOperationRequest = spiedJsonObjectMapper.convertJsonString(dataOperationBatchRequestJsonData, DataOperationRequest.class)
- dataOperationRequest.dataOperationDefinitions[0].cmHandleIds = [cmHandleId]
+ dataOperationRequest.dataOperationDefinitions[0].cmHandleReferences = [cmHandleId]
and: 'a positive response from DMI service when it is called with valid request parameters'
def responseFromDmi = Mono.just(new ResponseEntity<Object>(HttpStatus.ACCEPTED))
def expectedUrlTemplateWithVariables = new UrlTemplateParameters('myServiceName/dmi/v1/data?requestId={requestId}&topic={topic}', ['requestId': 'requestId', 'topic': 'my-topic-name'])
@@ -129,7 +129,7 @@ class DmiDataOperationsSpec extends DmiOperationsBaseSpec {
mockYangModelCmHandleCollectionRetrieval([yangModelCmHandleProperty])
def dataOperationBatchRequestJsonData = TestUtils.getResourceFileContent('dataOperationRequest.json')
def dataOperationRequest = spiedJsonObjectMapper.convertJsonString(dataOperationBatchRequestJsonData, DataOperationRequest.class)
- dataOperationRequest.dataOperationDefinitions[0].cmHandleIds = [cmHandleId]
+ dataOperationRequest.dataOperationDefinitions[0].cmHandleReferences = [cmHandleId]
and: 'the published cloud event will be captured'
def actualDataOperationCloudEvent = null
eventsPublisher.publishCloudEvent('my-topic-name', 'my-request-id', _) >> { args -> actualDataOperationCloudEvent = args[2] }
@@ -143,7 +143,7 @@ class DmiDataOperationsSpec extends DmiOperationsBaseSpec {
assert eventDataValue.statusMessage == UNKNOWN_ERROR.message
and: 'the event contains the correct operation details'
assert eventDataValue.operationId == dataOperationRequest.dataOperationDefinitions[0].operationId
- assert eventDataValue.ids == dataOperationRequest.dataOperationDefinitions[0].cmHandleIds
+ assert eventDataValue.ids == dataOperationRequest.dataOperationDefinitions[0].cmHandleReferences
}
def 'call get all resource data.'() {
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/NcmpDatastoreRequestHandlerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/NcmpDatastoreRequestHandlerSpec.groovy
index d5db24cc33..d5f705f2fd 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/NcmpDatastoreRequestHandlerSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/NcmpDatastoreRequestHandlerSpec.groovy
@@ -73,7 +73,7 @@ class NcmpDatastoreRequestHandlerSpec extends Specification {
and: 'notification feature is turned on/off'
objectUnderTest.notificationFeatureEnabled = notificationFeatureEnabled
when: 'data operation request is executed'
- def dataOperationDefinition = new DataOperationDefinition(operation: 'read', datastore: 'ncmp-datastore:passthrough-running', cmHandleIds: ['ch'])
+ def dataOperationDefinition = new DataOperationDefinition(operation: 'read', datastore: 'ncmp-datastore:passthrough-running', cmHandleReferences: ['ch'])
def result = objectUnderTest.executeAsynchronousRequest('someTopic', new DataOperationRequest(dataOperationDefinitions:[dataOperationDefinition]), NO_AUTH_HEADER)
then: 'the task is executed in an async fashion or not'
expectedCalls * dmiDataOperations.requestResourceDataFromDmi('someTopic', _, _, NO_AUTH_HEADER)
@@ -120,7 +120,7 @@ class NcmpDatastoreRequestHandlerSpec extends Specification {
given: 'a data operation definition with too many cm handles'
def tooMany = objectUnderTest.MAXIMUM_CM_HANDLES_PER_OPERATION + 1
def cmHandleIds = new String[tooMany]
- def dataOperationDefinition = new DataOperationDefinition(operationId: 'abc', operation: 'read', datastore: 'ncmp-datastore:passthrough-running', cmHandleIds: cmHandleIds)
+ def dataOperationDefinition = new DataOperationDefinition(operationId: 'abc', operation: 'read', datastore: 'ncmp-datastore:passthrough-running', cmHandleReferences: cmHandleIds)
when: 'data operation request is executed'
objectUnderTest.executeAsynchronousRequest('someTopic', new DataOperationRequest(dataOperationDefinitions:[dataOperationDefinition]), NO_AUTH_HEADER)
then: 'a payload too large exception is thrown'
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/utils/DmiDataOperationsHelperSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/utils/DmiDataOperationsHelperSpec.groovy
index 84eafb0da3..77e2c4fa25 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/utils/DmiDataOperationsHelperSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/utils/DmiDataOperationsHelperSpec.groovy
@@ -74,15 +74,16 @@ class DmiDataOperationsHelperSpec extends MessagingBaseSpec {
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 {
+ assert dmiDataOperationRequestBodyAsJsonNode.get('cmHandles').size() == expectedCmHandleReferences.size()
+ expectedCmHandleReferences.each {
dmiDataOperationRequestBodyAsJsonNode.get('cmHandles').toString().contains(it)
}
where: 'the following dmi service and operations are checked'
- serviceName | operationIndex || expectedOperationId | expectedDatastore | expectedCmHandleIds
+ serviceName | operationIndex || expectedOperationId | expectedDatastore | expectedCmHandleReferences
'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']
+ 'dmi1' | 3 || 'operational-16' | 'ncmp-datastore:passthrough-operational' | ['alt6-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']
@@ -137,14 +138,14 @@ class DmiDataOperationsHelperSpec extends MessagingBaseSpec {
def dmiProperties = [new YangModelCmHandle.Property('prop', 'some DMI property')]
def readyState = new CompositeStateBuilder().withCmHandleState(READY).withLastUpdatedTimeNow().build()
def advisedState = new CompositeStateBuilder().withCmHandleState(ADVISED).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),
- new YangModelCmHandle(id: 'non-ready-cm-handle', dmiServiceName: 'dmi2', dmiProperties: dmiProperties, compositeState: advisedState)
+ return [new YangModelCmHandle(id: 'ch1-dmi1', 'alternateId': 'alt1-dmi1', dmiServiceName: 'dmi1', dmiProperties: dmiProperties, compositeState: readyState),
+ new YangModelCmHandle(id: 'ch2-dmi1', 'alternateId': 'alt2-dmi1', dmiServiceName: 'dmi1', dmiProperties: dmiProperties, compositeState: readyState),
+ new YangModelCmHandle(id: 'ch6-dmi1', 'alternateId': 'alt6-dmi1', dmiServiceName: 'dmi1', dmiProperties: dmiProperties, compositeState: readyState),
+ new YangModelCmHandle(id: 'ch8-dmi1', 'alternateId': 'alt8-dmi1', dmiServiceName: 'dmi1', dmiProperties: dmiProperties, compositeState: readyState),
+ new YangModelCmHandle(id: 'ch3-dmi2', 'alternateId': 'alt3-dmi2', dmiServiceName: 'dmi2', dmiProperties: dmiProperties, compositeState: readyState),
+ new YangModelCmHandle(id: 'ch4-dmi2', 'alternateId': 'alt4-dmi2', dmiServiceName: 'dmi2', dmiProperties: dmiProperties, compositeState: readyState),
+ new YangModelCmHandle(id: 'ch7-dmi2', 'alternateId': 'alt7-dmi2', dmiServiceName: 'dmi2', dmiProperties: dmiProperties, compositeState: readyState),
+ new YangModelCmHandle(id: 'non-ready-cm-handle', 'alternateId': 'non-ready-alternate', dmiServiceName: 'dmi2', dmiProperties: dmiProperties, compositeState: advisedState)
]
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/dmi/DmiOperationsBaseSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/dmi/DmiOperationsBaseSpec.groovy
index 65fda8718c..d00d3ab8f6 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/dmi/DmiOperationsBaseSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/dmi/DmiOperationsBaseSpec.groovy
@@ -61,7 +61,7 @@ abstract class DmiOperationsBaseSpec extends Specification {
def mockYangModelCmHandleCollectionRetrieval(dmiProperties) {
populateYangModelCmHandle(dmiProperties, '')
- mockInventoryPersistence.getYangModelCmHandles(_) >> [yangModelCmHandle]
+ mockInventoryPersistence.getYangModelCmHandlesFromCmHandleReferences(_) >> [yangModelCmHandle]
}
def populateYangModelCmHandle(dmiProperties, moduleSetTag) {
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImplSpec.groovy
index e2261f4b7c..34d9374f78 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImplSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImplSpec.groovy
@@ -38,7 +38,6 @@ import org.onap.cps.spi.model.ModuleDefinition
import org.onap.cps.spi.model.ModuleReference
import org.onap.cps.utils.ContentType
import org.onap.cps.utils.JsonObjectMapper
-import org.testcontainers.shaded.com.fasterxml.jackson.databind.introspect.BasicClassIntrospector
import spock.lang.Shared
import spock.lang.Specification
@@ -75,12 +74,16 @@ class InventoryPersistenceImplSpec extends Specification {
.format(OffsetDateTime.of(2022, 12, 31, 20, 30, 40, 1, ZoneOffset.UTC))
def cmHandleId = 'some-cm-handle'
- def leaves = ["id":cmHandleId,"dmi-service-name":"common service name","dmi-data-service-name":"data service name","dmi-model-service-name":"model service name"]
+ def alternateId = 'some-alternate-id'
+ def leaves = ["id":cmHandleId, "alternateId":alternateId,"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 alternateId2 = 'another-alternate-id'
def xpath2 = "/dmi-registry/cm-handles[@id='another-cm-handle']"
+ def dataNode = new DataNode(xpath: "/dmi-registry/cm-handles[@id='some cm handle']/additional-properties[@name='name1']", leaves: ["name":"name1", "value":"value1"])
+
@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"])]
@@ -135,7 +138,7 @@ class InventoryPersistenceImplSpec extends Specification {
1 * mockCpsValidator.validateNameCharacters(cmHandleId)
}
- def "Retrieve multiple YangModelCmHandles"() {
+ def "Retrieve multiple YangModelCmHandles using cm handle ids"() {
given: 'the cps data service returns 2 data nodes from the DMI registry'
def dataNodes = [new DataNode(xpath: xpath, leaves: ['id': cmHandleId]), new DataNode(xpath: xpath2, leaves: ['id': cmHandleId2])]
mockCpsDataService.getDataNodesForMultipleXpaths(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, [xpath, xpath2] , INCLUDE_ALL_DESCENDANTS) >> dataNodes
@@ -146,6 +149,17 @@ class InventoryPersistenceImplSpec extends Specification {
assert results.id.containsAll([cmHandleId, cmHandleId2])
}
+ def "Retrieve multiple YangModelCmHandles using cm handle references"() {
+ given: 'the cps data service returns 2 data nodes from the DMI registry'
+ def dataNodes = [new DataNode(xpath: xpath, leaves: ['id': cmHandleId, 'alternate-id':alternateId]), new DataNode(xpath: xpath2, leaves: ['id': cmHandleId2,'alternate-id':alternateId2])]
+ mockCmHandleQueries.queryNcmpRegistryByCpsPath(_, INCLUDE_ALL_DESCENDANTS) >> dataNodes
+ when: 'retrieving the yang modelled cm handle'
+ def results = objectUnderTest.getYangModelCmHandlesFromCmHandleReferences([cmHandleId, cmHandleId2])
+ then: 'verify both have returned and cmhandleIds are correct'
+ assert results.size() == 2
+ assert results.id.containsAll([cmHandleId, cmHandleId2])
+ }
+
def 'Get a Cm Handle Composite State'() {
given: 'a valid cm handle id'
def cmHandleId = 'Some-Cm-Handle'
@@ -317,15 +331,6 @@ class InventoryPersistenceImplSpec extends Specification {
assert thrownException.getMessage().contains('DataNode not found')
}
- def 'Get multiple cm handle data nodes by alternate ids'() {
- given: 'expected xPath to get cmHandle data node'
- def expectedXPath = "/dmi-registry/cm-handles[@alternate-id='A' or @alternate-id='B']"
- when: 'getting the cm handle data node'
- objectUnderTest.getCmHandleDataNodesByAlternateIds(['A', 'B'])
- then: 'query service is invoked with expected xpath'
- 1 * mockCmHandleQueries.queryNcmpRegistryByCpsPath(expectedXPath, OMIT_DESCENDANTS)
- }
-
def 'Get multiple cm handle data nodes by alternate ids, passing empty collection'() {
when: 'getting the cm handle data node for no alternate ids'
objectUnderTest.getCmHandleDataNodesByAlternateIds([])
@@ -372,4 +377,13 @@ class InventoryPersistenceImplSpec extends Specification {
then: 'the cps data service method to delete data nodes is invoked once with the same xPaths'
1 * mockCpsDataService.deleteDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, ['xpath1', 'xpath2'], NO_TIMESTAMP);
}
+
+ def 'Check if cm handle exists for a given cm handle id'() {
+ given: 'data service returns a datanode with correct cm handle id'
+ mockCpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, xpath, INCLUDE_ALL_DESCENDANTS) >> [dataNode]
+ when: 'method is called to check if cm handle exists from cm handle id'
+ def result = objectUnderTest.isExistingCmHandleId('some-cm-handle')
+ then: 'check if cm handle id in datanode is equal to given cm handle id'
+ assert result == true
+ }
}
diff --git a/cps-ncmp-service/src/test/resources/dataOperationRequest.json b/cps-ncmp-service/src/test/resources/dataOperationRequest.json
index f69b87631f..3faaf2b0dc 100644
--- a/cps-ncmp-service/src/test/resources/dataOperationRequest.json
+++ b/cps-ncmp-service/src/test/resources/dataOperationRequest.json
@@ -36,6 +36,17 @@
"ch4-dmi2",
"ch6-dmi1"
]
+ },
+ {
+ "operation": "read",
+ "operationId": "operational-16",
+ "datastore": "ncmp-datastore:passthrough-operational",
+ "options": "some option",
+ "resourceIdentifier": "some resource identifier",
+ "targetIds": [
+ "ch4-dmi2",
+ "alt6-dmi1"
+ ]
}
]
}