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.spi.model.ModuleReference
26 import org.springframework.beans.factory.annotation.Autowired
27 import org.springframework.boot.test.context.SpringBootTest
28 import spock.lang.Specification
30 @SpringBootTest(classes = [ModuleSetTagCacheConfig])
31 class ModuleSetTagCacheConfigSpec extends Specification {
34 private Map<String, Collection<ModuleReference>> moduleSetTagCache
36 def 'Embedded (hazelcast) caches for module set tag.'() {
37 expect: 'system is able to create an instance of a map to hold module set tags'
38 assert null != moduleSetTagCache
39 and: 'there is at least 1 instance'
40 assert Hazelcast.allHazelcastInstances.size() > 0
41 and: 'hazelcast instance name of module set tag is correct'
42 assert Hazelcast.allHazelcastInstances.name.contains('moduleSetTags')
45 def 'Verify configs of module set tag distributed object.'(){
46 when: 'retrieving the map config of module set tag'
47 def cacheConfig = Hazelcast.getHazelcastInstanceByName('moduleSetTags').config
48 def moduleSetTagMapConfig = cacheConfig.mapConfigs.get('moduleSetTagCacheMapConfig')
49 then: 'the module set tag map config has correct backup counts'
50 assert moduleSetTagMapConfig.backupCount == 3
51 assert moduleSetTagMapConfig.asyncBackupCount == 3
54 def 'Verify deployment network configs of distributed cache of module set tag object.'() {
55 given: 'network config of module set tag cache'
56 def moduleSetTagNetworkConfig = Hazelcast.getHazelcastInstanceByName('moduleSetTags').config.networkConfig
57 expect: 'module set tag cache has the correct settings'
58 assert moduleSetTagNetworkConfig.join.autoDetectionConfig.enabled
59 assert !moduleSetTagNetworkConfig.join.kubernetesConfig.enabled
62 def 'Verify network of module set tag cache'() {
63 given: 'Synchronization config object and test configuration'
64 def objectUnderTest = new ModuleSetTagCacheConfig()
65 def testConfig = new Config()
66 when: 'kubernetes properties are enabled'
67 objectUnderTest.cacheKubernetesEnabled = true
68 objectUnderTest.cacheKubernetesServiceName = 'test-service-name'
69 and: 'method called to update the discovery mode'
70 objectUnderTest.updateDiscoveryMode(testConfig)
71 then: 'applied properties are reflected'
72 assert testConfig.networkConfig.join.kubernetesConfig.enabled
73 assert testConfig.networkConfig.join.kubernetesConfig.properties.get('service-name') == 'test-service-name'