2 * ============LICENSE_START========================================================
3 * Copyright (C) 2022-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.spi.model.DataNode
24 import spock.lang.Specification
26 class YangDataConverterSpec extends Specification{
28 def 'Convert a cm handle data node with private and public properties.'() {
29 given: 'a datanode with some additional (dmi, private) and public properties'
30 def dataNodeAdditionalProperties = new DataNode(xpath:'/additional-properties[@name="dmiProp1"]',
31 leaves: ['name': 'dmiProp1', 'value': 'dmiValue1'])
32 def dataNodePublicProperties = new DataNode(xpath:'/public-properties[@name="pubProp1"]',
33 leaves: ['name': 'pubProp1', 'value': 'pubValue1'])
34 def dataNodeCmHandle = new DataNode(childDataNodes:[dataNodeAdditionalProperties, dataNodePublicProperties])
35 when: 'the dataNode is converted'
36 def yangModelCmHandle = YangDataConverter.convertCmHandleToYangModel(dataNodeCmHandle,'sample-id')
37 then: 'the converted object has the correct id'
38 assert yangModelCmHandle.id == 'sample-id'
39 and: 'the additional (dmi, private) properties are included'
40 assert yangModelCmHandle.dmiProperties[0].name == 'dmiProp1'
41 assert yangModelCmHandle.dmiProperties[0].value == 'dmiValue1'
42 and: 'the public properties are included'
43 assert yangModelCmHandle.publicProperties[0].name == 'pubProp1'
44 assert yangModelCmHandle.publicProperties[0].value == 'pubValue1'
47 def 'Convert multiple cm handle data nodes'(){
48 given: 'two data nodes in a collection'
49 def dataNodes = [new DataNode(xpath:'/dmi-registry/cm-handles[@id=\'some-cm-handle\']'),
50 new DataNode(xpath:'/dmi-registry/cm-handles[@id=\'another-cm-handle\']')]
51 when: 'the data nodes are converted'
52 def yangModelCmHandles = YangDataConverter.convertDataNodesToYangModelCmHandles(dataNodes)
53 then: 'verify both have returned and CmHandleIds are correct'
54 assert yangModelCmHandles.size() == 2
55 assert yangModelCmHandles.id.containsAll(['some-cm-handle', 'another-cm-handle'])