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