Cm Subscription: Remove subscription method
[cps.git] / integration-test / src / test / groovy / org / onap / cps / integration / functional / NcmpCmNotificationSubscriptionSpec.groovy
1 package org.onap.cps.integration.functional
2
3 import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_RUNNING;
4 import org.onap.cps.integration.base.CpsIntegrationSpecBase;
5 import org.onap.cps.ncmp.api.impl.events.cmsubscription.service.CmNotificationSubscriptionPersistenceService;
6 import org.springframework.beans.factory.annotation.Autowired;
7
8 class NcmpCmNotificationSubscriptionSpec extends CpsIntegrationSpecBase {
9
10     @Autowired
11     CmNotificationSubscriptionPersistenceService cmNotificationSubscriptionPersistenceService;
12
13     def 'Adding a new cm notification subscription'() {
14         given: 'there is no ongoing cm subscription for the following'
15             def datastoreType = PASSTHROUGH_RUNNING
16             def cmHandleId = 'ch-1'
17             def xpath = '/x/y'
18             assert cmNotificationSubscriptionPersistenceService.
19                 getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,xpath).size() == 0
20         when: 'we add a new cm notification subscription'
21             cmNotificationSubscriptionPersistenceService.addCmNotificationSubscription(datastoreType,cmHandleId,xpath,
22                 'subId-1')
23         then: 'there is an ongoing cm subscription for that CM handle and xpath'
24             assert cmNotificationSubscriptionPersistenceService.isOngoingCmNotificationSubscription(datastoreType,cmHandleId,xpath)
25         and: 'only one subscription id is related to now ongoing cm subscription'
26             assert cmNotificationSubscriptionPersistenceService.
27                 getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,xpath).size() == 1
28     }
29
30     def 'Adding a cm notification subscription to the already existing'() {
31         given: 'an ongoing cm subscription with the following details'
32             def datastoreType = PASSTHROUGH_RUNNING
33             def cmHandleId = 'ch-1'
34             def xpath = '/x/y'
35         when: 'a new cm notification subscription is made for the SAME CM handle and xpath'
36             cmNotificationSubscriptionPersistenceService.addCmNotificationSubscription(datastoreType,cmHandleId,xpath,
37                 'subId-2')
38         then: 'it is added to the ongoing list of subscription ids'
39             def subscriptionIds = cmNotificationSubscriptionPersistenceService.getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,xpath)
40             assert subscriptionIds.size() == 2
41         and: 'both subscription ids exists for the CM handle and xpath'
42             assert subscriptionIds.contains("subId-1") && subscriptionIds.contains("subId-2")
43     }
44
45     def 'Removing cm notification subscriber among other subscribers'() {
46         given: 'an ongoing cm subscription with the following details'
47             def datastoreType = PASSTHROUGH_RUNNING
48             def cmHandleId = 'ch-1'
49             def xpath = '/x/y'
50         and: 'the number of subscribers is as follows'
51             def originalNumberOfSubscribers =
52                 cmNotificationSubscriptionPersistenceService.getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,xpath).size()
53         when: 'a subscriber is removed'
54             cmNotificationSubscriptionPersistenceService.removeCmNotificationSubscription(datastoreType,cmHandleId,xpath,'subId-2')
55         then: 'the number of subscribers is reduced by 1'
56             def updatedNumberOfSubscribers =
57                 cmNotificationSubscriptionPersistenceService.getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,xpath).size()
58             assert updatedNumberOfSubscribers == originalNumberOfSubscribers-1
59     }
60
61     def 'Removing the LAST cm notification subscriber for a given cm handle, datastore and xpath'() {
62         given: 'an ongoing cm subscription with the following details'
63             def datastoreType = PASSTHROUGH_RUNNING
64             def cmHandleId = 'ch-1'
65             def xpath = '/x/y'
66         and: 'there is only one subscriber'
67             assert cmNotificationSubscriptionPersistenceService
68                 .getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,xpath).size() == 1
69         when: 'only subscriber is removed'
70             cmNotificationSubscriptionPersistenceService.removeCmNotificationSubscription(datastoreType,cmHandleId,xpath,'subId-1')
71         then: 'there are no longer any subscriptions for the cm handle, datastore and xpath'
72             assert !cmNotificationSubscriptionPersistenceService.isOngoingCmNotificationSubscription(datastoreType, cmHandleId, xpath)
73     }
74
75 }