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.openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(deviceTransactionManager);
119 this.openRoadmInterfacesImpl22 = new OpenRoadmInterfacesImpl221(deviceTransactionManager);
120 this.openRoadmInterfacesImpl710 = new OpenRoadmInterfacesImpl710(deviceTransactionManager);
121 this.openRoadmInterfaces = new OpenRoadmInterfacesImpl((this.deviceTransactionManager),
122 this.mappingUtils,this.openRoadmInterfacesImpl121,this.openRoadmInterfacesImpl22,
123 this.openRoadmInterfacesImpl710);
124 this.portMappingVersion710 =
125 new PortMappingVersion710(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
126 this.portMappingVersion22 =
127 new PortMappingVersion221(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
128 this.portMappingVersion121 =
129 new PortMappingVersion121(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
130 this.portMapping = new PortMappingImpl(getDataBroker(), this.portMappingVersion710,
131 this.portMappingVersion22, this.portMappingVersion121);
132 this.portMapping = Mockito.spy(this.portMapping);
133 this.powerMgmt = new PowerMgmtImpl(getDataBroker(), this.openRoadmInterfaces, this.crossConnect,
134 this.deviceTransactionManager);
135 this.olmPowerService = new OlmPowerServiceImpl(getDataBroker(), this.powerMgmt,
136 this.deviceTransactionManager, this.portMapping,mappingUtils,openRoadmInterfaces);
137 this.olmPowerServiceRpc = new OlmPowerServiceRpcImpl(this.olmPowerService);
139 this.olmPowerServiceRpc = Mockito.mock(OlmPowerServiceRpcImpl.class);
143 public void pmIsNotPresentTest() throws ExecutionException, InterruptedException {
144 GetPmInput input = OlmPowerServiceRpcImplUtil.getGetPmInput();
146 // ListenableFuture<RpcResult<GetPmOutput>> output = this.olmPowerServiceRpc.getPm(input);
147 // Assert.assertEquals(new GetPmOutputBuilder().build(), output.get().getResult());
148 // Assert.assertEquals(null, output.get().getResult().getResourceId());
149 // Assert.assertEquals(null, output.get().getResult().getMeasurements());
150 // Assert.assertEquals(null, output.get().getResult().getGranularity());
151 // Assert.assertEquals(null, output.get().getResult().getNodeId());
152 // Assert.assertEquals(null, output.get().getResult().getResourceIdentifier());
153 // Assert.assertEquals(null, output.get().getResult().getResourceType());
157 public void testGetPm1() throws ExecutionException, InterruptedException {
158 Measurements measurements = new MeasurementsBuilder().setMeasurement(
159 new MeasurementBuilder()
160 .setPmParameterUnit("unit")
161 .setPmParameterName(new PmParameterNameBuilder()
163 .setType(PmNamesEnum.DefectSeconds).build())
164 .setPmParameterValue(new PmDataType(Uint64.valueOf(1234))).build())
166 List<Measurements> measurementsList = new ArrayList<Measurements>();
167 measurementsList.add(measurements);
169 org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev161014.resource.Resource resource =
170 new org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev161014.resource.ResourceBuilder()
171 .setResource(new CircuitPackBuilder().setCircuitPackName("circuit pack name").build()).build();
173 org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.current.pm.Resource resource2 =
174 new org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.current.pm.ResourceBuilder()
175 .setDevice(new DeviceBuilder().setNodeId("node 1").build())
176 .setResourceType(new ResourceTypeBuilder()
178 .setType(ResourceTypeEnum.Device).build())
179 .setResource(resource).build();
180 CurrentPm currentPm = new CurrentPmBuilder()
181 .setGranularity(PmGranularity._15min)
183 .setLayerRate(new LayerRateBuilder().build())
184 .setMeasurements(measurementsList)
185 .setResource(resource2)
186 .setRetrievalTime(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715
187 .DateAndTime("2018-11-01T12:00:31.456449+06:00")).build();
189 Map<CurrentPmKey, CurrentPm> currentPmList = new HashMap<>();
190 currentPmList.put(currentPm.key(),currentPm);
192 Optional<CurrentPmlist> currentPmlistOptional = Optional.of(new CurrentPmlistBuilder()
193 .setCurrentPm(currentPmList).build());
195 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.get.pm.output.Measurements
196 measurements1 = new org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.get.pm
197 .output.MeasurementsBuilder().setPmparameterName("name").setPmparameterValue("1234").build();
200 List<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.get.pm.output
201 .Measurements> measurementsList1 = new ArrayList<>();
202 measurementsList1.add(measurements1);
204 GetPmInput input = OlmPowerServiceRpcImplUtil.getGetPmInput();
205 GetPmOutputBuilder pmOutputBuilder = new GetPmOutputBuilder().setNodeId(input.getNodeId())
206 .setResourceType(input.getResourceType())
207 .setResourceIdentifier(input.getResourceIdentifier())
208 .setGranularity(input.getGranularity())
209 .setMeasurements(measurementsList1);
212 ListenableFuture<RpcResult<GetPmOutput>> output = this.olmPowerServiceRpc.getPm(input);
214 // Assert.assertEquals(new GetPmOutputBuilder().build(), output.get().getResult());
215 // Assert.assertEquals(null, output.get().getResult().getResourceId());
219 // public void testGetPm2() throws ExecutionException, InterruptedException {
220 // this.olmPowerService = Mockito.spy(this.olmPowerService);
221 // GetPmInput input = new GetPmInputBuilder().setGranularity(PmGranularity._15min).setNodeId("node1")
222 // .setResourceIdentifier(new ResourceIdentifierBuilder().setCircuitPackName("circuit pack name")
223 // .setResourceName("resource name").build()).setResourceType(ResourceTypeEnum.Device).build();
224 // org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.get.pm.output.Measurements
225 // measurements1 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.get.pm
226 // .output.MeasurementsBuilder().setPmparameterName("name").setPmparameterValue("1234").build();
229 // List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.get.pm.output
230 // .Measurements> measurementsList1 = new ArrayList<>();
231 // measurementsList1.add(measurements1);
233 // GetPmOutputBuilder pmOutputBuilder = new GetPmOutputBuilder().setNodeId(input.getNodeId())
234 // .setResourceType(input.getResourceType())
235 // .setResourceIdentifier(input.getResourceIdentifier())
236 // .setGranularity(input.getGranularity())
237 // .setMeasurements(measurementsList1);
239 // Mockito.doReturn(pmOutputBuilder.build()).when(this.olmPowerService).getPm(Mockito.any());
240 // ListenableFuture<RpcResult<GetPmOutput>> output = this.olmPowerServiceRpc.getPm(input);
241 // Assert.assertEquals(pmOutputBuilder.build(), output.get().getResult());
242 // Assert.assertEquals(true, output.get().isSuccessful());
246 public void testGetPm3() throws ExecutionException, InterruptedException {
247 GetPmInput input = OlmPowerServiceRpcImplUtil.getGetPmInput();
248 ListenableFuture<RpcResult<GetPmOutput>> output = this.olmPowerServiceRpc.getPm(input);
250 // Assert.assertEquals(new GetPmOutputBuilder().build(), output.get().getResult());
251 // Assert.assertEquals(null, output.get().getResult().getResourceId());
252 // Assert.assertEquals(null, output.get().getResult().getMeasurements());
253 // Assert.assertEquals(null, output.get().getResult().getGranularity());
254 // Assert.assertEquals(null, output.get().getResult().getNodeId());
255 // Assert.assertEquals(null, output.get().getResult().getResourceIdentifier());
256 // Assert.assertEquals(null, output.get().getResult().getResourceType());
260 public void testServicePowerSetup1() throws ExecutionException, InterruptedException {
261 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
263 Mockito.when(this.olmPowerServiceRpc.servicePowerSetup(Mockito.any()))
264 .thenReturn(RpcResultBuilder.success(new ServicePowerSetupOutputBuilder()
265 .setResult("Success").build()).buildFuture());
266 ListenableFuture<RpcResult<ServicePowerSetupOutput>> output = this.olmPowerServiceRpc.servicePowerSetup(input);
267 Assert.assertEquals(new ServicePowerSetupOutputBuilder().setResult("Success").build(), output.get()
269 Assert.assertEquals("Success", output.get().getResult().getResult());
270 Assert.assertEquals(true, output.get().isSuccessful());
275 public void testServicePowerTurndown1() throws ExecutionException, InterruptedException {
276 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
278 Mockito.when(this.olmPowerServiceRpc.servicePowerTurndown(Mockito.any()))
279 .thenReturn(RpcResultBuilder.success(new ServicePowerTurndownOutputBuilder()
280 .setResult("Success").build()).buildFuture());
281 ListenableFuture<RpcResult<ServicePowerTurndownOutput>> output = this.olmPowerServiceRpc
282 .servicePowerTurndown(input);
283 Assert.assertEquals(new ServicePowerTurndownOutputBuilder().setResult("Success").build(), output.get()
285 Assert.assertEquals("Success", output.get().getResult().getResult());
286 Assert.assertEquals(true, output.get().isSuccessful());
291 public void testCalculateSpanlossBase1() throws ExecutionException, InterruptedException {
292 CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInput();
294 Mockito.when(this.olmPowerServiceRpc.calculateSpanlossBase(Mockito.any()))
295 .thenReturn(RpcResultBuilder.success(new CalculateSpanlossBaseOutputBuilder()
296 .setResult("Failed").build()).buildFuture());
297 ListenableFuture<RpcResult<CalculateSpanlossBaseOutput>> output = this.olmPowerServiceRpc
298 .calculateSpanlossBase(input);
299 Assert.assertEquals(new CalculateSpanlossBaseOutputBuilder().setResult("Failed").build(),
300 output.get().getResult());
301 Assert.assertEquals("Failed", output.get().getResult().getResult());
302 Assert.assertEquals(true, output.get().isSuccessful());
307 public void testCalculateSpanlossCurrent1() throws ExecutionException, InterruptedException {
308 CalculateSpanlossCurrentInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossCurrentInput();
310 Mockito.when(this.olmPowerServiceRpc.calculateSpanlossCurrent(Mockito.any()))
311 .thenReturn(RpcResultBuilder.success(new CalculateSpanlossCurrentOutputBuilder()
312 .setResult("success").build()).buildFuture());
313 ListenableFuture<RpcResult<CalculateSpanlossCurrentOutput>> output = this.olmPowerServiceRpc
314 .calculateSpanlossCurrent(input);
315 Assert.assertEquals(null, output.get().getResult());
316 Assert.assertEquals(true, output.get().isSuccessful());
320 public void testServicePowerResetInput() throws ExecutionException, InterruptedException {
321 ServicePowerResetInput input = OlmPowerServiceRpcImplUtil.getServicePowerResetInput();
323 Mockito.when(this.olmPowerServiceRpc.calculateSpanlossCurrent(Mockito.any()))
324 .thenReturn(RpcResultBuilder.success(new CalculateSpanlossCurrentOutputBuilder()
325 .setResult(null).build()).buildFuture());
326 ListenableFuture<RpcResult<ServicePowerResetOutput>> output = this.olmPowerServiceRpc
327 .servicePowerReset(input);
328 Assert.assertEquals(null, output.get().getResult());
329 Assert.assertEquals(true, output.get().isSuccessful());