b926e0c130fa32d57863523d437325f49e4e3cdd
[ccsdk/features.git] /
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.openroadm.test;
23
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.HashMap;
30 import java.util.List;
31 import java.util.Map;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.impl.PmDataBuilderOpenRoadm;
35 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
36 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils;
37 import org.opendaylight.mdsal.binding.api.DataBroker;
38 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.alarm.pm.types.rev191129.Direction;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.alarm.pm.types.rev191129.Location;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.HistoricalPmList;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.group.HistoricalPm;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.group.HistoricalPmBuilder;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.group.HistoricalPmKey;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.list.HistoricalPmEntry;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.list.HistoricalPmEntryBuilder;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.list.HistoricalPmEntryKey;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.val.group.Measurement;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.val.group.MeasurementBuilder;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.val.group.MeasurementKey;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmDataType;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmGranularity;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmNamesEnum;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.Validity;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.types.rev191129.ResourceTypeEnum;
56 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.units.rev200413.Celsius;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.units.rev200413.PerformanceMeasurementUnitId;
59 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
60 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
61 import org.opendaylight.yangtools.yang.common.Uint16;
62 import org.opendaylight.yangtools.yang.common.Uint64;
63
64 public class TestOpenRoadmPMDataBuilder {
65     // variables
66
67     private NetconfBindingAccessor acessor = mock(NetconfBindingAccessor.class);
68     private DataBroker dataBroker = mock(DataBroker.class);
69     private TransactionUtils transactionUtils = mock(TransactionUtils.class);
70     private PmDataBuilderOpenRoadm pmDataBuilderORoadm;
71     private NodeId nodeId = new NodeId("RoadmA");
72     private HistoricalPmList historicalPmDatalist = mock(HistoricalPmList.class);
73     private HistoricalPm historicalPm = mock(HistoricalPm.class);
74     private PmDataType pmDataType = new PmDataType(Uint64.valueOf(67508));
75     private MeasurementBuilder measurementBuilder = new MeasurementBuilder();
76     private HistoricalPmBuilder historicalPmBuilder = new HistoricalPmBuilder();
77     private HistoricalPmEntryBuilder historicalPmEntryBuiler = new HistoricalPmEntryBuilder();
78     private List<Class<? extends PerformanceMeasurementUnitId>> performanceMeasUnitList =
79             new ArrayList<Class<? extends PerformanceMeasurementUnitId>>();
80     private Map<MeasurementKey, Measurement> measurementData = new HashMap<MeasurementKey, Measurement>();
81     private Map<HistoricalPmKey, HistoricalPm> historicalPMCollection = new HashMap<HistoricalPmKey, HistoricalPm>();
82     private Map<HistoricalPmEntryKey, HistoricalPmEntry> historicalPmEntryCollection =
83             new HashMap<HistoricalPmEntryKey, HistoricalPmEntry>();
84
85     // end of variables
86
87     // public methods
88     @Before
89     public void init() {
90         when(acessor.getDataBroker()).thenReturn(dataBroker);
91         when(acessor.getTransactionUtils()).thenReturn(transactionUtils);
92
93
94
95     }
96
97     @Test
98     public void testGetPmData() {
99         when(acessor.getNodeId()).thenReturn(nodeId);
100         pmDataBuilderORoadm = new PmDataBuilderOpenRoadm(acessor);
101
102         final Class<HistoricalPmList> pmDataClass = HistoricalPmList.class;
103         InstanceIdentifier<HistoricalPmList> pmDataListId = InstanceIdentifier.builder(pmDataClass).build();
104                 when(acessor.getTransactionUtils().readData(acessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
105                         pmDataListId)).thenReturn(historicalPmDatalist);
106
107         assertEquals(historicalPmDatalist,pmDataBuilderORoadm.getPmData(acessor));
108
109     }
110
111     @Test
112     public void testBuildPmDataEntity() {
113         when(acessor.getNodeId()).thenReturn(nodeId);
114         pmDataBuilderORoadm = new PmDataBuilderOpenRoadm(acessor);
115
116         performanceMeasUnitList.add(Celsius.class);
117         measurementBuilder.setBinNumber(Uint16.valueOf(24657))
118                 .setCompletionTime(new DateAndTime("2020-10-22T15:23:43Z")).setGranularity(PmGranularity._24Hour)
119                 .setPmParameterUnit("dBm").setPmParameterValue(pmDataType).setValidity(Validity.Suspect);
120
121         measurementData.put(measurementBuilder.key(), measurementBuilder.build());
122         historicalPmBuilder.setType(PmNamesEnum.SeverelyErroredSeconds).setDirection(Direction.Bidirectional)
123                 .setExtension("sajhsiwiduwugdhegdeuz").setLocation(Location.NearEnd).setMeasurement(measurementData);
124         when(historicalPm.getMeasurement()).thenReturn(measurementData);
125
126         historicalPMCollection.put(historicalPmBuilder.key(), historicalPmBuilder.build());
127         historicalPmEntryBuiler.setPmResourceTypeExtension("dshjdekjdewkk")
128                 .setPmResourceType(ResourceTypeEnum.CircuitPack).setHistoricalPm(historicalPMCollection);
129
130         historicalPmEntryCollection.put(historicalPmEntryBuiler.key(), historicalPmEntryBuiler.build());
131         when(historicalPmDatalist.getHistoricalPmEntry()).thenReturn(historicalPmEntryCollection);
132
133         assertNotNull(pmDataBuilderORoadm.buildPmDataEntity(historicalPmDatalist));
134     }
135     @Test
136     public void testBuildPmDataEntity1() {
137         when(acessor.getNodeId()).thenReturn(nodeId);
138         pmDataBuilderORoadm = new PmDataBuilderOpenRoadm(acessor);
139
140         performanceMeasUnitList.add(Celsius.class);
141         measurementBuilder.setBinNumber(Uint16.valueOf(24657))
142                 .setCompletionTime(new DateAndTime("2020-10-22T15:23:43Z")).setGranularity(PmGranularity._15min)
143                 .setPmParameterUnit("celsius").setPmParameterValue(pmDataType).setValidity(Validity.Suspect);
144
145         measurementData.put(measurementBuilder.key(), measurementBuilder.build());
146         historicalPmBuilder.setType(PmNamesEnum.ErroredSeconds).setDirection(Direction.Rx)
147                 .setExtension("sajhsiwiduwugdhegdeuz").setLocation(Location.FarEnd).setMeasurement(measurementData);
148         when(historicalPm.getMeasurement()).thenReturn(measurementData);
149
150         historicalPMCollection.put(historicalPmBuilder.key(), historicalPmBuilder.build());
151         historicalPmEntryBuiler.setPmResourceTypeExtension("dshjdekjdewkk")
152                 .setPmResourceType(ResourceTypeEnum.Device).setHistoricalPm(historicalPMCollection);
153
154         historicalPmEntryCollection.put(historicalPmEntryBuiler.key(), historicalPmEntryBuiler.build());
155         when(historicalPmDatalist.getHistoricalPmEntry()).thenReturn(historicalPmEntryCollection);
156
157         assertNotNull(pmDataBuilderORoadm.buildPmDataEntity(historicalPmDatalist));
158     }
159     // end of public methods
160
161 }