4752b6802dce8ab565b4f0f84cf1fb445eb46a02
[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.assertEquals;
21 import static org.junit.Assert.assertTrue;
22 import static org.mockito.Mockito.mock;
23 import static org.mockito.Mockito.when;
24 import static org.mockito.Mockito.*;
25
26 import java.util.List;
27 import java.util.Optional;
28 import java.io.IOException;
29 import java.util.Date;
30
31 import org.junit.After;
32 import org.junit.BeforeClass;
33 import org.junit.Test;
34 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.ORanNetworkElementFactory;
37 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.test.mock.TransactionUtilsMock;
38 import org.opendaylight.yang.gen.v1.urn.o.ran.hardware._1._0.rev190328.ORANHWCOMPONENT;
39 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.network.topology.simulator.rev191025.SimulatorStatus;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ConnectionlogEntity;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EventlogEntity;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultcurrentEntity;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultlogEntity;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Inventory;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.NetworkElementConnectionEntity;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.PmdataEntity;
47 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
48 import org.opendaylight.yangtools.yang.common.QName;
49 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
50 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.test.mock.NetconfAccessorMock;
51 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
52
53 public class TestORanNetworkElement {
54
55         static NetconfAccessorMock accessor;
56         static DeviceManagerServiceProvider serviceProvider;
57         static Capabilities capabilities;
58         QName qCapability;
59
60         @SuppressWarnings("unchecked")
61         @BeforeClass
62         public static void init() throws InterruptedException, IOException {
63                 capabilities = mock(Capabilities.class);
64                 //accessor = mock(NetconfAccessorMock.class);
65                 accessor = spy(new NetconfAccessorMock(null, null, null, null));
66                 serviceProvider = mock(DeviceManagerServiceProvider.class);
67                 
68                 NodeId nNodeId = new NodeId("nSky");
69                 when(accessor.getCapabilites()).thenReturn(capabilities);
70                 when (accessor.getNodeId()).thenReturn(nNodeId);
71                 when (accessor.getTransactionUtils()).thenReturn(new TransactionUtilsMock());
72                 
73                 when(serviceProvider.getDataProvider()).thenReturn(new DataProvider() {
74
75                         @Override
76                         public void writeConnectionLog(ConnectionlogEntity event) {
77                                 // TODO Auto-generated method stub
78
79                         }
80
81                         @Override
82                         public void writeEventLog(EventlogEntity event) {
83                                 // TODO Auto-generated method stub
84
85                         }
86
87                         @Override
88                         public void writeFaultLog(FaultlogEntity fault) {
89                                 // TODO Auto-generated method stub
90
91                         }
92
93                         @Override
94                         public void updateFaultCurrent(FaultcurrentEntity fault) {
95                                 // TODO Auto-generated method stub
96
97                         }
98
99                         @Override
100                         public int clearFaultsCurrentOfNode(String nodeName) {
101                                 // TODO Auto-generated method stub
102                                 return 0;
103                         }
104
105                         @Override
106                         public int clearFaultsCurrentOfNodeWithObjectId(String nodeName, String objectId) {
107                                 // TODO Auto-generated method stub
108                                 return 0;
109                         }
110
111                         @Override
112                         public List<String> getAllNodesWithCurrentAlarms() {
113                                 // TODO Auto-generated method stub
114                                 return null;
115                         }
116
117                         @Override
118                         public void writeInventory(Inventory internalEquipment) {
119                                 // TODO Auto-generated method stub
120
121                         }
122
123                         @Override
124                         public void updateNetworkConnectionDeviceType(
125                                         NetworkElementConnectionEntity networkElementConnectionEntitiy, String nodeId) {
126                                 // TODO Auto-generated method stub
127
128                         }
129
130                         @Override
131                         public void updateNetworkConnection22(NetworkElementConnectionEntity networkElementConnectionEntitiy,
132                                         String nodeId) {
133                                 // TODO Auto-generated method stub
134
135                         }
136
137                         @Override
138                         public void removeNetworkConnection(String nodeId) {
139                                 // TODO Auto-generated method stub
140
141                         }
142
143                         @Override
144                         public int doIndexClean(Date olderAreOutdated) {
145                                 // TODO Auto-generated method stub
146                                 return 0;
147                         }
148
149                         @Override
150                         public int getNumberOfOldObjects(Date olderAreOutdated) {
151                                 // TODO Auto-generated method stub
152                                 return 0;
153                         }
154
155                         @Override
156                         public List<NetworkElementConnectionEntity> getNetworkElementConnections() {
157                                 // TODO Auto-generated method stub
158                                 return null;
159                         }
160
161                         @Override
162                         public void doWritePerformanceData(List<PmdataEntity> list) {
163                                 // TODO Auto-generated method stub
164
165                         }
166
167                 });
168
169
170         }
171
172         @Test
173         public void test() {
174                 Optional<NetworkElement> oRanNe;
175                 when(accessor.getCapabilites().isSupportingNamespace(ORANHWCOMPONENT.QNAME)).thenReturn(true);
176                 when(accessor.getCapabilites().isSupportingNamespace(SimulatorStatus.QNAME)).thenReturn(false);
177                 ORanNetworkElementFactory factory = new ORanNetworkElementFactory();
178                 oRanNe = factory.create(accessor, serviceProvider);
179                 assertTrue((factory.create(accessor, serviceProvider)).isPresent());
180                 oRanNe.get().register();
181                 oRanNe.get().deregister();
182                 oRanNe.get().getAcessor();
183                 oRanNe.get().getDeviceType();
184                 assertEquals(oRanNe.get().getNodeId().getValue(), "nSky");
185         }
186
187         @After
188         public void cleanUp() throws Exception {
189
190         }
191 }