2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2023 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.cps.ncmp.impl.inventory.trustlevel
23 import com.hazelcast.config.Config
24 import com.hazelcast.core.Hazelcast
25 import org.onap.cps.ncmp.api.inventory.models.TrustLevel
26 import org.springframework.beans.factory.annotation.Autowired
27 import org.springframework.boot.test.context.SpringBootTest
28 import spock.lang.Specification
30 @SpringBootTest(classes = [TrustLevelCacheConfig])
31 class TrustLevelCacheConfigSpec extends Specification {
34 private Map<String, TrustLevel> trustLevelPerDmiPlugin
37 private Map<String, TrustLevel> trustLevelPerCmHandle
40 Hazelcast.getHazelcastInstanceByName('cps-and-ncmp-hazelcast-instance-test-config').shutdown()
43 def 'Hazelcast cache for trust level per dmi plugin'() {
44 expect: 'system is able to create an instance of the trust level per dmi plugin cache'
45 assert null != trustLevelPerDmiPlugin
46 and: 'there is at least 1 instance'
47 assert Hazelcast.allHazelcastInstances.size() > 0
48 and: 'Dmi Plugin Trust Level Cache is present'
49 assert Hazelcast.allHazelcastInstances.name.contains('cps-and-ncmp-hazelcast-instance-test-config')
52 def 'Hazelcast cache for trust level per cm handle'() {
53 expect: 'system is able to create an instance of the trust level per cm handle cache'
54 assert null != trustLevelPerCmHandle
55 and: 'there is at least 1 instance'
56 assert Hazelcast.allHazelcastInstances.size() > 0
57 and: 'Hazelcast cache instance for trust level is present'
58 assert Hazelcast.allHazelcastInstances.name.contains('cps-and-ncmp-hazelcast-instance-test-config')
61 def 'Trust level cache configurations: #scenario'() {
62 given: 'retrieving the common cache config'
63 def cacheConfig = Hazelcast.getHazelcastInstanceByName('cps-and-ncmp-hazelcast-instance-test-config').config
64 and: 'the cache config has the right cluster'
65 assert cacheConfig.clusterName == 'cps-and-ncmp-test-caches'
66 when: 'retrieving the map config for trustLevel'
67 def mapConfig = cacheConfig.mapConfigs.get(hazelcastMapConfigName)
68 then: 'the map config has the correct backup counts'
69 assert mapConfig.backupCount == 1
70 assert mapConfig.asyncBackupCount == 0
71 where: 'the following caches are used'
72 scenario | hazelcastMapConfigName
73 'cmhandle map' | 'trustLevelPerCmHandleCacheConfig'
74 'dmi plugin map' | 'trustLevelPerDmiPluginCacheConfig'
77 def 'Verify deployment network configs for Distributed Caches'() {
78 given: 'the Trust Level Per Dmi Plugin Cache config'
79 def trustLevelDmiPerPluginCacheConfig = Hazelcast.getHazelcastInstanceByName('cps-and-ncmp-hazelcast-instance-test-config').config.networkConfig
80 expect: 'system created instance with correct config'
81 assert trustLevelDmiPerPluginCacheConfig.join.autoDetectionConfig.enabled
82 assert !trustLevelDmiPerPluginCacheConfig.join.kubernetesConfig.enabled
85 def 'Verify deployment network configs for Cm Handle Distributed Caches'() {
86 given: 'the Trust Level Per Cm Handle Cache config'
87 def trustLevelPerCmHandlePluginCacheConfig = Hazelcast.getHazelcastInstanceByName('cps-and-ncmp-hazelcast-instance-test-config').config.networkConfig
88 expect: 'system created instance with correct config'
89 assert trustLevelPerCmHandlePluginCacheConfig.join.autoDetectionConfig.enabled
90 assert !trustLevelPerCmHandlePluginCacheConfig.join.kubernetesConfig.enabled
93 def 'Verify network config'() {
94 given: 'Synchronization config object and test configuration'
95 def objectUnderTest = new TrustLevelCacheConfig()
96 def testConfig = new Config()
97 when: 'kubernetes properties are enabled'
98 objectUnderTest.cacheKubernetesEnabled = true
99 objectUnderTest.cacheKubernetesServiceName = 'test-service-name'
100 and: 'method called to update the discovery mode'
101 objectUnderTest.updateDiscoveryMode(testConfig)
102 then: 'applied properties are reflected'
103 assert testConfig.networkConfig.join.kubernetesConfig.enabled
104 assert testConfig.networkConfig.join.kubernetesConfig.properties.get('service-name') == 'test-service-name'