df74a05b50da3b0389321022dfe39996b4c33648
[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.addOrUpdateCmNotificationSubscription(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 an already existing'() {
31         given: 'an ongoing cm subscription'
32             def datastoreType = PASSTHROUGH_RUNNING
33             def cmHandleId = 'ch-1'
34             def xpath = '/x/y'
35             cmNotificationSubscriptionPersistenceService.addOrUpdateCmNotificationSubscription(datastoreType,cmHandleId,xpath,
36                 'subId-1')
37         when: 'a new cm notification subscription is made for the SAME CM handle and xpath'
38             cmNotificationSubscriptionPersistenceService.addOrUpdateCmNotificationSubscription(datastoreType,cmHandleId,xpath,
39                 'subId-2')
40         then: 'it is added to the ongoing list of subscription ids'
41             def subscriptionIds = cmNotificationSubscriptionPersistenceService.getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,xpath)
42             assert subscriptionIds.size() == 2
43         and: 'both subscription ids exists for the CM handle and xpath'
44             assert subscriptionIds.contains("subId-1") && subscriptionIds.contains("subId-2")
45     }
46 }