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.Uint16;
 
  68 import org.opendaylight.yangtools.yang.common.Uint64;
 
  71 public class TestOpenRoadmPMDataBuilder {
 
  74     private NetconfBindingAccessor acessor = mock(NetconfBindingAccessor.class);
 
  75     private DataBroker dataBroker = mock(DataBroker.class);
 
  76     private TransactionUtils transactionUtils = mock(TransactionUtils.class);
 
  77     //    String nodeId = "RdmA";
 
  78     private PmDataBuilderOpenRoadm pmDataBuilderORoadm;
 
  79     private NodeId nodeId = new NodeId("RoadmA");
 
  80     private HistoricalPmList historicalPmDatalist = mock(HistoricalPmList.class);
 
  81     private HistoricalPm historicalPm = mock(HistoricalPm.class);
 
  82     private PmDataType pmDataType = new PmDataType(Uint64.valueOf(67508));
 
  83     private MeasurementBuilder measurementBuilder = new MeasurementBuilder();
 
  84     private HistoricalPmBuilder historicalPmBuilder = new HistoricalPmBuilder();
 
  85     private HistoricalPmEntryBuilder historicalPmEntryBuiler = new HistoricalPmEntryBuilder();
 
  86     private List<Class<? extends PerformanceMeasurementUnitId>> performanceMeasUnitList =
 
  87             new ArrayList<Class<? extends PerformanceMeasurementUnitId>>();
 
  88     private Map<MeasurementKey, Measurement> measurementData = new HashMap<MeasurementKey, Measurement>();
 
  89     private Map<HistoricalPmKey, HistoricalPm> historicalPMCollection = new HashMap<HistoricalPmKey, HistoricalPm>();
 
  90     private Map<HistoricalPmEntryKey, HistoricalPmEntry> historicalPmEntryCollection =
 
  91             new HashMap<HistoricalPmEntryKey, HistoricalPmEntry>();
 
  98         when(acessor.getDataBroker()).thenReturn(dataBroker);
 
  99         when(acessor.getTransactionUtils()).thenReturn(transactionUtils);
 
 106     public void testGetPmData() {
 
 107         when(acessor.getNodeId()).thenReturn(nodeId);
 
 108         pmDataBuilderORoadm = new PmDataBuilderOpenRoadm(acessor);
 
 110         final Class<HistoricalPmList> pmDataClass = HistoricalPmList.class;
 
 111         InstanceIdentifier<HistoricalPmList> pmDataListId = InstanceIdentifier.builder(pmDataClass).build();
 
 112                 when(acessor.getTransactionUtils().readData(acessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
 
 113                         pmDataListId)).thenReturn(historicalPmDatalist);
 
 115         assertEquals(historicalPmDatalist,pmDataBuilderORoadm.getPmData(acessor));
 
 120     public void testBuildPmDataEntity() {
 
 121         when(acessor.getNodeId()).thenReturn(nodeId);
 
 122         pmDataBuilderORoadm = new PmDataBuilderOpenRoadm(acessor);
 
 124         performanceMeasUnitList.add(Celsius.class);
 
 125         measurementBuilder.setBinNumber(Uint16.valueOf(24657))
 
 126                 .setCompletionTime(new DateAndTime("2020-10-22T15:23:43Z")).setGranularity(PmGranularity._24Hour)
 
 127                 .setPmParameterUnit("dBm").setPmParameterValue(pmDataType).setValidity(Validity.Suspect);
 
 129         measurementData.put(measurementBuilder.key(), measurementBuilder.build());
 
 130         historicalPmBuilder.setType(PmNamesEnum.SeverelyErroredSeconds).setDirection(Direction.Bidirectional)
 
 131                 .setExtension("sajhsiwiduwugdhegdeuz").setLocation(Location.NearEnd).setMeasurement(measurementData);
 
 132         when(historicalPm.getMeasurement()).thenReturn(measurementData);
 
 134         historicalPMCollection.put(historicalPmBuilder.key(), historicalPmBuilder.build());
 
 135         PathArgument pa =new PathArgument() {
 
 138             public int compareTo(PathArgument o) {
 
 139                 // TODO Auto-generated method stub
 
 144             public @NonNull Class<? extends DataObject> getType() {
 
 145                 // TODO Auto-generated method stub
 
 146                 return Component.class;
 
 149         historicalPmEntryBuiler.setPmResourceInstance(InstanceIdentifier.unsafeOf(Arrays.asList(pa)))
 
 150         .setPmResourceTypeExtension("dshjdekjdewkk")
 
 151                 .setPmResourceType(ResourceTypeEnum.CircuitPack).setHistoricalPm(historicalPMCollection);
 
 153         historicalPmEntryCollection.put(historicalPmEntryBuiler.key(), historicalPmEntryBuiler.build());
 
 154         when(historicalPmDatalist.getHistoricalPmEntry()).thenReturn(historicalPmEntryCollection);
 
 156         assertNotNull(pmDataBuilderORoadm.buildPmDataEntity(historicalPmDatalist));
 
 159     public void testBuildPmDataEntity1() {
 
 160         when(acessor.getNodeId()).thenReturn(nodeId);
 
 161         pmDataBuilderORoadm = new PmDataBuilderOpenRoadm(acessor);
 
 163         performanceMeasUnitList.add(Celsius.class);
 
 164         measurementBuilder.setBinNumber(Uint16.valueOf(24657))
 
 165                 .setCompletionTime(new DateAndTime("2020-10-22T15:23:43Z")).setGranularity(PmGranularity._15min)
 
 166                 .setPmParameterUnit("celsius").setPmParameterValue(pmDataType).setValidity(Validity.Suspect);
 
 168         measurementData.put(measurementBuilder.key(), measurementBuilder.build());
 
 169         historicalPmBuilder.setType(PmNamesEnum.ErroredSeconds).setDirection(Direction.Rx)
 
 170                 .setExtension("sajhsiwiduwugdhegdeuz").setLocation(Location.FarEnd).setMeasurement(measurementData);
 
 171         when(historicalPm.getMeasurement()).thenReturn(measurementData);
 
 172         PathArgument pa =new PathArgument() {
 
 175             public int compareTo(PathArgument o) {
 
 176                 // TODO Auto-generated method stub
 
 181             public Class<? extends DataObject> getType() {
 
 182                 // TODO Auto-generated method stub
 
 183                 return Component.class;
 
 186         historicalPMCollection.put(historicalPmBuilder.key(), historicalPmBuilder.build());
 
 187         historicalPmEntryBuiler.setPmResourceInstance(InstanceIdentifier.unsafeOf(Arrays.asList(pa)))
 
 188             .setPmResourceTypeExtension("dshjdekjdewkk")
 
 189                 .setPmResourceType(ResourceTypeEnum.Device).setHistoricalPm(historicalPMCollection);
 
 191         historicalPmEntryCollection.put(historicalPmEntryBuiler.key(), historicalPmEntryBuiler.build());
 
 192         when(historicalPmDatalist.getHistoricalPmEntry()).thenReturn(historicalPmEntryCollection);
 
 194         assertNotNull(pmDataBuilderORoadm.buildPmDataEntity(historicalPmDatalist));
 
 196     // end of public methods
 
 206     // end of constructors
 
 208     // getters and setters
 
 209     // end of getters and setters
 
 212     // end of private methods
 
 215     // end of public methods
 
 218     // end of static methods
 
 221     // end of private classes