Replace deprecated WebSecurityConfigurerAdapter
[cps.git] / cps-ncmp-service / src / test / groovy / org / onap / cps / ncmp / api / impl / utils / DataNodeHelperSpec.groovy
1 /*
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
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.utils
22
23 import org.onap.cps.spi.model.DataNodeBuilder
24
25 class DataNodeHelperSpec extends DataNodeBaseSpec {
26
27     def 'Get data node leaves as expected from a nested data node.'() {
28         given: 'a nested data node'
29             def dataNode = new DataNodeBuilder().withDataspace('NCMP-Admin')
30                 .withAnchor('AVC-Subscriptions').withXpath('/subscription-registry/subscription')
31                 .withLeaves([clientID:'SCO-9989752', isTagged:false, subscriptionName:'cm-subscription-001'])
32                 .withChildDataNodes([dataNode4]).build()
33         when: 'the nested data node is flatten and retrieves the leaves '
34             def result = DataNodeHelper.getDataNodeLeaves([dataNode])
35         then: 'the result list size is 5'
36             result.size() == 5
37         and: 'all the leaves result list are equal to given leaves of data nodes'
38             result[0] == [clientID:'SCO-9989752', isTagged:false, subscriptionName:'cm-subscription-001']
39             result[1] == [datastore:'passthrough-running']
40             result[2] == [status:'PENDING', cmHandleId:'CMHandle3']
41             result[3] == [status:'ACCEPTED', cmHandleId:'CMHandle2']
42             result[4] == [status:'REJECTED', cmHandleId:'CMHandle1']
43     }
44
45     def 'Get cm handle id to status as expected from a nested data node.'() {
46         given: 'a nested data node'
47             def dataNode = new DataNodeBuilder().withDataspace('NCMP-Admin')
48                 .withAnchor('AVC-Subscriptions').withXpath('/subscription-registry/subscription')
49                 .withLeaves([clientID:'SCO-9989752', isTagged:false, subscriptionName:'cm-subscription-001'])
50                 .withChildDataNodes([dataNode4]).build()
51         and: 'the nested data node is flatten and retrieves the leaves '
52             def leaves = DataNodeHelper.getDataNodeLeaves([dataNode])
53         when:'cm handle id to status is retrieved'
54             def result = DataNodeHelper.getCmHandleIdToStatus(leaves);
55         then: 'the result list size is 3'
56             result.size() == 3
57     }
58 }