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.service;
11 import java.util.Optional;
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.mockito.Mockito;
16 import org.opendaylight.mdsal.binding.api.DataBroker;
17 import org.opendaylight.transportpce.common.StringConstants;
18 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
19 import org.opendaylight.transportpce.common.mapping.MappingUtils;
20 import org.opendaylight.transportpce.common.mapping.PortMapping;
21 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
22 import org.opendaylight.transportpce.olm.power.PowerMgmt;
23 import org.opendaylight.transportpce.olm.power.PowerMgmtImpl;
24 import org.opendaylight.transportpce.olm.util.OlmPowerServiceRpcImplUtil;
25 import org.opendaylight.transportpce.test.AbstractTest;
26 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmInput;
27 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmOutput;
28 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerResetInput;
29 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerResetOutput;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupInput;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupOutput;
32 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupOutputBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownInput;
34 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownOutput;
35 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownOutputBuilder;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev161014.PmNamesEnum;
38 public class OlmPowerServiceImplTest extends AbstractTest {
40 private DeviceTransactionManager deviceTransactionManager;
41 private OpenRoadmInterfaces openRoadmInterfaces;
42 private PortMapping portMapping;
43 private PowerMgmt powerMgmt;
44 private MappingUtils mappingUtils;
45 private OlmPowerService olmPowerService;
46 private DataBroker dataBroker;
50 this.dataBroker = Mockito.mock(DataBroker.class);
51 this.powerMgmt = Mockito.mock(PowerMgmtImpl.class);
52 this.deviceTransactionManager = Mockito.mock(DeviceTransactionManager.class);
53 this.portMapping = Mockito.mock(PortMapping.class);
54 this.mappingUtils = Mockito.mock(MappingUtils.class);
55 this.openRoadmInterfaces = Mockito.mock(OpenRoadmInterfaces.class);
56 this.olmPowerService = new OlmPowerServiceImpl(this.dataBroker, this.powerMgmt,
57 this.deviceTransactionManager, this.portMapping, this.mappingUtils, this.openRoadmInterfaces);
61 public void dummyTest() {
62 OlmPowerServiceImpl olmPowerServiceImpl = (OlmPowerServiceImpl) this.olmPowerService;
63 olmPowerServiceImpl.init();
64 olmPowerServiceImpl.close();
68 public void testGetPm() {
69 Mockito.when(this.mappingUtils.getOpenRoadmVersion(Mockito.anyString()))
70 .thenReturn(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1);
71 Mockito.when(this.deviceTransactionManager.getDataFromDevice(Mockito.anyString(), Mockito.any(),
72 Mockito.any(), Mockito.anyLong(), Mockito.any()))
73 .thenReturn(Optional.of(OlmPowerServiceRpcImplUtil.getCurrentPmList121()));
75 GetPmInput input = OlmPowerServiceRpcImplUtil.getGetPmInput();
76 GetPmOutput result = this.olmPowerService.getPm(input);
78 org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.PmGranularity._15min,
79 result.getGranularity());
80 Assert.assertEquals(PmNamesEnum.OpticalPowerInput.toString(),
81 result.getMeasurements().stream().findFirst().get().getPmparameterName());
82 Assert.assertEquals(String.valueOf(3.0),
83 result.getMeasurements().stream().findFirst().get().getPmparameterValue());
84 Assert.assertEquals("ots-deg1",
85 result.getResourceIdentifier().getResourceName());
89 public void testServicePowerSetupSuccess() {
90 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
91 Mockito.when(this.powerMgmt.setPower(Mockito.any())).thenReturn(true);
92 ServicePowerSetupOutput result = this.olmPowerService.servicePowerSetup(input);
93 Assert.assertEquals(new ServicePowerSetupOutputBuilder().setResult("Success").build(), result);
94 Assert.assertEquals("Success", result.getResult());
98 public void testServicePowerSetupFailed() {
99 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
100 Mockito.when(this.powerMgmt.setPower(Mockito.any())).thenReturn(false);
101 ServicePowerSetupOutput output = this.olmPowerService.servicePowerSetup(input);
102 Assert.assertEquals("Failed", output.getResult());
106 public void testServicePowerTurnDownSuccess() {
107 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
108 Mockito.when(this.powerMgmt.powerTurnDown(Mockito.any())).thenReturn(true);
109 ServicePowerTurndownOutput output = this.olmPowerService.servicePowerTurndown(input);
110 Assert.assertEquals(new ServicePowerTurndownOutputBuilder().setResult("Success").build(), output);
111 Assert.assertEquals("Success", output.getResult());
115 public void testServicePowerTurnDownFailed() {
116 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
117 Mockito.when(this.powerMgmt.powerTurnDown(Mockito.any())).thenReturn(false);
118 ServicePowerTurndownOutput output = this.olmPowerService.servicePowerTurndown(input);
119 Assert.assertEquals(new ServicePowerTurndownOutputBuilder().setResult("Failed").build(), output);
120 Assert.assertEquals("Failed", output.getResult());
124 public void testServicePowerReset() {
125 ServicePowerResetInput input = OlmPowerServiceRpcImplUtil.getServicePowerResetInput();
126 ServicePowerResetOutput output = this.olmPowerService.servicePowerReset(input);
127 Assert.assertEquals(null, output);