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