Use getDataNodes (plural version) into NCMP to get CM handles
[cps.git] / cps-ncmp-service / src / test / groovy / org / onap / cps / ncmp / api / impl / utils / YangDataConverterSpec.groovy
1 /*
2  * ============LICENSE_START========================================================
3  *  Copyright (C) 2022 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.DataNode
24 import spock.lang.Specification
25
26 class YangDataConverterSpec extends Specification{
27
28     def 'Convert a cm handle data node with private properties.'() {
29         given: 'a datanode with some additional (dmi, private) properties'
30             def dataNodeAdditionalProperties = new DataNode(xpath:'/additional-properties[@name="dmiProp1"]',
31                 leaves: ['name': 'dmiProp1', 'value': 'dmiValue1'])
32             def dataNode = new DataNode(childDataNodes:[dataNodeAdditionalProperties])
33         when: 'the dataNode is converted'
34             def yangModelCmHandle = YangDataConverter.convertCmHandleToYangModel(dataNode,'sample-id')
35         then: 'the converted object has the correct id'
36             assert yangModelCmHandle.id == 'sample-id'
37         and: 'the additional (dmi, private) properties are included'
38             assert yangModelCmHandle.dmiProperties[0].name == 'dmiProp1'
39             assert yangModelCmHandle.dmiProperties[0].value == 'dmiValue1'
40     }
41
42     def 'Convert multiple cm handle data nodes'(){
43         given: 'two data nodes in a collection one with private properties'
44             def dataNodeAdditionalProperties = new DataNode(xpath:'/additional-properties[@name="dmiProp1"]',
45                     leaves: ['name': 'dmiProp1', 'value': 'dmiValue1'])
46             def dataNodes = [new DataNode(xpath:'/dmi-registry/cm-handles[@id=\'some-cm-handle\']'),
47                              new DataNode(xpath:'/dmi-registry/cm-handles[@id=\'another-cm-handle\']', childDataNodes:[dataNodeAdditionalProperties])]
48         when: 'the data nodes are converted'
49             def yangModelCmHandles = YangDataConverter.convertDataNodesToYangModelCmHandles(dataNodes)
50         then: 'verify both have returned and cmhandleIds are correct'
51             assert yangModelCmHandles.size() == 2
52             assert yangModelCmHandles.id.containsAll(['some-cm-handle', 'another-cm-handle'])
53     }
54
55 }