f6103ef3bafd17545dc33354708397830e00aa38
[cps.git] / cps-ncmp-service / src / test / groovy / org / onap / cps / ncmp / api / impl / events / cmsubscription / service / CmNotificationSubscriptionPersistenceServiceImplSpec.groovy
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.ncmp.api.impl.events.cmsubscription.service
22
23
24 import org.onap.cps.api.CpsQueryService
25 import org.onap.cps.ncmp.api.impl.operations.DatastoreType
26 import org.onap.cps.spi.FetchDescendantsOption
27 import org.onap.cps.spi.model.DataNode
28 import spock.lang.Specification
29
30 class CmNotificationSubscriptionPersistenceServiceImplSpec extends Specification {
31
32     def mockCpsQueryService = Mock(CpsQueryService)
33
34     def objectUnderTest = new CmNotificationSubscriptionPersistenceServiceImpl(mockCpsQueryService)
35
36     def 'Check ongoing cm subscription #scenario'() {
37         given: 'a valid cm subscription query'
38             def cpsPathQuery = "/datastores/datastore[@name='ncmp-datastore:passthrough-running']/cm-handles/cm-handle[@id='ch-1']/filters/filter[@xpath='/cps/path']";
39         and: 'datanodes optionally returned'
40             1 * mockCpsQueryService.queryDataNodes('NCMP-Admin', 'cm-data-subscriptions',
41                 cpsPathQuery, FetchDescendantsOption.OMIT_DESCENDANTS) >> dataNode
42         when: 'we check for an ongoing cm subscription'
43             def response = objectUnderTest.isOngoingCmNotificationSubscription(DatastoreType.PASSTHROUGH_RUNNING, 'ch-1', '/cps/path')
44         then: 'we get expected response'
45             assert response == isOngoingCmSubscription
46         where: 'following scenarios are used'
47             scenario                  | dataNode                                                                        || isOngoingCmSubscription
48             'valid datanodes present' | [new DataNode(xpath: '/cps/path', leaves: ['subscribers': ['sub-1', 'sub-2']])] || true
49             'no datanodes present'    | []                                                                              || false
50     }
51 }