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.cache
23 import com.hazelcast.config.Config
24 import com.hazelcast.config.RestEndpointGroup
25 import spock.lang.Specification
27 class HazelcastCacheConfigSpec extends Specification {
29 def objectUnderTest = new HazelcastCacheConfig()
31 def 'Create Hazelcast instance with a #scenario'() {
32 given: 'a cluster name'
33 objectUnderTest.clusterName = 'my cluster'
34 when: 'an hazelcast instance is created (name has to be unique)'
35 def result = objectUnderTest.createHazelcastInstance(scenario, config)
36 then: 'the instance is created and has the correct name'
37 assert result.name == scenario
38 and: 'if applicable it has a map config with the expected name'
39 if (expectMapConfig) {
40 assert result.config.mapConfigs.values()[0].name == 'my map config'
42 assert result.config.mapConfigs.isEmpty()
44 and: 'if applicable it has a queue config with the expected name'
45 if (expectQueueConfig) {
46 assert result.config.queueConfigs.values()[0].name == 'my queue config'
48 assert result.config.queueConfigs.isEmpty()
50 and: 'if applicable it has a set config with the expected name'
51 if (expectSetConfig) {
52 assert result.config.setConfigs.values()[0].name == 'my set config'
54 assert result.config.setConfigs.isEmpty()
56 where: 'the following configs are used'
57 scenario | config || expectMapConfig | expectQueueConfig | expectSetConfig
58 'Map Config' | HazelcastCacheConfig.createMapConfig('my map config') || true | false | false
59 'Queue Config' | HazelcastCacheConfig.createQueueConfig('my queue config') || false | true | false
60 'Set Config' | HazelcastCacheConfig.createSetConfig('my set config') || false | false | true
63 def 'Verify Hazelcast Cluster Information'() {
64 given: 'a test configuration'
65 def testConfig = new Config()
66 when: 'cluster information is exposed'
67 objectUnderTest.exposeClusterInformation(testConfig)
68 then: 'REST api configs are enabled'
69 assert testConfig.networkConfig.restApiConfig.enabled
70 and: 'only health check and cluster read are enabled'
71 def enabledGroups = testConfig.networkConfig.restApiConfig.enabledGroups
72 assert enabledGroups.size() == 2
73 assert enabledGroups.containsAll([RestEndpointGroup.CLUSTER_READ, RestEndpointGroup.HEALTH_CHECK])