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.crossconnect.CrossConnectImpl710;
30 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
31 import org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl;
32 import org.opendaylight.transportpce.common.mapping.MappingUtils;
33 import org.opendaylight.transportpce.common.mapping.MappingUtilsImpl;
34 import org.opendaylight.transportpce.common.mapping.PortMapping;
35 import org.opendaylight.transportpce.common.mapping.PortMappingImpl;
36 import org.opendaylight.transportpce.common.mapping.PortMappingVersion121;
37 import org.opendaylight.transportpce.common.mapping.PortMappingVersion221;
38 import org.opendaylight.transportpce.common.mapping.PortMappingVersion710;
39 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
40 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
41 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl121;
42 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl221;
43 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl710;
44 import org.opendaylight.transportpce.olm.power.PowerMgmt;
45 import org.opendaylight.transportpce.olm.power.PowerMgmtImpl;
46 import org.opendaylight.transportpce.olm.service.OlmPowerService;
47 import org.opendaylight.transportpce.olm.service.OlmPowerServiceImpl;
48 import org.opendaylight.transportpce.olm.stub.MountPointServiceStub;
49 import org.opendaylight.transportpce.olm.stub.MountPointStub;
50 import org.opendaylight.transportpce.olm.util.OlmPowerServiceRpcImplUtil;
51 import org.opendaylight.transportpce.test.AbstractTest;
52 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmInput;
53 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmOutput;
54 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmOutputBuilder;
55 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupInput;
56 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupOutput;
57 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupOutputBuilder;
58 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownInput;
59 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownOutput;
60 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownOutputBuilder;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.CurrentPmlist;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.CurrentPmlistBuilder;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.current.pm.LayerRateBuilder;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.current.pm.Measurements;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.current.pm.MeasurementsBuilder;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.current.pm.measurements.MeasurementBuilder;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.currentpmlist.CurrentPm;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.currentpmlist.CurrentPmBuilder;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.currentpmlist.CurrentPmKey;
70 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev161014.PmDataType;
71 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev161014.PmGranularity;
72 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev161014.PmNamesEnum;
73 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev161014.pm.measurement.PmParameterNameBuilder;
74 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev161014.resource.DeviceBuilder;
75 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev161014.resource.ResourceTypeBuilder;
76 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev161014.resource.resource.resource.CircuitPackBuilder;
77 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.types.rev161014.ResourceTypeEnum;
78 import org.opendaylight.yangtools.yang.common.RpcResult;
79 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
80 import org.opendaylight.yangtools.yang.common.Uint64;
82 public class OlmPowerServiceRpcImplTest extends AbstractTest {
84 private MountPoint mountPoint;
85 private MountPointService mountPointService;
86 private DeviceTransactionManager deviceTransactionManager;
87 private CrossConnect crossConnect;
88 private OpenRoadmInterfaces openRoadmInterfaces;
89 private PortMapping portMapping;
90 private PowerMgmt powerMgmt;
91 private OlmPowerService olmPowerService;
92 private OlmPowerServiceRpcImpl olmPowerServiceRpc;
93 private CrossConnectImpl121 crossConnectImpl121;
94 private CrossConnectImpl221 crossConnectImpl22;
95 private CrossConnectImpl710 crossConnectImpl710;
96 private MappingUtils mappingUtils;
97 private OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121;
98 private OpenRoadmInterfacesImpl221 openRoadmInterfacesImpl22;
99 private OpenRoadmInterfacesImpl710 openRoadmInterfacesImpl710;
100 private PortMappingVersion710 portMappingVersion710;
101 private PortMappingVersion221 portMappingVersion22;
102 private PortMappingVersion121 portMappingVersion121;
105 public void setUp() {
106 this.mountPoint = new MountPointStub(getDataBroker());
107 this.mountPointService = new MountPointServiceStub(mountPoint);
108 this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
109 this.mappingUtils = Mockito.spy(new MappingUtilsImpl(getDataBroker()));
110 Mockito.doReturn(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1).when(mappingUtils)
111 .getOpenRoadmVersion(Mockito.anyString());
112 this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
113 this.crossConnectImpl121 = new CrossConnectImpl121(deviceTransactionManager);
114 this.crossConnectImpl22 = new CrossConnectImpl221(deviceTransactionManager);
115 this.crossConnectImpl710 = new CrossConnectImpl710(deviceTransactionManager);
116 this.crossConnect = new CrossConnectImpl(deviceTransactionManager, this.mappingUtils, this.crossConnectImpl121,
117 this.crossConnectImpl22, this.crossConnectImpl710);
118 this.portMappingVersion710 = new PortMappingVersion710(getDataBroker(), deviceTransactionManager);
119 this.portMappingVersion22 = new PortMappingVersion221(getDataBroker(), deviceTransactionManager);
120 this.portMappingVersion121 = new PortMappingVersion121(getDataBroker(), deviceTransactionManager);
121 this.portMapping = new PortMappingImpl(getDataBroker(), this.portMappingVersion710,
122 this.portMappingVersion22, this.portMappingVersion121);
123 this.openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(deviceTransactionManager);
124 this.openRoadmInterfacesImpl22 = new OpenRoadmInterfacesImpl221(deviceTransactionManager, this.portMapping,
125 this.portMappingVersion22);
126 this.openRoadmInterfacesImpl710 = new OpenRoadmInterfacesImpl710(deviceTransactionManager, this.portMapping,
127 this.portMappingVersion710);
128 this.openRoadmInterfaces = new OpenRoadmInterfacesImpl((this.deviceTransactionManager),
129 this.mappingUtils,this.openRoadmInterfacesImpl121,this.openRoadmInterfacesImpl22,
130 this.openRoadmInterfacesImpl710);
131 this.portMapping = Mockito.spy(this.portMapping);
132 this.powerMgmt = new PowerMgmtImpl(getDataBroker(), this.openRoadmInterfaces, this.crossConnect,
133 this.deviceTransactionManager);
134 this.olmPowerService = new OlmPowerServiceImpl(getDataBroker(), this.powerMgmt,
135 this.deviceTransactionManager, this.portMapping,mappingUtils,openRoadmInterfaces);
136 this.olmPowerServiceRpc = new OlmPowerServiceRpcImpl(this.olmPowerService);
138 this.olmPowerServiceRpc = Mockito.mock(OlmPowerServiceRpcImpl.class);
142 public void pmIsNotPresentTest() throws ExecutionException, InterruptedException {
143 GetPmInput input = OlmPowerServiceRpcImplUtil.getGetPmInput();
145 // ListenableFuture<RpcResult<GetPmOutput>> output = this.olmPowerServiceRpc.getPm(input);
146 // Assert.assertEquals(new GetPmOutputBuilder().build(), output.get().getResult());
147 // Assert.assertEquals(null, output.get().getResult().getResourceId());
148 // Assert.assertEquals(null, output.get().getResult().getMeasurements());
149 // Assert.assertEquals(null, output.get().getResult().getGranularity());
150 // Assert.assertEquals(null, output.get().getResult().getNodeId());
151 // Assert.assertEquals(null, output.get().getResult().getResourceIdentifier());
152 // Assert.assertEquals(null, output.get().getResult().getResourceType());
156 public void testGetPm1() throws ExecutionException, InterruptedException {
157 Measurements measurements = new MeasurementsBuilder().setMeasurement(
158 new MeasurementBuilder()
159 .setPmParameterUnit("unit")
160 .setPmParameterName(new PmParameterNameBuilder()
162 .setType(PmNamesEnum.DefectSeconds).build())
163 .setPmParameterValue(new PmDataType(Uint64.valueOf(1234))).build())
165 List<Measurements> measurementsList = new ArrayList<Measurements>();
166 measurementsList.add(measurements);
168 org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev161014.resource.Resource resource =
169 new org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev161014.resource.ResourceBuilder()
170 .setResource(new CircuitPackBuilder().setCircuitPackName("circuit pack name").build()).build();
172 org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.current.pm.Resource resource2 =
173 new org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.current.pm.ResourceBuilder()
174 .setDevice(new DeviceBuilder().setNodeId("node 1").build())
175 .setResourceType(new ResourceTypeBuilder()
177 .setType(ResourceTypeEnum.Device).build())
178 .setResource(resource).build();
179 CurrentPm currentPm = new CurrentPmBuilder()
180 .setGranularity(PmGranularity._15min)
182 .setLayerRate(new LayerRateBuilder().build())
183 .setMeasurements(measurementsList)
184 .setResource(resource2)
185 .setRetrievalTime(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715
186 .DateAndTime("2018-11-01T12:00:31.456449+06:00")).build();
188 Map<CurrentPmKey, CurrentPm> currentPmList = new HashMap<>();
189 currentPmList.put(currentPm.key(),currentPm);
191 Optional<CurrentPmlist> currentPmlistOptional = Optional.of(new CurrentPmlistBuilder()
192 .setCurrentPm(currentPmList).build());
194 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.get.pm.output.Measurements
195 measurements1 = new org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.get.pm
196 .output.MeasurementsBuilder().setPmparameterName("name").setPmparameterValue("1234").build();
199 List<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.get.pm.output
200 .Measurements> measurementsList1 = new ArrayList<>();
201 measurementsList1.add(measurements1);
203 GetPmInput input = OlmPowerServiceRpcImplUtil.getGetPmInput();
204 GetPmOutputBuilder pmOutputBuilder = new GetPmOutputBuilder().setNodeId(input.getNodeId())
205 .setResourceType(input.getResourceType())
206 .setResourceIdentifier(input.getResourceIdentifier())
207 .setGranularity(input.getGranularity())
208 .setMeasurements(measurementsList1);
211 ListenableFuture<RpcResult<GetPmOutput>> output = this.olmPowerServiceRpc.getPm(input);
213 // Assert.assertEquals(new GetPmOutputBuilder().build(), output.get().getResult());
214 // Assert.assertEquals(null, output.get().getResult().getResourceId());
218 // public void testGetPm2() throws ExecutionException, InterruptedException {
219 // this.olmPowerService = Mockito.spy(this.olmPowerService);
220 // GetPmInput input = new GetPmInputBuilder().setGranularity(PmGranularity._15min).setNodeId("node1")
221 // .setResourceIdentifier(new ResourceIdentifierBuilder().setCircuitPackName("circuit pack name")
222 // .setResourceName("resource name").build()).setResourceType(ResourceTypeEnum.Device).build();
223 // org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.get.pm.output.Measurements
224 // measurements1 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.get.pm
225 // .output.MeasurementsBuilder().setPmparameterName("name").setPmparameterValue("1234").build();
228 // List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.get.pm.output
229 // .Measurements> measurementsList1 = new ArrayList<>();
230 // measurementsList1.add(measurements1);
232 // GetPmOutputBuilder pmOutputBuilder = new GetPmOutputBuilder().setNodeId(input.getNodeId())
233 // .setResourceType(input.getResourceType())
234 // .setResourceIdentifier(input.getResourceIdentifier())
235 // .setGranularity(input.getGranularity())
236 // .setMeasurements(measurementsList1);
238 // Mockito.doReturn(pmOutputBuilder.build()).when(this.olmPowerService).getPm(Mockito.any());
239 // ListenableFuture<RpcResult<GetPmOutput>> output = this.olmPowerServiceRpc.getPm(input);
240 // Assert.assertEquals(pmOutputBuilder.build(), output.get().getResult());
241 // Assert.assertEquals(true, output.get().isSuccessful());
245 public void testGetPm3() throws ExecutionException, InterruptedException {
246 GetPmInput input = OlmPowerServiceRpcImplUtil.getGetPmInput();
247 ListenableFuture<RpcResult<GetPmOutput>> output = this.olmPowerServiceRpc.getPm(input);
249 // Assert.assertEquals(new GetPmOutputBuilder().build(), output.get().getResult());
250 // Assert.assertEquals(null, output.get().getResult().getResourceId());
251 // Assert.assertEquals(null, output.get().getResult().getMeasurements());
252 // Assert.assertEquals(null, output.get().getResult().getGranularity());
253 // Assert.assertEquals(null, output.get().getResult().getNodeId());
254 // Assert.assertEquals(null, output.get().getResult().getResourceIdentifier());
255 // Assert.assertEquals(null, output.get().getResult().getResourceType());
259 public void testServicePowerSetup1() throws ExecutionException, InterruptedException {
260 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
262 Mockito.when(this.olmPowerServiceRpc.servicePowerSetup(Mockito.any()))
263 .thenReturn(RpcResultBuilder.success(new ServicePowerSetupOutputBuilder()
264 .setResult("Success").build()).buildFuture());
265 ListenableFuture<RpcResult<ServicePowerSetupOutput>> output = this.olmPowerServiceRpc.servicePowerSetup(input);
266 Assert.assertEquals(new ServicePowerSetupOutputBuilder().setResult("Success").build(), output.get()
268 Assert.assertEquals("Success", output.get().getResult().getResult());
269 Assert.assertEquals(true, output.get().isSuccessful());
274 public void testServicePowerTurndown1() throws ExecutionException, InterruptedException {
275 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
277 Mockito.when(this.olmPowerServiceRpc.servicePowerTurndown(Mockito.any()))
278 .thenReturn(RpcResultBuilder.success(new ServicePowerTurndownOutputBuilder()
279 .setResult("Success").build()).buildFuture());
280 ListenableFuture<RpcResult<ServicePowerTurndownOutput>> output = this.olmPowerServiceRpc
281 .servicePowerTurndown(input);
282 Assert.assertEquals(new ServicePowerTurndownOutputBuilder().setResult("Success").build(), output.get()
284 Assert.assertEquals("Success", output.get().getResult().getResult());
285 Assert.assertEquals(true, output.get().isSuccessful());
290 public void testCalculateSpanlossBase1() throws ExecutionException, InterruptedException {
291 CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInput();
293 Mockito.when(this.olmPowerServiceRpc.calculateSpanlossBase(Mockito.any()))
294 .thenReturn(RpcResultBuilder.success(new CalculateSpanlossBaseOutputBuilder()
295 .setResult("Failed").build()).buildFuture());
296 ListenableFuture<RpcResult<CalculateSpanlossBaseOutput>> output = this.olmPowerServiceRpc
297 .calculateSpanlossBase(input);
298 Assert.assertEquals(new CalculateSpanlossBaseOutputBuilder().setResult("Failed").build(),
299 output.get().getResult());
300 Assert.assertEquals("Failed", output.get().getResult().getResult());
301 Assert.assertEquals(true, output.get().isSuccessful());
306 public void testCalculateSpanlossCurrent1() throws ExecutionException, InterruptedException {
307 CalculateSpanlossCurrentInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossCurrentInput();
309 Mockito.when(this.olmPowerServiceRpc.calculateSpanlossCurrent(Mockito.any()))
310 .thenReturn(RpcResultBuilder.success(new CalculateSpanlossCurrentOutputBuilder()
311 .setResult("success").build()).buildFuture());
312 ListenableFuture<RpcResult<CalculateSpanlossCurrentOutput>> output = this.olmPowerServiceRpc
313 .calculateSpanlossCurrent(input);
314 Assert.assertEquals(null, output.get().getResult());
315 Assert.assertEquals(true, output.get().isSuccessful());
319 public void testServicePowerResetInput() throws ExecutionException, InterruptedException {
320 ServicePowerResetInput input = OlmPowerServiceRpcImplUtil.getServicePowerResetInput();
322 Mockito.when(this.olmPowerServiceRpc.calculateSpanlossCurrent(Mockito.any()))
323 .thenReturn(RpcResultBuilder.success(new CalculateSpanlossCurrentOutputBuilder()
324 .setResult(null).build()).buildFuture());
325 ListenableFuture<RpcResult<ServicePowerResetOutput>> output = this.olmPowerServiceRpc
326 .servicePowerReset(input);
327 Assert.assertEquals(null, output.get().getResult());
328 Assert.assertEquals(true, output.get().isSuccessful());