0da5ec1f44f3c8a98a4ec5c135fbfddf73891761
[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.test;
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.devicemanager.oran.impl.ORanNetworkElementFactory;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
31 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
32 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
33 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils;
34 import org.opendaylight.yang.gen.v1.urn.o.ran.hardware._1._0.rev190328.ORANHWCOMPONENT;
35 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
36
37 public class TestORanNetworkElementFactory {
38
39     private static String NODEIDSTRING = "nSky";
40
41     private static NetconfBindingAccessor accessor;
42     private static DeviceManagerServiceProvider serviceProvider;
43     private static Capabilities capabilities;
44     private static VESCollectorService vesCollectorService;
45
46     @BeforeClass
47     public static void init() throws InterruptedException, IOException {
48         NetconfBindingAccessor bindingCommunicator = mock(NetconfBindingAccessor.class);
49         NodeId nodeId = new NodeId(NODEIDSTRING);
50         when(bindingCommunicator.getTransactionUtils()).thenReturn(mock(TransactionUtils.class));
51         when(bindingCommunicator.getNodeId()).thenReturn(nodeId);
52
53         capabilities = mock(Capabilities.class);
54         accessor = mock(NetconfBindingAccessor.class);
55         serviceProvider = mock(DeviceManagerServiceProvider.class);
56         vesCollectorService = mock(VESCollectorService.class);
57
58         when(accessor.getCapabilites()).thenReturn(capabilities);
59         when(accessor.getNetconfBindingAccessor()).thenReturn(Optional.of(bindingCommunicator));
60         when(serviceProvider.getDataProvider()).thenReturn(null);
61         when(serviceProvider.getVESCollectorService()).thenReturn(vesCollectorService);
62     }
63
64     @Test
65     public void testCreateORANHWComponent() throws Exception {
66         when(accessor.getCapabilites().isSupportingNamespace(ORANHWCOMPONENT.QNAME)).thenReturn(true);
67         ORanNetworkElementFactory factory = new ORanNetworkElementFactory();
68         assertTrue((factory.create(accessor, serviceProvider)).isPresent());
69     }
70
71     @Test
72     public void testCreateNone() throws Exception {
73         when(accessor.getCapabilites().isSupportingNamespace(ORANHWCOMPONENT.QNAME)).thenReturn(false);
74         ORanNetworkElementFactory factory = new ORanNetworkElementFactory();
75         assertTrue(!(factory.create(accessor, serviceProvider).isPresent()));
76     }
77
78     @After
79     public void cleanUp() throws Exception {
80
81     }
82 }
83