diff options
author | 2023-09-26 15:07:08 +0100 | |
---|---|---|
committer | 2023-10-12 10:00:52 +0100 | |
commit | 7aae9b8af2c82336882d0ae864b970b1885a63a8 (patch) | |
tree | a3165ff503592c17d91702e59855b5332806d9c1 /cps-ncmp-service/src/test/groovy | |
parent | 4bc19fe118ca7d81891c12d40719a569bc528a21 (diff) |
Add withTrustLevel condition to CmHandle Query API
- Change untrustworthyCmHandleSet with trustLevelPerCmHandleMap
- Change trust level cache config accordingly
- Change device heartbet consumer accordingly
- Add json schema for device trust level
- Add with_trust_level enum into cm handle query conditions
- Add query cm handle by trustlevel function to cm handle
queries
- Add query cm handle by trustlevel service to network cm proxy cm
handle service
- Add unit tests and fix code smells
Issue-ID: CPS-1864
Change-Id: Ie214f0713cef779307d3379df81e2b95115b6d6d
Signed-off-by: halil.cakal <halil.cakal@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/test/groovy')
9 files changed, 168 insertions, 84 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandleQueryServiceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandleQueryServiceSpec.groovy index c2e2b91cf..4a4c2e3e3 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandleQueryServiceSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandleQueryServiceSpec.groovy @@ -39,7 +39,7 @@ import spock.lang.Specification class NetworkCmProxyCmHandleQueryServiceSpec extends Specification { def cmHandleQueries = Mock(CmHandleQueries) - def partiallyMockedCmHandleQueries = Spy(CmHandleQueriesImpl) + def partiallyMockedCmHandleQueries = Spy(CmHandleQueries) def mockInventoryPersistence = Mock(InventoryPersistence) def dmiRegistry = new DataNode(xpath: NCMP_DMI_REGISTRY_PARENT, childDataNodes: createDataNodeList(['PNFDemo1', 'PNFDemo2', 'PNFDemo3', 'PNFDemo4'])) @@ -106,6 +106,17 @@ class NetworkCmProxyCmHandleQueryServiceSpec extends Specification { 'No anchors are returned' | [] } + def 'Query cm handles with some trust level query parameters'() { + given: 'a trust level condition property' + def trustLevelQueryParameters = new CmHandleQueryServiceParameters() + def trustLevelConditionProperties = createConditionProperties('cmHandleWithTrustLevel', [['trustLevel': 'COMPLETE'] as Map]) + trustLevelQueryParameters.setCmHandleQueryParameters([trustLevelConditionProperties]) + when: 'the query is being executed' + objectUnderTest.queryCmHandleIds(trustLevelQueryParameters) + then: 'the query is being delegated to the cm handle query service with correct parameter' + 1 * cmHandleQueries.queryCmHandlesByTrustLevel(['trustLevel': 'COMPLETE'] as Map) + } + def 'Query cm handle details with module names when #scenario from query.'() { given: 'a modules condition property' def cmHandleQueryParameters = new CmHandleQueryServiceParameters() 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 01a0600af..3b507a566 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 @@ -76,7 +76,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { def mockCpsCmHandlerQueryService = Mock(NetworkCmProxyCmHandleQueryService) def mockLcmEventsCmHandleStateHandler = Mock(LcmEventsCmHandleStateHandler) def stubModuleSyncStartedOnCmHandles = Stub(IMap<String, Object>) - def stubTrustLevelPerDmiPlugin = Stub(IMap<String, TrustLevel>) + def stubTrustLevelPerDmiPlugin = Stub(Map<String, TrustLevel>) def NO_TOPIC = null def NO_REQUEST_ID = null 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/api/impl/config/embeddedcache/TrustLevelCacheConfigSpec.groovy index 6184a9722..3eff96d79 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/api/impl/config/embeddedcache/TrustLevelCacheConfigSpec.groovy @@ -22,7 +22,6 @@ package org.onap.cps.ncmp.api.impl.config.embeddedcache import com.hazelcast.config.Config import com.hazelcast.core.Hazelcast -import com.hazelcast.map.IMap import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.context.SpringBootTest @@ -32,7 +31,10 @@ import spock.lang.Specification class TrustLevelCacheConfigSpec extends Specification { @Autowired - private IMap<String, TrustLevel> trustLevelPerDmiPlugin + private Map<String, TrustLevel> trustLevelPerDmiPlugin + + @Autowired + private Map<String, TrustLevel> trustLevelPerCmHandle def 'Hazelcast cache for trust level per dmi plugin'() { expect: 'system is able to create an instance of the trust level per dmi plugin cache' @@ -43,23 +45,29 @@ class TrustLevelCacheConfigSpec extends Specification { assert Hazelcast.allHazelcastInstances.name.contains('hazelcastInstanceTrustLevelPerDmiPluginMap') } - def 'Verify Trust Level Per Dmi Plugin Cache for basic hazelcast map operations'() { - when: 'the key inserted into Trust Level Per Dmi Plugin Cache' - trustLevelPerDmiPlugin.put('dmi1', TrustLevel.COMPLETE) - trustLevelPerDmiPlugin.put('dmi2', TrustLevel.NONE) - then: 'the value for each dmi can be retrieved' - assert trustLevelPerDmiPlugin.get('dmi1') == TrustLevel.COMPLETE - assert trustLevelPerDmiPlugin.get('dmi2') == TrustLevel.NONE + def 'Hazelcast cache for trust level per cm handle'() { + expect: 'system is able to create an instance of the trust level per cm handle cache' + assert null != trustLevelPerCmHandle + and: 'there is at least 1 instance' + assert Hazelcast.allHazelcastInstances.size() > 0 + and: 'Hazelcast cache instance for trust level is present' + assert Hazelcast.allHazelcastInstances.name.contains('hazelcastInstanceTrustLevelPerCmHandleMap') } - def 'Verify configs for Distributed Caches'(){ - given: 'the Trust Level Per Dmi Plugin Cache config' - def trustLevelDmiPerPluginCacheConfig = Hazelcast.getHazelcastInstanceByName('hazelcastInstanceTrustLevelPerDmiPluginMap').config - def trustLevelDmiPerPluginCacheMapConfig = trustLevelDmiPerPluginCacheConfig.mapConfigs.get('trustLevelPerDmiPluginCacheConfig') - expect: 'system created instance with correct config' - assert trustLevelDmiPerPluginCacheConfig.clusterName == 'cps-and-ncmp-test-caches' - assert trustLevelDmiPerPluginCacheMapConfig.backupCount == 3 - assert trustLevelDmiPerPluginCacheMapConfig.asyncBackupCount == 3 + def 'Trust level cache configurations: #scenario'() { + when: 'retrieving the cache config for trustLevel' + def cacheConfig = Hazelcast.getHazelcastInstanceByName(hazelcastInstanceName).config + then: 'the cache config has the right cluster' + assert cacheConfig.clusterName == 'cps-and-ncmp-test-caches' + when: 'retrieving the map config for trustLevel' + def mapConfig = cacheConfig.mapConfigs.get(hazelcastMapConfigName) + then: 'the map config has the correct backup counts' + assert mapConfig.backupCount == 3 + assert mapConfig.asyncBackupCount == 3 + where: 'the following caches are used' + scenario | hazelcastInstanceName | hazelcastMapConfigName + 'cmhandle map' | 'hazelcastInstanceTrustLevelPerCmHandleMap' | 'trustLevelPerCmHandleCacheConfig' + 'dmi plugin map' | 'hazelcastInstanceTrustLevelPerDmiPluginMap' | 'trustLevelPerDmiPluginCacheConfig' } def 'Verify deployment network configs for Distributed Caches'() { @@ -70,6 +78,14 @@ class TrustLevelCacheConfigSpec extends Specification { assert !trustLevelDmiPerPluginCacheConfig.join.kubernetesConfig.enabled } + def 'Verify deployment network configs for Cm Handle Distributed Caches'() { + given: 'the Trust Level Per Cm Handle Cache config' + def trustLevelPerCmHandlePluginCacheConfig = Hazelcast.getHazelcastInstanceByName('hazelcastInstanceTrustLevelPerCmHandleMap').config.networkConfig + expect: 'system created instance with correct config' + assert trustLevelPerCmHandlePluginCacheConfig.join.autoDetectionConfig.enabled + assert !trustLevelPerCmHandlePluginCacheConfig.join.kubernetesConfig.enabled + } + def 'Verify network config'() { given: 'Synchronization config object and test configuration' def objectUnderTest = new TrustLevelCacheConfig() diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/mapper/CloudEventMapperSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/mapper/CloudEventMapperSpec.groovy index 380aea405..e6d383128 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/mapper/CloudEventMapperSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/mapper/CloudEventMapperSpec.groovy @@ -34,17 +34,30 @@ class CloudEventMapperSpec extends Specification { @Autowired JsonObjectMapper jsonObjectMapper - def 'Cloud event to Target event type when it is #scenario'() { - expect: 'Events mapped correctly' - assert mappedCloudEvent == (CloudEventMapper.toTargetEvent(testCloudEvent(), targetClass) != null) + def 'Cloud event to target event type'() { + given: 'a cloud event with valid payload' + def cloudEvent = testCloudEvent(new CmSubscriptionNcmpInEvent()) + when: 'the cloud event mapped to target event' + def result = CloudEventMapper.toTargetEvent((cloudEvent), CmSubscriptionNcmpInEvent.class) + then: 'the cloud event is mapped' + assert result instanceof CmSubscriptionNcmpInEvent + } + + def 'Cloud event to target event type when it is #scenario'() { + given: 'a cloud event with invalid payload' + def cloudEvent = testCloudEvent(payload) + when: 'the cloud event mapped to target event' + def result = CloudEventMapper.toTargetEvent(cloudEvent, CmSubscriptionNcmpInEvent.class) + then: 'result is null' + assert result == null where: 'below are the scenarios' - scenario | targetClass || mappedCloudEvent - 'valid concrete type' | CmSubscriptionNcmpInEvent.class || true - 'invalid concrete type' | ArrayList.class || false + scenario | payload + 'invalid payload type' | ArrayList.class + 'without payload' | null } - def testCloudEvent() { - return CloudEventBuilder.v1().withData(jsonObjectMapper.asJsonBytes(new CmSubscriptionNcmpInEvent())) + def testCloudEvent(payload) { + return CloudEventBuilder.v1().withData(jsonObjectMapper.asJsonBytes(payload)) .withId("cmhandle1") .withSource(URI.create('test-source')) .withDataSchema(URI.create('test')) 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/api/impl/trustlevel/DeviceHeartbeatConsumerSpec.groovy index 48de23dca..80778b9c7 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/api/impl/trustlevel/DeviceHeartbeatConsumerSpec.groovy @@ -21,81 +21,70 @@ package org.onap.cps.ncmp.api.impl.trustlevel import com.fasterxml.jackson.databind.ObjectMapper -import com.hazelcast.collection.ISet +import com.hazelcast.map.IMap import io.cloudevents.CloudEvent import io.cloudevents.core.builder.CloudEventBuilder import org.apache.kafka.clients.consumer.ConsumerRecord +import org.onap.cps.ncmp.events.trustlevel.DeviceTrustLevel import org.onap.cps.utils.JsonObjectMapper +import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.context.SpringBootTest import spock.lang.Specification @SpringBootTest(classes = [ObjectMapper, JsonObjectMapper]) class DeviceHeartbeatConsumerSpec extends Specification { - def mockUntrustworthyCmHandlesSet = Mock(ISet<String>) + def mockTrustLevelPerCmHandle = Mock(Map<String, TrustLevel>) + + def objectUnderTest = new DeviceHeartbeatConsumer(mockTrustLevelPerCmHandle) def objectMapper = new ObjectMapper() - def objectUnderTest = new DeviceHeartbeatConsumer(mockUntrustworthyCmHandlesSet) + @Autowired + JsonObjectMapper jsonObjectMapper + + def static trustLevelString = '{"data":{"trustLevel": "COMPLETE"}}' - def 'Operations to be done in an empty untrustworthy set for #scenario'() { - given: 'an event with trustlevel as #trustLevel' - def incomingEvent = testCloudEvent(trustLevel) - and: 'transformed as a kafka record' - def consumerRecord = new ConsumerRecord<String, CloudEvent>('test-device-heartbeat', 0, 0, 'cmhandle1', incomingEvent) + def 'Consume a trustlevel event'() { + given: 'an event from dmi with trust level complete' + def payload = jsonObjectMapper.convertJsonString(trustLevelString, DeviceTrustLevel.class) + def eventFromDmi = createTrustLevelEvent(payload) + and: 'transformed to a consumer record with a cloud event id (ce_id)' + def consumerRecord = new ConsumerRecord<String, CloudEvent>('test-device-heartbeat', 0, 0, 'sample-message-key', eventFromDmi) consumerRecord.headers().add('ce_id', objectMapper.writeValueAsBytes('cmhandle1')) when: 'the event is consumed' objectUnderTest.heartbeatListener(consumerRecord) - then: 'untrustworthy cmhandles are stored' - untrustworthyCmHandlesSetInvocationForAdd * mockUntrustworthyCmHandlesSet.add(_) - and: 'trustworthy cmHandles will be removed from untrustworthy set' - untrustworthyCmHandlesSetInvocationForContains * mockUntrustworthyCmHandlesSet.contains(_) - - where: 'below scenarios are applicable' - scenario | trustLevel || untrustworthyCmHandlesSetInvocationForAdd | untrustworthyCmHandlesSetInvocationForContains - 'None trust' | TrustLevel.NONE || 1 | 0 - 'Complete trust' | TrustLevel.COMPLETE || 0 | 1 + then: 'cm handles are stored with correct trust level' + 1 * mockTrustLevelPerCmHandle.put('"cmhandle1"', TrustLevel.COMPLETE) } - def 'Invalid trust'() { - when: 'we provide an invalid trust in the event' - def consumerRecord = new ConsumerRecord<String, CloudEvent>('test-device-heartbeat', 0, 0, 'cmhandle1', testCloudEvent(null)) - consumerRecord.headers().add('ce_id', objectMapper.writeValueAsBytes('cmhandle1')) + def 'Consume trustlevel event without cloud event id'() { + given: 'an event from dmi' + def payload = jsonObjectMapper.convertJsonString(trustLevelString, DeviceTrustLevel.class) + def eventFromDmi = createTrustLevelEvent(payload) + and: 'transformed to a consumer record WITHOUT Cloud event ID (ce_id)' + def consumerRecord = new ConsumerRecord<String, CloudEvent>('test-device-heartbeat', 0, 0, 'sample-message-key', eventFromDmi) + when: 'the event is consumed' objectUnderTest.heartbeatListener(consumerRecord) - then: 'no interaction with the untrustworthy cmhandles set' - 0 * mockUntrustworthyCmHandlesSet.add(_) - 0 * mockUntrustworthyCmHandlesSet.contains(_) - 0 * mockUntrustworthyCmHandlesSet.remove(_) - and: 'control flow returns without any exception' - noExceptionThrown() - + then: 'no cm handle has been stored in the map' + 0 * mockTrustLevelPerCmHandle.put(*_) } - def 'Remove trustworthy cmhandles from untrustworthy cmhandles set'() { - given: 'an event with COMPLETE trustlevel' - def incomingEvent = testCloudEvent(TrustLevel.COMPLETE) - and: 'transformed as a kafka record' - def consumerRecord = new ConsumerRecord<String, CloudEvent>('test-device-heartbeat', 0, 0, 'cmhandle1', incomingEvent) - consumerRecord.headers().add('ce_id', objectMapper.writeValueAsBytes('cmhandle1')) - and: 'untrustworthy cmhandles set contains cmhandle1' - 1 * mockUntrustworthyCmHandlesSet.contains(_) >> true + def 'Consume a trust level event without payload'() { + given: 'a consumer record with ce_id header but without payload' + def consumerRecord = new ConsumerRecord<String, CloudEvent>('test-device-heartbeat', 0, 0, 'cmhandle1', createTrustLevelEvent(null)) + consumerRecord.headers().add('some_other_header_value', objectMapper.writeValueAsBytes('cmhandle1')) when: 'the event is consumed' objectUnderTest.heartbeatListener(consumerRecord) - then: 'cmhandle removed from untrustworthy cmhandles set' - 1 * mockUntrustworthyCmHandlesSet.remove(_) >> { - args -> - { - args[0].equals('cmhandle1') - } - } - + then: 'no cm handle has been stored in the map' + 0 * mockTrustLevelPerCmHandle.put(*_) } - def testCloudEvent(trustLevel) { - return CloudEventBuilder.v1().withData(objectMapper.writeValueAsBytes(new DeviceTrustLevel(trustLevel))) + def createTrustLevelEvent(eventPayload) { + return CloudEventBuilder.v1().withData(objectMapper.writeValueAsBytes(eventPayload)) .withId("cmhandle1") .withSource(URI.create('DMI')) .withDataSchema(URI.create('test')) - .withType('org.onap.cm.events.trustlevel-notification') + .withType('org.onap.cps.ncmp.events.trustlevel.DeviceTrustLevel') .build() } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevelFilterSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevelFilterSpec.groovy new file mode 100644 index 000000000..8f6621d24 --- /dev/null +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevelFilterSpec.groovy @@ -0,0 +1,41 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2023 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.trustlevel + + +import spock.lang.Specification + +class TrustLevelFilterSpec extends Specification { + + def targetTrustLevel = TrustLevel.COMPLETE + + def trustLevelPerCmHandle = [ 'my completed cm handle': TrustLevel.COMPLETE, 'my untrusted cm handle': TrustLevel.NONE ] + + def objectUnderTest = new TrustLevelFilter(targetTrustLevel, trustLevelPerCmHandle) + + def 'Obtain cm handle ids by a given trust level value'() { + when: 'cm handles are retrieved' + def result = objectUnderTest.getAllCmHandleIdsByTargetTrustLevel() + then: 'the result only contains the completed cm handle' + assert result.size() == 1 + assert result[0] == 'my completed cm handle' + } +} 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/api/impl/trustlevel/dmiavailability/DMiPluginWatchDogSpec.groovy index af546b7f5..b6259bdf3 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/api/impl/trustlevel/dmiavailability/DMiPluginWatchDogSpec.groovy @@ -20,7 +20,6 @@ package org.onap.cps.ncmp.api.impl.trustlevel.dmiavailability -import com.hazelcast.map.IMap import org.onap.cps.ncmp.api.impl.client.DmiRestClient import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel import spock.lang.Specification @@ -28,7 +27,7 @@ import spock.lang.Specification class DMiPluginWatchDogSpec extends Specification { - def mockTrustLevelPerDmiPlugin = Mock(IMap<String, TrustLevel>) + def mockTrustLevelPerDmiPlugin = Mock(Map<String, TrustLevel>) def mockDmiRestClient = Mock(DmiRestClient) def objectUnderTest = new DMiPluginWatchDog(mockTrustLevelPerDmiPlugin, mockDmiRestClient) diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/CmHandleQueryConditionsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/CmHandleQueryConditionsSpec.groovy index f0e2d9f0b..100705ff5 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/CmHandleQueryConditionsSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/CmHandleQueryConditionsSpec.groovy @@ -26,10 +26,11 @@ class CmHandleQueryConditionsSpec extends Specification { def 'CmHandle query condition names.'() { expect: '3 conditions with the correct names' - assert CmHandleQueryConditions.ALL_CONDITION_NAMES.size() == 3 + assert CmHandleQueryConditions.ALL_CONDITION_NAMES.size() == 4 assert CmHandleQueryConditions.ALL_CONDITION_NAMES.containsAll('hasAllProperties', 'hasAllModules', - 'cmHandleWithCpsPath') + 'cmHandleWithCpsPath', + 'cmHandleWithTrustLevel') } } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CmHandleQueriesImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CmHandleQueriesImplSpec.groovy index ffdd67265..e0f20aed0 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CmHandleQueriesImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CmHandleQueriesImplSpec.groovy @@ -21,12 +21,15 @@ package org.onap.cps.ncmp.api.inventory +import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel + import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DATASPACE_NAME import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_ANCHOR import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_PARENT import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS +import com.hazelcast.map.IMap import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueriesImpl import org.onap.cps.ncmp.api.impl.inventory.CmHandleState import org.onap.cps.ncmp.api.impl.inventory.DataStoreSyncState @@ -37,8 +40,9 @@ import spock.lang.Specification class CmHandleQueriesImplSpec extends Specification { def cpsDataPersistenceService = Mock(CpsDataPersistenceService) + def trustLevelPerCmHandle = [ 'my completed cm handle': TrustLevel.COMPLETE, 'my untrusted cm handle': TrustLevel.NONE ] - def objectUnderTest = new CmHandleQueriesImpl(cpsDataPersistenceService) + def objectUnderTest = new CmHandleQueriesImpl(cpsDataPersistenceService, trustLevelPerCmHandle) @Shared def static sampleDataNodes = [new DataNode()] @@ -60,11 +64,21 @@ class CmHandleQueriesImplSpec extends Specification { result.containsAll(expectedCmHandleIds) result.size() == expectedCmHandleIds.size() where: 'the following data is used' - scenario | publicPropertyPairs || expectedCmHandleIds - 'single property matches' | ['Contact' : 'newemailforstore@bookstore.com'] || ['PNFDemo', 'PNFDemo2', 'PNFDemo4'] - 'public property does not match' | ['wont_match' : 'wont_match'] || [] - '2 properties, only one match' | ['Contact' : 'newemailforstore@bookstore.com', 'Contact2': 'newemailforstore2@bookstore.com'] || ['PNFDemo4'] - '2 properties, no matches' | ['Contact' : 'newemailforstore@bookstore.com', 'Contact2': ''] || [] + scenario | publicPropertyPairs || expectedCmHandleIds + 'single property matches' | [Contact: 'newemailforstore@bookstore.com'] || ['PNFDemo', 'PNFDemo2', 'PNFDemo4'] + 'public property does not match' | [wont_match: 'wont_match'] || [] + '2 properties, only one match' | [Contact: 'newemailforstore@bookstore.com', Contact2: 'newemailforstore2@bookstore.com'] || ['PNFDemo4'] + '2 properties, no matches' | [Contact: 'newemailforstore@bookstore.com', Contact2: ''] || [] + } + + def 'Query cm handles on trust level'() { + given: 'query properties for trustlevel COMPLETE' + def trustLevelPropertyQueryPairs = ['trustLevel' : TrustLevel.COMPLETE.toString()] + when: 'the query is executed' + def result = objectUnderTest.queryCmHandlesByTrustLevel(trustLevelPropertyQueryPairs) + then: 'the result only contains the completed cm handle' + assert result.size() == 1 + assert result[0] == 'my completed cm handle' } def 'Query CmHandles using empty public properties query pair.'() { |