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.openroadm.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.openroadm.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.pm.rev191129.HistoricalPmList;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.group.HistoricalPm;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.group.HistoricalPmBuilder;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.group.HistoricalPmKey;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.list.HistoricalPmEntry;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.list.HistoricalPmEntryBuilder;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.list.HistoricalPmEntryKey;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.val.group.Measurement;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.val.group.MeasurementBuilder;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.val.group.MeasurementKey;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmDataType;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmGranularity;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmNamesEnum;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.Validity;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.types.rev191129.ResourceTypeEnum;
58 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Pmdata15mEntity;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.units.rev200413.Celsius;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.units.rev200413.PerformanceMeasurementUnitId;
62 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
63 import org.opendaylight.yangtools.yang.binding.DataObject;
64 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
65 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
66 import org.opendaylight.yangtools.yang.common.Uint16;
67 import org.opendaylight.yangtools.yang.common.Uint64;
69 public class TestOpenRoadmPMDataBuilder {
72 private NetconfBindingAccessor acessor = mock(NetconfBindingAccessor.class);
73 private DataBroker dataBroker = mock(DataBroker.class);
74 private TransactionUtils transactionUtils = mock(TransactionUtils.class);
75 // String nodeId = "RdmA";
76 private PmDataBuilderOpenRoadm pmDataBuilderORoadm;
77 private NodeId nodeId = new NodeId("RoadmA");
78 private HistoricalPmList historicalPmDatalist = mock(HistoricalPmList.class);
79 private HistoricalPm historicalPm = mock(HistoricalPm.class);
80 private PmDataType pmDataType = new PmDataType(Uint64.valueOf(67508));
81 private MeasurementBuilder measurementBuilder = new MeasurementBuilder();
82 private HistoricalPmBuilder historicalPmBuilder = new HistoricalPmBuilder();
83 private HistoricalPmEntryBuilder historicalPmEntryBuiler = new HistoricalPmEntryBuilder();
84 private List<Class<? extends PerformanceMeasurementUnitId>> performanceMeasUnitList =
85 new ArrayList<Class<? extends PerformanceMeasurementUnitId>>();
86 private Map<MeasurementKey, Measurement> measurementData = new HashMap<MeasurementKey, Measurement>();
87 private Map<HistoricalPmKey, HistoricalPm> historicalPMCollection = new HashMap<HistoricalPmKey, HistoricalPm>();
88 private Map<HistoricalPmEntryKey, HistoricalPmEntry> historicalPmEntryCollection =
89 new HashMap<HistoricalPmEntryKey, HistoricalPmEntry>();
90 private PathArgument pa =new PathArgument() {
92 public int compareTo(PathArgument o) {
96 public @NonNull Class<? extends DataObject> getType() {
97 return Pmdata15mEntity.class;
104 when(acessor.getDataBroker()).thenReturn(dataBroker);
105 when(acessor.getTransactionUtils()).thenReturn(transactionUtils);
112 public void testGetPmData() {
113 when(acessor.getNodeId()).thenReturn(nodeId);
114 pmDataBuilderORoadm = new PmDataBuilderOpenRoadm(acessor);
116 final Class<HistoricalPmList> pmDataClass = HistoricalPmList.class;
117 InstanceIdentifier<HistoricalPmList> pmDataListId = InstanceIdentifier.builder(pmDataClass).build();
118 when(acessor.getTransactionUtils().readData(acessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
119 pmDataListId)).thenReturn(historicalPmDatalist);
121 assertEquals(historicalPmDatalist,pmDataBuilderORoadm.getPmData(acessor));
126 public void testBuildPmDataEntity() {
127 when(acessor.getNodeId()).thenReturn(nodeId);
128 pmDataBuilderORoadm = new PmDataBuilderOpenRoadm(acessor);
130 performanceMeasUnitList.add(Celsius.class);
131 measurementBuilder.setBinNumber(Uint16.valueOf(24657))
132 .setCompletionTime(new DateAndTime("2020-10-22T15:23:43Z")).setGranularity(PmGranularity._24Hour)
133 .setPmParameterUnit("dBm").setPmParameterValue(pmDataType).setValidity(Validity.Suspect);
135 measurementData.put(measurementBuilder.key(), measurementBuilder.build());
136 historicalPmBuilder.setType(PmNamesEnum.SeverelyErroredSeconds).setDirection(Direction.Bidirectional)
137 .setExtension("sajhsiwiduwugdhegdeuz").setLocation(Location.NearEnd).setMeasurement(measurementData);
138 when(historicalPm.getMeasurement()).thenReturn(measurementData);
140 historicalPMCollection.put(historicalPmBuilder.key(), historicalPmBuilder.build());
141 historicalPmEntryBuiler.setPmResourceInstance(InstanceIdentifier.create(Arrays.asList(pa)))
142 .setPmResourceTypeExtension("dshjdekjdewkk")
143 .setPmResourceType(ResourceTypeEnum.CircuitPack).setHistoricalPm(historicalPMCollection);
145 historicalPmEntryCollection.put(historicalPmEntryBuiler.key(), historicalPmEntryBuiler.build());
146 when(historicalPmDatalist.getHistoricalPmEntry()).thenReturn(historicalPmEntryCollection);
148 assertNotNull(pmDataBuilderORoadm.buildPmDataEntity(historicalPmDatalist));
151 public void testBuildPmDataEntity1() {
152 when(acessor.getNodeId()).thenReturn(nodeId);
153 pmDataBuilderORoadm = new PmDataBuilderOpenRoadm(acessor);
155 performanceMeasUnitList.add(Celsius.class);
156 measurementBuilder.setBinNumber(Uint16.valueOf(24657))
157 .setCompletionTime(new DateAndTime("2020-10-22T15:23:43Z")).setGranularity(PmGranularity._15min)
158 .setPmParameterUnit("celsius").setPmParameterValue(pmDataType).setValidity(Validity.Suspect);
160 measurementData.put(measurementBuilder.key(), measurementBuilder.build());
161 historicalPmBuilder.setType(PmNamesEnum.ErroredSeconds).setDirection(Direction.Rx)
162 .setExtension("sajhsiwiduwugdhegdeuz").setLocation(Location.FarEnd).setMeasurement(measurementData);
163 when(historicalPm.getMeasurement()).thenReturn(measurementData);
165 historicalPMCollection.put(historicalPmBuilder.key(), historicalPmBuilder.build());
166 historicalPmEntryBuiler.setPmResourceInstance(InstanceIdentifier.create(Arrays.asList(pa)))
167 .setPmResourceTypeExtension("dshjdekjdewkk")
168 .setPmResourceType(ResourceTypeEnum.Device).setHistoricalPm(historicalPMCollection);
170 historicalPmEntryCollection.put(historicalPmEntryBuiler.key(), historicalPmEntryBuiler.build());
171 when(historicalPmDatalist.getHistoricalPmEntry()).thenReturn(historicalPmEntryCollection);
173 assertNotNull(pmDataBuilderORoadm.buildPmDataEntity(historicalPmDatalist));
175 // end of public methods
185 // end of constructors
187 // getters and setters
188 // end of getters and setters
191 // end of private methods
194 // end of public methods
197 // end of static methods
200 // end of private classes