migrate sdnr features to sulfur
[ccsdk/features.git] / sdnr / wt / devicemanager-onap / openroadm71 / provider / src / test / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / openroadm71 / test / TestOpenRoadmNetworkElement.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm71.test;
23
24 import static org.mockito.Mockito.mock;
25 import static org.mockito.Mockito.verify;
26 import static org.mockito.Mockito.when;
27 import java.util.Arrays;
28 import java.util.HashMap;
29 import java.util.Map;
30 import org.eclipse.jdt.annotation.Nullable;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm71.impl.OpenroadmInventoryInput;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm71.impl.OpenroadmNetworkElement;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
37 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
38 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
39 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
40 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils;
41 import org.opendaylight.mdsal.binding.api.DataBroker;
42 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev200529.ActiveAlarmList;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev200529.Severity;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev200529.active.alarm.list.ActiveAlarms;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev200529.active.alarm.list.ActiveAlarmsKey;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev200529.alarm.ProbableCauseBuilder;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev200529.alarm.ResourceBuilder;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev191129.NodeIdType;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.LifecycleState;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev200529.OpenroadmVersionType;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.OrgOpenroadmDevice;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.circuit.pack.ParentCircuitPack;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.circuit.packs.CircuitPacks;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.circuit.packs.CircuitPacksKey;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.interfaces.grp.Interface;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.interfaces.grp.InterfaceKey;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.Info;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.InfoBuilder;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.Xponder;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.XponderKey;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.shelf.Slots;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.shelf.SlotsKey;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.shelves.Shelves;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.shelves.ShelvesKey;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.NodeTypes;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.XpdrNodeTypes;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.HistoricalPmList;
70 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.group.HistoricalPm;
71 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.group.HistoricalPmKey;
72 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.list.HistoricalPmEntry;
73 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.list.HistoricalPmEntryKey;
74 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.val.group.Measurement;
75 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.val.group.MeasurementKey;
76 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev200327.PmDataType;
77 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev200327.PmGranularity;
78 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev200327.PmNamesEnum;
79 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev200327.Validity;
80 import org.opendaylight.yang.gen.v1.http.org.openroadm.probablecause.rev200529.ProbableCauseEnum;
81 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.DeviceBuilder;
82 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.types.rev191129.ResourceTypeEnum;
83 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
84 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
85 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
86 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
87 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
88 import org.opendaylight.yangtools.yang.common.Uint16;
89 import org.opendaylight.yangtools.yang.common.Uint32;
90 import org.opendaylight.yangtools.yang.common.Uint64;
91 import org.opendaylight.yangtools.yang.common.Uint8;
92
93 public class TestOpenRoadmNetworkElement {
94
95     NetconfBindingAccessor accessor = mock(NetconfBindingAccessor.class);
96     DeviceManagerServiceProvider serviceProvider = mock(DeviceManagerServiceProvider.class);
97     DataProvider dataprovider = mock(DataProvider.class);
98     Capabilities capabilities = mock(Capabilities.class);
99     TransactionUtils transactionUtils = mock(TransactionUtils.class);
100     DataBroker dataBroker = mock(DataBroker.class);
101     FaultService faultService = mock(FaultService.class);
102     OrgOpenroadmDevice device;
103     OpenroadmInventoryInput inventoryData;
104     long level = 1;
105     private Shelves shelf = mock(Shelves.class);
106     private @Nullable Map<ShelvesKey, Shelves> shelfList;
107     private CircuitPacks cp, cp1, cp2, cp3;
108     private Interface interfaces = mock(Interface.class);
109     private Xponder xpdr = mock(Xponder.class);
110     private IpAddress ipAddress = new IpAddress(new Ipv4Address("127.0.0.11"));
111     private Info info = new InfoBuilder().setNodeId(NodeIdType.getDefaultInstance("zNhe2i5")).setClli("NodeB")
112             .setSerialId("0002").setModel("model2").setVendor("VendorA").setCurrentIpAddress(ipAddress)
113             .setCurrentIpAddress(ipAddress).setCurrentDefaultGateway(new IpAddress(new Ipv4Address("127.0.0.20")))
114             .setCurrentDefaultGateway(new IpAddress(new Ipv4Address("127.0.0.20"))).setNodeType(NodeTypes.Rdm)
115             .setCurrentDatetime(new DateAndTime("2017-10-22T15:23:43Z")).setSoftwareVersion("swversion1234")
116             .setCurrentPrefixLength(Uint8.valueOf(45)).setMaxDegrees(Uint16.valueOf(56)).setMaxSrgs(Uint16.valueOf(251))
117             .setMaxNumBin15minHistoricalPm(Uint16.valueOf(324)).setMaxNumBin24hourHistoricalPm(Uint16.valueOf(142))
118             .setOpenroadmVersion(OpenroadmVersionType._20).build();
119     private ActiveAlarmList alarmList = mock(ActiveAlarmList.class);
120     private ActiveAlarms activeAlarms = mock(ActiveAlarms.class);
121     private HistoricalPmList pmDataList = mock(HistoricalPmList.class);
122     private HistoricalPm historicalPm = mock(HistoricalPm.class);
123
124     @Before
125     public void init() {
126         when(accessor.getCapabilites()).thenReturn(capabilities);
127         when(serviceProvider.getFaultService()).thenReturn(faultService);
128         when(serviceProvider.getDataProvider()).thenReturn(dataprovider);
129         NodeId nNodeId = new NodeId("RoadmA");
130         when(accessor.getNodeId()).thenReturn(nNodeId);
131         when(accessor.getDataBroker()).thenReturn(dataBroker);
132         when(accessor.getTransactionUtils()).thenReturn(transactionUtils);
133         when(accessor.getCapabilites().isSupportingNamespaceAndRevision(OrgOpenroadmDevice.QNAME)).thenReturn(true);
134         final Class<OrgOpenroadmDevice> openRoadmDev = OrgOpenroadmDevice.class;
135         // Reading data from device
136         InstanceIdentifier<OrgOpenroadmDevice> deviceId = InstanceIdentifier.create(openRoadmDev);
137         device = mock(OrgOpenroadmDevice.class);
138         when(accessor.getTransactionUtils().readData(accessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
139                 deviceId)).thenReturn(device);
140
141         when(device.getInfo()).thenReturn(info);
142         inventoryData = new OpenroadmInventoryInput(accessor, device);
143         // Reading the shelfs data;
144         when(shelf.getShelfPosition()).thenReturn("10");
145         when(shelf.getOperationalState()).thenReturn(State.InService);
146         when(shelf.getSerialId()).thenReturn("nodeid-1");
147         when(shelf.getShelfName()).thenReturn("Shelf1");
148         when(shelf.getShelfType()).thenReturn("Shelf");
149         when(shelf.getClei()).thenReturn("1234567890");
150         when(shelf.getVendor()).thenReturn("vendorA");
151         when(shelf.getModel()).thenReturn("1");
152         when(shelf.getHardwareVersion()).thenReturn("0.1");
153         when(shelf.getManufactureDate()).thenReturn(new DateAndTime("2017-10-22T15:23:43Z"));
154         @Nullable
155         Map<SlotsKey, Slots> slotList = null;
156         Slots slots = mock(Slots.class);
157         when(slots.getLabel()).thenReturn("Slot56746");
158         when(slots.getSlotName()).thenReturn("slotofRoadmA");
159         when(slots.getProvisionedCircuitPack()).thenReturn("1/0");
160         slotList = new HashMap<>();
161         slotList.put(slots.key(), slots);
162         when(shelf.getSlots()).thenReturn(slotList);
163         shelfList = new HashMap<>();
164         shelfList.put(shelf.key(), shelf);
165         when(device.getShelves()).thenReturn(shelfList);
166
167         // Reading data from CircuitPacks
168         cp = mock(CircuitPacks.class);
169         when(cp.getCircuitPackName()).thenReturn("1/0");
170         when(cp.getVendor()).thenReturn("VendorA");
171         when(cp.getModel()).thenReturn("Model1");
172         when(cp.getSerialId()).thenReturn("46277sgh6");
173         when(cp.getClei()).thenReturn("136268785");
174         when(cp.getHardwareVersion()).thenReturn("0.1");
175         when(cp.getType()).thenReturn("WSS");
176         when(cp.getProductCode()).thenReturn("oooooo");
177         when(cp.getCircuitPackMode()).thenReturn("inServiceMode");
178
179         ParentCircuitPack parentCp = mock(ParentCircuitPack.class);
180         when(parentCp.getCircuitPackName()).thenReturn("1/0");
181         when(parentCp.getCpSlotName()).thenReturn("Slot1");
182         cp1 = mock(CircuitPacks.class);
183         when(cp1.getCircuitPackName()).thenReturn("1/0 EThernet");
184         when(cp1.getVendor()).thenReturn("VendorA");
185         when(cp1.getModel()).thenReturn("Model1678");
186         when(cp1.getSerialId()).thenReturn("4627dgs7sgh6");
187         when(cp1.getClei()).thenReturn("1362d68785");
188         when(cp1.getHardwareVersion()).thenReturn("0.1");
189         when(cp1.getType()).thenReturn("EthPlug");
190         when(cp1.getProductCode()).thenReturn("oooooo");
191         when(cp1.getCircuitPackMode()).thenReturn("inServiceMode");
192         when(cp1.getParentCircuitPack()).thenReturn(parentCp);
193
194         cp2 = mock(CircuitPacks.class);
195         when(cp2.getCircuitPackName()).thenReturn("2/0");
196         when(cp2.getVendor()).thenReturn("VendorA");
197         when(cp2.getModel()).thenReturn("Model1678");
198         when(cp2.getSerialId()).thenReturn("4sads7sgh6");
199         when(cp2.getClei()).thenReturn("1wew362d68785");
200         when(cp2.getHardwareVersion()).thenReturn("0.1");
201         when(cp2.getType()).thenReturn("WSS");
202         when(cp2.getProductCode()).thenReturn("osooooo");
203         when(cp2.getCircuitPackMode()).thenReturn("inServiceMode");
204
205         cp3 = mock(CircuitPacks.class);
206         when(parentCp.getCircuitPackName()).thenReturn("2/0");
207         when(parentCp.getCpSlotName()).thenReturn("Slot1");
208         when(cp3.getCircuitPackName()).thenReturn("2/0  OCS");
209         when(cp3.getVendor()).thenReturn("VendorA");
210         when(cp3.getModel()).thenReturn("Model1678");
211         when(cp3.getSerialId()).thenReturn("dswsads7sgh6");
212         when(cp3.getClei()).thenReturn("1ew62d68785");
213         when(cp3.getHardwareVersion()).thenReturn("0.1");
214         when(cp3.getType()).thenReturn("OCS Plug");
215         when(cp3.getProductCode()).thenReturn("osooooo");
216         when(cp3.getCircuitPackMode()).thenReturn("inServiceMode");
217         when(cp3.getParentCircuitPack()).thenReturn(parentCp);
218         @Nullable
219         Map<CircuitPacksKey, CircuitPacks> cpList = new HashMap<>();
220         cpList.put(cp.key(), cp);
221         cpList.put(cp1.key(), cp1);
222         cpList.put(cp2.key(), cp2);
223         cpList.put(cp3.key(), cp3);
224         when(device.getCircuitPacks()).thenReturn(cpList);
225
226         // Reading Interface Data
227         when(interfaces.getName()).thenReturn("1GE-interface-1");
228         when(interfaces.getDescription()).thenReturn("Ethernet Interface");
229         when(interfaces.getSupportingCircuitPackName()).thenReturn("1/0 EThernet");
230         @Nullable
231         Map<InterfaceKey, Interface> interfacesList = new HashMap<>();
232         interfacesList.put(interfaces.key(), interfaces);
233         when(device.getInterface()).thenReturn(interfacesList);
234
235         // Reading Xponder Data
236         when(xpdr.getXpdrNumber()).thenReturn(Uint16.valueOf(1));
237         when(xpdr.getXpdrType()).thenReturn(XpdrNodeTypes.Mpdr);
238         when(xpdr.getLifecycleState()).thenReturn(LifecycleState.Deployed);
239         @Nullable
240         Map<XponderKey, Xponder> xpnderList = new HashMap<>();
241         xpnderList.put(xpdr.key(), xpdr);
242         when(device.getXponder()).thenReturn(xpnderList);
243
244         // Read initial Alarm data
245         final Class<ActiveAlarmList> classAlarm = ActiveAlarmList.class;
246         InstanceIdentifier<ActiveAlarmList> alarmDataIid = InstanceIdentifier.builder(classAlarm).build();
247         when(accessor.getTransactionUtils().readData(accessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
248                 alarmDataIid)).thenReturn(alarmList);
249         when(activeAlarms.getId()).thenReturn("Alarm1");
250         when(activeAlarms.getCircuitId()).thenReturn("1/0");
251         when(activeAlarms.getRaiseTime()).thenReturn(new DateAndTime("2017-10-22T15:23:43Z"));
252         when(activeAlarms.getSeverity()).thenReturn(Severity.Critical);
253         when(activeAlarms.getProbableCause())
254                 .thenReturn(new ProbableCauseBuilder().setCause(ProbableCauseEnum.AutomaticLaserShutdown).build());
255         when(activeAlarms.getAdditionalDetail()).thenReturn("LaserShutdown");
256         when(activeAlarms.getResource()).thenReturn(new ResourceBuilder()
257                 .setDevice(new DeviceBuilder().setNodeId(NodeIdType.getDefaultInstance("zNhe2i5")).build()).build());
258         @Nullable
259         Map<ActiveAlarmsKey, ActiveAlarms> activeAlarmlist = new HashMap<>();
260         activeAlarmlist.put(activeAlarms.key(), activeAlarms);
261         when(alarmList.getActiveAlarms()).thenReturn(activeAlarmlist);
262
263         // Read PM Data
264         final Class<HistoricalPmList> pmDataClass = HistoricalPmList.class;
265         InstanceIdentifier<HistoricalPmList> pmDataIid = InstanceIdentifier.builder(pmDataClass).build();
266         when(accessor.getTransactionUtils().readData(accessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
267                 pmDataIid)).thenReturn(pmDataList);
268
269         Measurement measurement = mock(Measurement.class);
270         PmDataType pmDataType = mock(PmDataType.class);
271         when(pmDataType.getUint64()).thenReturn(Uint64.valueOf(2425425));
272         when(measurement.getBinNumber()).thenReturn(Uint16.valueOf(1452));
273         when(measurement.getCompletionTime()).thenReturn(new DateAndTime("2018-10-22T15:23:43Z"));
274         when(measurement.getGranularity()).thenReturn(PmGranularity._24Hour);
275         when(measurement.getPmParameterUnit()).thenReturn("6824545199534863756");
276         when(measurement.getPmParameterValue()).thenReturn(pmDataType);
277         when(measurement.getValidity()).thenReturn(Validity.Partial);
278
279         @Nullable
280         Map<MeasurementKey, Measurement> measurementList = new HashMap<>();
281         measurementList.put(measurement.key(), measurement);
282         when(historicalPm.getMeasurement()).thenReturn(measurementList);
283         when(historicalPm.getType()).thenReturn(PmNamesEnum.ErroredSeconds);
284         when(historicalPm.getExtension()).thenReturn("OpticalPowerOutput");
285         @Nullable
286         Map<HistoricalPmKey, HistoricalPm> historicalPmList = new HashMap<>();
287         historicalPmList.put(historicalPm.key(), historicalPm);
288         HistoricalPmEntry histPmEntry = mock(HistoricalPmEntry.class);
289         when(histPmEntry.getHistoricalPm()).thenReturn(historicalPmList);
290         when(histPmEntry.getPmResourceType()).thenReturn(ResourceTypeEnum.CircuitPack);
291         @Nullable
292         Map<HistoricalPmEntryKey, HistoricalPmEntry> histPmList = new HashMap<>();
293         histPmList.put(histPmEntry.key(), histPmEntry);
294         when(pmDataList.getHistoricalPmEntry()).thenReturn(histPmList);
295
296     }
297
298
299
300     @Test
301     public void test() {
302         OpenroadmNetworkElement optionalNe = new OpenroadmNetworkElement(accessor, serviceProvider);
303         optionalNe.initialReadFromNetworkElement();
304         verify(dataprovider).writeInventory(accessor.getNodeId().getValue(),
305                 Arrays.asList(inventoryData.getInventoryData(Uint32.valueOf(0)),
306                         inventoryData.getShelvesInventory(shelf, Uint32.valueOf(1)),
307                         inventoryData.getXponderInventory(xpdr, Uint32.valueOf(1)),
308                         inventoryData.getCircuitPackInventory(cp3, Uint32.valueOf(2))));
309     }
310
311 }