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 static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DATASPACE_NAME
25 import org.onap.cps.spi.model.DataNodeBuilder
27 class DataNodeHelperSpec extends DataNodeBaseSpec {
29 def 'Get data node leaves as expected from a nested data node.'() {
30 given: 'a nested data node'
31 def dataNode = new DataNodeBuilder().withDataspace(NCMP_DATASPACE_NAME)
32 .withAnchor('AVC-Subscriptions').withXpath('/subscription-registry/subscription')
33 .withLeaves([clientID:'SCO-9989752', isTagged:false, subscriptionName:'cm-subscription-001'])
34 .withChildDataNodes([dataNode4]).build()
35 when: 'the nested data node is flatten and retrieves the leaves '
36 def result = DataNodeHelper.getDataNodeLeaves([dataNode])
37 then: 'the result list size is 5'
39 and: 'all the leaves result list are equal to given leaves of data nodes'
40 result[0] == [clientID:'SCO-9989752', isTagged:false, subscriptionName:'cm-subscription-001']
41 result[1] == [datastore:'passthrough-running']
42 result[2] == [status:'PENDING', cmHandleId:'CMHandle3', details:'Subscription forwarded to dmi plugin']
43 result[3] == [status:'ACCEPTED', cmHandleId:'CMHandle2', details:'']
44 result[4] == [status:'REJECTED', cmHandleId:'CMHandle1', details:'Cm handle does not exist']
47 def 'Get cm handle id to status as expected from a nested data node.'() {
48 given: 'a nested data node'
49 def dataNode = new DataNodeBuilder().withDataspace(NCMP_DATASPACE_NAME)
50 .withAnchor('AVC-Subscriptions').withXpath('/subscription-registry/subscription')
51 .withLeaves([clientID:'SCO-9989752', isTagged:false, subscriptionName:'cm-subscription-001'])
52 .withChildDataNodes([dataNode4]).build()
53 and: 'the nested data node is flatten and retrieves the leaves '
54 def leaves = DataNodeHelper.getDataNodeLeaves([dataNode])
55 when:'cm handle id to status is retrieved'
56 def result = DataNodeHelper.cmHandleIdToStatusAndDetailsAsMap(leaves)
57 then: 'the result list size is 3'
59 and: 'the result contains expected values'
61 CMHandle3: [details:'Subscription forwarded to dmi plugin',status:'PENDING'] as Map,
62 CMHandle2: [details:'',status:'ACCEPTED'] as Map,
63 CMHandle1: [details:'Cm handle does not exist',status:'REJECTED'] as Map
68 def 'Get cm handle id to status map as expected from a nested data node.'() {
69 given: 'a nested data node'
70 def dataNode = new DataNodeBuilder().withDataspace(NCMP_DATASPACE_NAME)
71 .withAnchor('AVC-Subscriptions').withXpath('/subscription-registry/subscription')
72 .withLeaves([clientID:'SCO-9989752', isTagged:false, subscriptionName:'cm-subscription-001'])
73 .withChildDataNodes([dataNode4]).build()
74 when:'cm handle id to status is being extracted'
75 def result = DataNodeHelper.cmHandleIdToStatusAndDetailsAsMapFromDataNode([dataNode]);
76 then: 'the result list size is 3'
78 and: 'the result contains expected values'
80 CMHandle3: [details:'Subscription forwarded to dmi plugin',status:'PENDING'] as Map,
81 CMHandle2: [details:'',status:'ACCEPTED'] as Map,
82 CMHandle1: [details:'Cm handle does not exist',status:'REJECTED'] as Map