Merge "Optimize cm-handle registration with CPS-DMI Plugin to upload yang model"
[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 / TestORanNetworkElementFactory.java
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.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.NetconfBindingAccessor;
34 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils;
35 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
36 import org.opendaylight.yang.gen.v1.urn.o.ran.hardware._1._0.rev190328.ORANHWCOMPONENT;
37 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
38
39 public class TestORanNetworkElementFactory {
40
41     private static String NODEIDSTRING = "nSky";
42
43     private static NetconfBindingAccessor accessor;
44     private static DeviceManagerServiceProvider serviceProvider;
45     private static Capabilities capabilities;
46     private static VESCollectorService vesCollectorService;
47     private static FaultService faultService;
48     private static WebsocketManagerService notificationService;
49     private static DataProvider databaseService;
50
51     @BeforeClass
52     public static void init() throws InterruptedException, IOException {
53         NetconfBindingAccessor bindingAccessor = mock(NetconfBindingAccessor.class);
54         NodeId nodeId = new NodeId(NODEIDSTRING);
55         when(bindingAccessor.getTransactionUtils()).thenReturn(mock(TransactionUtils.class));
56         when(bindingAccessor.getNodeId()).thenReturn(nodeId);
57
58         capabilities = mock(Capabilities.class);
59         accessor = mock(NetconfBindingAccessor.class);
60         serviceProvider = mock(DeviceManagerServiceProvider.class);
61         vesCollectorService = mock(VESCollectorService.class);
62         faultService = mock(FaultService.class);
63         notificationService = mock(WebsocketManagerService.class);
64         databaseService = mock(DataProvider.class);
65
66         when(accessor.getCapabilites()).thenReturn(capabilities);
67         when(accessor.getNetconfBindingAccessor()).thenReturn(Optional.of(bindingAccessor));
68         when(serviceProvider.getFaultService()).thenReturn(faultService);
69         when(serviceProvider.getWebsocketService()).thenReturn(notificationService);
70         when(serviceProvider.getDataProvider()).thenReturn(databaseService);
71         when(serviceProvider.getVESCollectorService()).thenReturn(vesCollectorService);
72
73     }
74
75     @Test
76     public void testCreateORANHWComponent() throws Exception {
77         when(accessor.getCapabilites().isSupportingNamespace(ORANHWCOMPONENT.QNAME)).thenReturn(true);
78         ORanNetworkElementFactory factory = new ORanNetworkElementFactory();
79         assertTrue((factory.create(accessor, serviceProvider)).isPresent());
80     }
81
82     @Test
83     public void testCreateNone() throws Exception {
84         when(accessor.getCapabilites().isSupportingNamespace(ORANHWCOMPONENT.QNAME)).thenReturn(false);
85         ORanNetworkElementFactory factory = new ORanNetworkElementFactory();
86         assertTrue(!(factory.create(accessor, serviceProvider).isPresent()));
87     }
88
89     @After
90     public void cleanUp() throws Exception {
91
92     }
93 }
94