a0321206c0642746a370010d148eee24f2569dfd
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : 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.onap.ccsdk.features.sdnr.wt.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.when;
24 import java.io.IOException;
25 import java.util.Optional;
26 import org.junit.After;
27 import org.junit.BeforeClass;
28 import org.junit.Test;
29 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.ORanNetworkElementFactory;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.test.mock.TransactionUtilsMock;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
34 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
35 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
36 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils;
37 import org.opendaylight.yang.gen.v1.urn.o.ran.hardware._1._0.rev190328.ORANHWCOMPONENT;
38 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
39
40 public class TestORanNetworkElement {
41
42     private static String NODEIDSTRING = "nSky";
43
44     private static NetconfBindingAccessor accessor;
45     private static DeviceManagerServiceProvider serviceProvider;
46     private static Capabilities capabilities;
47
48     @BeforeClass
49     public static void init() throws InterruptedException, IOException {
50         capabilities = mock(Capabilities.class);
51         accessor = mock(NetconfBindingAccessor.class);
52         serviceProvider = mock(DeviceManagerServiceProvider.class);
53
54         NetconfBindingAccessor bindingCommunicator = mock(NetconfBindingAccessor.class);
55         NodeId nodeId = new NodeId(NODEIDSTRING);
56         when(bindingCommunicator.getTransactionUtils()).thenReturn(mock(TransactionUtils.class));
57         when(bindingCommunicator.getNodeId()).thenReturn(nodeId);
58
59         NodeId nNodeId = new NodeId("nSky");
60         when(accessor.getCapabilites()).thenReturn(capabilities);
61         when(accessor.getNodeId()).thenReturn(nNodeId);
62         when(accessor.getTransactionUtils()).thenReturn(new TransactionUtilsMock());
63
64         DataProvider dataProvider = mock(DataProvider.class);
65         when(serviceProvider.getDataProvider()).thenReturn(dataProvider);
66         when(accessor.getNetconfBindingAccessor()).thenReturn(Optional.of(bindingCommunicator));
67
68
69     }
70
71     @Test
72     public void test() {
73         NetconfBindingAccessor bindingCommunicator = mock(NetconfBindingAccessor.class);
74         NodeId nodeId = new NodeId(NODEIDSTRING);
75         when(bindingCommunicator.getTransactionUtils()).thenReturn(mock(TransactionUtils.class));
76         when(bindingCommunicator.getNodeId()).thenReturn(nodeId);
77
78         Optional<NetworkElement> oRanNe;
79         when(accessor.getCapabilites().isSupportingNamespace(ORANHWCOMPONENT.QNAME)).thenReturn(true);
80         ORanNetworkElementFactory factory = new ORanNetworkElementFactory();
81         oRanNe = factory.create(accessor, serviceProvider);
82         assertTrue(factory.create(accessor, serviceProvider).isPresent());
83         oRanNe.get().register();
84         oRanNe.get().deregister();
85         oRanNe.get().getAcessor();
86         oRanNe.get().getDeviceType();
87         assertEquals(oRanNe.get().getNodeId().getValue(), "nSky");
88     }
89
90     @After
91     public void cleanUp() throws Exception {
92
93     }
94 }