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
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
30 class CmNotificationSubscriptionPersistenceServiceImplSpec extends Specification {
32 def mockCpsQueryService = Mock(CpsQueryService)
34 def objectUnderTest = new CmNotificationSubscriptionPersistenceServiceImpl(mockCpsQueryService)
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: ['subscriptionIds': ['sub-1', 'sub-2']])] || true
49 'no datanodes present' | [] || false
52 def 'Checking uniqueness of incoming subscription ID'() {
53 given: 'a cps path with a subscription ID for querying'
54 def cpsPathQuery = objectUnderTest.SUBSCRIPTION_IDS_CPS_PATH_QUERY.formatted('some-sub')
55 and: 'relevant datanodes are returned'
56 1 * mockCpsQueryService.queryDataNodes('NCMP-Admin', 'cm-data-subscriptions', cpsPathQuery, FetchDescendantsOption.OMIT_DESCENDANTS) >>
58 when: 'a subscription ID is tested for uniqueness'
59 def result = objectUnderTest.isUniqueSubscriptionId('some-sub')
60 then: 'result is as expected'
61 assert result == isValidSubscriptionId
62 where: 'following scenarios are used'
63 scenario | dataNodes || isValidSubscriptionId
64 'datanodes present' | [new DataNode()] || false
65 'no datanodes present' | [] || true