2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
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.openroadm71.test;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.when;
28 import java.util.ArrayList;
29 import java.util.Arrays;
30 import java.util.HashMap;
31 import java.util.List;
33 import org.eclipse.jdt.annotation.NonNull;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm71.impl.PmDataBuilderOpenRoadm;
37 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
38 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils;
39 import org.opendaylight.mdsal.binding.api.DataBroker;
40 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.alarm.pm.types.rev191129.Direction;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.alarm.pm.types.rev191129.Location;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.circuit.pack.features.circuit.pack.components.Component;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.HistoricalPmList;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.group.HistoricalPm;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.group.HistoricalPmBuilder;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.group.HistoricalPmKey;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.list.HistoricalPmEntry;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.list.HistoricalPmEntryBuilder;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.list.HistoricalPmEntryKey;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.val.group.Measurement;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.val.group.MeasurementBuilder;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.val.group.MeasurementKey;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev200327.PmDataType;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev200327.PmGranularity;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev200327.PmNamesEnum;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev200327.Validity;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.types.rev191129.ResourceTypeEnum;
59 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Pmdata15mEntity;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.units.rev200413.Celsius;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.units.rev200413.PerformanceMeasurementUnitId;
63 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
64 import org.opendaylight.yangtools.yang.binding.DataObject;
65 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
66 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
67 import org.opendaylight.yangtools.yang.common.Decimal64;
68 import org.opendaylight.yangtools.yang.common.Uint16;
69 import org.opendaylight.yangtools.yang.common.Uint64;
72 public class TestOpenRoadmPMDataBuilder {
75 private NetconfBindingAccessor acessor = mock(NetconfBindingAccessor.class);
76 private DataBroker dataBroker = mock(DataBroker.class);
77 private TransactionUtils transactionUtils = mock(TransactionUtils.class);
78 // String nodeId = "RdmA";
79 private PmDataBuilderOpenRoadm pmDataBuilderORoadm;
80 private NodeId nodeId = new NodeId("RoadmA");
81 private HistoricalPmList historicalPmDatalist = mock(HistoricalPmList.class);
82 private HistoricalPm historicalPm = mock(HistoricalPm.class);
83 private PmDataType pmDataType = new PmDataType(Decimal64.valueOf(1,67508));
84 private MeasurementBuilder measurementBuilder = new MeasurementBuilder();
85 private HistoricalPmBuilder historicalPmBuilder = new HistoricalPmBuilder();
86 private HistoricalPmEntryBuilder historicalPmEntryBuiler = new HistoricalPmEntryBuilder();
87 private List<Class<? extends PerformanceMeasurementUnitId>> performanceMeasUnitList =
88 new ArrayList<Class<? extends PerformanceMeasurementUnitId>>();
89 private Map<MeasurementKey, Measurement> measurementData = new HashMap<MeasurementKey, Measurement>();
90 private Map<HistoricalPmKey, HistoricalPm> historicalPMCollection = new HashMap<HistoricalPmKey, HistoricalPm>();
91 private Map<HistoricalPmEntryKey, HistoricalPmEntry> historicalPmEntryCollection =
92 new HashMap<HistoricalPmEntryKey, HistoricalPmEntry>();
99 when(acessor.getDataBroker()).thenReturn(dataBroker);
100 when(acessor.getTransactionUtils()).thenReturn(transactionUtils);
107 public void testGetPmData() {
108 when(acessor.getNodeId()).thenReturn(nodeId);
109 pmDataBuilderORoadm = new PmDataBuilderOpenRoadm(acessor);
111 final Class<HistoricalPmList> pmDataClass = HistoricalPmList.class;
112 InstanceIdentifier<HistoricalPmList> pmDataListId = InstanceIdentifier.builder(pmDataClass).build();
113 when(acessor.getTransactionUtils().readData(acessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
114 pmDataListId)).thenReturn(historicalPmDatalist);
116 assertEquals(historicalPmDatalist,pmDataBuilderORoadm.getPmData(acessor));
121 public void testBuildPmDataEntity() {
122 when(acessor.getNodeId()).thenReturn(nodeId);
123 pmDataBuilderORoadm = new PmDataBuilderOpenRoadm(acessor);
125 performanceMeasUnitList.add(Celsius.class);
126 measurementBuilder.setBinNumber(Uint16.valueOf(24657))
127 .setCompletionTime(new DateAndTime("2020-10-22T15:23:43Z")).setGranularity(PmGranularity._24Hour)
128 .setPmParameterUnit("dBm").setPmParameterValue(pmDataType).setValidity(Validity.Suspect);
130 measurementData.put(measurementBuilder.key(), measurementBuilder.build());
131 historicalPmBuilder.setType(PmNamesEnum.SeverelyErroredSeconds).setDirection(Direction.Bidirectional)
132 .setExtension("sajhsiwiduwugdhegdeuz").setLocation(Location.NearEnd).setMeasurement(measurementData);
133 when(historicalPm.getMeasurement()).thenReturn(measurementData);
135 historicalPMCollection.put(historicalPmBuilder.key(), historicalPmBuilder.build());
136 PathArgument pa =new PathArgument() {
139 public int compareTo(PathArgument o) {
140 // TODO Auto-generated method stub
145 public @NonNull Class<? extends DataObject> getType() {
146 // TODO Auto-generated method stub
147 return Component.class;
150 historicalPmEntryBuiler.setPmResourceInstance(InstanceIdentifier.unsafeOf(Arrays.asList(pa)))
151 .setPmResourceTypeExtension("dshjdekjdewkk")
152 .setPmResourceType(ResourceTypeEnum.CircuitPack).setHistoricalPm(historicalPMCollection);
154 historicalPmEntryCollection.put(historicalPmEntryBuiler.key(), historicalPmEntryBuiler.build());
155 when(historicalPmDatalist.getHistoricalPmEntry()).thenReturn(historicalPmEntryCollection);
157 assertNotNull(pmDataBuilderORoadm.buildPmDataEntity(historicalPmDatalist));
160 public void testBuildPmDataEntity1() {
161 when(acessor.getNodeId()).thenReturn(nodeId);
162 pmDataBuilderORoadm = new PmDataBuilderOpenRoadm(acessor);
164 performanceMeasUnitList.add(Celsius.class);
165 measurementBuilder.setBinNumber(Uint16.valueOf(24657))
166 .setCompletionTime(new DateAndTime("2020-10-22T15:23:43Z")).setGranularity(PmGranularity._15min)
167 .setPmParameterUnit("celsius").setPmParameterValue(pmDataType).setValidity(Validity.Suspect);
169 measurementData.put(measurementBuilder.key(), measurementBuilder.build());
170 historicalPmBuilder.setType(PmNamesEnum.ErroredSeconds).setDirection(Direction.Rx)
171 .setExtension("sajhsiwiduwugdhegdeuz").setLocation(Location.FarEnd).setMeasurement(measurementData);
172 when(historicalPm.getMeasurement()).thenReturn(measurementData);
173 PathArgument pa =new PathArgument() {
176 public int compareTo(PathArgument o) {
177 // TODO Auto-generated method stub
182 public Class<? extends DataObject> getType() {
183 // TODO Auto-generated method stub
184 return Component.class;
187 historicalPMCollection.put(historicalPmBuilder.key(), historicalPmBuilder.build());
188 historicalPmEntryBuiler.setPmResourceInstance(InstanceIdentifier.unsafeOf(Arrays.asList(pa)))
189 .setPmResourceTypeExtension("dshjdekjdewkk")
190 .setPmResourceType(ResourceTypeEnum.Device).setHistoricalPm(historicalPMCollection);
192 historicalPmEntryCollection.put(historicalPmEntryBuiler.key(), historicalPmEntryBuiler.build());
193 when(historicalPmDatalist.getHistoricalPmEntry()).thenReturn(historicalPmEntryCollection);
195 assertNotNull(pmDataBuilderORoadm.buildPmDataEntity(historicalPmDatalist));
197 // end of public methods
207 // end of constructors
209 // getters and setters
210 // end of getters and setters
213 // end of private methods
216 // end of public methods
219 // end of static methods
222 // end of private classes