summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/test/groovy
diff options
context:
space:
mode:
authorDylanB95EST <dylan.byrne@est.tech>2021-12-14 16:34:38 +0000
committerDylanB95EST <dylan.byrne@est.tech>2022-01-28 14:32:11 +0000
commit63132cec2c18363a8224646039cc23b6144d8e6c (patch)
tree0821e401a14655ecba60d213f5dbacac12e8f0b4 /cps-ncmp-service/src/test/groovy
parenta5ce86d02493f141848f9d609c65883d2198894a (diff)
Support 'public' Cm Handle Properties
Add support for new Public Additional Properties list to Register CM Handles API Issue-ID: CPS-677 Change-Id: I6efc88734da2416f72f71a403622e519398b502d Signed-off-by: DylanB95EST <dylan.byrne@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/NetworkCmProxyDataServiceImplModelSyncSpec.groovy32
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy17
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy90
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiDataOperationsSpec.groovy25
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiModelOperationsSpec.groovy59
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiOperationsBaseSpec.groovy28
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/PersistenceCmHandleRetrieverSpec.groovy39
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/PersistenceCmHandleSpec.groovy33
8 files changed, 167 insertions, 156 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplModelSyncSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplModelSyncSpec.groovy
index 464757158f..67108a5fe1 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplModelSyncSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplModelSyncSpec.groovy
@@ -24,6 +24,7 @@ import org.onap.cps.api.CpsAdminService
import org.onap.cps.api.CpsModuleService
import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations
import org.onap.cps.ncmp.api.impl.operations.DmiModelOperations
+import org.onap.cps.ncmp.api.models.CmHandle
import org.onap.cps.ncmp.api.models.PersistenceCmHandle
import org.onap.cps.spi.model.ModuleReference
import org.onap.cps.utils.JsonObjectMapper
@@ -44,30 +45,29 @@ class NetworkCmProxyDataServiceImplModelSyncSpec extends Specification {
def 'Sync model for a (new) cm handle with #scenario'() {
given: 'persistence cm handle is given'
- def cmHandleForModelSync = new PersistenceCmHandle(id:'some cm handle', dmiServiceName: 'some service name')
- and: 'additional properties are set as required'
- if (additionalProperties!=null) {
- cmHandleForModelSync.asAdditionalProperties(additionalProperties)
- }
- and: 'dmi operations returns some module references'
+ def cmHandle = new CmHandle()
+ def dmiServiceName = 'some service name'
+ cmHandle.cmHandleID = 'cm handle id 1'
+ cmHandle.dmiProperties = dmiProperties
+ def persistenceCmHandle = PersistenceCmHandle.toPersistenceCmHandle(dmiServiceName, '' , '', cmHandle)
+ and: 'DMI operations returns some module references'
def moduleReferences = [ new ModuleReference(moduleName:'module1',revision:'1'),
new ModuleReference(moduleName:'module2',revision:'2') ]
- mockDmiModelOperations.getModuleReferences(cmHandleForModelSync) >> moduleReferences
+ mockDmiModelOperations.getModuleReferences(persistenceCmHandle) >> moduleReferences
and: 'CPS-Core returns list of existing module resources'
mockCpsModuleService.getYangResourceModuleReferences(expectedDataspaceName) >> existingModuleResourcesInCps
and: 'DMI-Plugin returns resource(s) for "new" module(s)'
- mockDmiModelOperations.getNewYangResourcesFromDmi(cmHandleForModelSync, [new ModuleReference('module1', '1')]) >> yangResourceToContentMap
+ mockDmiModelOperations.getNewYangResourcesFromDmi(persistenceCmHandle, [new ModuleReference('module1', '1')]) >> yangResourceToContentMap
when: 'module sync is triggered'
- objectUnderTest.syncModulesAndCreateAnchor(cmHandleForModelSync)
+ objectUnderTest.syncModulesAndCreateAnchor(persistenceCmHandle)
then: 'the CPS module service is called once with the correct parameters'
- 1 * mockCpsModuleService.createSchemaSetFromModules(expectedDataspaceName, cmHandleForModelSync.getId(), yangResourceToContentMap, expectedKnownModules)
+ 1 * mockCpsModuleService.createSchemaSetFromModules(expectedDataspaceName, persistenceCmHandle.getId(), yangResourceToContentMap, expectedKnownModules)
and: 'admin service create anchor method has been called with correct parameters'
- 1 * mockCpsAdminService.createAnchor(expectedDataspaceName, cmHandleForModelSync.getId(), cmHandleForModelSync.getId())
+ 1 * mockCpsAdminService.createAnchor(expectedDataspaceName, persistenceCmHandle.getId(), persistenceCmHandle.getId())
where: 'the following parameters are used'
- scenario | additionalProperties | existingModuleResourcesInCps | yangResourceToContentMap || expectedKnownModules | expectedJsonForAdditionalProperties
- 'one unknown module' | ['name1': 'value1'] | [new ModuleReference('module2', '2'), new ModuleReference('module3', '3')] | [module1: 'some yang source'] || [new ModuleReference('module2', '2')] | '{"name1":"value1"}'
- 'no add. properties' | [:] | [new ModuleReference('module2', '2'), new ModuleReference('module3', '3')] | [module1: 'some yang source'] || [new ModuleReference('module2', '2')] | '{}'
- 'additional properties is null' | null | [new ModuleReference('module2', '2'), new ModuleReference('module3', '3')] | [module1: 'some yang source'] || [new ModuleReference('module2', '2')] | '{}'
- 'no unknown module' | [:] | [new ModuleReference('module1', '1'), new ModuleReference('module2', '2')] | [:] || [new ModuleReference('module1', '1'), new ModuleReference('module2', '2')] | '{}'
+ scenario | dmiProperties | existingModuleResourcesInCps | yangResourceToContentMap || expectedKnownModules
+ 'one unknown module' | ['name1': 'value1'] | [new ModuleReference('module2', '2'), new ModuleReference('module3', '3')] | [module1: 'some yang source'] || [new ModuleReference('module2', '2')]
+ 'no add. properties' | [:] | [new ModuleReference('module2', '2'), new ModuleReference('module3', '3')] | [module1: 'some yang source'] || [new ModuleReference('module2', '2')]
+ 'no unknown module' | [:] | [new ModuleReference('module1', '1'), new ModuleReference('module2', '2')] | [:] || [new ModuleReference('module1', '1'), new ModuleReference('module2', '2')]
}
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy
index b954b41ef2..3ec6f3a00d 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy
@@ -60,11 +60,15 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
def objectUnderTest = getObjectUnderTestWithModelSyncDisabled()
def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin:'my-server')
persistenceCmHandle.cmHandleID = '123'
- persistenceCmHandle.cmHandleProperties = [name1: 'value1', name2: 'value2']
+ persistenceCmHandle.dmiProperties = [dmiProp1: 'dmiValue1', dmiProp2: 'dmiValue2']
+ persistenceCmHandle.publicProperties = [publicProp1: 'publicValue1', publicProp2: 'publicValue2' ]
dmiPluginRegistration.createdCmHandles = createdCmHandles
dmiPluginRegistration.updatedCmHandles = updatedCmHandles
dmiPluginRegistration.removedCmHandles = removedCmHandles
- def expectedJsonData = '{"cm-handles":[{"id":"123","dmi-service-name":"my-server","dmi-data-service-name":null,"dmi-model-service-name":null,"additional-properties":[{"name":"name1","value":"value1"},{"name":"name2","value":"value2"}]}]}'
+ def expectedJsonData = '{"cm-handles":[{"id":"123","dmi-service-name":"my-server","dmi-data-service-name":null,"dmi-model-service-name":null,' +
+ '"additional-properties":[{"name":"dmiProp1","value":"dmiValue1"},{"name":"dmiProp2","value":"dmiValue2"}],' +
+ '"public-properties":[{"name":"publicProp1","value":"publicValue1"},{"name":"publicProp2","value":"publicValue2"}]' +
+ '}]}'
when: 'registration is updated and modules are synced'
objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
then: 'save list elements is invoked with the expected parameters'
@@ -87,14 +91,15 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
'no valid data' | null | null | null || 0 | 0 | 0
}
- def 'Register a DMI Plugin for the given cm-handle(s) without additional properties.'() {
+ def 'Register a DMI Plugin for the given cm-handle(s) without DMI properties.'() {
given: 'a registration without cm-handle properties'
NetworkCmProxyDataServiceImpl objectUnderTest = getObjectUnderTestWithModelSyncDisabled()
def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin:'my-server')
persistenceCmHandle.cmHandleID = '123'
- persistenceCmHandle.cmHandleProperties = null
+ persistenceCmHandle.dmiProperties = Collections.emptyMap()
+ persistenceCmHandle.publicProperties = Collections.emptyMap()
dmiPluginRegistration.createdCmHandles = [persistenceCmHandle]
- def expectedJsonData = '{"cm-handles":[{"id":"123","dmi-service-name":"my-server","dmi-data-service-name":null,"dmi-model-service-name":null,"additional-properties":[]}]}'
+ def expectedJsonData = '{"cm-handles":[{"id":"123","dmi-service-name":"my-server","dmi-data-service-name":null,"dmi-model-service-name":null,"additional-properties":[],"public-properties":[]}]}'
when: 'registration is updated'
objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
then: 'save list elements is invoked with the expected parameters'
@@ -163,7 +168,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
'data & model using same service' | '' | 'service1' | 'service1'
}
- def 'Invalid dmi plugin registration with #scenario'() {
+ def 'Invalid DMI plugin registration with #scenario'() {
given: 'a registration '
def objectUnderTest = getObjectUnderTestWithModelSyncDisabled()
def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin:dmiPlugin, dmiModelPlugin:dmiModelPlugin,
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 51af0f55e1..7f127003d2 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
@@ -57,34 +57,28 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
def cmHandleXPath = "/dmi-registry/cm-handles[@id='testCmHandle']"
+ def dataNode = new DataNode(leaves: ['dmi-service-name': 'testDmiService'])
- def 'Write resource data for pass-through running from dmi using POST #scenario cm handle properties.'() {
- given: 'a data node'
- def dataNode = getDataNode(includeCmHandleProperties)
- and: 'cpsDataService returns valid datanode'
+
+ def 'Write resource data for pass-through running from DMI using POST #scenario cm handle properties.'() {
+ given: 'cpsDataService returns valid datanode'
mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
when: 'get resource data is called'
objectUnderTest.writeResourceDataPassThroughRunningForCmHandle('testCmHandle',
'testResourceId', CREATE,
'{some-json}', 'application/json')
- then: 'dmi called with correct data'
+ then: 'DMI called with correct data'
1 * mockDmiDataOperations.writeResourceDataPassThroughRunningFromDmi('testCmHandle', 'testResourceId',
CREATE, '{some-json}', 'application/json')
>> { new ResponseEntity<>(HttpStatus.CREATED) }
- where:
- scenario | includeCmHandleProperties || expectedJsonForCmhandleProperties
- 'with' | true || '{"testName":"testValue"}'
- 'without' | false || '{}'
}
- def 'Write resource data for pass-through running from dmi using POST "not found" response (from DMI).'() {
- given: 'a data node'
- def dataNode = getDataNode(true)
- and: 'cpsDataService returns valid dataNode'
+ def 'Write resource data for pass-through running from DMI using POST "not found" response (from DMI).'() {
+ given: 'cpsDataService returns valid dataNode'
mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
- and: 'dmi returns a response with 404 status code'
+ and: 'DMI returns a response with 404 status code'
mockDmiDataOperations.writeResourceDataPassThroughRunningFromDmi('testCmHandle',
'testResourceId', CREATE,
'{some-json}', 'application/json')
@@ -100,13 +94,11 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
}
- def 'Get resource data for pass-through operational from dmi.'() {
- given: 'a data node'
- def dataNode = getDataNode(true)
- and: 'get data node is called'
+ def 'Get resource data for pass-through operational from DMI.'() {
+ given: 'get data node is called'
mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
- and: 'get resource data from dmi is called'
+ and: 'get resource data from DMI is called'
mockDmiDataOperations.getResourceDataFromDmi(
'testCmHandle',
'testResourceId',
@@ -118,19 +110,17 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
'testResourceId',
'testAcceptParam',
'(a=1,b=2)')
- then: 'dmi returns a json response'
+ then: 'DMI returns a json response'
response == 'result-json'
}
- def 'Get resource data for pass-through operational from dmi with Json Processing Exception.'() {
- given: 'a data node'
- def dataNode = getDataNode(true)
- and: 'cps data service returns valid data node'
+ def 'Get resource data for pass-through operational from DMI with Json Processing Exception.'() {
+ given: 'cps data service returns valid data node'
mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
and: 'objectMapper not able to parse object'
spiedJsonObjectMapper.asJsonString(_) >> { throw new JsonProcessingException('testException') }
- and: 'dmi returns NOK response'
+ and: 'DMI returns NOK response'
mockDmiDataOperations.getResourceDataFromDmi(*_)
>> new ResponseEntity<>('NOK-json', HttpStatus.NOT_FOUND)
when: 'get resource data is called'
@@ -143,13 +133,11 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
exceptionThrown.details == 'DMI status code: 404, DMI response body: NOK-json'
}
- def 'Get resource data for pass-through operational from dmi return NOK response.'() {
- given: 'a data node'
- def dataNode = getDataNode(true)
- and: 'cps data service returns valid data node'
+ def 'Get resource data for pass-through operational from DMI return NOK response.'() {
+ given: 'cps data service returns valid data node'
mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
- and: 'dmi returns NOK response'
+ and: 'DMI returns NOK response'
mockDmiDataOperations.getResourceDataFromDmi('testCmHandle',
'testResourceId',
'(a=1,b=2)',
@@ -167,13 +155,11 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
exceptionThrown.details.contains('NOK-json')
}
- def 'Get resource data for pass-through running from dmi.'() {
- given: 'a data node'
- def dataNode = getDataNode(true)
- and: 'cpsDataService returns valid data node'
+ def 'Get resource data for pass-through running from DMI.'() {
+ given: 'cpsDataService returns valid data node'
mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
- and: 'dmi returns valid response and data'
+ and: 'DMI returns valid response and data'
mockDmiDataOperations.getResourceDataFromDmi('testCmHandle',
'testResourceId',
'(a=1,b=2)',
@@ -188,13 +174,11 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
response == '{result-json}'
}
- def 'Get resource data for pass-through running from dmi return NOK response.'() {
- given: 'a data node'
- def dataNode = getDataNode(true)
- and: 'cpsDataService returns valid dataNode'
+ def 'Get resource data for pass-through running from DMI return NOK response.'() {
+ given: 'cpsDataService returns valid dataNode'
mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
- and: 'dmi returns NOK response'
+ and: 'DMI returns NOK response'
mockDmiDataOperations.getResourceDataFromDmi('testCmHandle',
'testResourceId',
'(a=1,b=2)',
@@ -226,25 +210,18 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
1 * mockCpsAdminService.queryAnchorNames('NFP-Operational', ['some-module-name'])
}
-
- def 'Update resource data for pass-through running from dmi using POST #scenario cm handle properties.'() {
- given: 'a data node'
- def dataNode = getDataNode(includeCmHandleProperties)
- and: 'cpsDataService returns valid datanode'
+ def 'Update resource data for pass-through running from dmi using POST #scenario DMI properties.'() {
+ given: 'cpsDataService returns valid datanode'
mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
when: 'get resource data is called'
objectUnderTest.writeResourceDataPassThroughRunningForCmHandle('testCmHandle',
'testResourceId', UPDATE,
'{some-json}', 'application/json')
- then: 'dmi called with correct data'
+ then: 'DMI called with correct data'
1 * mockDmiDataOperations.writeResourceDataPassThroughRunningFromDmi('testCmHandle', 'testResourceId',
UPDATE, '{some-json}', 'application/json')
>> { new ResponseEntity<>(HttpStatus.OK) }
- where:
- scenario | includeCmHandleProperties || expectedJsonForCmhandleProperties
- 'with' | true || '{"testName":"testValue"}'
- 'without' | false || '{}'
}
def 'Verify error message from handleResponse is correct for #scenario operation.'() {
@@ -252,7 +229,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
mockDmiDataOperations.writeResourceDataPassThroughRunningFromDmi(*_)
>> new ResponseEntity<>(HttpStatus.NOT_FOUND)
when: 'get resource data is called'
- def response = objectUnderTest.writeResourceDataPassThroughRunningForCmHandle(
+ objectUnderTest.writeResourceDataPassThroughRunningForCmHandle(
'testCmHandle',
'testResourceId',
givenOperation,
@@ -267,15 +244,4 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
'READ' | READ || 'Not able to read resource data.'
'UPDATE' | UPDATE || 'Not able to update resource data.'
}
-
- def getDataNode(boolean includeCmHandleProperties) {
- def dataNode = new DataNode()
- dataNode.leaves = ['dmi-service-name': 'testDmiService']
- if (includeCmHandleProperties) {
- def cmHandlePropertyDataNode = new DataNode()
- cmHandlePropertyDataNode.leaves = ['name': 'testName', 'value': 'testValue']
- dataNode.childDataNodes = [cmHandlePropertyDataNode]
- }
- return dataNode
- }
}
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 54ae0aa6fe..7873f39bbd 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
@@ -47,30 +47,29 @@ class DmiDataOperationsSpec extends DmiOperationsBaseSpec {
def 'call get resource data for #expectedDatastoreInUrl from DMI #scenario.'() {
given: 'a persistence cm handle for #cmHandleId'
- mockPersistenceCmHandleRetrieval(additionalProperties)
- and: 'a positive response from dmi service when it is called with the expected parameters'
+ mockPersistenceCmHandleRetrieval(dmiProperties)
+ and: 'a positive response from DMI service when it is called with the expected parameters'
def responseFromDmi = new ResponseEntity<Object>(HttpStatus.OK)
mockDmiRestClient.postOperationWithJsonData(
"${dmiServiceName}/dmi/v1/ch/${cmHandleId}/data/ds/ncmp-datastore:${expectedDatastoreInUrl}?resourceIdentifier=${resourceIdentifier}${expectedOptionsInUrl}",
expectedJson, [Accept:['sample accept header']]) >> responseFromDmi
when: 'get resource data is invoked'
def result = objectUnderTest.getResourceDataFromDmi(cmHandleId,resourceIdentifier, options,'sample accept header', dataStore)
- then: 'the result is the response from the dmi service'
+ then: 'the result is the response from the DMI service'
assert result == responseFromDmi
where: 'the following parameters are used'
- scenario | additionalProperties | dataStore | options || expectedJson | expectedDatastoreInUrl | expectedOptionsInUrl
- 'without properties' | [] | PASSTHROUGH_OPERATIONAL | '(a=1,b=2)' || '{"operation":"read","cmHandleProperties":{}}' | 'passthrough-operational' | '&options=(a=1,b=2)'
- 'null properties' | null | PASSTHROUGH_OPERATIONAL | '(a=1,b=2)' || '{"operation":"read","cmHandleProperties":{}}' | 'passthrough-operational' | '&options=(a=1,b=2)'
- 'with properties' | [sampleAdditionalProperty] | PASSTHROUGH_OPERATIONAL | '(a=1,b=2)' || '{"operation":"read","cmHandleProperties":{"prop1":"val1"}}' | 'passthrough-operational' | '&options=(a=1,b=2)'
- 'null options' | [sampleAdditionalProperty] | PASSTHROUGH_OPERATIONAL | null || '{"operation":"read","cmHandleProperties":{"prop1":"val1"}}' | 'passthrough-operational' | ''
- 'empty options' | [sampleAdditionalProperty] | PASSTHROUGH_OPERATIONAL | '' || '{"operation":"read","cmHandleProperties":{"prop1":"val1"}}' | 'passthrough-operational' | ''
- 'datastore running' | [] | PASSTHROUGH_RUNNING | '(a=1,b=2)' || '{"operation":"read","cmHandleProperties":{}}' | 'passthrough-running' | '&options=(a=1,b=2)'
+ scenario | dmiProperties | dataStore | options || expectedJson | expectedDatastoreInUrl | expectedOptionsInUrl
+ 'without properties' | [] | PASSTHROUGH_OPERATIONAL | '(a=1,b=2)' || '{"operation":"read","cmHandleProperties":{}}' | 'passthrough-operational' | '&options=(a=1,b=2)'
+ 'with properties' | [dmiSampleProperty] | PASSTHROUGH_OPERATIONAL | '(a=1,b=2)' || '{"operation":"read","cmHandleProperties":{"prop1":"val1"}}' | 'passthrough-operational' | '&options=(a=1,b=2)'
+ 'null options' | [dmiSampleProperty] | PASSTHROUGH_OPERATIONAL | null || '{"operation":"read","cmHandleProperties":{"prop1":"val1"}}' | 'passthrough-operational' | ''
+ 'empty options' | [dmiSampleProperty] | PASSTHROUGH_OPERATIONAL | '' || '{"operation":"read","cmHandleProperties":{"prop1":"val1"}}' | 'passthrough-operational' | ''
+ 'datastore running' | [] | PASSTHROUGH_RUNNING | '(a=1,b=2)' || '{"operation":"read","cmHandleProperties":{}}' | 'passthrough-running' | '&options=(a=1,b=2)'
}
def 'Write data for pass-through:running datastore in DMI.'() {
given: 'a persistence cm handle for #cmHandleId'
- mockPersistenceCmHandleRetrieval([sampleAdditionalProperty])
- and: 'a positive response from dmi service when it is called with the expected parameters'
+ mockPersistenceCmHandleRetrieval([dmiSampleProperty])
+ and: 'a positive response from DMI service when it is called with the expected parameters'
def expectedUrl = "${dmiServiceName}/dmi/v1/ch/${cmHandleId}/data/ds" +
"/ncmp-datastore:passthrough-running?resourceIdentifier=${resourceIdentifier}"
def expectedJson = '{"operation":"' + expectedOperationInUrl + '","dataType":"some data type","data":"requestData","cmHandleProperties":{"prop1":"val1"}}'
@@ -78,7 +77,7 @@ class DmiDataOperationsSpec extends DmiOperationsBaseSpec {
mockDmiRestClient.postOperationWithJsonData(expectedUrl, expectedJson, [:]) >> responseFromDmi
when: 'write resource method is invoked'
def result = objectUnderTest.writeResourceDataPassThroughRunningFromDmi(cmHandleId,'parent/child', operation, 'requestData', 'some data type')
- then: 'the result is the response from the dmi service'
+ then: 'the result is the response from the DMI service'
assert result == responseFromDmi
where: 'the following operation is performed'
operation || expectedOperationInUrl
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiModelOperationsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiModelOperationsSpec.groovy
index 2efd6c2b3a..bd5fe6f87c 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiModelOperationsSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiModelOperationsSpec.groovy
@@ -49,7 +49,7 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
def 'Retrieving module references.'() {
given: 'a persistence cm handle'
mockPersistenceCmHandleRetrieval([])
- and: 'a positive response from dmi service when it is called with the expected parameters'
+ and: 'a positive response from DMI service when it is called with the expected parameters'
def moduleReferencesAsLisOfMaps = [[moduleName:'mod1',revision:'A'],[moduleName:'mod2',revision:'X']]
def responseFromDmi = new ResponseEntity([schemas:moduleReferencesAsLisOfMaps], HttpStatus.OK)
mockDmiRestClient.postOperationWithJsonData("${dmiServiceName}/dmi/v1/ch/${cmHandleId}/modules",
@@ -63,7 +63,7 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
def 'Retrieving module references edge case: #scenario.'() {
given: 'a persistence cm handle'
mockPersistenceCmHandleRetrieval([])
- and: 'any response from dmi service when it is called with the expected parameters'
+ and: 'any response from DMI service when it is called with the expected parameters'
// TODO (toine): production code ignores any error code from DMI, this should be improved in future
def responseFromDmi = new ResponseEntity(bodyAsMap, HttpStatus.NO_CONTENT)
mockDmiRestClient.postOperationWithJsonData(*_) >> responseFromDmi
@@ -71,7 +71,7 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
def result = objectUnderTest.getModuleReferences(persistenceCmHandle)
then: 'the result is empty'
assert result == []
- where: 'the dmi response body has the following content'
+ where: 'the DMI response body has the following content'
scenario | bodyAsMap
'no modules' | [schemas:[]]
'modules null' | [schemas:null]
@@ -79,34 +79,33 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
'no body' | null
}
- def 'Retrieving module references, additional property handling: #scenario.'() {
+ def 'Retrieving module references, DMI property handling: #scenario.'() {
given: 'a persistence cm handle'
- mockPersistenceCmHandleRetrieval(additionalPropertiesObject)
- and: 'a positive response from dmi service when it is called with tha expected parameters'
+ mockPersistenceCmHandleRetrieval(dmiProperties)
+ and: 'a positive response from DMI service when it is called with tha expected parameters'
def responseFromDmi = new ResponseEntity<String>(HttpStatus.OK)
mockDmiRestClient.postOperationWithJsonData("${dmiServiceName}/dmi/v1/ch/${cmHandleId}/modules",
'{"cmHandleProperties":' + expectedAdditionalPropertiesInRequest + '}', [:]) >> responseFromDmi
when: 'a get module references is called'
def result = objectUnderTest.getModuleReferences(persistenceCmHandle)
- then: 'the result is the response from dmi service'
+ then: 'the result is the response from DMI service'
assert result == []
- where: 'the following additional properties are used'
- scenario | additionalPropertiesObject || expectedAdditionalPropertiesInRequest
- 'with properties' | [sampleAdditionalProperty] || '{"prop1":"val1"}'
- 'with null properties' | null || '{}'
- 'without properties' | [] || '{}'
+ where: 'the following DMI properties are used'
+ scenario | dmiProperties || expectedAdditionalPropertiesInRequest
+ 'with properties' | [dmiSampleProperty] || '{"prop1":"val1"}'
+ 'without properties' | [] || '{}'
}
def 'Retrieving yang resources.'() {
given: 'a persistence cm handle'
mockPersistenceCmHandleRetrieval([])
- and: 'a positive response from dmi service when it is called with tha expected parameters'
+ and: 'a positive response from DMI service when it is called with the expected parameters'
def responseFromDmi = new ResponseEntity([[moduleName: 'mod1', revision: 'A', yangSource: 'some yang source'],
[moduleName: 'mod2', revision: 'C', yangSource: 'other yang source']], HttpStatus.OK)
def expectedModuleReferencesInRequest = '{"name":"mod1","revision":"A"},{"name":"mod2","revision":"X"}'
mockDmiRestClient.postOperationWithJsonData("${dmiServiceName}/dmi/v1/ch/${cmHandleId}/moduleResources",
'{"data":{"modules":[' + expectedModuleReferencesInRequest + ']},"cmHandleProperties":{}}', [:]) >> responseFromDmi
- when: 'get new yang resources from dmi service'
+ when: 'get new yang resources from DMI service'
def result = objectUnderTest.getNewYangResourcesFromDmi(persistenceCmHandle, newModuleReferences)
then: 'the result has the 2 expected yang (re)sources (order is not guaranteed)'
assert result.size() == 2
@@ -117,43 +116,43 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
def 'Retrieving yang resources, edge case: scenario.'() {
given: 'a persistence cm handle'
mockPersistenceCmHandleRetrieval([])
- and: 'a positive response from dmi service when it is called with tha expected parameters'
+ and: 'a positive response from DMI service when it is called with tha expected parameters'
// TODO (toine): production code ignores any error code from DMI, this should be improved in future
def responseFromDmi = new ResponseEntity(responseFromDmiBody, HttpStatus.NO_CONTENT)
mockDmiRestClient.postOperationWithJsonData(*_) >> responseFromDmi
- when: 'get new yang resources from dmi service'
+ when: 'get new yang resources from DMI service'
def result = objectUnderTest.getNewYangResourcesFromDmi(persistenceCmHandle, newModuleReferences)
then: 'the result is empty'
assert result == [:]
- where: 'the dmi response body has the following content'
+ where: 'the DMI response body has the following content'
scenario | responseFromDmiBody
'empty array' | []
'null array' | null
}
- def 'Retrieving yang resources, additional property handling #scenario.'() {
+ def 'Retrieving yang resources, DMI property handling #scenario.'() {
given: 'a persistence cm handle'
- mockPersistenceCmHandleRetrieval(additionalPropertiesObject)
- and: 'a positive response from dmi service when it is called with the expected parameters'
+ mockPersistenceCmHandleRetrieval(dmiProperties)
+ and: 'a positive response from DMI service when it is called with the expected parameters'
def responseFromDmi = new ResponseEntity<>([[moduleName: 'mod1', revision: 'A', yangSource: 'some yang source']], HttpStatus.OK)
mockDmiRestClient.postOperationWithJsonData("${dmiServiceName}/dmi/v1/ch/${cmHandleId}/moduleResources",
'{"data":{"modules":[' + expectedModuleReferencesInRequest + ']},"cmHandleProperties":'+expectedAdditionalPropertiesInRequest+'}',
[:]) >> responseFromDmi
- when: 'get new yang resources from dmi service'
+ when: 'get new yang resources from DMI service'
def result = objectUnderTest.getNewYangResourcesFromDmi(persistenceCmHandle, unknownModuleReferences)
- then: 'the result is the response from dmi service'
+ then: 'the result is the response from DMI service'
assert result == [mod1:'some yang source']
- where: 'the following additional properties are used'
- scenario | additionalPropertiesObject | unknownModuleReferences || expectedAdditionalPropertiesInRequest | expectedModuleReferencesInRequest
- 'with module references and properties' | [sampleAdditionalProperty] | newModuleReferences || '{"prop1":"val1"}' | '{"name":"mod1","revision":"A"},{"name":"mod2","revision":"X"}'
- 'without module references' | [sampleAdditionalProperty] | [] || '{"prop1":"val1"}' | ''
- 'without properties' | [] | newModuleReferences || '{}' | '{"name":"mod1","revision":"A"},{"name":"mod2","revision":"X"}'
+ where: 'the following DMI properties are used'
+ scenario | dmiProperties | unknownModuleReferences || expectedAdditionalPropertiesInRequest | expectedModuleReferencesInRequest
+ 'with module references and properties' | [dmiSampleProperty] | newModuleReferences || '{"prop1":"val1"}' | '{"name":"mod1","revision":"A"},{"name":"mod2","revision":"X"}'
+ 'without module references' | [dmiSampleProperty] | [] || '{"prop1":"val1"}' | ''
+ 'without properties' | [] | newModuleReferences || '{}' | '{"name":"mod1","revision":"A"},{"name":"mod2","revision":"X"}'
}
- def 'Retrieving yang resources from dmi with additional properties null.'() {
+ def 'Retrieving yang resources from DMI with null DMI properties.'() {
given: 'a persistence cm handle'
mockPersistenceCmHandleRetrieval(null)
- when: 'a get new yang resources from dmi is called'
+ when: 'a get new yang resources from DMI is called'
objectUnderTest.getNewYangResourcesFromDmi(persistenceCmHandle, [])
then: 'a null pointer is thrown (we might need to address this later)'
thrown(NullPointerException)
@@ -164,7 +163,7 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
mockPersistenceCmHandleRetrieval([])
and: 'a Json processing exception occurs'
spiedJsonObjectMapper.asJsonString(_) >> {throw (new JsonProcessingException('parsing error'))}
- when: 'a dmi operation is executed'
+ when: 'a DMI operation is executed'
objectUnderTest.getModuleReferences(persistenceCmHandle)
then: 'an ncmp exception is thrown'
def exceptionThrown = thrown(JsonProcessingException)
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiOperationsBaseSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiOperationsBaseSpec.groovy
index 4bf7dad8b9..7b295f68b1 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiOperationsBaseSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiOperationsBaseSpec.groovy
@@ -1,3 +1,23 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021-2022 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.operations
import com.fasterxml.jackson.databind.ObjectMapper
@@ -10,7 +30,7 @@ import spock.lang.Specification
abstract class DmiOperationsBaseSpec extends Specification {
@Shared
- def sampleAdditionalProperty = new PersistenceCmHandle.AdditionalProperty('prop1', 'val1')
+ def dmiSampleProperty = new PersistenceCmHandle.Property('prop1', 'val1')
@SpringBean
DmiRestClient mockDmiRestClient = Mock()
@@ -26,11 +46,11 @@ abstract class DmiOperationsBaseSpec extends Specification {
def static cmHandleId = 'some cm handle'
def static resourceIdentifier = 'parent/child'
- def mockPersistenceCmHandleRetrieval(additionalProperties) {
+ def mockPersistenceCmHandleRetrieval(dmiProperties) {
persistenceCmHandle.dmiDataServiceName = dmiServiceName
persistenceCmHandle.dmiServiceName = dmiServiceName
- persistenceCmHandle.additionalProperties = additionalProperties
+ persistenceCmHandle.dmiProperties = dmiProperties
persistenceCmHandle.id = cmHandleId
- mockCmHandlePropertiesRetriever.retrieveCmHandleDmiServiceNameAndProperties(cmHandleId) >> persistenceCmHandle
+ mockCmHandlePropertiesRetriever.retrieveCmHandleDmiServiceNameAndDmiProperties(cmHandleId) >> persistenceCmHandle
}
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/PersistenceCmHandleRetrieverSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/PersistenceCmHandleRetrieverSpec.groovy
index 3ab9266ba4..c92234f9a6 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/PersistenceCmHandleRetrieverSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/PersistenceCmHandleRetrieverSpec.groovy
@@ -1,3 +1,23 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021-2022 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.operations
import org.onap.cps.api.CpsDataService
@@ -19,26 +39,25 @@ class PersistenceCmHandleRetrieverSpec extends Specification {
def xpath = "/dmi-registry/cm-handles[@id='some cm handle']"
@Shared
- def childDataNodesForCmHandleProperties = [new DataNode(leaves: ["name":"name1","value":"value1"]),
- new DataNode(leaves: ["name":"name2","value":"value2"])]
+ def childDataNodesForCmHandleProperties = [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"])]
def "Retrieve CmHandle using datanode #scenario."() {
- given: 'the cps data service returns a data node from the dmi registry'
+ given: 'the cps data service returns a data node from the DMI registry'
def dataNode = new DataNode(childDataNodes:childDataNodes, leaves: leaves)
mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry', xpath, INCLUDE_ALL_DESCENDANTS) >> dataNode
when: 'retrieving the persisted cm handle'
- def result = objectUnderTest.retrieveCmHandleDmiServiceNameAndProperties(cmHandleId)
+ def result = objectUnderTest.retrieveCmHandleDmiServiceNameAndDmiProperties(cmHandleId)
then: 'the result has the correct id and service names'
result.id == cmHandleId
result.dmiServiceName == 'common service name'
result.dmiDataServiceName == 'data service name'
result.dmiModelServiceName == 'model service name'
- and: 'the expected additional properties'
- result.additionalProperties == expectedCmHandleProperties
+ and: 'the expected DMI properties'
+ result.dmiProperties == expectedCmHandleProperties
where: 'the following parameters are used'
- scenario | childDataNodes || expectedCmHandleProperties
- 'without additional properties' | [] || []
- 'with additional properties' | childDataNodesForCmHandleProperties || [new PersistenceCmHandle.AdditionalProperty("name1", "value1"),
- new PersistenceCmHandle.AdditionalProperty("name2", "value2")]
+ scenario | childDataNodes || expectedCmHandleProperties
+ 'without DMI properties' | [] || []
+ 'with DMI properties' | childDataNodesForCmHandleProperties || [new PersistenceCmHandle.Property("name1", "value1")]
}
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/PersistenceCmHandleSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/PersistenceCmHandleSpec.groovy
index c66eaa9b42..49de4422e5 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/PersistenceCmHandleSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/PersistenceCmHandleSpec.groovy
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation
+ * Copyright (C) 2021-2022 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
+
package org.onap.cps.ncmp.api.models
import spock.lang.Specification
@@ -26,24 +27,26 @@ import static org.onap.cps.ncmp.api.impl.operations.RequiredDmiService.MODEL
class PersistenceCmHandleSpec extends Specification {
- def 'Setting and getting additional properties.'() {
- given: 'a map of one property is added'
- def objectUnderTest = new PersistenceCmHandle()
- objectUnderTest.asAdditionalProperties([myProperty: 'some value'])
- when: 'the additional properties are retrieved'
- def result = objectUnderTest.getAdditionalProperties()
+ def 'Creating persistence cm handle from a cm handle.'() {
+ given: 'a cm handle with properties'
+ def cmHandle = new CmHandle()
+ cmHandle.dmiProperties = [myDmiProperty:'value1']
+ cmHandle.publicProperties = [myPublicProperty:'value2']
+ when: 'it is converted to a persistence cm handle'
+ def objectUnderTest = PersistenceCmHandle.toPersistenceCmHandle('','','', cmHandle)
then: 'the result has the right size'
- assert result.size() == 1
- and: 'the property in the result has the correct name and value'
- def actualAdditionalProperty = result.get(0)
- def expectedAdditionalProperty = new PersistenceCmHandle.AdditionalProperty('myProperty','some value')
- assert actualAdditionalProperty.name == expectedAdditionalProperty.name
- assert actualAdditionalProperty.value == expectedAdditionalProperty.value
+ assert objectUnderTest.dmiProperties.size() == 1
+ and: 'the DMI property in the result has the correct name and value'
+ assert objectUnderTest.dmiProperties[0].name == 'myDmiProperty'
+ assert objectUnderTest.dmiProperties[0].value == 'value1'
+ and: 'the public property in the result has the correct name and value'
+ assert objectUnderTest.publicProperties[0].name == 'myPublicProperty'
+ assert objectUnderTest.publicProperties[0].value == 'value2'
}
- def 'Resolve dmi service name: #scenario and #requiredService service require.'() {
+ def 'Resolve DMI service name: #scenario and #requiredService service require.'() {
given: 'a Persistence CM Handle'
- def objectUnderTest = PersistenceCmHandle.toPersistenceCmHandle(dmiServiceName, dmiDataServiceName, dmiModelServiceName, new CmHandle('some id', null))
+ def objectUnderTest = PersistenceCmHandle.toPersistenceCmHandle(dmiServiceName, dmiDataServiceName, dmiModelServiceName, new CmHandle())
expect:
assert objectUnderTest.resolveDmiServiceName(requiredService) == expectedService
where: