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