af7664ab8a7c1a94e9e879618c8ca3e09e000aa7
[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.impl;
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.eclipse.jdt.annotation.NonNull;
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.service.DeviceManagerServiceProvider;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationProxyParser;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
36 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
37 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
38 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
39 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils;
40 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
41 import org.opendaylight.yang.gen.v1.urn.o.ran.hardware._1._0.rev190328.ORANHWCOMPONENT;
42 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
43 import org.opendaylight.yangtools.yang.common.QName;
44
45 public class TestORanNetworkElement {
46
47     private static final QName OneCell =
48             QName.create("urn:onf:otcc:wireless:yang:radio-access:commscope-onecell", "2020-06-22", "onecell").intern();
49     private static final @NonNull QName OnapSystem = QName.create("urn:onap:system", "2020-10-26", "onap-system").intern();
50     private static String NODEIDSTRING = "nSky";
51     private static NodeId nodeId = new NodeId(NODEIDSTRING);
52
53     private static NetconfAccessor accessor;
54     private static DeviceManagerServiceProvider serviceProvider;
55     private static Capabilities capabilities;
56     private static TransactionUtils transactionUtils;
57     private static NetconfBindingAccessor bindingAccessor;
58     private static VESCollectorService vesCollectorService;
59     private static NotificationProxyParser notificationProxyParser;
60     private static VESCollectorCfgService vesCfgService;
61     private static WebsocketManagerService websocketManagerService;
62
63     @BeforeClass
64     public static void init() throws InterruptedException, IOException {
65         capabilities = mock(Capabilities.class);
66         accessor = mock(NetconfAccessor.class);
67         serviceProvider = mock(DeviceManagerServiceProvider.class);
68         transactionUtils = mock(TransactionUtils.class);
69         bindingAccessor = mock(NetconfBindingAccessor.class);
70         vesCollectorService = mock(VESCollectorService.class);
71         notificationProxyParser = mock(NotificationProxyParser.class);
72         vesCfgService = mock(VESCollectorCfgService.class);
73         websocketManagerService = mock(WebsocketManagerService.class);
74
75         when(accessor.getCapabilites()).thenReturn(capabilities);
76         when(accessor.getNodeId()).thenReturn(nodeId);
77         when(accessor.getNetconfBindingAccessor()).thenReturn(Optional.of(bindingAccessor));
78         when(bindingAccessor.getCapabilites()).thenReturn(capabilities);
79         when(bindingAccessor.getTransactionUtils()).thenReturn(transactionUtils);
80         when(bindingAccessor.getNodeId()).thenReturn(nodeId);
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(ORANHWCOMPONENT.QNAME)).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
111  }