RTD change to document migration to Spring Boot 3.0
[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', details:'Subscription forwarded to dmi plugin']
41             result[3] == [status:'ACCEPTED', cmHandleId:'CMHandle2', details:'']
42             result[4] == [status:'REJECTED', cmHandleId:'CMHandle1', details:'Cm handle does not exist']
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.cmHandleIdToStatusAndDetailsAsMap(leaves)
55         then: 'the result list size is 3'
56             result.size() == 3
57         and: 'the result contains expected values'
58             result == [
59                 CMHandle3: [details:'Subscription forwarded to dmi plugin',status:'PENDING'] as Map,
60                 CMHandle2: [details:'',status:'ACCEPTED'] as Map,
61                 CMHandle1: [details:'Cm handle does not exist',status:'REJECTED'] as Map
62             ] as Map
63
64     }
65
66     def 'Get cm handle id to status map as expected from a nested data node.'() {
67         given: 'a nested data node'
68             def dataNode = new DataNodeBuilder().withDataspace('NCMP-Admin')
69                 .withAnchor('AVC-Subscriptions').withXpath('/subscription-registry/subscription')
70                 .withLeaves([clientID:'SCO-9989752', isTagged:false, subscriptionName:'cm-subscription-001'])
71                 .withChildDataNodes([dataNode4]).build()
72         when:'cm handle id to status is being extracted'
73             def result = DataNodeHelper.cmHandleIdToStatusAndDetailsAsMapFromDataNode([dataNode]);
74         then: 'the result list size is 3'
75             result.size() == 3
76         and: 'the result contains expected values'
77             result == [
78                 CMHandle3: [details:'Subscription forwarded to dmi plugin',status:'PENDING'] as Map,
79                 CMHandle2: [details:'',status:'ACCEPTED'] as Map,
80                 CMHandle1: [details:'Cm handle does not exist',status:'REJECTED'] as Map
81             ] as Map
82     }
83 }