aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/test
diff options
context:
space:
mode:
authorDaniel Hanrahan <daniel.hanrahan@est.tech>2025-01-28 15:00:33 +0000
committerGerrit Code Review <gerrit@onap.org>2025-01-28 15:00:33 +0000
commitff8da28caba2d287376966eff92653e749c2f25c (patch)
treec94dae8343bc3e94e21d5a64f4998f260d4baad3 /cps-ncmp-service/src/test
parent8ea43417708c3858b0d590d68fdb1f9a3e192410 (diff)
parentd91020d983c686977158d0900eddda9f2bb1058c (diff)
Merge "Send new module set tag to DMI during model upgrade"
Diffstat (limited to 'cps-ncmp-service/src/test')
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/DmiModelOperationsSpec.groovy69
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncServiceSpec.groovy12
2 files changed, 46 insertions, 35 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/DmiModelOperationsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/DmiModelOperationsSpec.groovy
index 714555958a..302e43f170 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/DmiModelOperationsSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/DmiModelOperationsSpec.groovy
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2024 Nordix Foundation
+ * Copyright (C) 2021-2025 Nordix Foundation
* Modifications Copyright (C) 2022 Bell Canada
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,14 +21,11 @@
package org.onap.cps.ncmp.impl.inventory.sync
-import com.fasterxml.jackson.core.JsonProcessingException
-import com.fasterxml.jackson.databind.ObjectMapper
import org.onap.cps.ncmp.impl.dmi.DmiOperationsBaseSpec
import org.onap.cps.ncmp.impl.dmi.DmiProperties
import org.onap.cps.ncmp.impl.utils.http.UrlTemplateParameters
import org.onap.cps.api.model.ModuleReference
import org.onap.cps.utils.JsonObjectMapper
-import org.spockframework.spring.SpringBean
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.http.HttpStatus
@@ -40,9 +37,12 @@ import static org.onap.cps.ncmp.api.data.models.OperationType.READ
import static org.onap.cps.ncmp.impl.models.RequiredDmiService.MODEL
@SpringBootTest
-@ContextConfiguration(classes = [DmiProperties, DmiModelOperations])
+@ContextConfiguration(classes = [DmiProperties, DmiModelOperations, JsonObjectMapper])
class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
+ def NO_AUTH_HEADER = null
+ def NO_MODULE_SET_TAG = ''
+
def expectedModulesUrlTemplateWithVariables = new UrlTemplateParameters('myServiceName/dmi/v1/ch/{cmHandleId}/modules', ['cmHandleId': cmHandleId])
def expectedModuleResourcesUrlTemplateWithVariables = new UrlTemplateParameters('myServiceName/dmi/v1/ch/{cmHandleId}/moduleResources', ['cmHandleId': cmHandleId])
@@ -52,11 +52,6 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
@Autowired
DmiModelOperations objectUnderTest
- @SpringBean
- JsonObjectMapper spiedJsonObjectMapper = Spy(new JsonObjectMapper(new ObjectMapper()))
-
- def NO_AUTH_HEADER = null
-
def 'Retrieving module references.'() {
given: 'a cm handle'
mockYangModelCmHandleRetrieval([])
@@ -65,7 +60,7 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
def responseFromDmi = new ResponseEntity([schemas: moduleReferencesAsLisOfMaps], HttpStatus.OK)
mockDmiRestClient.synchronousPostOperationWithJsonData(MODEL, expectedModulesUrlTemplateWithVariables, '{"cmHandleProperties":{},"moduleSetTag":""}', READ, NO_AUTH_HEADER) >> responseFromDmi
when: 'get module references is called'
- def result = objectUnderTest.getModuleReferences(yangModelCmHandle)
+ def result = objectUnderTest.getModuleReferences(yangModelCmHandle, NO_MODULE_SET_TAG)
then: 'the result consists of expected module references'
assert result == [new ModuleReference(moduleName: 'mod1', revision: 'A'), new ModuleReference(moduleName: 'mod2', revision: 'X')]
}
@@ -78,7 +73,7 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
def responseFromDmi = new ResponseEntity(bodyAsMap, HttpStatus.NO_CONTENT)
mockDmiRestClient.synchronousPostOperationWithJsonData(*_) >> responseFromDmi
when: 'get module references is called'
- def result = objectUnderTest.getModuleReferences(yangModelCmHandle)
+ def result = objectUnderTest.getModuleReferences(yangModelCmHandle, NO_MODULE_SET_TAG)
then: 'the result is empty'
assert result == []
where: 'the DMI response body has the following content'
@@ -97,7 +92,7 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
mockDmiRestClient.synchronousPostOperationWithJsonData(MODEL, expectedModulesUrlTemplateWithVariables,
'{"cmHandleProperties":' + expectedAdditionalPropertiesInRequest + ',"moduleSetTag":""}', READ, NO_AUTH_HEADER) >> responseFromDmi
when: 'a get module references is called'
- def result = objectUnderTest.getModuleReferences(yangModelCmHandle)
+ def result = objectUnderTest.getModuleReferences(yangModelCmHandle, NO_MODULE_SET_TAG)
then: 'the result is the response from DMI service'
assert result == []
where: 'the following DMI properties are used'
@@ -116,7 +111,7 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
mockDmiRestClient.synchronousPostOperationWithJsonData(MODEL, expectedModuleResourcesUrlTemplateWithVariables,
'{"data":{"modules":[' + expectedModuleReferencesInRequest + ']},"cmHandleProperties":{}}', READ, NO_AUTH_HEADER) >> responseFromDmi
when: 'get new yang resources from DMI service'
- def result = objectUnderTest.getNewYangResourcesFromDmi(yangModelCmHandle, newModuleReferences)
+ def result = objectUnderTest.getNewYangResourcesFromDmi(yangModelCmHandle, NO_MODULE_SET_TAG, newModuleReferences)
then: 'the result has the 2 expected yang (re)sources (order is not guaranteed)'
assert result.size() == 2
assert result.get('mod1') == 'some yang source'
@@ -131,7 +126,7 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
def responseFromDmi = new ResponseEntity(responseFromDmiBody, HttpStatus.NO_CONTENT)
mockDmiRestClient.synchronousPostOperationWithJsonData(*_) >> responseFromDmi
when: 'get new yang resources from DMI service'
- def result = objectUnderTest.getNewYangResourcesFromDmi(yangModelCmHandle, newModuleReferences)
+ def result = objectUnderTest.getNewYangResourcesFromDmi(yangModelCmHandle, NO_MODULE_SET_TAG, newModuleReferences)
then: 'the result is empty'
assert result == [:]
where: 'the DMI response body has the following content'
@@ -149,7 +144,7 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
'{"data":{"modules":[{"name":"mod1","revision":"A"},{"name":"mod2","revision":"X"}]},"cmHandleProperties":' + expectedAdditionalPropertiesInRequest + '}',
READ, NO_AUTH_HEADER) >> responseFromDmi
when: 'get new yang resources from DMI service'
- def result = objectUnderTest.getNewYangResourcesFromDmi(yangModelCmHandle, newModuleReferences)
+ def result = objectUnderTest.getNewYangResourcesFromDmi(yangModelCmHandle, NO_MODULE_SET_TAG, newModuleReferences)
then: 'the result is the response from DMI service'
assert result == [mod1:'some yang source']
where: 'the following DMI properties are used'
@@ -166,7 +161,7 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
mockDmiRestClient.synchronousPostOperationWithJsonData(MODEL, expectedModuleResourcesUrlTemplateWithVariables,
'{' + expectedModuleSetTagInRequest + '"data":{"modules":[{"name":"mod1","revision":"A"},{"name":"mod2","revision":"X"}]},"cmHandleProperties":{}}', READ, NO_AUTH_HEADER) >> responseFromDmi
when: 'get new yang resources from DMI service'
- def result = objectUnderTest.getNewYangResourcesFromDmi(yangModelCmHandle, newModuleReferences)
+ def result = objectUnderTest.getNewYangResourcesFromDmi(yangModelCmHandle, moduleSetTag, newModuleReferences)
then: 'the result is the response from DMI service'
assert result == [mod1:'some yang source']
where: 'the following Module Set Tags are used'
@@ -180,7 +175,7 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
given: 'a cm handle'
mockYangModelCmHandleRetrieval([])
when: 'a get new yang resources from DMI is called with no module references'
- def result = objectUnderTest.getNewYangResourcesFromDmi(yangModelCmHandle, [])
+ def result = objectUnderTest.getNewYangResourcesFromDmi(yangModelCmHandle, NO_MODULE_SET_TAG, [])
then: 'no resources are returned'
assert result == [:]
and: 'no request is sent to DMI'
@@ -191,21 +186,35 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
given: 'a cm handle'
mockYangModelCmHandleRetrieval(null)
when: 'a get new yang resources from DMI is called'
- objectUnderTest.getNewYangResourcesFromDmi(yangModelCmHandle, [new ModuleReference('mod1', 'A')])
+ objectUnderTest.getNewYangResourcesFromDmi(yangModelCmHandle, NO_MODULE_SET_TAG, [new ModuleReference('mod1', 'A')])
then: 'a null pointer is thrown (we might need to address this later)'
thrown(NullPointerException)
}
- def 'Retrieving module references with Json processing exception.'() {
- given: 'a cm handle'
- mockYangModelCmHandleRetrieval([])
- and: 'a Json processing exception occurs'
- spiedJsonObjectMapper.asJsonString(_) >> {throw (new JsonProcessingException('parsing error'))}
- when: 'a DMI operation is executed'
- objectUnderTest.getModuleReferences(yangModelCmHandle)
- then: 'an ncmp exception is thrown'
- def exceptionThrown = thrown(JsonProcessingException)
- and: 'the message indicates a parsing error'
- exceptionThrown.message.toLowerCase().contains('parsing error')
+ def 'Retrieving module references forwards the new module set tag to DMI during CM-handle upgrade.'() {
+ given: 'a cm handle with an existing module set tag'
+ mockYangModelCmHandleRetrieval([], 'OLD-TAG')
+ when: 'get module references is called'
+ objectUnderTest.getModuleReferences(yangModelCmHandle, 'NEW-TAG')
+ then: 'a request was sent to DMI with the NEW module set tag in the body'
+ 1 * mockDmiRestClient.synchronousPostOperationWithJsonData(*_) >> { args ->
+ def requestBodyAsJson = args[2] as String
+ assert requestBodyAsJson.contains('"moduleSetTag":"NEW-TAG"')
+ return new ResponseEntity([schemas: [[moduleName: 'mod1', revision: 'A'], [moduleName: 'mod2', revision: 'X']]], HttpStatus.OK)
+ }
+ }
+
+ def 'Retrieving yang resources forwards the new module set tag to DMI during CM-handle upgrade.'() {
+ given: 'a cm handle with an existing module set tag'
+ mockYangModelCmHandleRetrieval([], 'OLD-TAG')
+ when: 'get new yang resources from DMI service'
+ objectUnderTest.getNewYangResourcesFromDmi(yangModelCmHandle, 'NEW-TAG', newModuleReferences)
+ then: 'a request was sent to DMI with the NEW module set tag in the body'
+ 1 * mockDmiRestClient.synchronousPostOperationWithJsonData(*_) >> { args ->
+ def requestBodyAsJson = args[2] as String
+ assert requestBodyAsJson.contains('"moduleSetTag":"NEW-TAG"')
+ return new ResponseEntity([[moduleName: 'mod1', revision: 'A', yangSource: 'some yang source'],
+ [moduleName: 'mod2', revision: 'X', yangSource: 'other yang source']], HttpStatus.OK)
+ }
}
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncServiceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncServiceSpec.groovy
index 868609e282..b4837f7bab 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncServiceSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncServiceSpec.groovy
@@ -39,6 +39,8 @@ import static org.onap.cps.ncmp.api.inventory.models.LockReasonCategory.MODULE_U
class ModuleSyncServiceSpec extends Specification {
+ def NO_MODULE_SET_TAG = ''
+
def mockCpsModuleService = Mock(CpsModuleService)
def mockDmiModelOperations = Mock(DmiModelOperations)
def mockCpsAnchorService = Mock(CpsAnchorService)
@@ -53,9 +55,9 @@ class ModuleSyncServiceSpec extends Specification {
def yangModelCmHandle = createAdvisedCmHandle(moduleSetTag)
and: 'DMI operations returns some module references'
def moduleReferences = [ new ModuleReference('module1','1'), new ModuleReference('module2','2') ]
- mockDmiModelOperations.getModuleReferences(yangModelCmHandle) >> moduleReferences
+ mockDmiModelOperations.getModuleReferences(yangModelCmHandle, moduleSetTag) >> moduleReferences
and: 'DMI-Plugin returns resource(s) for "new" module(s)'
- mockDmiModelOperations.getNewYangResourcesFromDmi(yangModelCmHandle, identifiedNewModuleReferences) >> newModuleNameContentToMap
+ mockDmiModelOperations.getNewYangResourcesFromDmi(yangModelCmHandle, moduleSetTag, identifiedNewModuleReferences) >> newModuleNameContentToMap
and: 'the module service identifies #identifiedNewModuleReferences.size() new modules'
mockCpsModuleService.identifyNewModuleReferences(moduleReferences) >> identifiedNewModuleReferences
when: 'module sync is triggered'
@@ -140,8 +142,8 @@ class ModuleSyncServiceSpec extends Specification {
def yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle(dmiServiceName, '', '', ncmpServiceCmHandle,'', '', '')
and: 'DMI operations returns some module references for upgraded cm handle'
def moduleReferences = [ new ModuleReference('module1','1') ]
- mockDmiModelOperations.getModuleReferences(yangModelCmHandle) >> moduleReferences
- mockDmiModelOperations.getNewYangResourcesFromDmi(_, []) >> [:]
+ mockDmiModelOperations.getModuleReferences(yangModelCmHandle, NO_MODULE_SET_TAG) >> moduleReferences
+ mockDmiModelOperations.getNewYangResourcesFromDmi(_, NO_MODULE_SET_TAG, []) >> [:]
and: 'none of these module references are new (all already known to the system)'
mockCpsModuleService.identifyNewModuleReferences(_) >> []
when: 'module sync is triggered'
@@ -163,7 +165,7 @@ class ModuleSyncServiceSpec extends Specification {
mockCpsModuleService.schemaSetExists(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, tagTo) >> schemaExists
and: 'DMI operations returns some module references for upgraded cm handle'
def moduleReferences = [ new ModuleReference('module1','1') ]
- expectedCallsToDmi * mockDmiModelOperations.getModuleReferences(yangModelCmHandle) >> moduleReferences
+ expectedCallsToDmi * mockDmiModelOperations.getModuleReferences(yangModelCmHandle, tagTo) >> moduleReferences
and: 'dmi returns no new yang resources'
mockDmiModelOperations.getNewYangResourcesFromDmi(*_) >> [:]
and: 'none of these module references are new (all already known to the system)'