cfeca1342c37fa3695ae13a0b571fa616d011ff8
[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.openroadm71.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.Arrays;
30 import java.util.HashMap;
31 import java.util.List;
32 import java.util.Map;
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;
70
71
72 public class TestOpenRoadmPMDataBuilder {
73     // variables
74     // end of variables
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>();
93
94
95
96     // public methods
97     @Before
98     public void init() {
99         when(acessor.getDataBroker()).thenReturn(dataBroker);
100         when(acessor.getTransactionUtils()).thenReturn(transactionUtils);
101
102
103
104     }
105
106     @Test
107     public void testGetPmData() {
108         when(acessor.getNodeId()).thenReturn(nodeId);
109         pmDataBuilderORoadm = new PmDataBuilderOpenRoadm(acessor);
110
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);
115
116         assertEquals(historicalPmDatalist,pmDataBuilderORoadm.getPmData(acessor));
117
118     }
119
120     @Test
121     public void testBuildPmDataEntity() {
122         when(acessor.getNodeId()).thenReturn(nodeId);
123         pmDataBuilderORoadm = new PmDataBuilderOpenRoadm(acessor);
124
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);
129
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);
134
135         historicalPMCollection.put(historicalPmBuilder.key(), historicalPmBuilder.build());
136         PathArgument pa =new PathArgument() {
137
138             @Override
139             public int compareTo(PathArgument o) {
140                 // TODO Auto-generated method stub
141                 return 0;
142             }
143
144             @Override
145             public @NonNull Class<? extends DataObject> getType() {
146                 // TODO Auto-generated method stub
147                 return Component.class;
148             }
149         };
150         historicalPmEntryBuiler.setPmResourceInstance(InstanceIdentifier.unsafeOf(Arrays.asList(pa)))
151         .setPmResourceTypeExtension("dshjdekjdewkk")
152                 .setPmResourceType(ResourceTypeEnum.CircuitPack).setHistoricalPm(historicalPMCollection);
153
154         historicalPmEntryCollection.put(historicalPmEntryBuiler.key(), historicalPmEntryBuiler.build());
155         when(historicalPmDatalist.getHistoricalPmEntry()).thenReturn(historicalPmEntryCollection);
156
157         assertNotNull(pmDataBuilderORoadm.buildPmDataEntity(historicalPmDatalist));
158     }
159     @Test
160     public void testBuildPmDataEntity1() {
161         when(acessor.getNodeId()).thenReturn(nodeId);
162         pmDataBuilderORoadm = new PmDataBuilderOpenRoadm(acessor);
163
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);
168
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() {
174
175             @Override
176             public int compareTo(PathArgument o) {
177                 // TODO Auto-generated method stub
178                 return 0;
179             }
180
181             @Override
182             public Class<? extends DataObject> getType() {
183                 // TODO Auto-generated method stub
184                 return Component.class;
185             }
186         };
187         historicalPMCollection.put(historicalPmBuilder.key(), historicalPmBuilder.build());
188         historicalPmEntryBuiler.setPmResourceInstance(InstanceIdentifier.unsafeOf(Arrays.asList(pa)))
189             .setPmResourceTypeExtension("dshjdekjdewkk")
190                 .setPmResourceType(ResourceTypeEnum.Device).setHistoricalPm(historicalPMCollection);
191
192         historicalPmEntryCollection.put(historicalPmEntryBuiler.key(), historicalPmEntryBuiler.build());
193         when(historicalPmDatalist.getHistoricalPmEntry()).thenReturn(historicalPmEntryCollection);
194
195         assertNotNull(pmDataBuilderORoadm.buildPmDataEntity(historicalPmDatalist));
196     }
197     // end of public methods
198
199
200     // constants
201     // end of constants
202
203     // variables
204     // end of variables
205
206     // constructors
207     // end of constructors
208
209     // getters and setters
210     // end of getters and setters
211
212     // private methods
213     // end of private methods
214
215
216     // end of public methods
217
218     // static methods
219     // end of static methods
220
221     // private classes
222     // end of private classes
223 }