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