Merge "Use DB for checking Alternate IDs"
[cps.git] / cps-ncmp-service / src / test / groovy / org / onap / cps / ncmp / api / impl / config / embeddedcache / AlternateIdCacheConfigSpec.groovy
1 /*
2  * ============LICENSE_START========================================================
3  *  Copyright (C) 2024 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.core.Hazelcast
24 import org.springframework.beans.factory.annotation.Autowired
25 import org.springframework.boot.test.context.SpringBootTest
26 import spock.lang.Specification
27
28 @SpringBootTest(classes = [AlternateIdCacheConfig])
29 class AlternateIdCacheConfigSpec extends Specification {
30
31     @Autowired
32     private Map<String, String> cmHandleIdPerAlternateId
33     @Autowired
34     private Map<String, String> alternateIdPerCmHandleId
35
36     def 'Embedded (hazelcast) cache for alternate id - cm handle id caches.'() {
37         expect: 'system is able to create an instance of the Alternate ID Cache'
38             assert null != cmHandleIdPerAlternateId
39             assert null != alternateIdPerCmHandleId
40         and: 'there are at least 2 instances'
41             assert Hazelcast.allHazelcastInstances.size() > 1
42         and: 'Alternate ID Caches are present'
43             assert Hazelcast.allHazelcastInstances.name.contains('hazelcastInstanceAlternateIdPerCmHandleIdMap')
44                     && Hazelcast.allHazelcastInstances.name.contains('hazelcastInstanceCmHandleIdPerAlternateIdMap')
45     }
46
47     def 'Verify configs of the alternate id distributed objects.'(){
48         when: 'retrieving the map config of module set tag'
49             def alternateIdConfig =  Hazelcast.getHazelcastInstanceByName('hazelcastInstanceAlternateIdPerCmHandleIdMap').config
50             def alternateIdMapConfig = alternateIdConfig.mapConfigs.get('alternateIdPerCmHandleIdMapConfig')
51             def cmHandleIdConfig =  Hazelcast.getHazelcastInstanceByName('hazelcastInstanceCmHandleIdPerAlternateIdMap').config
52             def cmHandleIdIdMapConfig = cmHandleIdConfig.mapConfigs.get('cmHandleIdPerAlternateIdMapConfig')
53         then: 'the map configs have the correct number of backups'
54             assert alternateIdMapConfig.backupCount == 3
55             assert alternateIdMapConfig.asyncBackupCount == 3
56             assert cmHandleIdIdMapConfig.backupCount == 3
57             assert cmHandleIdIdMapConfig.asyncBackupCount == 3
58     }
59 }