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
 
   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.impl.cmnotificationsubscription.cache
 
  23 import com.hazelcast.core.Hazelcast
 
  24 import com.hazelcast.map.IMap
 
  25 import org.onap.cps.ncmp.api.data.models.DatastoreType
 
  26 import org.onap.cps.ncmp.impl.cmnotificationsubscription.models.CmSubscriptionStatus
 
  27 import org.onap.cps.ncmp.impl.cmnotificationsubscription.models.DmiCmSubscriptionDetails
 
  28 import org.onap.cps.ncmp.impl.cmnotificationsubscription.models.DmiCmSubscriptionPredicate
 
  29 import org.springframework.beans.factory.annotation.Autowired
 
  30 import org.springframework.boot.test.context.SpringBootTest
 
  31 import spock.lang.Specification
 
  33 @SpringBootTest(classes = [CmSubscriptionConfig])
 
  34 class CmSubscriptionConfigSpec extends Specification {
 
  37     IMap<String, Map<String, DmiCmSubscriptionDetails>> cmNotificationSubscriptionCache;
 
  40         Hazelcast.getHazelcastInstanceByName('cps-and-ncmp-hazelcast-instance-test-config').shutdown()
 
  43     def 'Embedded (hazelcast) cache for Cm Notification Subscription Cache.'() {
 
  44         expect: 'system is able to create an instance of the Cm Notification Subscription Cache'
 
  45             assert null != cmNotificationSubscriptionCache
 
  46         and: 'there is at least 1 instance'
 
  47             assert Hazelcast.allHazelcastInstances.size() > 0
 
  48         and: 'Cm Notification Subscription Cache is present'
 
  49             assert Hazelcast.allHazelcastInstances.name.contains('cps-and-ncmp-hazelcast-instance-test-config')
 
  52     def 'Provided CM Subscription data'() {
 
  53         given: 'a cm subscription properties'
 
  54             def subscriptionId = 'sub123'
 
  55             def dmiPluginName = 'dummydmi'
 
  56             def cmSubscriptionPredicates = new DmiCmSubscriptionPredicate(['cmhandle1', 'cmhandle2'].toSet(), DatastoreType.PASSTHROUGH_RUNNING, ['/a/b/c'].toSet())
 
  57             def cmSubscriptionCacheObject = new DmiCmSubscriptionDetails([cmSubscriptionPredicates], CmSubscriptionStatus.PENDING)
 
  58         when: 'the cache is populated'
 
  59             cmNotificationSubscriptionCache.put(subscriptionId, [(dmiPluginName): cmSubscriptionCacheObject])
 
  60         then: 'the values are present in memory'
 
  61             assert cmNotificationSubscriptionCache.get(subscriptionId) != null
 
  62         and: 'properties match'
 
  63             assert dmiPluginName == cmNotificationSubscriptionCache.get(subscriptionId).keySet()[0]
 
  64             assert cmSubscriptionCacheObject.cmSubscriptionStatus == cmNotificationSubscriptionCache.get(subscriptionId).values().cmSubscriptionStatus[0]
 
  65             assert cmSubscriptionCacheObject.dmiCmSubscriptionPredicates[0].targetCmHandleIds == cmNotificationSubscriptionCache.get(subscriptionId).values().dmiCmSubscriptionPredicates[0].targetCmHandleIds[0]