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.api.impl.config.embeddedcache
23 import com.hazelcast.config.Config
24 import com.hazelcast.core.Hazelcast
25 import org.onap.cps.ncmp.api.impl.trustlevel.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
39 def 'Hazelcast cache for trust level per dmi plugin'() {
40 expect: 'system is able to create an instance of the trust level per dmi plugin cache'
41 assert null != trustLevelPerDmiPlugin
42 and: 'there is at least 1 instance'
43 assert Hazelcast.allHazelcastInstances.size() > 0
44 and: 'Dmi Plugin Trust Level Cache is present'
45 assert Hazelcast.allHazelcastInstances.name.contains('hazelcastInstanceTrustLevelPerDmiPluginMap')
48 def 'Hazelcast cache for trust level per cm handle'() {
49 expect: 'system is able to create an instance of the trust level per cm handle cache'
50 assert null != trustLevelPerCmHandle
51 and: 'there is at least 1 instance'
52 assert Hazelcast.allHazelcastInstances.size() > 0
53 and: 'Hazelcast cache instance for trust level is present'
54 assert Hazelcast.allHazelcastInstances.name.contains('hazelcastInstanceTrustLevelPerCmHandleMap')
57 def 'Trust level cache configurations: #scenario'() {
58 when: 'retrieving the cache config for trustLevel'
59 def cacheConfig = Hazelcast.getHazelcastInstanceByName(hazelcastInstanceName).config
60 then: 'the cache config has the right cluster'
61 assert cacheConfig.clusterName == 'cps-and-ncmp-test-caches'
62 when: 'retrieving the map config for trustLevel'
63 def mapConfig = cacheConfig.mapConfigs.get(hazelcastMapConfigName)
64 then: 'the map config has the correct backup counts'
65 assert mapConfig.backupCount == 3
66 assert mapConfig.asyncBackupCount == 3
67 where: 'the following caches are used'
68 scenario | hazelcastInstanceName | hazelcastMapConfigName
69 'cmhandle map' | 'hazelcastInstanceTrustLevelPerCmHandleMap' | 'trustLevelPerCmHandleCacheConfig'
70 'dmi plugin map' | 'hazelcastInstanceTrustLevelPerDmiPluginMap' | 'trustLevelPerDmiPluginCacheConfig'
73 def 'Verify deployment network configs for Distributed Caches'() {
74 given: 'the Trust Level Per Dmi Plugin Cache config'
75 def trustLevelDmiPerPluginCacheConfig = Hazelcast.getHazelcastInstanceByName('hazelcastInstanceTrustLevelPerDmiPluginMap').config.networkConfig
76 expect: 'system created instance with correct config'
77 assert trustLevelDmiPerPluginCacheConfig.join.autoDetectionConfig.enabled
78 assert !trustLevelDmiPerPluginCacheConfig.join.kubernetesConfig.enabled
81 def 'Verify deployment network configs for Cm Handle Distributed Caches'() {
82 given: 'the Trust Level Per Cm Handle Cache config'
83 def trustLevelPerCmHandlePluginCacheConfig = Hazelcast.getHazelcastInstanceByName('hazelcastInstanceTrustLevelPerCmHandleMap').config.networkConfig
84 expect: 'system created instance with correct config'
85 assert trustLevelPerCmHandlePluginCacheConfig.join.autoDetectionConfig.enabled
86 assert !trustLevelPerCmHandlePluginCacheConfig.join.kubernetesConfig.enabled
89 def 'Verify network config'() {
90 given: 'Synchronization config object and test configuration'
91 def objectUnderTest = new TrustLevelCacheConfig()
92 def testConfig = new Config()
93 when: 'kubernetes properties are enabled'
94 objectUnderTest.cacheKubernetesEnabled = true
95 objectUnderTest.cacheKubernetesServiceName = 'test-service-name'
96 and: 'method called to update the discovery mode'
97 objectUnderTest.updateDiscoveryMode(testConfig)
98 then: 'applied properties are reflected'
99 assert testConfig.networkConfig.join.kubernetesConfig.enabled
100 assert testConfig.networkConfig.join.kubernetesConfig.properties.get('service-name') == 'test-service-name'