b889f39c9f6120582749da9ab5171653c93405b4
[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         MapNode equipmentMap = (MapNode) cn.getChildByArg(new NodeIdentifier(QName.create(qnm, "equipment")));
75         List<Inventory> inventoryList = new ArrayList<Inventory>();
76
77         Collection<MapEntryNode> containerMapEntries = equipmentMap.body();
78         for (MapEntryNode mapEntryNode : containerMapEntries) {
79             inventoryList.add(model.getInternalEquipment(new NodeId("nSky"), mapEntryNode, null, 0,
80                     CoreModel14.getModule(netconfDomAccessor).get()));
81         }
82         assertEquals("All elements", 1, inventoryList.size());
83
84     }
85
86     @Test
87     public void testWithNormalizedNodeFromXML()
88             throws IOException, URISyntaxException, XMLStreamException, SAXException {
89
90         Onf14DomToInternalDataModel model = new Onf14DomToInternalDataModel();
91
92         ContainerNode cn = (ContainerNode) Onf14DomTestUtils.getNormalizedNodeFromXML();
93         MapNode equipmentMap = (MapNode) cn.getChildByArg(new NodeIdentifier(QName.create(qnm, "equipment")));
94         List<Inventory> inventoryList = new ArrayList<Inventory>();
95
96         Collection<MapEntryNode> containerMapEntries = equipmentMap.body();
97         for (MapEntryNode mapEntryNode : containerMapEntries) {
98             inventoryList.add(model.getInternalEquipment(new NodeId("nSky"), mapEntryNode, null, 0,
99                     CoreModel14.getModule(netconfDomAccessor).get()));
100         }
101         assertEquals("All elements", 1, inventoryList.size());
102
103     }
104
105 }