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
12 // * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 //package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.test;
24 //import static org.mockito.Mockito.mock;
25 //import static org.mockito.Mockito.when;
26 //import java.math.BigInteger;
27 //import java.util.Arrays;
28 //import java.util.HashMap;
29 //import java.util.List;
30 //import java.util.Map;
32 //import org.eclipse.jdt.annotation.Nullable;
33 //import org.junit.Before;
34 //import org.junit.Test;
35 //import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
36 //import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.impl.OpenroadmInventoryInput;
37 //import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.impl.OpenroadmNetworkElement;
38 //import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
39 //import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
40 //import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
41 //import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
42 //import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils;
43 //import org.opendaylight.mdsal.binding.api.DataBroker;
44 //import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
45 //import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.ActiveAlarmList;
46 //import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.Severity;
47 //import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.active.alarm.list.ActiveAlarms;
48 //import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.active.alarm.list.ActiveAlarmsKey;
49 //import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.alarm.ProbableCauseBuilder;
50 //import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.alarm.ResourceBuilder;
51 //import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev191129.NodeIdType;
52 //import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.LifecycleState;
53 //import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
54 //import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev191129.OpenroadmVersionType;
55 //import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.OrgOpenroadmDevice;
56 //import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.circuit.pack.ParentCircuitPack;
57 //import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.circuit.packs.CircuitPacks;
58 //import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.circuit.packs.CircuitPacksKey;
59 //import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.interfaces.grp.Interface;
60 //import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.interfaces.grp.InterfaceKey;
61 //import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.org.openroadm.device.Info;
62 //import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.org.openroadm.device.InfoBuilder;
63 //import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.org.openroadm.device.Xponder;
64 //import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.org.openroadm.device.XponderKey;
65 //import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.shelf.Slots;
66 //import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.shelf.SlotsKey;
67 //import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.shelves.Shelves;
68 //import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.shelves.ShelvesKey;
69 //import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.NodeTypes;
70 //import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.XpdrNodeTypes;
71 //import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.HistoricalPmList;
72 //import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.group.HistoricalPm;
73 //import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.group.HistoricalPmKey;
74 //import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.list.HistoricalPmEntry;
75 //import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.list.HistoricalPmEntryKey;
76 //import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.val.group.Measurement;
77 //import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.val.group.MeasurementKey;
78 //import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmDataType;
79 //import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmGranularity;
80 //import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmNamesEnum;
81 //import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.Validity;
82 //import org.opendaylight.yang.gen.v1.http.org.openroadm.probablecause.rev191129.ProbableCauseEnum;
83 //import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev191129.resource.DeviceBuilder;
84 //import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.types.rev191129.ResourceTypeEnum;
85 //import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
86 //import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
87 //import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
88 //import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory;
89 //import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
90 //import org.opendaylight.yangtools.yang.binding.DataObject;
91 //import org.opendaylight.yangtools.yang.binding.Identifiable;
92 //import org.opendaylight.yangtools.yang.binding.Identifier;
93 //import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
94 //import org.opendaylight.yangtools.yang.common.Uint16;
95 //import org.opendaylight.yangtools.yang.common.Uint64;
97 //public class TestOpenRoadmNetworkElement {
99 // NetconfAccessor accessor = mock(NetconfAccessor.class);
100 // DeviceManagerServiceProvider serviceProvider = mock(DeviceManagerServiceProvider.class);
101 // DataProvider dataprovider = mock(DataProvider.class);
102 // Capabilities capabilities = mock(Capabilities.class);
103 // TransactionUtils transactionUtils = mock(TransactionUtils.class);
104 // DataBroker dataBroker = mock(DataBroker.class);
105 // // OscaNetworkElement optionalNe = mock(OscaNetworkElement.class);
107 // FaultService faultService = mock(FaultService.class);
108 // OrgOpenroadmDevice device;
109 // // OscaInventoryInput inventoryData = mock(OscaInventoryInput.class);
110 // OpenroadmInventoryInput inventoryData;
111 // private Inventory equipment = mock(Inventory.class);
113 // private Shelves shelf = mock(Shelves.class);
114 // private @Nullable Map<ShelvesKey, Shelves> shelfList;
115 // private CircuitPacks cp, cp1, cp2, cp3;
116 // private Interface interfaces = mock(Interface.class);
117 // private Xponder xpdr = mock(Xponder.class);
118 // private IpAddress ipAddress = new IpAddress(new Ipv4Address("127.0.0.11"));
119 // private Info info = new InfoBuilder().setNodeId(NodeIdType.getDefaultInstance("zNhe2i5")).setClli("NodeB")
120 // .setSerialId("0002").setModel("model2").setVendor("VendorA").setCurrentIpAddress(ipAddress)
121 // .setCurrentIpAddress(ipAddress).setCurrentDefaultGateway(new IpAddress(new Ipv4Address("127.0.0.20")))
122 // .setCurrentDefaultGateway(new IpAddress(new Ipv4Address("127.0.0.20"))).setNodeType(NodeTypes.Rdm)
123 // .setCurrentDatetime(new DateAndTime("2017-10-22T15:23:43Z")).setSoftwareVersion("swversion1234")
124 // .setPrefixLength((short) 28).setMaxDegrees(2).setMaxSrgs(3).setMaxNumBin15minHistoricalPm(32)
125 // .setMaxNumBin24hourHistoricalPm(7).setOpenroadmVersion(OpenroadmVersionType._20).build();
126 // private ActiveAlarmList alarmList = mock(ActiveAlarmList.class);
127 // private ActiveAlarms activeAlarms = mock(ActiveAlarms.class);
128 // private HistoricalPmList pmDataList = mock(HistoricalPmList.class);
129 // private HistoricalPm historicalPm = mock(HistoricalPm.class);
131 // public void init() {
132 // when(accessor.getCapabilites()).thenReturn(capabilities);
133 // when(serviceProvider.getFaultService()).thenReturn(faultService);
134 // when(serviceProvider.getDataProvider()).thenReturn(dataprovider);
135 // NodeId nNodeId = new NodeId("RoadmA");
136 // when(accessor.getNodeId()).thenReturn(nNodeId);
137 // when(accessor.getDataBroker()).thenReturn(dataBroker);
138 // when(accessor.getTransactionUtils()).thenReturn(transactionUtils);
139 // when(accessor.getCapabilites().isSupportingNamespaceAndRevision(OrgOpenroadmDevice.QNAME)).thenReturn(true);
140 // final Class<OrgOpenroadmDevice> openRoadmDev = OrgOpenroadmDevice.class;
141 // // Reading data from device
142 // InstanceIdentifier<OrgOpenroadmDevice> deviceId = InstanceIdentifier.builder(openRoadmDev).build();
143 // device = mock(OrgOpenroadmDevice.class);
144 // when(accessor.getTransactionUtils().readData(accessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
145 // deviceId)).thenReturn(device);
147 // when(device.getInfo()).thenReturn(info);
148 // inventoryData = new OpenroadmInventoryInput(accessor, device);
149 // // Reading the shelfs data;
150 // when(shelf.getShelfPosition()).thenReturn("10");
151 // when(shelf.getOperationalState()).thenReturn(State.InService);
152 // when(shelf.getSerialId()).thenReturn("nodeid-1");
153 // when(shelf.getShelfName()).thenReturn("Shelf1");
154 // when(shelf.getShelfType()).thenReturn("Shelf");
155 // when(shelf.getClei()).thenReturn("1234567890");
156 // when(shelf.getVendor()).thenReturn("vendorA");
157 // when(shelf.getModel()).thenReturn("1");
158 // when(shelf.getHardwareVersion()).thenReturn("0.1");
159 // when(shelf.getManufactureDate()).thenReturn(new DateAndTime("2017-10-22T15:23:43Z"));
160 // @Nullable Map<SlotsKey, Slots> slotList = null;
161 // Slots slots = mock(Slots.class);
162 // when(slots.getLabel()).thenReturn("Slot56746");
163 // when(slots.getSlotName()).thenReturn("slotofRoadmA");
164 // when(slots.getProvisionedCircuitPack()).thenReturn("1/0");
165 // slotList = new HashMap<>();
166 // slotList.put(slots.key(),slots);
167 // when(shelf.getSlots()).thenReturn(slotList);
168 // shelfList = new HashMap<>();
169 // shelfList.put(shelf.key(),shelf);
170 // when(device.getShelves()).thenReturn(shelfList);
172 // // Reading data from CircuitPacks
173 // cp = mock(CircuitPacks.class);
174 // when(cp.getCircuitPackName()).thenReturn("1/0");
175 // when(cp.getVendor()).thenReturn("VendorA");
176 // when(cp.getModel()).thenReturn("Model1");
177 // when(cp.getSerialId()).thenReturn("46277sgh6");
178 // when(cp.getClei()).thenReturn("136268785");
179 // when(cp.getHardwareVersion()).thenReturn("0.1");
180 // when(cp.getType()).thenReturn("WSS");
181 // when(cp.getProductCode()).thenReturn("oooooo");
182 // when(cp.getCircuitPackMode()).thenReturn("inServiceMode");
184 // ParentCircuitPack parentCp = mock(ParentCircuitPack.class);
185 // when(parentCp.getCircuitPackName()).thenReturn("1/0");
186 // when(parentCp.getCpSlotName()).thenReturn("Slot1");
187 // cp1 = mock(CircuitPacks.class);
188 // when(cp1.getCircuitPackName()).thenReturn("1/0 EThernet");
189 // when(cp1.getVendor()).thenReturn("VendorA");
190 // when(cp1.getModel()).thenReturn("Model1678");
191 // when(cp1.getSerialId()).thenReturn("4627dgs7sgh6");
192 // when(cp1.getClei()).thenReturn("1362d68785");
193 // when(cp1.getHardwareVersion()).thenReturn("0.1");
194 // when(cp1.getType()).thenReturn("EthPlug");
195 // when(cp1.getProductCode()).thenReturn("oooooo");
196 // when(cp1.getCircuitPackMode()).thenReturn("inServiceMode");
197 // when(cp1.getParentCircuitPack()).thenReturn(parentCp);
199 // cp2 = mock(CircuitPacks.class);
200 // when(cp2.getCircuitPackName()).thenReturn("2/0");
201 // when(cp2.getVendor()).thenReturn("VendorA");
202 // when(cp2.getModel()).thenReturn("Model1678");
203 // when(cp2.getSerialId()).thenReturn("4sads7sgh6");
204 // when(cp2.getClei()).thenReturn("1wew362d68785");
205 // when(cp2.getHardwareVersion()).thenReturn("0.1");
206 // when(cp2.getType()).thenReturn("WSS");
207 // when(cp2.getProductCode()).thenReturn("osooooo");
208 // when(cp2.getCircuitPackMode()).thenReturn("inServiceMode");
210 // cp3 = mock(CircuitPacks.class);
211 // when(parentCp.getCircuitPackName()).thenReturn("2/0");
212 // when(parentCp.getCpSlotName()).thenReturn("Slot1");
213 // when(cp3.getCircuitPackName()).thenReturn("2/0 OCS");
214 // when(cp3.getVendor()).thenReturn("VendorA");
215 // when(cp3.getModel()).thenReturn("Model1678");
216 // when(cp3.getSerialId()).thenReturn("dswsads7sgh6");
217 // when(cp3.getClei()).thenReturn("1ew62d68785");
218 // when(cp3.getHardwareVersion()).thenReturn("0.1");
219 // when(cp3.getType()).thenReturn("OCS Plug");
220 // when(cp3.getProductCode()).thenReturn("osooooo");
221 // when(cp3.getCircuitPackMode()).thenReturn("inServiceMode");
222 // when(cp3.getParentCircuitPack()).thenReturn(parentCp);
223 // @Nullable Map<CircuitPacksKey, CircuitPacks> cpList = new HashMap<>();
224 // cpList.put(cp.key(),cp);
225 // cpList.put(cp1.key(),cp1);
226 // cpList.put(cp2.key(),cp2);
227 // cpList.put(cp3.key(),cp3);
228 // when(device.getCircuitPacks()).thenReturn(cpList);
230 // // Reading Interface Data
231 // when(interfaces.getName()).thenReturn("1GE-interface-1");
232 // when(interfaces.getDescription()).thenReturn("Ethernet Interface");
233 // when(interfaces.getSupportingCircuitPackName()).thenReturn("1/0 EThernet");
234 // @Nullable Map<InterfaceKey, Interface> interfacesList = new HashMap<>();
235 // interfacesList.put(interfaces.key(),interfaces);
236 // when(device.getInterface()).thenReturn(interfacesList);
238 // // Reading Xponder Data
239 // when(xpdr.getXpdrNumber()).thenReturn(Uint16.valueOf(1));
240 // when(xpdr.getXpdrType()).thenReturn(XpdrNodeTypes.Mpdr);
241 // when(xpdr.getLifecycleState()).thenReturn(LifecycleState.Deployed);
242 // @Nullable Map<XponderKey, Xponder> xpnderList = new HashMap<>();
243 // xpnderList.put(xpdr.key(), xpdr);
244 // when(device.getXponder()).thenReturn(xpnderList);
246 // // Read initial Alarm data
247 // final Class<ActiveAlarmList> classAlarm = ActiveAlarmList.class;
248 // InstanceIdentifier<ActiveAlarmList> alarmDataIid = InstanceIdentifier.builder(classAlarm).build();
249 // when(accessor.getTransactionUtils().readData(accessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
250 // alarmDataIid)).thenReturn(alarmList);
251 // when(activeAlarms.getId()).thenReturn("Alarm1");
252 // when(activeAlarms.getCircuitId()).thenReturn("1/0");
253 // when(activeAlarms.getRaiseTime()).thenReturn(new DateAndTime("2017-10-22T15:23:43Z"));
254 // when(activeAlarms.getSeverity()).thenReturn(Severity.Critical);
255 // when(activeAlarms.getProbableCause())
256 // .thenReturn(new ProbableCauseBuilder().setCause(ProbableCauseEnum.AutomaticLaserShutdown).build());
257 // when(activeAlarms.getAdditionalDetail()).thenReturn("LaserShutdown");
258 // when(activeAlarms.getResource()).thenReturn(new ResourceBuilder()
259 // .setDevice(new DeviceBuilder().setNodeId(NodeIdType.getDefaultInstance("zNhe2i5")).build()).build());
260 // @Nullable Map<ActiveAlarmsKey, ActiveAlarms> activeAlarmlist = new HashMap<>();
261 // activeAlarmlist.put(activeAlarms.key(),activeAlarms);
262 // when(alarmList.getActiveAlarms()).thenReturn(activeAlarmlist);
265 // final Class<HistoricalPmList> pmDataClass = HistoricalPmList.class;
266 // InstanceIdentifier<HistoricalPmList> pmDataIid = InstanceIdentifier.builder(pmDataClass).build();
267 // when(accessor.getTransactionUtils().readData(accessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
268 // pmDataIid)).thenReturn(pmDataList);
270 // Measurement measurement = mock(Measurement.class);
271 // PmDataType pmDataType = mock(PmDataType.class);
272 // when(pmDataType.getUint64()).thenReturn(Uint64.valueOf(2425425));
273 // when(measurement.getBinNumber()).thenReturn(Uint16.valueOf(1452));
274 // when(measurement.getCompletionTime()).thenReturn(new DateAndTime("2018-10-22T15:23:43Z"));
275 // when(measurement.getGranularity()).thenReturn(PmGranularity._24Hour);
276 // when(measurement.getPmParameterUnit()).thenReturn("6824545199534863756");
277 // when(measurement.getPmParameterValue()).thenReturn(pmDataType);
278 // when(measurement.getValidity()).thenReturn(Validity.Partial);
280 // @Nullable Map<MeasurementKey, Measurement> measurementList = new HashMap<>();
281 // measurementList.put(measurement.key(),measurement);
282 // when(historicalPm.getMeasurement()).thenReturn(measurementList);
283 // when(historicalPm.getType()).thenReturn(PmNamesEnum.DelayTCM1Down);
284 // when(historicalPm.getExtension()).thenReturn("OpticalPowerOutput");
285 // @Nullable Map<HistoricalPmKey, HistoricalPm> historicalPmList = new HashMap<>();
286 // historicalPmList.put(historicalPm.key(),historicalPm);
287 // HistoricalPmEntry histPmEntry = mock(HistoricalPmEntry.class);
288 // when(histPmEntry.getHistoricalPm()).thenReturn(historicalPmList);
289 // when(histPmEntry.getPmResourceType()).thenReturn(ResourceTypeEnum.CircuitPack);
290 // @Nullable Map<HistoricalPmEntryKey, HistoricalPmEntry> histPmList = new HashMap<>();
291 // histPmList.put(histPmEntry.key(),histPmEntry);
292 // when(pmDataList.getHistoricalPmEntry()).thenReturn(histPmList);
299 // public void test() {
300 // OpenroadmNetworkElement optionalNe = new OpenroadmNetworkElement(accessor, serviceProvider);
301 // optionalNe.initialReadFromNetworkElement();