diff options
Diffstat (limited to 'cps-ncmp-service/src/test')
9 files changed, 53 insertions, 45 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevelSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/models/TrustLevelSpec.groovy index f2521b560..1e1dfaaa9 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevelSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/models/TrustLevelSpec.groovy @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.cps.ncmp.api.impl.trustlevel +package org.onap.cps.ncmp.api.inventory.models import spock.lang.Specification diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy index 52ddcfb6c..36fd75577 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy @@ -21,7 +21,7 @@ package org.onap.cps.ncmp.impl.inventory -import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel +import org.onap.cps.ncmp.api.inventory.models.TrustLevel import org.onap.cps.ncmp.impl.inventory.models.CmHandleState import org.onap.cps.spi.CpsDataPersistenceService import org.onap.cps.spi.model.DataNode 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 da3116283..9d4d9565e 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 @@ -26,16 +26,16 @@ import org.onap.cps.api.CpsDataService import org.onap.cps.api.CpsModuleService import org.onap.cps.ncmp.api.impl.events.lcm.LcmEventsCmHandleStateHandler import org.onap.cps.ncmp.api.impl.exception.DmiRequestException -import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel -import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevelManager import org.onap.cps.ncmp.api.impl.utils.AlternateIdChecker import org.onap.cps.ncmp.api.inventory.models.CmHandleRegistrationResponse import org.onap.cps.ncmp.api.inventory.models.CompositeState import org.onap.cps.ncmp.api.inventory.models.DmiPluginRegistration import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle +import org.onap.cps.ncmp.api.inventory.models.TrustLevel import org.onap.cps.ncmp.api.inventory.models.UpgradedCmHandles import org.onap.cps.ncmp.impl.inventory.models.CmHandleState import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle +import org.onap.cps.ncmp.impl.inventory.trustlevel.TrustLevelManager import org.onap.cps.spi.exceptions.AlreadyDefinedException import org.onap.cps.spi.exceptions.CpsException import org.onap.cps.spi.exceptions.DataNodeNotFoundException 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 49d4c39a1..716efd8fd 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 @@ -31,6 +31,7 @@ import org.onap.cps.ncmp.api.inventory.models.CompositeState import org.onap.cps.ncmp.api.inventory.models.ConditionApiProperties import org.onap.cps.ncmp.api.inventory.models.DmiPluginRegistration import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle +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 @@ -38,8 +39,6 @@ import org.onap.cps.spi.model.ConditionProperties import org.onap.cps.utils.JsonObjectMapper import spock.lang.Specification -import java.util.stream.Collectors - class NetworkCmProxyInventoryFacadeSpec extends Specification { def mockCmHandleRegistrationService = Mock(CmHandleRegistrationService) @@ -47,8 +46,9 @@ class NetworkCmProxyInventoryFacadeSpec extends Specification { def mockParameterizedCmHandleQueryService = Mock(ParameterizedCmHandleQueryService) def spiedJsonObjectMapper = Spy(new JsonObjectMapper(new ObjectMapper())) def mockInventoryPersistence = Mock(InventoryPersistence) + def trustLevelPerCmHandle = [:] - def objectUnderTest = new NetworkCmProxyInventoryFacade(mockCmHandleRegistrationService, mockCmHandleQueryService, mockParameterizedCmHandleQueryService, mockInventoryPersistence, spiedJsonObjectMapper) + def objectUnderTest = new NetworkCmProxyInventoryFacade(mockCmHandleRegistrationService, mockCmHandleQueryService, mockParameterizedCmHandleQueryService, mockInventoryPersistence, spiedJsonObjectMapper, trustLevelPerCmHandle) def 'Update DMI Registration'() { given: 'an (updated) dmi plugin registration' @@ -98,7 +98,7 @@ class NetworkCmProxyInventoryFacadeSpec extends Specification { given: 'the system returns a yang modelled cm handle' def dmiServiceName = 'some service name' def compositeState = new CompositeState(cmHandleState: CmHandleState.ADVISED, - lockReason: CompositeState.LockReason.builder().lockReasonCategory(LockReasonCategory.MODULE_SYNC_FAILED).details("lock details").build(), + lockReason: CompositeState.LockReason.builder().lockReasonCategory(LockReasonCategory.MODULE_SYNC_FAILED).details('lock details').build(), lastUpdateTime: 'some-timestamp', dataSyncEnabled: false, dataStores: dataStores()) @@ -106,26 +106,29 @@ class NetworkCmProxyInventoryFacadeSpec extends Specification { def publicProperties = [new YangModelCmHandle.Property('Public Book', 'Public Romance Novel')] def moduleSetTag = 'some-module-set-tag' def alternateId = 'some-alternate-id' - def yangModelCmHandle = new YangModelCmHandle(id: 'some-cm-handle', dmiServiceName: dmiServiceName, - dmiProperties: dmiProperties, publicProperties: publicProperties, compositeState: compositeState, - moduleSetTag: moduleSetTag, alternateId: alternateId) - 1 * mockInventoryPersistence.getYangModelCmHandle('some-cm-handle') >> yangModelCmHandle + def yangModelCmHandle = new YangModelCmHandle(id: 'ch-1', dmiServiceName: dmiServiceName, dmiProperties: dmiProperties, + 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) when: 'getting cm handle details for a given cm handle id from ncmp service' - def result = objectUnderTest.getNcmpServiceCmHandle('some-cm-handle') + def result = objectUnderTest.getNcmpServiceCmHandle('ch-1') then: 'the result is a ncmpServiceCmHandle' - result.class == NcmpServiceCmHandle.class + assert result.class == NcmpServiceCmHandle.class and: 'the cm handle contains the cm handle id' - result.cmHandleId == 'some-cm-handle' + assert result.cmHandleId == 'ch-1' and: 'the cm handle contains the alternate id' - result.alternateId == 'some-alternate-id' + assert result.alternateId == 'some-alternate-id' and: 'the cm handle contains the module-set-tag' - result.moduleSetTag == 'some-module-set-tag' + assert result.moduleSetTag == 'some-module-set-tag' and: 'the cm handle contains the DMI Properties' - result.dmiProperties ==[ Book:'Romance Novel' ] + assert result.dmiProperties ==[ Book:'Romance Novel' ] and: 'the cm handle contains the public Properties' - result.publicProperties == [ "Public Book":'Public Romance Novel' ] + assert result.publicProperties == [ "Public Book":'Public Romance Novel' ] and: 'the cm handle contains the cm handle composite state' - result.compositeState == compositeState + assert result.compositeState == compositeState + and: 'the cm handle contains the trust level from the cache' + assert result.currentTrustLevel == TrustLevel.COMPLETE } def 'Get cm handle public properties'() { @@ -138,7 +141,7 @@ class NetworkCmProxyInventoryFacadeSpec extends Specification { when: 'getting cm handle public properties for a given cm handle id from ncmp service' def result = objectUnderTest.getCmHandlePublicProperties('some-cm-handle') then: 'the result returns the correct data' - result == [ 'public prop' : 'some public prop' ] + assert result == [ 'public prop' : 'some public prop' ] } def 'Get cm handle composite state'() { @@ -156,7 +159,7 @@ class NetworkCmProxyInventoryFacadeSpec extends Specification { when: 'getting cm handle composite state for a given cm handle id from ncmp service' def result = objectUnderTest.getCmHandleCompositeState('some-cm-handle') then: 'the result returns the correct data' - result == compositeState + assert result == compositeState } def 'Execute cm handle id search'() { @@ -197,14 +200,21 @@ class NetworkCmProxyInventoryFacadeSpec extends Specification { conditionApiProperties.conditionName = 'hasAllModules' conditionApiProperties.conditionParameters = [[moduleName: 'module-name-1']] cmHandleQueryApiParameters.cmHandleQueryParameters = [conditionApiProperties] - and: 'query cm handle method return with a data node list' + and: 'query cm handle method returns two cm handles' mockParameterizedCmHandleQueryService.queryCmHandles( spiedJsonObjectMapper.convertToValueType(cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class)) - >> [new NcmpServiceCmHandle(cmHandleId: 'cm-handle-id-1')] + >> [new NcmpServiceCmHandle(cmHandleId: 'ch-0'), new NcmpServiceCmHandle(cmHandleId: 'ch-1')] + and: ' a trust level for ch-1' + trustLevelPerCmHandle.put('ch-1', TrustLevel.COMPLETE) when: 'execute cm handle search is called' def result = objectUnderTest.executeCmHandleSearch(cmHandleQueryApiParameters) - then: 'result is the same collection as returned by the CPS Data Service' - assert result.stream().map(cmHandle -> cmHandle.cmHandleId).collect(Collectors.toSet()) == ['cm-handle-id-1'] as Set + 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 + assert result[1].currentTrustLevel == TrustLevel.COMPLETE } def 'Set Cm Handle Data Sync flag.'() { @@ -215,8 +225,7 @@ class NetworkCmProxyInventoryFacadeSpec extends Specification { } def dataStores() { - CompositeState.DataStores.builder() - .operationalDataStore(CompositeState.Operational.builder() + CompositeState.DataStores.builder().operationalDataStore(CompositeState.Operational.builder() .dataStoreSyncState(DataStoreSyncState.NONE_REQUESTED) .lastSyncTime('some-timestamp').build()).build() } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/DeviceHeartbeatConsumerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/DeviceTrustLevelMessageConsumerSpec.groovy index 42a1c5d5a..6db304acd 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/DeviceHeartbeatConsumerSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/DeviceTrustLevelMessageConsumerSpec.groovy @@ -18,23 +18,24 @@ * ============LICENSE_END========================================================= */ -package org.onap.cps.ncmp.api.impl.trustlevel +package org.onap.cps.ncmp.impl.inventory.trustlevel import com.fasterxml.jackson.databind.ObjectMapper import io.cloudevents.CloudEvent import io.cloudevents.core.builder.CloudEventBuilder import org.apache.kafka.clients.consumer.ConsumerRecord +import org.onap.cps.ncmp.api.inventory.models.TrustLevel import org.onap.cps.ncmp.events.trustlevel.DeviceTrustLevel import org.onap.cps.utils.JsonObjectMapper import org.springframework.boot.test.context.SpringBootTest import spock.lang.Specification @SpringBootTest(classes = [ObjectMapper, JsonObjectMapper]) -class DeviceHeartbeatConsumerSpec extends Specification { +class DeviceTrustLevelMessageConsumerSpec extends Specification { def mockTrustLevelManager = Mock(TrustLevelManager) - def objectUnderTest = new DeviceHeartbeatConsumer(mockTrustLevelManager) + def objectUnderTest = new DeviceTrustLevelMessageConsumer(mockTrustLevelManager) def objectMapper = new ObjectMapper() def jsonObjectMapper = new JsonObjectMapper(objectMapper) @@ -46,7 +47,7 @@ class DeviceHeartbeatConsumerSpec extends Specification { def consumerRecord = new ConsumerRecord<String, CloudEvent>('test-device-heartbeat', 0, 0, 'sample-message-key', eventFromDmi) consumerRecord.headers().add('ce_id', objectMapper.writeValueAsBytes('ch-1')) when: 'the event is consumed' - objectUnderTest.heartbeatListener(consumerRecord) + objectUnderTest.deviceTrustLevelListener(consumerRecord) then: 'cm handles are stored with correct trust level' 1 * mockTrustLevelManager.handleUpdateOfDeviceTrustLevel('"ch-1"', TrustLevel.COMPLETE) } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DmiPluginWatchDogSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/DmiPluginTrustLevelWatchDogSpec.groovy index f5835ff85..7fa8b2cce 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DmiPluginWatchDogSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/DmiPluginTrustLevelWatchDogSpec.groovy @@ -18,15 +18,14 @@ * ============LICENSE_END========================================================= */ -package org.onap.cps.ncmp.api.impl.trustlevel.dmiavailability +package org.onap.cps.ncmp.impl.inventory.trustlevel import org.onap.cps.ncmp.api.impl.client.DmiRestClient -import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel -import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevelManager +import org.onap.cps.ncmp.api.inventory.models.TrustLevel import org.onap.cps.ncmp.impl.inventory.CmHandleQueryService import spock.lang.Specification -class DmiPluginWatchDogSpec extends Specification { +class DmiPluginTrustLevelWatchDogSpec extends Specification { def mockDmiRestClient = Mock(DmiRestClient) def mockCmHandleQueryService = Mock(CmHandleQueryService) @@ -34,7 +33,7 @@ class DmiPluginWatchDogSpec extends Specification { def trustLevelPerDmiPlugin = [:] - def objectUnderTest = new DmiPluginWatchDog(mockDmiRestClient, mockCmHandleQueryService, mockTrustLevelManager, trustLevelPerDmiPlugin) + def objectUnderTest = new DmiPluginTrustLevelWatchDog(mockDmiRestClient, mockCmHandleQueryService, mockTrustLevelManager, trustLevelPerDmiPlugin) def 'watch dmi plugin health status for #dmiHealhStatus'() { given: 'the cache has been initialised and "knows" about dmi-1' diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/TrustLevelCacheConfigSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelCacheConfigSpec.groovy index c213ab626..e79a47101 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/TrustLevelCacheConfigSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelCacheConfigSpec.groovy @@ -18,11 +18,11 @@ * ============LICENSE_END========================================================= */ -package org.onap.cps.ncmp.api.impl.config.embeddedcache +package org.onap.cps.ncmp.impl.inventory.trustlevel import com.hazelcast.config.Config import com.hazelcast.core.Hazelcast -import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel +import org.onap.cps.ncmp.api.inventory.models.TrustLevel import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.context.SpringBootTest import spock.lang.Specification diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevelManagerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelManagerSpec.groovy index 65ab7a7fd..4c22dbaed 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevelManagerSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/trustlevel/TrustLevelManagerSpec.groovy @@ -18,9 +18,10 @@ * ============LICENSE_END========================================================= */ -package org.onap.cps.ncmp.api.impl.trustlevel +package org.onap.cps.ncmp.impl.inventory.trustlevel import org.onap.cps.ncmp.api.impl.events.avc.ncmptoclient.AvcEventPublisher +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 spock.lang.Specification diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/YangDataConverterSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/utils/YangDataConverterSpec.groovy index 3f0d98934..bb45e8ad9 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/YangDataConverterSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/utils/YangDataConverterSpec.groovy @@ -18,9 +18,8 @@ * ============LICENSE_END========================================================= */ -package org.onap.cps.ncmp.api.impl.utils +package org.onap.cps.ncmp.impl.utils -import org.onap.cps.ncmp.impl.utils.YangDataConverter import org.onap.cps.spi.model.DataNode import spock.lang.Specification @@ -34,8 +33,7 @@ class YangDataConverterSpec extends Specification{ leaves: ['name': 'pubProp1', 'value': 'pubValue1']) def dataNodeCmHandle = new DataNode(leaves:['id':'sample-id'], childDataNodes:[dataNodeAdditionalProperties, dataNodePublicProperties]) when: 'the dataNode is converted' - def yangModelCmHandle = - YangDataConverter.convertCmHandleToYangModel(dataNodeCmHandle) + def yangModelCmHandle = YangDataConverter.toYangModelCmHandle(dataNodeCmHandle) then: 'the converted object has the correct id' assert yangModelCmHandle.id == 'sample-id' and: 'the additional (dmi, private) properties are included' @@ -51,7 +49,7 @@ class YangDataConverterSpec extends Specification{ def dataNodes = [new DataNode(xpath:'/dmi-registry/cm-handles[@id=\'some-cm-handle\']', leaves: ['id':'some-cm-handle']), new DataNode(xpath:'/dmi-registry/cm-handles[@id=\'another-cm-handle\']', leaves: ['id':'another-cm-handle'])] when: 'the data nodes are converted' - def yangModelCmHandles = YangDataConverter.convertDataNodesToYangModelCmHandles(dataNodes) + def yangModelCmHandles = YangDataConverter.toYangModelCmHandles(dataNodes) then: 'verify both have returned and CmHandleIds are correct' assert yangModelCmHandles.size() == 2 assert yangModelCmHandles.id.containsAll(['some-cm-handle', 'another-cm-handle']) |