2 * ============LICENSE_START========================================================
3 * Copyright (c) 2023 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.utils
23 import org.onap.cps.ncmp.api.impl.subscriptions.SubscriptionStatus
24 import org.onap.cps.spi.model.DataNodeBuilder
26 class DataNodeHelperSpec extends DataNodeBaseSpec {
28 def 'Get data node leaves as expected from a nested data node.'() {
29 given: 'a nested data node'
30 def dataNode = new DataNodeBuilder().withDataspace('NCMP-Admin')
31 .withAnchor('AVC-Subscriptions').withXpath('/subscription-registry/subscription')
32 .withLeaves([clientID:'SCO-9989752', isTagged:false, subscriptionName:'cm-subscription-001'])
33 .withChildDataNodes([dataNode4]).build()
34 when: 'the nested data node is flatten and retrieves the leaves '
35 def result = DataNodeHelper.getDataNodeLeaves([dataNode])
36 then: 'the result list size is 5'
38 and: 'all the leaves result list are equal to given leaves of data nodes'
39 result[0] == [clientID:'SCO-9989752', isTagged:false, subscriptionName:'cm-subscription-001']
40 result[1] == [datastore:'passthrough-running']
41 result[2] == [status:'PENDING', cmHandleId:'CMHandle3']
42 result[3] == [status:'ACCEPTED', cmHandleId:'CMHandle2']
43 result[4] == [status:'REJECTED', cmHandleId:'CMHandle1']
46 def 'Get cm handle id to status as expected from a nested data node.'() {
47 given: 'a nested data node'
48 def dataNode = new DataNodeBuilder().withDataspace('NCMP-Admin')
49 .withAnchor('AVC-Subscriptions').withXpath('/subscription-registry/subscription')
50 .withLeaves([clientID:'SCO-9989752', isTagged:false, subscriptionName:'cm-subscription-001'])
51 .withChildDataNodes([dataNode4]).build()
52 and: 'the nested data node is flatten and retrieves the leaves '
53 def leaves = DataNodeHelper.getDataNodeLeaves([dataNode])
54 when:'cm handle id to status is retrieved'
55 def result = DataNodeHelper.getCmHandleIdToStatus(leaves)
56 then: 'the result list size is 3'
58 and: 'the result contains expected values'
59 result[0] as List == ['PENDING', 'CMHandle3']
60 result[1] as List == ['ACCEPTED', 'CMHandle2']
61 result[2] as List == ['REJECTED', 'CMHandle1']
64 def 'Get cm handle id to status map as expected from list of collection' () {
65 given: 'a list of collection'
66 def cmHandleCollection = [['PENDING', 'CMHandle3'], ['ACCEPTED', 'CMHandle2'], ['REJECTED', 'CMHandle1']]
67 when: 'the map is formed up with a method call'
68 def result = DataNodeHelper.getCmHandleIdToStatusMap(cmHandleCollection)
69 then: 'the map values are as expected'
70 result.keySet() == ['CMHandle3', 'CMHandle2', 'CMHandle1'] as Set
71 result.values() as List == [SubscriptionStatus.PENDING, SubscriptionStatus.ACCEPTED, SubscriptionStatus.REJECTED]