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 cm handle but non existing xpath'() {
51 given: 'an ongoing cm subscription with the following details'
52 def datastoreType = PASSTHROUGH_RUNNING
53 def cmHandleId = 'ch-1'
54 def existingXpath = '/x/y'
55 assert cmNotificationSubscriptionPersistenceService.isOngoingCmNotificationSubscription(datastoreType,cmHandleId,existingXpath)
56 and: 'a non existing cm subscription with same datastore name and cm handle but different xpath'
57 def nonExistingXpath = '/x2/y2'
58 assert !cmNotificationSubscriptionPersistenceService.isOngoingCmNotificationSubscription(datastoreType,cmHandleId,nonExistingXpath)
59 when: 'a new cm notification subscription is made for the existing cm handle and non existing xpath'
60 cmNotificationSubscriptionPersistenceService.addCmNotificationSubscription(datastoreType,cmHandleId, nonExistingXpath,
62 then: 'there is an ongoing cm subscription for that CM handle and xpath'
63 assert cmNotificationSubscriptionPersistenceService.isOngoingCmNotificationSubscription(datastoreType,cmHandleId,nonExistingXpath)
64 and: 'only one subscription id is related to now ongoing cm subscription'
65 assert cmNotificationSubscriptionPersistenceService.
66 getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,nonExistingXpath).size() == 1
69 def 'Adding a cm notification subscription to the already existing cm handle and xpath'() {
70 given: 'an ongoing cm subscription with the following details'
71 def datastoreType = PASSTHROUGH_RUNNING
72 def cmHandleId = 'ch-1'
74 when: 'a new cm notification subscription is made for the SAME CM handle and xpath'
75 cmNotificationSubscriptionPersistenceService.addCmNotificationSubscription(datastoreType,cmHandleId,xpath,
77 then: 'it is added to the ongoing list of subscription ids'
78 def subscriptionIds = cmNotificationSubscriptionPersistenceService.getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,xpath)
79 assert subscriptionIds.size() == 2
80 and: 'both subscription ids exists for the CM handle and xpath'
81 assert subscriptionIds.contains("subId-1") && subscriptionIds.contains("subId-3")
84 def 'Removing cm notification subscriber among other subscribers'() {
85 given: 'an ongoing cm subscription with the following details'
86 def datastoreType = PASSTHROUGH_RUNNING
87 def cmHandleId = 'ch-1'
89 and: 'the number of subscribers is as follows'
90 def originalNumberOfSubscribers =
91 cmNotificationSubscriptionPersistenceService.getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,xpath).size()
92 when: 'a subscriber is removed'
93 cmNotificationSubscriptionPersistenceService.removeCmNotificationSubscription(datastoreType,cmHandleId,xpath,'subId-3')
94 then: 'the number of subscribers is reduced by 1'
95 def updatedNumberOfSubscribers =
96 cmNotificationSubscriptionPersistenceService.getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,xpath).size()
97 assert updatedNumberOfSubscribers == originalNumberOfSubscribers-1
100 def 'Removing the LAST cm notification subscriber for a given cm handle, datastore and xpath'() {
101 given: 'an ongoing cm subscription with the following details'
102 def datastoreType = PASSTHROUGH_RUNNING
103 def cmHandleId = 'ch-1'
105 and: 'there is only one subscriber'
106 assert cmNotificationSubscriptionPersistenceService
107 .getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,xpath).size() == 1
108 when: 'only subscriber is removed'
109 cmNotificationSubscriptionPersistenceService.removeCmNotificationSubscription(datastoreType,cmHandleId,xpath,'subId-1')
110 then: 'there are no longer any subscriptions for the cm handle, datastore and xpath'
111 assert !cmNotificationSubscriptionPersistenceService.isOngoingCmNotificationSubscription(datastoreType, cmHandleId, xpath)