2 * Copyright © 2018 Orange, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.transportpce.olm;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import java.util.ArrayList;
13 import java.util.HashMap;
14 import java.util.List;
16 import java.util.Optional;
17 import java.util.concurrent.ExecutionException;
18 import org.junit.Assert;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.mockito.Mockito;
22 import org.opendaylight.mdsal.binding.api.MountPoint;
23 import org.opendaylight.mdsal.binding.api.MountPointService;
24 import org.opendaylight.transportpce.common.StringConstants;
25 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
26 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl;
27 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl121;
28 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl221;
29 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
30 import org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl;
31 import org.opendaylight.transportpce.common.mapping.MappingUtils;
32 import org.opendaylight.transportpce.common.mapping.MappingUtilsImpl;
33 import org.opendaylight.transportpce.common.mapping.PortMapping;
34 import org.opendaylight.transportpce.common.mapping.PortMappingImpl;
35 import org.opendaylight.transportpce.common.mapping.PortMappingVersion121;
36 import org.opendaylight.transportpce.common.mapping.PortMappingVersion221;
37 import org.opendaylight.transportpce.common.mapping.PortMappingVersion710;
38 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
39 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
40 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl121;
41 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl221;
42 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl710;
43 import org.opendaylight.transportpce.olm.power.PowerMgmt;
44 import org.opendaylight.transportpce.olm.power.PowerMgmtImpl;
45 import org.opendaylight.transportpce.olm.service.OlmPowerService;
46 import org.opendaylight.transportpce.olm.service.OlmPowerServiceImpl;
47 import org.opendaylight.transportpce.olm.stub.MountPointServiceStub;
48 import org.opendaylight.transportpce.olm.stub.MountPointStub;
49 import org.opendaylight.transportpce.olm.util.OlmPowerServiceRpcImplUtil;
50 import org.opendaylight.transportpce.test.AbstractTest;
51 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.GetPmInput;
52 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.GetPmOutput;
53 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.GetPmOutputBuilder;
54 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerSetupInput;
55 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerSetupOutput;
56 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerSetupOutputBuilder;
57 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerTurndownInput;
58 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerTurndownOutput;
59 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerTurndownOutputBuilder;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.CurrentPmlist;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.CurrentPmlistBuilder;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.current.pm.LayerRateBuilder;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.current.pm.Measurements;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.current.pm.MeasurementsBuilder;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.current.pm.measurements.MeasurementBuilder;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.currentpmlist.CurrentPm;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.currentpmlist.CurrentPmBuilder;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.currentpmlist.CurrentPmKey;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev161014.PmDataType;
70 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev161014.PmGranularity;
71 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev161014.PmNamesEnum;
72 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev161014.pm.measurement.PmParameterNameBuilder;
73 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev161014.resource.DeviceBuilder;
74 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev161014.resource.ResourceTypeBuilder;
75 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev161014.resource.resource.resource.CircuitPackBuilder;
76 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.types.rev161014.ResourceTypeEnum;
77 import org.opendaylight.yangtools.yang.common.RpcResult;
78 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
79 import org.opendaylight.yangtools.yang.common.Uint64;
81 public class OlmPowerServiceRpcImplTest extends AbstractTest {
83 private MountPoint mountPoint;
84 private MountPointService mountPointService;
85 private DeviceTransactionManager deviceTransactionManager;
86 private CrossConnect crossConnect;
87 private OpenRoadmInterfaces openRoadmInterfaces;
88 private PortMapping portMapping;
89 private PowerMgmt powerMgmt;
90 private OlmPowerService olmPowerService;
91 private OlmPowerServiceRpcImpl olmPowerServiceRpc;
92 private CrossConnectImpl121 crossConnectImpl121;
93 private CrossConnectImpl221 crossConnectImpl22;
94 private MappingUtils mappingUtils;
95 private OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121;
96 private OpenRoadmInterfacesImpl221 openRoadmInterfacesImpl22;
97 private OpenRoadmInterfacesImpl710 openRoadmInterfacesImpl710;
98 private PortMappingVersion710 portMappingVersion710;
99 private PortMappingVersion221 portMappingVersion22;
100 private PortMappingVersion121 portMappingVersion121;
103 public void setUp() {
104 this.mountPoint = new MountPointStub(this.getDataBroker());
105 this.mountPointService = new MountPointServiceStub(mountPoint);
106 this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
107 this.mappingUtils = Mockito.spy(new MappingUtilsImpl(getDataBroker()));
108 Mockito.doReturn(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1).when(mappingUtils)
109 .getOpenRoadmVersion(Mockito.anyString());
110 this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
111 this.crossConnectImpl121 = new CrossConnectImpl121(deviceTransactionManager);
112 this.crossConnectImpl22 = new CrossConnectImpl221(deviceTransactionManager);
113 this.crossConnect = new CrossConnectImpl(deviceTransactionManager, this.mappingUtils, this.crossConnectImpl121,
114 this.crossConnectImpl22);
115 this.openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(deviceTransactionManager);
116 this.openRoadmInterfacesImpl22 = new OpenRoadmInterfacesImpl221(deviceTransactionManager);
117 this.openRoadmInterfacesImpl710 = new OpenRoadmInterfacesImpl710(deviceTransactionManager);
118 this.openRoadmInterfaces = new OpenRoadmInterfacesImpl((this.deviceTransactionManager),
119 this.mappingUtils,this.openRoadmInterfacesImpl121,this.openRoadmInterfacesImpl22,
120 this.openRoadmInterfacesImpl710);
121 this.portMappingVersion710 =
122 new PortMappingVersion710(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
123 this.portMappingVersion22 =
124 new PortMappingVersion221(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
125 this.portMappingVersion121 =
126 new PortMappingVersion121(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
127 this.portMapping = new PortMappingImpl(getDataBroker(), this.portMappingVersion710,
128 this.portMappingVersion22, this.portMappingVersion121);
129 this.portMapping = Mockito.spy(this.portMapping);
130 this.powerMgmt = new PowerMgmtImpl(this.getDataBroker(), this.openRoadmInterfaces, this.crossConnect,
131 this.deviceTransactionManager);
132 this.olmPowerService = new OlmPowerServiceImpl(this.getDataBroker(), this.powerMgmt,
133 this.deviceTransactionManager, this.portMapping,mappingUtils,openRoadmInterfaces);
134 this.olmPowerServiceRpc = new OlmPowerServiceRpcImpl(this.olmPowerService);
136 this.olmPowerServiceRpc = Mockito.mock(OlmPowerServiceRpcImpl.class);
140 public void pmIsNotPresentTest() throws ExecutionException, InterruptedException {
141 GetPmInput input = OlmPowerServiceRpcImplUtil.getGetPmInput();
143 // ListenableFuture<RpcResult<GetPmOutput>> output = this.olmPowerServiceRpc.getPm(input);
144 // Assert.assertEquals(new GetPmOutputBuilder().build(), output.get().getResult());
145 // Assert.assertEquals(null, output.get().getResult().getResourceId());
146 // Assert.assertEquals(null, output.get().getResult().getMeasurements());
147 // Assert.assertEquals(null, output.get().getResult().getGranularity());
148 // Assert.assertEquals(null, output.get().getResult().getNodeId());
149 // Assert.assertEquals(null, output.get().getResult().getResourceIdentifier());
150 // Assert.assertEquals(null, output.get().getResult().getResourceType());
154 public void testGetPm1() throws ExecutionException, InterruptedException {
155 Measurements measurements = new MeasurementsBuilder().setMeasurement(
156 new MeasurementBuilder()
157 .setPmParameterUnit("unit")
158 .setPmParameterName(new PmParameterNameBuilder()
160 .setType(PmNamesEnum.DefectSeconds).build())
161 .setPmParameterValue(new PmDataType(Uint64.valueOf(1234))).build())
163 List<Measurements> measurementsList = new ArrayList<Measurements>();
164 measurementsList.add(measurements);
166 org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev161014.resource.Resource resource =
167 new org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev161014.resource.ResourceBuilder()
168 .setResource(new CircuitPackBuilder().setCircuitPackName("circuit pack name").build()).build();
170 org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.current.pm.Resource resource2 =
171 new org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.current.pm.ResourceBuilder()
172 .setDevice(new DeviceBuilder().setNodeId("node 1").build())
173 .setResourceType(new ResourceTypeBuilder()
175 .setType(ResourceTypeEnum.Device).build())
176 .setResource(resource).build();
177 CurrentPm currentPm = new CurrentPmBuilder()
178 .setGranularity(PmGranularity._15min)
180 .setLayerRate(new LayerRateBuilder().build())
181 .setMeasurements(measurementsList)
182 .setResource(resource2)
183 .setRetrievalTime(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715
184 .DateAndTime("2018-11-01T12:00:31.456449+06:00")).build();
186 Map<CurrentPmKey, CurrentPm> currentPmList = new HashMap<>();
187 currentPmList.put(currentPm.key(),currentPm);
189 Optional<CurrentPmlist> currentPmlistOptional = Optional.of(new CurrentPmlistBuilder()
190 .setCurrentPm(currentPmList).build());
192 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.get.pm.output.Measurements
193 measurements1 = new org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.get.pm
194 .output.MeasurementsBuilder().setPmparameterName("name").setPmparameterValue("1234").build();
197 List<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.get.pm.output
198 .Measurements> measurementsList1 = new ArrayList<>();
199 measurementsList1.add(measurements1);
201 GetPmInput input = OlmPowerServiceRpcImplUtil.getGetPmInput();
202 GetPmOutputBuilder pmOutputBuilder = new GetPmOutputBuilder().setNodeId(input.getNodeId())
203 .setResourceType(input.getResourceType())
204 .setResourceIdentifier(input.getResourceIdentifier())
205 .setGranularity(input.getGranularity())
206 .setMeasurements(measurementsList1);
209 ListenableFuture<RpcResult<GetPmOutput>> output = this.olmPowerServiceRpc.getPm(input);
211 // Assert.assertEquals(new GetPmOutputBuilder().build(), output.get().getResult());
212 // Assert.assertEquals(null, output.get().getResult().getResourceId());
216 // public void testGetPm2() throws ExecutionException, InterruptedException {
217 // this.olmPowerService = Mockito.spy(this.olmPowerService);
218 // GetPmInput input = new GetPmInputBuilder().setGranularity(PmGranularity._15min).setNodeId("node1")
219 // .setResourceIdentifier(new ResourceIdentifierBuilder().setCircuitPackName("circuit pack name")
220 // .setResourceName("resource name").build()).setResourceType(ResourceTypeEnum.Device).build();
221 // org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.get.pm.output.Measurements
222 // measurements1 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.get.pm
223 // .output.MeasurementsBuilder().setPmparameterName("name").setPmparameterValue("1234").build();
226 // List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.get.pm.output
227 // .Measurements> measurementsList1 = new ArrayList<>();
228 // measurementsList1.add(measurements1);
230 // GetPmOutputBuilder pmOutputBuilder = new GetPmOutputBuilder().setNodeId(input.getNodeId())
231 // .setResourceType(input.getResourceType())
232 // .setResourceIdentifier(input.getResourceIdentifier())
233 // .setGranularity(input.getGranularity())
234 // .setMeasurements(measurementsList1);
236 // Mockito.doReturn(pmOutputBuilder.build()).when(this.olmPowerService).getPm(Mockito.any());
237 // ListenableFuture<RpcResult<GetPmOutput>> output = this.olmPowerServiceRpc.getPm(input);
238 // Assert.assertEquals(pmOutputBuilder.build(), output.get().getResult());
239 // Assert.assertEquals(true, output.get().isSuccessful());
243 public void testGetPm3() throws ExecutionException, InterruptedException {
244 GetPmInput input = OlmPowerServiceRpcImplUtil.getGetPmInput();
245 ListenableFuture<RpcResult<GetPmOutput>> output = this.olmPowerServiceRpc.getPm(input);
247 // Assert.assertEquals(new GetPmOutputBuilder().build(), output.get().getResult());
248 // Assert.assertEquals(null, output.get().getResult().getResourceId());
249 // Assert.assertEquals(null, output.get().getResult().getMeasurements());
250 // Assert.assertEquals(null, output.get().getResult().getGranularity());
251 // Assert.assertEquals(null, output.get().getResult().getNodeId());
252 // Assert.assertEquals(null, output.get().getResult().getResourceIdentifier());
253 // Assert.assertEquals(null, output.get().getResult().getResourceType());
257 public void testServicePowerSetup1() throws ExecutionException, InterruptedException {
258 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
260 Mockito.when(this.olmPowerServiceRpc.servicePowerSetup(Mockito.any()))
261 .thenReturn(RpcResultBuilder.success(new ServicePowerSetupOutputBuilder()
262 .setResult("Success").build()).buildFuture());
263 ListenableFuture<RpcResult<ServicePowerSetupOutput>> output = this.olmPowerServiceRpc.servicePowerSetup(input);
264 Assert.assertEquals(new ServicePowerSetupOutputBuilder().setResult("Success").build(), output.get()
266 Assert.assertEquals("Success", output.get().getResult().getResult());
267 Assert.assertEquals(true, output.get().isSuccessful());
272 public void testServicePowerTurndown1() throws ExecutionException, InterruptedException {
273 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
275 Mockito.when(this.olmPowerServiceRpc.servicePowerTurndown(Mockito.any()))
276 .thenReturn(RpcResultBuilder.success(new ServicePowerTurndownOutputBuilder()
277 .setResult("Success").build()).buildFuture());
278 ListenableFuture<RpcResult<ServicePowerTurndownOutput>> output = this.olmPowerServiceRpc
279 .servicePowerTurndown(input);
280 Assert.assertEquals(new ServicePowerTurndownOutputBuilder().setResult("Success").build(), output.get()
282 Assert.assertEquals("Success", output.get().getResult().getResult());
283 Assert.assertEquals(true, output.get().isSuccessful());
288 public void testCalculateSpanlossBase1() throws ExecutionException, InterruptedException {
289 CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInput();
291 Mockito.when(this.olmPowerServiceRpc.calculateSpanlossBase(Mockito.any()))
292 .thenReturn(RpcResultBuilder.success(new CalculateSpanlossBaseOutputBuilder()
293 .setResult("Failed").build()).buildFuture());
294 ListenableFuture<RpcResult<CalculateSpanlossBaseOutput>> output = this.olmPowerServiceRpc
295 .calculateSpanlossBase(input);
296 Assert.assertEquals(new CalculateSpanlossBaseOutputBuilder().setResult("Failed").build(),
297 output.get().getResult());
298 Assert.assertEquals("Failed", output.get().getResult().getResult());
299 Assert.assertEquals(true, output.get().isSuccessful());
304 public void testCalculateSpanlossCurrent1() throws ExecutionException, InterruptedException {
305 CalculateSpanlossCurrentInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossCurrentInput();
307 Mockito.when(this.olmPowerServiceRpc.calculateSpanlossCurrent(Mockito.any()))
308 .thenReturn(RpcResultBuilder.success(new CalculateSpanlossCurrentOutputBuilder()
309 .setResult("success").build()).buildFuture());
310 ListenableFuture<RpcResult<CalculateSpanlossCurrentOutput>> output = this.olmPowerServiceRpc
311 .calculateSpanlossCurrent(input);
312 Assert.assertEquals(null, output.get().getResult());
313 Assert.assertEquals(true, output.get().isSuccessful());
317 public void testServicePowerResetInput() throws ExecutionException, InterruptedException {
318 ServicePowerResetInput input = OlmPowerServiceRpcImplUtil.getServicePowerResetInput();
320 Mockito.when(this.olmPowerServiceRpc.calculateSpanlossCurrent(Mockito.any()))
321 .thenReturn(RpcResultBuilder.success(new CalculateSpanlossCurrentOutputBuilder()
322 .setResult(null).build()).buildFuture());
323 ListenableFuture<RpcResult<ServicePowerResetOutput>> output = this.olmPowerServiceRpc
324 .servicePowerReset(input);
325 Assert.assertEquals(null, output.get().getResult());
326 Assert.assertEquals(true, output.get().isSuccessful());