5069acec9d49cd53081beb61313dee6714842a4c
[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     // end of variables
67     private NetconfBindingAccessor acessor = mock(NetconfBindingAccessor.class);
68     private DataBroker dataBroker = mock(DataBroker.class);
69     private TransactionUtils transactionUtils = mock(TransactionUtils.class);
70     //    String nodeId = "RdmA";
71     private PmDataBuilderOpenRoadm pmDataBuilderORoadm;
72     private NodeId nodeId = new NodeId("RoadmA");
73     private HistoricalPmList historicalPmDatalist = mock(HistoricalPmList.class);
74     private HistoricalPm historicalPm = mock(HistoricalPm.class);
75     private PmDataType pmDataType = new PmDataType(Uint64.valueOf(67508));
76     private MeasurementBuilder measurementBuilder = new MeasurementBuilder();
77     private HistoricalPmBuilder historicalPmBuilder = new HistoricalPmBuilder();
78     private HistoricalPmEntryBuilder historicalPmEntryBuiler = new HistoricalPmEntryBuilder();
79     private List<Class<? extends PerformanceMeasurementUnitId>> performanceMeasUnitList =
80             new ArrayList<Class<? extends PerformanceMeasurementUnitId>>();
81     private Map<MeasurementKey, Measurement> measurementData = new HashMap<MeasurementKey, Measurement>();
82     private Map<HistoricalPmKey, HistoricalPm> historicalPMCollection = new HashMap<HistoricalPmKey, HistoricalPm>();
83     private Map<HistoricalPmEntryKey, HistoricalPmEntry> historicalPmEntryCollection =
84             new HashMap<HistoricalPmEntryKey, HistoricalPmEntry>();
85
86
87
88     // public methods
89     @Before
90     public void init() {
91         when(acessor.getDataBroker()).thenReturn(dataBroker);
92         when(acessor.getTransactionUtils()).thenReturn(transactionUtils);
93
94
95
96     }
97
98     @Test
99     public void testGetPmData() {
100         when(acessor.getNodeId()).thenReturn(nodeId);
101         pmDataBuilderORoadm = new PmDataBuilderOpenRoadm(acessor);
102
103         final Class<HistoricalPmList> pmDataClass = HistoricalPmList.class;
104         InstanceIdentifier<HistoricalPmList> pmDataListId = InstanceIdentifier.builder(pmDataClass).build();
105                 when(acessor.getTransactionUtils().readData(acessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
106                         pmDataListId)).thenReturn(historicalPmDatalist);
107
108         assertEquals(historicalPmDatalist,pmDataBuilderORoadm.getPmData(acessor));
109
110     }
111
112     @Test
113     public void testBuildPmDataEntity() {
114         when(acessor.getNodeId()).thenReturn(nodeId);
115         pmDataBuilderORoadm = new PmDataBuilderOpenRoadm(acessor);
116
117         performanceMeasUnitList.add(Celsius.class);
118         measurementBuilder.setBinNumber(Uint16.valueOf(24657))
119                 .setCompletionTime(new DateAndTime("2020-10-22T15:23:43Z")).setGranularity(PmGranularity._24Hour)
120                 .setPmParameterUnit("dBm").setPmParameterValue(pmDataType).setValidity(Validity.Suspect);
121
122         measurementData.put(measurementBuilder.key(), measurementBuilder.build());
123         historicalPmBuilder.setType(PmNamesEnum.SeverelyErroredSeconds).setDirection(Direction.Bidirectional)
124                 .setExtension("sajhsiwiduwugdhegdeuz").setLocation(Location.NearEnd).setMeasurement(measurementData);
125         when(historicalPm.getMeasurement()).thenReturn(measurementData);
126
127         historicalPMCollection.put(historicalPmBuilder.key(), historicalPmBuilder.build());
128         historicalPmEntryBuiler.setPmResourceTypeExtension("dshjdekjdewkk")
129                 .setPmResourceType(ResourceTypeEnum.CircuitPack).setHistoricalPm(historicalPMCollection);
130
131         historicalPmEntryCollection.put(historicalPmEntryBuiler.key(), historicalPmEntryBuiler.build());
132         when(historicalPmDatalist.getHistoricalPmEntry()).thenReturn(historicalPmEntryCollection);
133
134         assertNotNull(pmDataBuilderORoadm.buildPmDataEntity(historicalPmDatalist));
135     }
136     @Test
137     public void testBuildPmDataEntity1() {
138         when(acessor.getNodeId()).thenReturn(nodeId);
139         pmDataBuilderORoadm = new PmDataBuilderOpenRoadm(acessor);
140
141         performanceMeasUnitList.add(Celsius.class);
142         measurementBuilder.setBinNumber(Uint16.valueOf(24657))
143                 .setCompletionTime(new DateAndTime("2020-10-22T15:23:43Z")).setGranularity(PmGranularity._15min)
144                 .setPmParameterUnit("celsius").setPmParameterValue(pmDataType).setValidity(Validity.Suspect);
145
146         measurementData.put(measurementBuilder.key(), measurementBuilder.build());
147         historicalPmBuilder.setType(PmNamesEnum.ErroredSeconds).setDirection(Direction.Rx)
148                 .setExtension("sajhsiwiduwugdhegdeuz").setLocation(Location.FarEnd).setMeasurement(measurementData);
149         when(historicalPm.getMeasurement()).thenReturn(measurementData);
150
151         historicalPMCollection.put(historicalPmBuilder.key(), historicalPmBuilder.build());
152         historicalPmEntryBuiler.setPmResourceTypeExtension("dshjdekjdewkk")
153                 .setPmResourceType(ResourceTypeEnum.Device).setHistoricalPm(historicalPMCollection);
154
155         historicalPmEntryCollection.put(historicalPmEntryBuiler.key(), historicalPmEntryBuiler.build());
156         when(historicalPmDatalist.getHistoricalPmEntry()).thenReturn(historicalPmEntryCollection);
157
158         assertNotNull(pmDataBuilderORoadm.buildPmDataEntity(historicalPmDatalist));
159     }
160     // end of public methods
161
162
163     // constants
164     // end of constants
165
166     // variables
167     // end of variables
168
169     // constructors
170     // end of constructors
171
172     // getters and setters
173     // end of getters and setters
174
175     // private methods
176     // end of private methods
177
178
179     // end of public methods
180
181     // static methods
182     // end of static methods
183
184     // private classes
185     // end of private classes
186 }