a3f41c8ef48779fda5e2a0c118b39875ee410275
[cps.git] / cps-ncmp-service / src / test / groovy / org / onap / cps / ncmp / api / impl / config / embeddedcache / CmNotificationSubscriptionCacheConfigSpec.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 com.hazelcast.map.IMap
25 import org.onap.cps.ncmp.api.impl.events.cmsubscription.model.CmNotificationSubscriptionStatus
26 import org.onap.cps.ncmp.api.impl.events.cmsubscription.model.DmiCmNotificationSubscriptionDetails
27 import org.onap.cps.ncmp.api.impl.events.cmsubscription.model.DmiCmNotificationSubscriptionPredicate
28 import org.onap.cps.ncmp.api.impl.operations.DatastoreType
29 import org.springframework.beans.factory.annotation.Autowired
30 import org.springframework.boot.test.context.SpringBootTest
31 import spock.lang.Specification
32
33 @SpringBootTest(classes = [CmNotificationSubscriptionCacheConfig])
34 class CmNotificationSubscriptionCacheConfigSpec extends Specification {
35
36     @Autowired
37     IMap<String, Map<String, DmiCmNotificationSubscriptionDetails>> cmNotificationSubscriptionCache;
38
39     def 'Embedded (hazelcast) cache for Cm Notification Subscription Cache.'() {
40         expect: 'system is able to create an instance of the Cm Notification Subscription Cache'
41             assert null != cmNotificationSubscriptionCache
42         and: 'there is at least 1 instance'
43             assert Hazelcast.allHazelcastInstances.size() > 0
44         and: 'Cm Notification Subscription Cache is present'
45             assert Hazelcast.allHazelcastInstances.name.contains('hazelCastInstanceCmNotificationSubscription')
46     }
47
48     def 'Provided CM Subscription data'() {
49         given: 'a cm subscription properties'
50             def subscriptionId = 'sub123'
51             def dmiPluginName = 'dummydmi'
52             def cmSubscriptionPredicate = new DmiCmNotificationSubscriptionPredicate(targetCmHandleIds: ['cmhandle1', 'cmhandle2'], datastoreType: DatastoreType.PASSTHROUGH_RUNNING, xpaths: ['/a/b/c'])
53             def cmSubscriptionCacheObject = new DmiCmNotificationSubscriptionDetails(dmiCmNotificationSubscriptionPredicates: [cmSubscriptionPredicate], cmNotificationSubscriptionStatus: CmNotificationSubscriptionStatus.PENDING)
54         when: 'the cache is populated'
55             cmNotificationSubscriptionCache.put(subscriptionId, [(dmiPluginName): cmSubscriptionCacheObject])
56         then: 'the values are present in memory'
57             assert cmNotificationSubscriptionCache.get(subscriptionId) != null
58         and: 'properties match'
59             assert dmiPluginName == cmNotificationSubscriptionCache.get(subscriptionId).keySet()[0]
60             assert cmSubscriptionCacheObject.cmNotificationSubscriptionStatus == cmNotificationSubscriptionCache.get(subscriptionId).values().cmNotificationSubscriptionStatus[0]
61             assert cmSubscriptionCacheObject.dmiCmNotificationSubscriptionPredicates[0].targetCmHandleIds == cmNotificationSubscriptionCache.get(subscriptionId).values().dmiCmNotificationSubscriptionPredicates[0].targetCmHandleIds[0]
62     }
63 }