Use DOM API for ORAN Devicemanager
[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.service.DeviceManagerServiceProvider;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
37 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationProxyParser;
38 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService;
39 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
40 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
41 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
42 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
43 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
44 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
45 import org.opendaylight.yangtools.yang.common.QName;
46
47 public class TestORanDOMNetworkElement {
48
49     private static final QName OneCell =
50             QName.create("urn:onf:otcc:wireless:yang:radio-access:commscope-onecell", "2020-06-22", "onecell").intern();
51     private static final @NonNull QName OnapSystem =
52             QName.create("urn:onap:system", "2020-10-26", "onap-system").intern();
53     private static String NODEIDSTRING = "nSky";
54     private static NodeId nodeId = new NodeId(NODEIDSTRING);
55
56     private static NetconfAccessor accessor;
57     private static DeviceManagerServiceProvider serviceProvider;
58     private static Capabilities capabilities;
59     private static NetconfDomAccessor domAccessor;
60     private static VESCollectorService vesCollectorService;
61     private static NotificationProxyParser notificationProxyParser;
62     private static VESCollectorCfgService vesCfgService;
63     private static WebsocketManagerService websocketManagerService;
64
65     @BeforeClass
66     public static void init() throws InterruptedException, IOException {
67         capabilities = mock(Capabilities.class);
68         accessor = mock(NetconfAccessor.class);
69         serviceProvider = mock(DeviceManagerServiceProvider.class);
70         domAccessor = mock(NetconfDomAccessor.class);
71         vesCollectorService = mock(VESCollectorService.class);
72         notificationProxyParser = mock(NotificationProxyParser.class);
73         vesCfgService = mock(VESCollectorCfgService.class);
74         websocketManagerService = mock(WebsocketManagerService.class);
75
76         when(accessor.getCapabilites()).thenReturn(capabilities);
77         when(accessor.getNodeId()).thenReturn(nodeId);
78         when(accessor.getNetconfDomAccessor()).thenReturn(Optional.of(domAccessor));
79         when(domAccessor.getNodeId()).thenReturn(nodeId);
80         when(domAccessor.getCapabilites()).thenReturn(capabilities);
81         when(vesCollectorService.getNotificationProxyParser()).thenReturn(notificationProxyParser);
82
83         DataProvider dataProvider = mock(DataProvider.class);
84         FaultService faultService = mock(FaultService.class);
85         when(serviceProvider.getWebsocketService()).thenReturn(websocketManagerService);
86         when(serviceProvider.getFaultService()).thenReturn(faultService);
87         when(serviceProvider.getDataProvider()).thenReturn(dataProvider);
88         when(serviceProvider.getVESCollectorService()).thenReturn(vesCollectorService);
89         when(vesCollectorService.getConfig()).thenReturn(vesCfgService);
90         when(vesCfgService.isVESCollectorEnabled()).thenReturn(true);
91
92     }
93
94     @Test
95     public void test() {
96         Optional<NetworkElement> oRanNe;
97         when(capabilities.isSupportingNamespace(ORanDeviceManagerQNames.ORAN_HW_COMPONENT)).thenReturn(true);
98         when(capabilities.isSupportingNamespace(OneCell)).thenReturn(false);
99         when(capabilities.isSupportingNamespace(OnapSystem)).thenReturn(false);
100
101         ORanNetworkElementFactory factory = new ORanNetworkElementFactory();
102         oRanNe = factory.create(accessor, serviceProvider);
103         assertTrue(factory.create(accessor, serviceProvider).isPresent());
104         oRanNe.get().register();
105         oRanNe.get().deregister();
106         oRanNe.get().getAcessor();
107         oRanNe.get().getDeviceType();
108         assertEquals(oRanNe.get().getNodeId().getValue(), "nSky");
109     }
110 }