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