c75f4f5a12ced787a37189dc450fd653a68e026a
[ccsdk/features.git] / sdnr / wt / devicemanager-o-ran-sc / o-ran / ru-fh / provider / src / test / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / oran / impl / dom / TestORanDOMNetworkElement.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.dom;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertTrue;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.when;
28 import java.io.IOException;
29 import java.util.Optional;
30 import org.eclipse.jdt.annotation.NonNull;
31 import org.junit.BeforeClass;
32 import org.junit.Test;
33 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.startup.ORanNetworkElementFactory;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
37 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
38 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationProxyParser;
39 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService;
40 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
41 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
42 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
43 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
44 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
45 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
46 import org.opendaylight.yangtools.yang.common.QName;
47
48 public class TestORanDOMNetworkElement {
49
50     private static final QName OneCell =
51             QName.create("urn:onf:otcc:wireless:yang:radio-access:commscope-onecell", "2020-06-22", "onecell").intern();
52     private static final @NonNull QName OnapSystem =
53             QName.create("urn:onap:system", "2020-10-26", "onap-system").intern();
54     private static String NODEIDSTRING = "nSky";
55     private static NodeId nodeId = new NodeId(NODEIDSTRING);
56
57     private static NetconfAccessor accessor;
58     private static DeviceManagerServiceProvider serviceProvider;
59     private static Capabilities capabilities;
60     private static NetconfDomAccessor domAccessor;
61     private static VESCollectorService vesCollectorService;
62     private static NotificationProxyParser notificationProxyParser;
63     private static VESCollectorCfgService vesCfgService;
64     private static WebsocketManagerService websocketManagerService;
65
66     @BeforeClass
67     public static void init() throws InterruptedException, IOException {
68         capabilities = mock(Capabilities.class);
69         accessor = mock(NetconfAccessor.class);
70         serviceProvider = mock(DeviceManagerServiceProvider.class);
71         domAccessor = mock(NetconfDomAccessor.class);
72         vesCollectorService = mock(VESCollectorService.class);
73         notificationProxyParser = mock(NotificationProxyParser.class);
74         vesCfgService = mock(VESCollectorCfgService.class);
75         websocketManagerService = mock(WebsocketManagerService.class);
76
77         when(accessor.getCapabilites()).thenReturn(capabilities);
78         when(accessor.getNodeId()).thenReturn(nodeId);
79         when(accessor.getNetconfDomAccessor()).thenReturn(Optional.of(domAccessor));
80         when(domAccessor.getNodeId()).thenReturn(nodeId);
81         when(domAccessor.getCapabilites()).thenReturn(capabilities);
82         when(vesCollectorService.getNotificationProxyParser()).thenReturn(notificationProxyParser);
83
84         DataProvider dataProvider = mock(DataProvider.class);
85         FaultService faultService = mock(FaultService.class);
86         when(serviceProvider.getWebsocketService()).thenReturn(websocketManagerService);
87         when(serviceProvider.getFaultService()).thenReturn(faultService);
88         when(serviceProvider.getDataProvider()).thenReturn(dataProvider);
89         when(serviceProvider.getVESCollectorService()).thenReturn(vesCollectorService);
90         when(vesCollectorService.getConfig()).thenReturn(vesCfgService);
91         when(vesCfgService.isVESCollectorEnabled()).thenReturn(true);
92
93     }
94
95     @Test
96     public void test() {
97         Optional<NetworkElement> oRanNe;
98         when(capabilities.isSupportingNamespace(ORanDeviceManagerQNames.ORAN_HW_COMPONENT)).thenReturn(true);
99         when(capabilities.isSupportingNamespace(OneCell)).thenReturn(false);
100         when(capabilities.isSupportingNamespace(OnapSystem)).thenReturn(false);
101
102         ORanNetworkElementFactory factory = new ORanNetworkElementFactory();
103         oRanNe = factory.create(accessor, serviceProvider);
104         assertTrue(factory.create(accessor, serviceProvider).isPresent());
105         oRanNe.get().register();
106         oRanNe.get().deregister();
107         oRanNe.get().getAcessor();
108         oRanNe.get().getDeviceType();
109         assertEquals(oRanNe.get().getNodeId().getValue(), "nSky");
110     }
111 }