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 org.onap.cps.integration.base.CpsIntegrationSpecBase
24 import org.onap.cps.ncmp.api.impl.events.cmsubscription.service.CmNotificationSubscriptionPersistenceService
25 import org.springframework.beans.factory.annotation.Autowired
27 import static org.onap.cps.ncmp.api.data.models.DatastoreType.PASSTHROUGH_RUNNING
29 class NcmpCmNotificationSubscriptionSpec extends CpsIntegrationSpecBase {
32 CmNotificationSubscriptionPersistenceService cmNotificationSubscriptionPersistenceService;
34 def 'Adding a new cm notification subscription'() {
35 given: 'there is no ongoing cm subscription for the following'
36 def datastoreType = PASSTHROUGH_RUNNING
37 def cmHandleId = 'ch-1'
39 assert cmNotificationSubscriptionPersistenceService.
40 getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,xpath).size() == 0
41 when: 'we add a new cm notification subscription'
42 cmNotificationSubscriptionPersistenceService.addCmNotificationSubscription(datastoreType,cmHandleId,xpath,
44 then: 'there is an ongoing cm subscription for that CM handle and xpath'
45 assert cmNotificationSubscriptionPersistenceService.isOngoingCmNotificationSubscription(datastoreType,cmHandleId,xpath)
46 and: 'only one subscription id is related to now ongoing cm subscription'
47 assert cmNotificationSubscriptionPersistenceService.
48 getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,xpath).size() == 1
51 def 'Adding a cm notification subscription to the already existing cm handle but non existing xpath'() {
52 given: 'an ongoing cm subscription with the following details'
53 def datastoreType = PASSTHROUGH_RUNNING
54 def cmHandleId = 'ch-1'
55 def existingXpath = '/x/y'
56 assert cmNotificationSubscriptionPersistenceService.isOngoingCmNotificationSubscription(datastoreType,cmHandleId,existingXpath)
57 and: 'a non existing cm subscription with same datastore name and cm handle but different xpath'
58 def nonExistingXpath = '/x2/y2'
59 assert !cmNotificationSubscriptionPersistenceService.isOngoingCmNotificationSubscription(datastoreType,cmHandleId,nonExistingXpath)
60 when: 'a new cm notification subscription is made for the existing cm handle and non existing xpath'
61 cmNotificationSubscriptionPersistenceService.addCmNotificationSubscription(datastoreType,cmHandleId, nonExistingXpath,
63 then: 'there is an ongoing cm subscription for that CM handle and xpath'
64 assert cmNotificationSubscriptionPersistenceService.isOngoingCmNotificationSubscription(datastoreType,cmHandleId,nonExistingXpath)
65 and: 'only one subscription id is related to now ongoing cm subscription'
66 assert cmNotificationSubscriptionPersistenceService.
67 getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,nonExistingXpath).size() == 1
70 def 'Adding a cm notification subscription to the already existing cm handle and xpath'() {
71 given: 'an ongoing cm subscription with the following details'
72 def datastoreType = PASSTHROUGH_RUNNING
73 def cmHandleId = 'ch-1'
75 when: 'a new cm notification subscription is made for the SAME CM handle and xpath'
76 cmNotificationSubscriptionPersistenceService.addCmNotificationSubscription(datastoreType,cmHandleId,xpath,
78 then: 'it is added to the ongoing list of subscription ids'
79 def subscriptionIds = cmNotificationSubscriptionPersistenceService.getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,xpath)
80 assert subscriptionIds.size() == 2
81 and: 'both subscription ids exists for the CM handle and xpath'
82 assert subscriptionIds.contains("subId-1") && subscriptionIds.contains("subId-3")
85 def 'Removing cm notification subscriber among other subscribers'() {
86 given: 'an ongoing cm subscription with the following details'
87 def datastoreType = PASSTHROUGH_RUNNING
88 def cmHandleId = 'ch-1'
90 and: 'the number of subscribers is as follows'
91 def originalNumberOfSubscribers =
92 cmNotificationSubscriptionPersistenceService.getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,xpath).size()
93 when: 'a subscriber is removed'
94 cmNotificationSubscriptionPersistenceService.removeCmNotificationSubscription(datastoreType,cmHandleId,xpath,'subId-3')
95 then: 'the number of subscribers is reduced by 1'
96 def updatedNumberOfSubscribers =
97 cmNotificationSubscriptionPersistenceService.getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,xpath).size()
98 assert updatedNumberOfSubscribers == originalNumberOfSubscribers-1
101 def 'Removing the LAST cm notification subscriber for a given cm handle, datastore and xpath'() {
102 given: 'an ongoing cm subscription with the following details'
103 def datastoreType = PASSTHROUGH_RUNNING
104 def cmHandleId = 'ch-1'
106 and: 'there is only one subscriber'
107 assert cmNotificationSubscriptionPersistenceService
108 .getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,xpath).size() == 1
109 when: 'only subscriber is removed'
110 cmNotificationSubscriptionPersistenceService.removeCmNotificationSubscription(datastoreType,cmHandleId,xpath,'subId-1')
111 then: 'there are no longer any subscriptions for the cm handle, datastore and xpath'
112 assert !cmNotificationSubscriptionPersistenceService.isOngoingCmNotificationSubscription(datastoreType, cmHandleId, xpath)