01809bbb7e79cf6060085626fc7a69ded686c05d
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2022 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom;
19
20 import static org.junit.Assert.assertEquals;
21 import java.io.IOException;
22 import java.net.URISyntaxException;
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.List;
26 import javax.xml.stream.XMLStreamException;
27 import org.junit.After;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.mockito.Mockito;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.dataprovider.Onf14DomToInternalDataModel;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.yangspecs.CoreModel14;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.util.Onf14DomTestUtils;
34 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
35 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory;
37 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
38 import org.opendaylight.yangtools.yang.common.QName;
39 import org.opendaylight.yangtools.yang.common.QNameModule;
40 import org.opendaylight.yangtools.yang.common.Revision;
41 import org.opendaylight.yangtools.yang.common.XMLNamespace;
42 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
43 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
44 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
45 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
46 import org.xml.sax.SAXException;
47
48 public class TestOnf14ToInternalDataModel2 extends Mockito {
49
50     private static final QNameModule qnm =
51             QNameModule.create(XMLNamespace.of("urn:onf:yang:core-model-1-4"), Revision.of("2019-11-27"));
52     NetconfDomAccessor netconfDomAccessor;
53     Capabilities capabilities;
54
55     @Before
56     public void prepare() {
57         netconfDomAccessor = mock(NetconfDomAccessor.class);
58         capabilities = mock(Capabilities.class);
59         when(netconfDomAccessor.getCapabilites()).thenReturn(capabilities);
60         when(capabilities.isSupportingNamespaceAndRevision(qnm)).thenReturn(true);
61     }
62
63     @After
64     public void cleanUp() {
65         Onf14DomTestUtils.cleanup();
66     }
67
68     @Test
69     public void testWithNormalizedNodeFromJson() throws IOException, URISyntaxException {
70
71         Onf14DomToInternalDataModel model = new Onf14DomToInternalDataModel();
72
73         ContainerNode cn = (ContainerNode) Onf14DomTestUtils.getNormalizedNodeFromJson();
74         System.out.println("Container Node = "+cn);
75         MapNode equipmentMap = (MapNode) cn.getChildByArg(new NodeIdentifier(QName.create(qnm, "equipment")));
76         List<Inventory> inventoryList = new ArrayList<Inventory>();
77
78         Collection<MapEntryNode> containerMapEntries = equipmentMap.body();
79         for (MapEntryNode mapEntryNode : containerMapEntries) {
80             inventoryList.add(model.getInternalEquipment(new NodeId("nSky"), mapEntryNode, null, 0,
81                     CoreModel14.getModule(netconfDomAccessor).get()));
82         }
83         assertEquals("All elements", 1, inventoryList.size());
84
85     }
86
87     @Test
88     public void testWithNormalizedNodeFromXML()
89             throws IOException, URISyntaxException, XMLStreamException, SAXException {
90
91         Onf14DomToInternalDataModel model = new Onf14DomToInternalDataModel();
92
93         ContainerNode cn = (ContainerNode) Onf14DomTestUtils.getNormalizedNodeFromXML();
94         MapNode equipmentMap = (MapNode) cn.getChildByArg(new NodeIdentifier(QName.create(qnm, "equipment")));
95         List<Inventory> inventoryList = new ArrayList<Inventory>();
96
97         Collection<MapEntryNode> containerMapEntries = equipmentMap.body();
98         for (MapEntryNode mapEntryNode : containerMapEntries) {
99             inventoryList.add(model.getInternalEquipment(new NodeId("nSky"), mapEntryNode, null, 0,
100                     CoreModel14.getModule(netconfDomAccessor).get()));
101         }
102         assertEquals("All elements", 1, inventoryList.size());
103
104     }
105
106 }