a5f7d08c5884eac0a2ef6beb90ea83effd548116
[cps.git] /
1 /*
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
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.integration.functional.ncmp
22
23 import org.onap.cps.integration.base.CpsIntegrationSpecBase
24 import org.onap.cps.ncmp.impl.cmnotificationsubscription.utils.CmSubscriptionPersistenceService
25 import org.springframework.beans.factory.annotation.Autowired
26
27 import static org.onap.cps.ncmp.api.data.models.DatastoreType.PASSTHROUGH_RUNNING
28
29 class CmNotificationSubscriptionSpec extends CpsIntegrationSpecBase {
30
31     @Autowired
32     CmSubscriptionPersistenceService cmSubscriptionPersistenceService
33
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'
38             def xpath = '/x/y'
39             assert cmSubscriptionPersistenceService.
40                 getOngoingCmSubscriptionIds(datastoreType, cmHandleId, xpath).size() == 0
41         when: 'we add a new cm notification subscription'
42             cmSubscriptionPersistenceService.addCmSubscription(datastoreType, cmHandleId, xpath,
43                 'subId-1')
44         then: 'there is an ongoing cm subscription for that CM handle and xpath'
45             assert cmSubscriptionPersistenceService.isOngoingCmSubscription(datastoreType, cmHandleId, xpath)
46         and: 'only one subscription id is related to now ongoing cm subscription'
47             assert cmSubscriptionPersistenceService.getOngoingCmSubscriptionIds(datastoreType, cmHandleId, xpath).size() == 1
48     }
49
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 cmSubscriptionPersistenceService.isOngoingCmSubscription(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 !cmSubscriptionPersistenceService.isOngoingCmSubscription(datastoreType, cmHandleId, nonExistingXpath)
59         when: 'a new cm notification subscription is made for the existing cm handle and non existing xpath'
60             cmSubscriptionPersistenceService.addCmSubscription(datastoreType, cmHandleId, nonExistingXpath,
61                 'subId-2')
62         then: 'there is an ongoing cm subscription for that CM handle and xpath'
63             assert cmSubscriptionPersistenceService.isOngoingCmSubscription(datastoreType, cmHandleId, nonExistingXpath)
64         and: 'only one subscription id is related to now ongoing cm subscription'
65             assert cmSubscriptionPersistenceService.getOngoingCmSubscriptionIds(datastoreType, cmHandleId, nonExistingXpath).size() == 1
66     }
67
68     def 'Adding a cm notification subscription to the already existing cm handle and xpath'() {
69         given: 'an ongoing cm subscription with the following details'
70             def datastoreType = PASSTHROUGH_RUNNING
71             def cmHandleId = 'ch-1'
72             def xpath = '/x/y'
73         when: 'a new cm notification subscription is made for the SAME CM handle and xpath'
74             cmSubscriptionPersistenceService.addCmSubscription(datastoreType, cmHandleId, xpath,
75                 'subId-3')
76         then: 'it is added to the ongoing list of subscription ids'
77             def subscriptionIds = cmSubscriptionPersistenceService.getOngoingCmSubscriptionIds(datastoreType, cmHandleId, xpath)
78             assert subscriptionIds.size() == 2
79         and: 'both subscription ids exists for the CM handle and xpath'
80             assert subscriptionIds.contains("subId-1") && subscriptionIds.contains("subId-3")
81     }
82
83     def 'Removing cm notification subscriber among other subscribers'() {
84         given: 'an ongoing cm subscription with the following details'
85             def datastoreType = PASSTHROUGH_RUNNING
86             def cmHandleId = 'ch-1'
87             def xpath = '/x/y'
88         and: 'the number of subscribers is as follows'
89             def originalNumberOfSubscribers =
90                 cmSubscriptionPersistenceService.getOngoingCmSubscriptionIds(datastoreType, cmHandleId, xpath).size()
91         when: 'a subscriber is removed'
92             cmSubscriptionPersistenceService.removeCmSubscription(datastoreType, cmHandleId, xpath, 'subId-3')
93         then: 'the number of subscribers is reduced by 1'
94             def updatedNumberOfSubscribers = cmSubscriptionPersistenceService.getOngoingCmSubscriptionIds(datastoreType, cmHandleId, xpath).size()
95             assert updatedNumberOfSubscribers == originalNumberOfSubscribers - 1
96     }
97
98     def 'Removing the LAST cm notification subscriber for a given cm handle, datastore and xpath'() {
99         given: 'an ongoing cm subscription with the following details'
100             def datastoreType = PASSTHROUGH_RUNNING
101             def cmHandleId = 'ch-1'
102             def xpath = '/x/y'
103         and: 'there is only one subscriber'
104             assert cmSubscriptionPersistenceService
105                 .getOngoingCmSubscriptionIds(datastoreType, cmHandleId, xpath).size() == 1
106         when: 'only subscriber is removed'
107             cmSubscriptionPersistenceService.removeCmSubscription(datastoreType, cmHandleId, xpath, 'subId-1')
108         then: 'there are no longer any subscriptions for the cm handle, datastore and xpath'
109             assert !cmSubscriptionPersistenceService.isOngoingCmSubscription(datastoreType, cmHandleId, xpath)
110     }
111
112 }