diff options
author | Daniel Hanrahan <daniel.hanrahan@est.tech> | 2024-08-21 13:08:35 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2024-08-21 13:08:35 +0000 |
commit | de1aaf34503726c923a9b9e29598c7e817e492e7 (patch) | |
tree | 83db5ac41b4b3f9a747c06fbab70ff6f56945ece /cps-ncmp-service/src/test/groovy/org | |
parent | 580fb73de1a1647abfcae156455fd4d299c2907f (diff) | |
parent | 48ecbae87d0a72b408b2ed8690ce5dc71a76a06d (diff) |
Merge "Revert "Remove trust level entries from cache when cm handles deleted""
Diffstat (limited to 'cps-ncmp-service/src/test/groovy/org')
5 files changed, 27 insertions, 69 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationServiceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationServiceSpec.groovy index dcff2e9b89..0c702abea6 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationServiceSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationServiceSpec.groovy @@ -59,12 +59,13 @@ class CmHandleRegistrationServiceSpec extends Specification { def mockLcmEventsCmHandleStateHandler = Mock(LcmEventsCmHandleStateHandler) def mockCpsDataService = Mock(CpsDataService) def mockModuleSyncStartedOnCmHandles = Mock(IMap<String, Object>) + def trustLevelPerDmiPlugin = [:] def mockTrustLevelManager = Mock(TrustLevelManager) def mockAlternateIdChecker = Mock(AlternateIdChecker) def objectUnderTest = Spy(new CmHandleRegistrationService( mockNetworkCmProxyDataServicePropertyHandler, mockInventoryPersistence, mockCpsDataService, mockLcmEventsCmHandleStateHandler, - mockModuleSyncStartedOnCmHandles, mockTrustLevelManager, mockAlternateIdChecker)) + mockModuleSyncStartedOnCmHandles, trustLevelPerDmiPlugin , mockTrustLevelManager, mockAlternateIdChecker)) def setup() { // always accept all cm handles @@ -142,6 +143,9 @@ class CmHandleRegistrationServiceSpec extends Specification { objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration) then: 'create cm handles registration and sync modules is called with the correct plugin information' 1 * objectUnderTest.processCreatedCmHandles(dmiPluginRegistration, _) + and: 'dmi is added to the dmi trustLevel map' + assert trustLevelPerDmiPlugin.size() == 1 + assert trustLevelPerDmiPlugin.containsKey(expectedDmiPluginRegisteredName) where: scenario | dmiPlugin | dmiModelPlugin | dmiDataPlugin || expectedDmiPluginRegisteredName 'combined DMI plugin' | 'service1' | '' | '' || 'service1' @@ -208,7 +212,7 @@ class CmHandleRegistrationServiceSpec extends Specification { when: 'registration is updated' objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration) then: 'trustLevel is set for the created cm-handle' - 1 * mockTrustLevelManager.registerCmHandles(expectedMapping) + 1 * mockTrustLevelManager.handleInitialRegistrationOfTrustLevels(expectedMapping) where: scenario | registrationTrustLevel || expectedMapping 'with trusted cm handle' | TrustLevel.COMPLETE || [ 'ch-1' : TrustLevel.COMPLETE ] diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/NetworkCmProxyInventoryFacadeSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/NetworkCmProxyInventoryFacadeSpec.groovy index 739b2e8c2a..716efd8fdb 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/NetworkCmProxyInventoryFacadeSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/NetworkCmProxyInventoryFacadeSpec.groovy @@ -35,7 +35,6 @@ import org.onap.cps.ncmp.api.inventory.models.TrustLevel import org.onap.cps.ncmp.impl.inventory.models.CmHandleState import org.onap.cps.ncmp.impl.inventory.models.LockReasonCategory import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle -import org.onap.cps.ncmp.impl.inventory.trustlevel.TrustLevelManager import org.onap.cps.spi.model.ConditionProperties import org.onap.cps.utils.JsonObjectMapper import spock.lang.Specification @@ -47,9 +46,9 @@ class NetworkCmProxyInventoryFacadeSpec extends Specification { def mockParameterizedCmHandleQueryService = Mock(ParameterizedCmHandleQueryService) def spiedJsonObjectMapper = Spy(new JsonObjectMapper(new ObjectMapper())) def mockInventoryPersistence = Mock(InventoryPersistence) - def mockTrustLevelManager = Mock(TrustLevelManager) + def trustLevelPerCmHandle = [:] - def objectUnderTest = new NetworkCmProxyInventoryFacade(mockCmHandleRegistrationService, mockCmHandleQueryService, mockParameterizedCmHandleQueryService, mockInventoryPersistence, spiedJsonObjectMapper, mockTrustLevelManager) + def objectUnderTest = new NetworkCmProxyInventoryFacade(mockCmHandleRegistrationService, mockCmHandleQueryService, mockParameterizedCmHandleQueryService, mockInventoryPersistence, spiedJsonObjectMapper, trustLevelPerCmHandle) def 'Update DMI Registration'() { given: 'an (updated) dmi plugin registration' @@ -111,7 +110,7 @@ class NetworkCmProxyInventoryFacadeSpec extends Specification { publicProperties: publicProperties, compositeState: compositeState, moduleSetTag: moduleSetTag, alternateId: alternateId) 1 * mockInventoryPersistence.getYangModelCmHandle('ch-1') >> yangModelCmHandle and: 'a trust level for the cm handle in the cache' - mockTrustLevelManager.getEffectiveTrustLevel('ch-1') >> TrustLevel.COMPLETE + trustLevelPerCmHandle.put('ch-1', TrustLevel.COMPLETE) when: 'getting cm handle details for a given cm handle id from ncmp service' def result = objectUnderTest.getNcmpServiceCmHandle('ch-1') then: 'the result is a ncmpServiceCmHandle' @@ -206,7 +205,7 @@ class NetworkCmProxyInventoryFacadeSpec extends Specification { spiedJsonObjectMapper.convertToValueType(cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class)) >> [new NcmpServiceCmHandle(cmHandleId: 'ch-0'), new NcmpServiceCmHandle(cmHandleId: 'ch-1')] and: ' a trust level for ch-1' - mockTrustLevelManager.getEffectiveTrustLevel('ch-1') >> TrustLevel.COMPLETE + trustLevelPerCmHandle.put('ch-1', TrustLevel.COMPLETE) when: 'execute cm handle search is called' def result = objectUnderTest.executeCmHandleSearch(cmHandleQueryApiParameters) then: 'result consists of the two cm handles returned by the CPS Data Service' diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/DeviceTrustLevelMessageConsumerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/DeviceTrustLevelMessageConsumerSpec.groovy index c7d0616bb2..6db304acd1 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/DeviceTrustLevelMessageConsumerSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/DeviceTrustLevelMessageConsumerSpec.groovy @@ -49,7 +49,7 @@ class DeviceTrustLevelMessageConsumerSpec extends Specification { when: 'the event is consumed' objectUnderTest.deviceTrustLevelListener(consumerRecord) then: 'cm handles are stored with correct trust level' - 1 * mockTrustLevelManager.updateCmHandleTrustLevel('"ch-1"', TrustLevel.COMPLETE) + 1 * mockTrustLevelManager.handleUpdateOfDeviceTrustLevel('"ch-1"', TrustLevel.COMPLETE) } def createTrustLevelEvent(eventPayload) { diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/DmiPluginTrustLevelWatchDogSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/DmiPluginTrustLevelWatchDogSpec.groovy index d4c1f54ee8..0a34d267c5 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/DmiPluginTrustLevelWatchDogSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/DmiPluginTrustLevelWatchDogSpec.groovy @@ -46,7 +46,7 @@ class DmiPluginTrustLevelWatchDogSpec extends Specification { when: 'dmi watch dog method runs' objectUnderTest.checkDmiAvailability() then: 'the update delegated to manager' - numberOfCalls * mockTrustLevelManager.updateDmi('dmi-1', _, newDmiTrustLevel) + numberOfCalls * mockTrustLevelManager.handleUpdateOfDmiTrustLevel('dmi-1', _, newDmiTrustLevel) where: 'the following parameters are used' dmiHealhStatus | dmiOldTrustLevel | newDmiTrustLevel || numberOfCalls 'UP' | TrustLevel.COMPLETE | TrustLevel.COMPLETE || 0 diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelManagerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelManagerSpec.groovy index b017c8bcbd..b5bfbc165c 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelManagerSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelManagerSpec.groovy @@ -20,7 +20,6 @@ package org.onap.cps.ncmp.impl.inventory.trustlevel -import org.onap.cps.ncmp.api.inventory.models.DmiPluginRegistration import org.onap.cps.ncmp.api.inventory.models.TrustLevel import org.onap.cps.ncmp.impl.inventory.InventoryPersistence import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle @@ -36,20 +35,11 @@ class TrustLevelManagerSpec extends Specification { def mockAttributeValueChangeEventPublisher = Mock(CmAvcEventPublisher) def objectUnderTest = new TrustLevelManager(trustLevelPerCmHandle, trustLevelPerDmiPlugin, mockInventoryPersistence, mockAttributeValueChangeEventPublisher) - def 'Initial dmi registration'() { - given: 'a dmi plugin' - def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'dmi-1') - when: 'method to register to the cache is called' - objectUnderTest.registerDmiPlugin(dmiPluginRegistration) - then: 'dmi plugin in the cache and trusted' - assert trustLevelPerDmiPlugin.get('dmi-1') == TrustLevel.COMPLETE - } - def 'Initial cm handle registration'() { given: 'two cm handles: one with no trust level and one trusted' def cmHandleModelsToBeCreated = ['ch-1': null, 'ch-2': TrustLevel.COMPLETE] - when: 'method to register to the cache is called' - objectUnderTest.registerCmHandles(cmHandleModelsToBeCreated) + when: 'the initial registration handled' + objectUnderTest.handleInitialRegistrationOfTrustLevels(cmHandleModelsToBeCreated) then: 'no notification sent' 0 * mockAttributeValueChangeEventPublisher.publishAvcEvent(*_) and: 'both cm handles are in the cache and are trusted' @@ -60,8 +50,8 @@ class TrustLevelManagerSpec extends Specification { def 'Initial cm handle registration with a cm handle that is not trusted'() { given: 'a not trusted cm handle' def cmHandleModelsToBeCreated = ['ch-2': TrustLevel.NONE] - when: 'method to register to the cache is called' - objectUnderTest.registerCmHandles(cmHandleModelsToBeCreated) + when: 'the initial registration handled' + objectUnderTest.handleInitialRegistrationOfTrustLevels(cmHandleModelsToBeCreated) then: 'notification is sent' 1 * mockAttributeValueChangeEventPublisher.publishAvcEvent(*_) } @@ -72,7 +62,7 @@ class TrustLevelManagerSpec extends Specification { and: 'a trusted cm handle' trustLevelPerCmHandle.put('ch-1', TrustLevel.COMPLETE) when: 'the update is handled' - objectUnderTest.updateDmi('my-dmi', ['ch-1'], TrustLevel.NONE) + objectUnderTest.handleUpdateOfDmiTrustLevel('my-dmi', ['ch-1'], TrustLevel.NONE) then: 'notification is sent' 1 * mockAttributeValueChangeEventPublisher.publishAvcEvent('ch-1', 'trustLevel', 'COMPLETE', 'NONE') and: 'the dmi in the cache is not trusted' @@ -85,89 +75,54 @@ class TrustLevelManagerSpec extends Specification { and: 'a trusted cm handle' trustLevelPerCmHandle.put('ch-1', TrustLevel.COMPLETE) when: 'the update is handled' - objectUnderTest.updateDmi('my-dmi', ['ch-1'], TrustLevel.COMPLETE) + objectUnderTest.handleUpdateOfDmiTrustLevel('my-dmi', ['ch-1'], TrustLevel.COMPLETE) then: 'no notification is sent' 0 * mockAttributeValueChangeEventPublisher.publishAvcEvent(*_) and: 'the dmi in the cache is trusted' assert trustLevelPerDmiPlugin.get('my-dmi') == TrustLevel.COMPLETE } - def 'CmHandle trust level updated'() { + def 'Device trust level updated'() { given: 'a non trusted cm handle' trustLevelPerCmHandle.put('ch-1', TrustLevel.NONE) and: 'a trusted dmi plugin' trustLevelPerDmiPlugin.put('my-dmi', TrustLevel.COMPLETE) and: 'inventory persistence service returns yang model cm handle' mockInventoryPersistence.getYangModelCmHandle('ch-1') >> new YangModelCmHandle(id: 'ch-1', dmiDataServiceName: 'my-dmi') - when: 'update of CmHandle to COMPLETE trust level handled' - objectUnderTest.updateCmHandleTrustLevel('ch-1', TrustLevel.COMPLETE) + when: 'update of device to COMPLETE trust level handled' + objectUnderTest.handleUpdateOfDeviceTrustLevel('ch-1', TrustLevel.COMPLETE) then: 'the cm handle in the cache is trusted' assert trustLevelPerCmHandle.get('ch-1', TrustLevel.COMPLETE) and: 'notification is sent' 1 * mockAttributeValueChangeEventPublisher.publishAvcEvent('ch-1', 'trustLevel', 'NONE', 'COMPLETE') } - def 'CmHandle trust level updated with same value'() { + def 'Device trust level updated with same value'() { given: 'a non trusted cm handle' trustLevelPerCmHandle.put('ch-1', TrustLevel.NONE) and: 'a trusted dmi plugin' trustLevelPerDmiPlugin.put('my-dmi', TrustLevel.COMPLETE) and: 'inventory persistence service returns yang model cm handle' mockInventoryPersistence.getYangModelCmHandle('ch-1') >> new YangModelCmHandle(id: 'ch-1', dmiDataServiceName: 'my-dmi') - when: 'update of CmHandle trust to the same level (NONE)' - objectUnderTest.updateCmHandleTrustLevel('ch-1', TrustLevel.NONE) + when: 'update of device trust to the same level (NONE)' + objectUnderTest.handleUpdateOfDeviceTrustLevel('ch-1', TrustLevel.NONE) then: 'the cm handle in the cache is not trusted' assert trustLevelPerCmHandle.get('ch-1', TrustLevel.NONE) and: 'no notification is sent' 0 * mockAttributeValueChangeEventPublisher.publishAvcEvent(*_) } - def 'Dmi trust level restored to complete with non trusted CmHandle'() { + def 'Dmi trust level restored to complete with non trusted device'() { given: 'a non trusted dmi' trustLevelPerDmiPlugin.put('my-dmi', TrustLevel.NONE) - and: 'a non trusted CmHandle' + and: 'a non trusted device' trustLevelPerCmHandle.put('ch-1', TrustLevel.NONE) when: 'restore the dmi trust level to COMPLETE' - objectUnderTest.updateDmi('my-dmi', ['ch-1'], TrustLevel.COMPLETE) + objectUnderTest.handleUpdateOfDmiTrustLevel('my-dmi', ['ch-1'], TrustLevel.COMPLETE) then: 'the cm handle in the cache is still NONE' assert trustLevelPerCmHandle.get('ch-1') == TrustLevel.NONE and: 'no notification is sent' 0 * mockAttributeValueChangeEventPublisher.publishAvcEvent(*_) } - def 'Select effective trust level among CmHandle and dmi plugin'() { - given: 'a non trusted dmi' - trustLevelPerDmiPlugin.put('my-dmi', TrustLevel.NONE) - and: 'a trusted CmHandle' - trustLevelPerCmHandle.put('ch-1', TrustLevel.COMPLETE) - and: 'inventory persistence service returns yang model cm handle' - mockInventoryPersistence.getYangModelCmHandle('ch-1') >> new YangModelCmHandle(id: 'ch-1', dmiDataServiceName: 'my-dmi') - when: 'effective trust level selected' - def effectiveTrustLevel = objectUnderTest.getEffectiveTrustLevel('ch-1') - then: 'effective trust level is not trusted' - assert effectiveTrustLevel == TrustLevel.NONE - } - - def 'CmHandle trust level (COMPLETE) removed'() { - given: 'a trusted cm handle' - trustLevelPerCmHandle.put('ch-1', TrustLevel.COMPLETE) - when: 'the remove is handled' - objectUnderTest.removeCmHandles(['ch-1']) - then: 'cm handle removed from the cache' - assert trustLevelPerCmHandle.get('ch-1') == null - and: 'notification is sent' - 1 * mockAttributeValueChangeEventPublisher.publishAvcEvent(_,'trustLevel','COMPLETE','NONE') - } - - def 'CmHandle trust level (NONE) removed'() { - given: 'a non-trusted cm handle' - trustLevelPerCmHandle.put('ch-1', TrustLevel.NONE) - when: 'the remove is handled' - objectUnderTest.removeCmHandles(['ch-1']) - then: 'cm handle removed from the cache' - assert trustLevelPerCmHandle.get('ch-1') == null - and: 'no notification is sent' - 0 * mockAttributeValueChangeEventPublisher.publishAvcEvent(*_) - } - } |