diff options
Diffstat (limited to 'cps-ncmp-service/src/test/groovy')
5 files changed, 73 insertions, 30 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 0c702abea6..dcff2e9b89 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,13 +59,12 @@ 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, trustLevelPerDmiPlugin , mockTrustLevelManager, mockAlternateIdChecker)) + mockModuleSyncStartedOnCmHandles, mockTrustLevelManager, mockAlternateIdChecker)) def setup() { // always accept all cm handles @@ -143,9 +142,6 @@ 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' @@ -212,7 +208,7 @@ class CmHandleRegistrationServiceSpec extends Specification { when: 'registration is updated' objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration) then: 'trustLevel is set for the created cm-handle' - 1 * mockTrustLevelManager.handleInitialRegistrationOfTrustLevels(expectedMapping) + 1 * mockTrustLevelManager.registerCmHandles(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 716efd8fdb..d85dfe47ee 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,6 +35,7 @@ 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 @@ -46,9 +47,9 @@ class NetworkCmProxyInventoryFacadeSpec extends Specification { def mockParameterizedCmHandleQueryService = Mock(ParameterizedCmHandleQueryService) def spiedJsonObjectMapper = Spy(new JsonObjectMapper(new ObjectMapper())) def mockInventoryPersistence = Mock(InventoryPersistence) - def trustLevelPerCmHandle = [:] + def mockTrustLevelManager = Mock(TrustLevelManager) - def objectUnderTest = new NetworkCmProxyInventoryFacade(mockCmHandleRegistrationService, mockCmHandleQueryService, mockParameterizedCmHandleQueryService, mockInventoryPersistence, spiedJsonObjectMapper, trustLevelPerCmHandle) + def objectUnderTest = new NetworkCmProxyInventoryFacade(mockCmHandleRegistrationService, mockCmHandleQueryService, mockParameterizedCmHandleQueryService, mockInventoryPersistence, spiedJsonObjectMapper, mockTrustLevelManager) def 'Update DMI Registration'() { given: 'an (updated) dmi plugin registration' @@ -110,7 +111,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' - trustLevelPerCmHandle.put('ch-1', TrustLevel.COMPLETE) + mockTrustLevelManager.getEffectiveTrustLevel(*_) >> 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' @@ -204,16 +205,16 @@ class NetworkCmProxyInventoryFacadeSpec extends Specification { mockParameterizedCmHandleQueryService.queryCmHandles( spiedJsonObjectMapper.convertToValueType(cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class)) >> [new NcmpServiceCmHandle(cmHandleId: 'ch-0'), new NcmpServiceCmHandle(cmHandleId: 'ch-1')] - and: ' a trust level for ch-1' - trustLevelPerCmHandle.put('ch-1', TrustLevel.COMPLETE) + and: 'a trust level for cm handles' + mockTrustLevelManager.getEffectiveTrustLevel(*_) >> 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' assert result.size() == 2 assert result[0].cmHandleId == 'ch-0' assert result[1].cmHandleId == 'ch-1' - and: 'only ch-1 has a trust level' - assert result[0].currentTrustLevel == null + and: 'cm handles have trust level' + assert result[0].currentTrustLevel == TrustLevel.COMPLETE assert result[1].currentTrustLevel == TrustLevel.COMPLETE } 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 6db304acd1..c7d0616bb2 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.handleUpdateOfDeviceTrustLevel('"ch-1"', TrustLevel.COMPLETE) + 1 * mockTrustLevelManager.updateCmHandleTrustLevel('"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 3a1cd14c48..32f4503005 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.handleUpdateOfDmiTrustLevel('dmi-1', _, newDmiTrustLevel) + numberOfCalls * mockTrustLevelManager.updateDmi('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 b5bfbc165c..95d3db16cb 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,10 +20,12 @@ 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 import org.onap.cps.ncmp.utils.events.CmAvcEventPublisher +import spock.lang.Ignore import spock.lang.Specification class TrustLevelManagerSpec extends Specification { @@ -35,11 +37,20 @@ 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: 'the initial registration handled' - objectUnderTest.handleInitialRegistrationOfTrustLevels(cmHandleModelsToBeCreated) + when: 'method to register to the cache is called' + objectUnderTest.registerCmHandles(cmHandleModelsToBeCreated) then: 'no notification sent' 0 * mockAttributeValueChangeEventPublisher.publishAvcEvent(*_) and: 'both cm handles are in the cache and are trusted' @@ -50,8 +61,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: 'the initial registration handled' - objectUnderTest.handleInitialRegistrationOfTrustLevels(cmHandleModelsToBeCreated) + when: 'method to register to the cache is called' + objectUnderTest.registerCmHandles(cmHandleModelsToBeCreated) then: 'notification is sent' 1 * mockAttributeValueChangeEventPublisher.publishAvcEvent(*_) } @@ -62,7 +73,7 @@ class TrustLevelManagerSpec extends Specification { and: 'a trusted cm handle' trustLevelPerCmHandle.put('ch-1', TrustLevel.COMPLETE) when: 'the update is handled' - objectUnderTest.handleUpdateOfDmiTrustLevel('my-dmi', ['ch-1'], TrustLevel.NONE) + objectUnderTest.updateDmi('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' @@ -75,54 +86,89 @@ class TrustLevelManagerSpec extends Specification { and: 'a trusted cm handle' trustLevelPerCmHandle.put('ch-1', TrustLevel.COMPLETE) when: 'the update is handled' - objectUnderTest.handleUpdateOfDmiTrustLevel('my-dmi', ['ch-1'], TrustLevel.COMPLETE) + objectUnderTest.updateDmi('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 'Device trust level updated'() { + def 'CmHandle 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 device to COMPLETE trust level handled' - objectUnderTest.handleUpdateOfDeviceTrustLevel('ch-1', TrustLevel.COMPLETE) + when: 'update of CmHandle to COMPLETE trust level handled' + objectUnderTest.updateCmHandleTrustLevel('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 'Device trust level updated with same value'() { + def 'CmHandle 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 device trust to the same level (NONE)' - objectUnderTest.handleUpdateOfDeviceTrustLevel('ch-1', TrustLevel.NONE) + when: 'update of CmHandle trust to the same level (NONE)' + objectUnderTest.updateCmHandleTrustLevel('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 device'() { + def 'Dmi trust level restored to complete with non trusted CmHandle'() { given: 'a non trusted dmi' trustLevelPerDmiPlugin.put('my-dmi', TrustLevel.NONE) - and: 'a non trusted device' + and: 'a non trusted CmHandle' trustLevelPerCmHandle.put('ch-1', TrustLevel.NONE) when: 'restore the dmi trust level to COMPLETE' - objectUnderTest.handleUpdateOfDmiTrustLevel('my-dmi', ['ch-1'], TrustLevel.COMPLETE) + objectUnderTest.updateDmi('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(*_) } + @Ignore + // TODO: CPS-2375 + 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) + when: 'effective trust level selected' + def effectiveTrustLevel = objectUnderTest.getEffectiveTrustLevel('ch-1') + then: 'effective trust level is 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(*_) + } + } |