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 / TestORanNetworkElementFactory.java
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2021 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.dom;
19
20 import static org.junit.Assert.assertTrue;
21 import static org.mockito.Mockito.mock;
22 import static org.mockito.Mockito.when;
23 import java.io.IOException;
24 import java.util.Optional;
25 import org.junit.After;
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.service.DeviceManagerServiceProvider;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
32 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
33 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
34 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
35 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
36 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils;
37 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
38 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
39
40 public class TestORanNetworkElementFactory {
41
42     private static String NODEIDSTRING = "nSky";
43
44     private static NetconfAccessor accessor;
45     private static DeviceManagerServiceProvider serviceProvider;
46     private static Capabilities capabilities;
47     private static VESCollectorService vesCollectorService;
48     private static FaultService faultService;
49     private static WebsocketManagerService notificationService;
50     private static DataProvider databaseService;
51     private static NodeId nodeId = new NodeId(NODEIDSTRING);
52
53     @BeforeClass
54     public static void init() throws InterruptedException, IOException {
55         NetconfBindingAccessor bindingAccessor = mock(NetconfBindingAccessor.class);
56         when(bindingAccessor.getTransactionUtils()).thenReturn(mock(TransactionUtils.class));
57         when(bindingAccessor.getNodeId()).thenReturn(nodeId);
58
59         NetconfDomAccessor domAccessor = mock(NetconfDomAccessor.class);
60         when(domAccessor.getNodeId()).thenReturn(nodeId);
61
62         capabilities = mock(Capabilities.class);
63         //accessor = mock(NetconfBindingAccessor.class);
64         accessor = mock(NetconfAccessor.class);
65         serviceProvider = mock(DeviceManagerServiceProvider.class);
66         vesCollectorService = mock(VESCollectorService.class);
67         faultService = mock(FaultService.class);
68         notificationService = mock(WebsocketManagerService.class);
69         databaseService = mock(DataProvider.class);
70
71         when(accessor.getCapabilites()).thenReturn(capabilities);
72         when(accessor.getNetconfBindingAccessor()).thenReturn(Optional.of(bindingAccessor));
73         when(accessor.getNetconfDomAccessor()).thenReturn(Optional.of(domAccessor));
74         when(serviceProvider.getFaultService()).thenReturn(faultService);
75         when(serviceProvider.getWebsocketService()).thenReturn(notificationService);
76         when(serviceProvider.getDataProvider()).thenReturn(databaseService);
77         when(serviceProvider.getVESCollectorService()).thenReturn(vesCollectorService);
78
79     }
80
81     @Test
82     public void testCreateORANHWComponent() throws Exception {
83         when(accessor.getCapabilites().isSupportingNamespace(ORanDeviceManagerQNames.ORAN_HW_COMPONENT)).thenReturn(true);
84         ORanNetworkElementFactory factory = new ORanNetworkElementFactory();
85         assertTrue((factory.create(accessor, serviceProvider)).isPresent());
86     }
87
88     @Test
89     public void testCreateNone() throws Exception {
90         when(accessor.getCapabilites().isSupportingNamespace(ORanDeviceManagerQNames.ORAN_HW_COMPONENT)).thenReturn(false);
91         ORanNetworkElementFactory factory = new ORanNetworkElementFactory();
92         assertTrue(!(factory.create(accessor, serviceProvider).isPresent()));
93     }
94
95     @After
96     public void cleanUp() throws Exception {
97
98     }
99 }
100