Upgrade devicemanager-oran minus NTSim functionality
[oam.git] / features / devicemanager / o-ran / ru-fh / provider / src / test / java / org / oransc / oam / features / devicemanager / oran / test / TestORanNetworkElement.java
1 /*
2  * ============LICENSE_START========================================================================
3  * O-RAN-SC : oam/ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2020 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.oransc.oam.features.devicemanager.oran.test;
19
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertTrue;
22 import static org.mockito.Mockito.mock;
23 import static org.mockito.Mockito.spy;
24 import static org.mockito.Mockito.when;
25 import java.io.IOException;
26 import java.util.Optional;
27 import org.junit.After;
28 import org.junit.BeforeClass;
29 import org.junit.Test;
30 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
33 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
34 import org.opendaylight.yang.gen.v1.urn.o.ran.hardware._1._0.rev190328.ORANHWCOMPONENT;
35 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.network.topology.simulator.rev191025.SimulatorStatus;
36 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
37 import org.opendaylight.yangtools.yang.common.QName;
38 import org.oransc.oam.features.devicemanager.oran.impl.ORanNetworkElementFactory;
39 import org.oransc.oam.features.devicemanager.oran.test.mock.NetconfAccessorMock;
40 import org.oransc.oam.features.devicemanager.oran.test.mock.TransactionUtilsMock;
41
42 public class TestORanNetworkElement {
43
44     static NetconfAccessorMock accessor;
45     static DeviceManagerServiceProvider serviceProvider;
46     static Capabilities capabilities;
47     QName qCapability;
48
49     @BeforeClass
50     public static void init() throws InterruptedException, IOException {
51         capabilities = mock(Capabilities.class);
52         //accessor = mock(NetconfAccessorMock.class);
53         accessor = spy(new NetconfAccessorMock(null, null, null, null));
54         serviceProvider = mock(DeviceManagerServiceProvider.class);
55
56         NodeId nNodeId = new NodeId("nSky");
57         when(accessor.getCapabilites()).thenReturn(capabilities);
58         when (accessor.getNodeId()).thenReturn(nNodeId);
59         when (accessor.getTransactionUtils()).thenReturn(new TransactionUtilsMock());
60
61         DataProvider dataProvider = mock(DataProvider.class);
62         when(serviceProvider.getDataProvider()).thenReturn(dataProvider);
63     }
64
65     @Test
66     public void test() {
67         Optional<NetworkElement> oRanNe;
68         when(accessor.getCapabilites().isSupportingNamespace(ORANHWCOMPONENT.QNAME)).thenReturn(true);
69         when(accessor.getCapabilites().isSupportingNamespace(SimulatorStatus.QNAME)).thenReturn(false);
70         ORanNetworkElementFactory factory = new ORanNetworkElementFactory();
71         oRanNe = factory.create(accessor, serviceProvider);
72         assertTrue(factory.create(accessor, serviceProvider).isPresent());
73         oRanNe.get().register();
74         oRanNe.get().deregister();
75         oRanNe.get().getAcessor();
76         oRanNe.get().getDeviceType();
77         assertEquals(oRanNe.get().getNodeId().getValue(), "nSky");
78     }
79
80     @After
81     public void cleanUp() throws Exception {
82
83     }
84 }