Clean up Dependencies
[cps.git] / cps-ncmp-service / src / test / groovy / org / onap / cps / ncmp / api / impl / config / embeddedcache / TrustLevelCacheConfigSpec.groovy
1 /*
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
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  *  SPDX-License-Identifier: Apache-2.0
18  *  ============LICENSE_END=========================================================
19  */
20
21 package org.onap.cps.ncmp.api.impl.config.embeddedcache
22
23 import com.hazelcast.config.Config
24 import com.hazelcast.core.Hazelcast
25 import com.hazelcast.map.IMap
26 import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel
27 import org.springframework.beans.factory.annotation.Autowired
28 import org.springframework.boot.test.context.SpringBootTest
29 import spock.lang.Specification
30
31 @SpringBootTest(classes = [TrustLevelCacheConfig])
32 class TrustLevelCacheConfigSpec extends Specification {
33
34     @Autowired
35     private IMap<String, TrustLevel> trustLevelPerDmiPlugin
36
37     def 'Hazelcast cache for trust level per dmi plugin'() {
38         expect: 'system is able to create an instance of the trust level per dmi plugin cache'
39             assert null != trustLevelPerDmiPlugin
40         and: 'there is at least 1 instance'
41             assert Hazelcast.allHazelcastInstances.size() > 0
42         and: 'Dmi Plugin Trust Level Cache is present'
43             assert Hazelcast.allHazelcastInstances.name.contains('hazelcastInstanceTrustLevelPerDmiPluginMap')
44     }
45
46     def 'Verify Trust Level Per Dmi Plugin Cache for basic hazelcast map operations'() {
47         when: 'the key inserted into Trust Level Per Dmi Plugin Cache'
48             trustLevelPerDmiPlugin.put('dmi1', TrustLevel.COMPLETE)
49             trustLevelPerDmiPlugin.put('dmi2', TrustLevel.NONE)
50         then: 'the value for each dmi can be retrieved'
51             assert trustLevelPerDmiPlugin.get('dmi1') == TrustLevel.COMPLETE
52             assert trustLevelPerDmiPlugin.get('dmi2') == TrustLevel.NONE
53     }
54
55     def 'Verify configs for Distributed Caches'(){
56         given: 'the Trust Level Per Dmi Plugin Cache config'
57             def trustLevelDmiPerPluginCacheConfig =  Hazelcast.getHazelcastInstanceByName('hazelcastInstanceTrustLevelPerDmiPluginMap').config
58             def trustLevelDmiPerPluginCacheMapConfig =  trustLevelDmiPerPluginCacheConfig.mapConfigs.get('trustLevelPerDmiPluginCacheConfig')
59         expect: 'system created instance with correct config'
60             assert trustLevelDmiPerPluginCacheConfig.clusterName == 'cps-and-ncmp-test-caches'
61             assert trustLevelDmiPerPluginCacheMapConfig.backupCount == 3
62             assert trustLevelDmiPerPluginCacheMapConfig.asyncBackupCount == 3
63     }
64
65     def 'Verify deployment network configs for Distributed Caches'() {
66         given: 'the Trust Level Per Dmi Plugin Cache config'
67             def trustLevelDmiPerPluginCacheConfig = Hazelcast.getHazelcastInstanceByName('hazelcastInstanceTrustLevelPerDmiPluginMap').config.networkConfig
68         expect: 'system created instance with correct config'
69             assert trustLevelDmiPerPluginCacheConfig.join.autoDetectionConfig.enabled
70             assert !trustLevelDmiPerPluginCacheConfig.join.kubernetesConfig.enabled
71     }
72
73     def 'Verify network config'() {
74         given: 'Synchronization config object and test configuration'
75             def objectUnderTest = new TrustLevelCacheConfig()
76             def testConfig = new Config()
77         when: 'kubernetes properties are enabled'
78             objectUnderTest.cacheKubernetesEnabled = true
79             objectUnderTest.cacheKubernetesServiceName = 'test-service-name'
80         and: 'method called to update the discovery mode'
81             objectUnderTest.updateDiscoveryMode(testConfig)
82         then: 'applied properties are reflected'
83             assert testConfig.networkConfig.join.kubernetesConfig.enabled
84             assert testConfig.networkConfig.join.kubernetesConfig.properties.get('service-name') == 'test-service-name'
85     }
86
87 }