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.integration.functional
23 import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_RUNNING;
24 import org.onap.cps.integration.base.CpsIntegrationSpecBase;
25 import org.onap.cps.ncmp.api.impl.events.cmsubscription.service.CmNotificationSubscriptionPersistenceService;
26 import org.springframework.beans.factory.annotation.Autowired;
28 class NcmpCmNotificationSubscriptionSpec extends CpsIntegrationSpecBase {
31 CmNotificationSubscriptionPersistenceService cmNotificationSubscriptionPersistenceService;
33 def 'Adding a new cm notification subscription'() {
34 given: 'there is no ongoing cm subscription for the following'
35 def datastoreType = PASSTHROUGH_RUNNING
36 def cmHandleId = 'ch-1'
38 assert cmNotificationSubscriptionPersistenceService.
39 getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,xpath).size() == 0
40 when: 'we add a new cm notification subscription'
41 cmNotificationSubscriptionPersistenceService.addCmNotificationSubscription(datastoreType,cmHandleId,xpath,
43 then: 'there is an ongoing cm subscription for that CM handle and xpath'
44 assert cmNotificationSubscriptionPersistenceService.isOngoingCmNotificationSubscription(datastoreType,cmHandleId,xpath)
45 and: 'only one subscription id is related to now ongoing cm subscription'
46 assert cmNotificationSubscriptionPersistenceService.
47 getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,xpath).size() == 1
50 def 'Adding a cm notification subscription to the already existing'() {
51 given: 'an ongoing cm subscription with the following details'
52 def datastoreType = PASSTHROUGH_RUNNING
53 def cmHandleId = 'ch-1'
55 when: 'a new cm notification subscription is made for the SAME CM handle and xpath'
56 cmNotificationSubscriptionPersistenceService.addCmNotificationSubscription(datastoreType,cmHandleId,xpath,
58 then: 'it is added to the ongoing list of subscription ids'
59 def subscriptionIds = cmNotificationSubscriptionPersistenceService.getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,xpath)
60 assert subscriptionIds.size() == 2
61 and: 'both subscription ids exists for the CM handle and xpath'
62 assert subscriptionIds.contains("subId-1") && subscriptionIds.contains("subId-2")
65 def 'Removing cm notification subscriber among other subscribers'() {
66 given: 'an ongoing cm subscription with the following details'
67 def datastoreType = PASSTHROUGH_RUNNING
68 def cmHandleId = 'ch-1'
70 and: 'the number of subscribers is as follows'
71 def originalNumberOfSubscribers =
72 cmNotificationSubscriptionPersistenceService.getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,xpath).size()
73 when: 'a subscriber is removed'
74 cmNotificationSubscriptionPersistenceService.removeCmNotificationSubscription(datastoreType,cmHandleId,xpath,'subId-2')
75 then: 'the number of subscribers is reduced by 1'
76 def updatedNumberOfSubscribers =
77 cmNotificationSubscriptionPersistenceService.getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,xpath).size()
78 assert updatedNumberOfSubscribers == originalNumberOfSubscribers-1
81 def 'Removing the LAST cm notification subscriber for a given cm handle, datastore and xpath'() {
82 given: 'an ongoing cm subscription with the following details'
83 def datastoreType = PASSTHROUGH_RUNNING
84 def cmHandleId = 'ch-1'
86 and: 'there is only one subscriber'
87 assert cmNotificationSubscriptionPersistenceService
88 .getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,xpath).size() == 1
89 when: 'only subscriber is removed'
90 cmNotificationSubscriptionPersistenceService.removeCmNotificationSubscription(datastoreType,cmHandleId,xpath,'subId-1')
91 then: 'there are no longer any subscriptions for the cm handle, datastore and xpath'
92 assert !cmNotificationSubscriptionPersistenceService.isOngoingCmNotificationSubscription(datastoreType, cmHandleId, xpath)