3a0781e8fc84360fe85cb4e5c0fbcd8432b7eb90
[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.pm.rev200529.HistoricalPmList;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.group.HistoricalPm;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.group.HistoricalPmBuilder;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.group.HistoricalPmKey;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.list.HistoricalPmEntry;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.list.HistoricalPmEntryBuilder;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.list.HistoricalPmEntryKey;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.val.group.Measurement;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.val.group.MeasurementBuilder;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev200529.historical.pm.val.group.MeasurementKey;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev200327.PmDataType;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev200327.PmGranularity;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev200327.PmNamesEnum;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev200327.Validity;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.types.rev191129.ResourceTypeEnum;
58 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Pmdata15mEntity;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.units.rev200413.Celsius;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.units.rev200413.PerformanceMeasurementUnitId;
62 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
63 import org.opendaylight.yangtools.yang.binding.DataObject;
64 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
65 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
66 import org.opendaylight.yangtools.yang.common.Uint16;
67 import org.opendaylight.yangtools.yang.common.Uint64;
68
69
70 public class TestOpenRoadmPMDataBuilder {
71     // variables
72     // end of variables
73     private NetconfBindingAccessor acessor = mock(NetconfBindingAccessor.class);
74     private DataBroker dataBroker = mock(DataBroker.class);
75     private TransactionUtils transactionUtils = mock(TransactionUtils.class);
76     //    String nodeId = "RdmA";
77     private PmDataBuilderOpenRoadm pmDataBuilderORoadm;
78     private NodeId nodeId = new NodeId("RoadmA");
79     private HistoricalPmList historicalPmDatalist = mock(HistoricalPmList.class);
80     private HistoricalPm historicalPm = mock(HistoricalPm.class);
81     private PmDataType pmDataType = new PmDataType(Uint64.valueOf(67508));
82     private MeasurementBuilder measurementBuilder = new MeasurementBuilder();
83     private HistoricalPmBuilder historicalPmBuilder = new HistoricalPmBuilder();
84     private HistoricalPmEntryBuilder historicalPmEntryBuiler = new HistoricalPmEntryBuilder();
85     private List<Class<? extends PerformanceMeasurementUnitId>> performanceMeasUnitList =
86             new ArrayList<Class<? extends PerformanceMeasurementUnitId>>();
87     private Map<MeasurementKey, Measurement> measurementData = new HashMap<MeasurementKey, Measurement>();
88     private Map<HistoricalPmKey, HistoricalPm> historicalPMCollection = new HashMap<HistoricalPmKey, HistoricalPm>();
89     private Map<HistoricalPmEntryKey, HistoricalPmEntry> historicalPmEntryCollection =
90             new HashMap<HistoricalPmEntryKey, HistoricalPmEntry>();
91
92
93
94     // public methods
95     @Before
96     public void init() {
97         when(acessor.getDataBroker()).thenReturn(dataBroker);
98         when(acessor.getTransactionUtils()).thenReturn(transactionUtils);
99
100
101
102     }
103
104     @Test
105     public void testGetPmData() {
106         when(acessor.getNodeId()).thenReturn(nodeId);
107         pmDataBuilderORoadm = new PmDataBuilderOpenRoadm(acessor);
108
109         final Class<HistoricalPmList> pmDataClass = HistoricalPmList.class;
110         InstanceIdentifier<HistoricalPmList> pmDataListId = InstanceIdentifier.builder(pmDataClass).build();
111                 when(acessor.getTransactionUtils().readData(acessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
112                         pmDataListId)).thenReturn(historicalPmDatalist);
113
114         assertEquals(historicalPmDatalist,pmDataBuilderORoadm.getPmData(acessor));
115
116     }
117
118     @Test
119     public void testBuildPmDataEntity() {
120         when(acessor.getNodeId()).thenReturn(nodeId);
121         pmDataBuilderORoadm = new PmDataBuilderOpenRoadm(acessor);
122
123         performanceMeasUnitList.add(Celsius.class);
124         measurementBuilder.setBinNumber(Uint16.valueOf(24657))
125                 .setCompletionTime(new DateAndTime("2020-10-22T15:23:43Z")).setGranularity(PmGranularity._24Hour)
126                 .setPmParameterUnit("dBm").setPmParameterValue(pmDataType).setValidity(Validity.Suspect);
127
128         measurementData.put(measurementBuilder.key(), measurementBuilder.build());
129         historicalPmBuilder.setType(PmNamesEnum.SeverelyErroredSeconds).setDirection(Direction.Bidirectional)
130                 .setExtension("sajhsiwiduwugdhegdeuz").setLocation(Location.NearEnd).setMeasurement(measurementData);
131         when(historicalPm.getMeasurement()).thenReturn(measurementData);
132
133         historicalPMCollection.put(historicalPmBuilder.key(), historicalPmBuilder.build());
134         PathArgument pa =new PathArgument() {
135
136             @Override
137             public int compareTo(PathArgument o) {
138                 // TODO Auto-generated method stub
139                 return 0;
140             }
141
142             @Override
143             public @NonNull Class<? extends DataObject> getType() {
144                 // TODO Auto-generated method stub
145                 return Pmdata15mEntity.class;
146             }
147         };
148         historicalPmEntryBuiler.setPmResourceInstance(InstanceIdentifier.create(Arrays.asList(pa)))
149         .setPmResourceTypeExtension("dshjdekjdewkk")
150                 .setPmResourceType(ResourceTypeEnum.CircuitPack).setHistoricalPm(historicalPMCollection);
151
152         historicalPmEntryCollection.put(historicalPmEntryBuiler.key(), historicalPmEntryBuiler.build());
153         when(historicalPmDatalist.getHistoricalPmEntry()).thenReturn(historicalPmEntryCollection);
154
155         assertNotNull(pmDataBuilderORoadm.buildPmDataEntity(historicalPmDatalist));
156     }
157     @Test
158     public void testBuildPmDataEntity1() {
159         when(acessor.getNodeId()).thenReturn(nodeId);
160         pmDataBuilderORoadm = new PmDataBuilderOpenRoadm(acessor);
161
162         performanceMeasUnitList.add(Celsius.class);
163         measurementBuilder.setBinNumber(Uint16.valueOf(24657))
164                 .setCompletionTime(new DateAndTime("2020-10-22T15:23:43Z")).setGranularity(PmGranularity._15min)
165                 .setPmParameterUnit("celsius").setPmParameterValue(pmDataType).setValidity(Validity.Suspect);
166
167         measurementData.put(measurementBuilder.key(), measurementBuilder.build());
168         historicalPmBuilder.setType(PmNamesEnum.ErroredSeconds).setDirection(Direction.Rx)
169                 .setExtension("sajhsiwiduwugdhegdeuz").setLocation(Location.FarEnd).setMeasurement(measurementData);
170         when(historicalPm.getMeasurement()).thenReturn(measurementData);
171         PathArgument pa =new PathArgument() {
172
173             @Override
174             public int compareTo(PathArgument o) {
175                 // TODO Auto-generated method stub
176                 return 0;
177             }
178
179             @Override
180             public Class<? extends DataObject> getType() {
181                 // TODO Auto-generated method stub
182                 return Pmdata15mEntity.class;
183             }
184         };
185         historicalPMCollection.put(historicalPmBuilder.key(), historicalPmBuilder.build());
186         historicalPmEntryBuiler.setPmResourceInstance(InstanceIdentifier.create(Arrays.asList(pa)))
187             .setPmResourceTypeExtension("dshjdekjdewkk")
188                 .setPmResourceType(ResourceTypeEnum.Device).setHistoricalPm(historicalPMCollection);
189
190         historicalPmEntryCollection.put(historicalPmEntryBuiler.key(), historicalPmEntryBuiler.build());
191         when(historicalPmDatalist.getHistoricalPmEntry()).thenReturn(historicalPmEntryCollection);
192
193         assertNotNull(pmDataBuilderORoadm.buildPmDataEntity(historicalPmDatalist));
194     }
195     // end of public methods
196
197
198     // constants
199     // end of constants
200
201     // variables
202     // end of variables
203
204     // constructors
205     // end of constructors
206
207     // getters and setters
208     // end of getters and setters
209
210     // private methods
211     // end of private methods
212
213
214     // end of public methods
215
216     // static methods
217     // end of static methods
218
219     // private classes
220     // end of private classes
221 }