2ca59d9168354e781f897c4b35e5aa8ddd97778c
[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.BeforeClass;
27 import org.junit.Test;
28 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.ORanNetworkElementFactory;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationProxyParser;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
35 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
36 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
37 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
38 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils;
39 import org.opendaylight.yang.gen.v1.urn.o.ran.hardware._1._0.rev190328.ORANHWCOMPONENT;
40 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
41 import org.opendaylight.yangtools.yang.common.QName;
42
43 public class TestORanNetworkElement {
44
45     private static final QName OneCell =
46             QName.create("urn:onf:otcc:wireless:yang:radio-access:commscope-onecell", "2020-06-22", "onecell").intern();
47     private static String NODEIDSTRING = "nSky";
48     private static NodeId nodeId = new NodeId(NODEIDSTRING);
49     private static NodeId nNodeId = new NodeId("nSky");
50
51     private static NetconfAccessor accessor;
52     private static DeviceManagerServiceProvider serviceProvider;
53     private static Capabilities capabilities;
54     private static TransactionUtils transactionUtils;
55     private static NetconfBindingAccessor bindingCommunicator;
56     private static VESCollectorService vesCollectorService;
57     private static NotificationProxyParser notificationProxyParser;
58     private static VESCollectorCfgService vesCfgService;
59
60     @BeforeClass
61     public static void init() throws InterruptedException, IOException {
62         capabilities = mock(Capabilities.class);
63         accessor = mock(NetconfAccessor.class);
64         serviceProvider = mock(DeviceManagerServiceProvider.class);
65         transactionUtils = mock(TransactionUtils.class);
66         bindingCommunicator = mock(NetconfBindingAccessor.class);
67         vesCollectorService = mock(VESCollectorService.class);
68         notificationProxyParser = mock(NotificationProxyParser.class);
69         vesCfgService = mock(VESCollectorCfgService.class);
70
71         when(accessor.getCapabilites()).thenReturn(capabilities);
72         when(accessor.getNodeId()).thenReturn(nNodeId);
73         when(accessor.getNetconfBindingAccessor()).thenReturn(Optional.of(bindingCommunicator));
74         when(bindingCommunicator.getTransactionUtils()).thenReturn(transactionUtils);
75         when(bindingCommunicator.getNodeId()).thenReturn(nodeId);
76         when(vesCollectorService.getNotificationProxyParser()).thenReturn(notificationProxyParser);
77
78         DataProvider dataProvider = mock(DataProvider.class);
79         when(serviceProvider.getDataProvider()).thenReturn(dataProvider);
80         when(serviceProvider.getVESCollectorService()).thenReturn(vesCollectorService);
81         when(vesCollectorService.getConfig()).thenReturn(vesCfgService);
82         when(vesCfgService.isVESCollectorEnabled()).thenReturn(true);
83
84     }
85
86     @Test
87     public void test() {
88
89         NodeId nodeId = new NodeId(NODEIDSTRING);
90         when(bindingCommunicator.getTransactionUtils()).thenReturn(mock(TransactionUtils.class));
91         when(bindingCommunicator.getNodeId()).thenReturn(nodeId);
92
93         Optional<NetworkElement> oRanNe;
94         when(capabilities.isSupportingNamespace(ORANHWCOMPONENT.QNAME)).thenReturn(true);
95         when(capabilities.isSupportingNamespace(OneCell)).thenReturn(false);
96         ORanNetworkElementFactory factory = new ORanNetworkElementFactory();
97         oRanNe = factory.create(accessor, serviceProvider);
98         assertTrue(factory.create(accessor, serviceProvider).isPresent());
99         oRanNe.get().register();
100         oRanNe.get().deregister();
101         oRanNe.get().getAcessor();
102         oRanNe.get().getDeviceType();
103         assertEquals(oRanNe.get().getNodeId().getValue(), "nSky");
104     }
105
106  }