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 static org.junit.jupiter.api.Assertions.assertEquals;
12 import static org.mockito.ArgumentMatchers.any;
13 import static org.mockito.ArgumentMatchers.anyLong;
14 import static org.mockito.ArgumentMatchers.anyString;
15 import static org.mockito.Mockito.mock;
16 import static org.mockito.Mockito.when;
18 import java.util.Optional;
19 import org.junit.jupiter.api.BeforeEach;
20 import org.junit.jupiter.api.Test;
21 import org.opendaylight.mdsal.binding.api.DataBroker;
22 import org.opendaylight.transportpce.common.StringConstants;
23 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
24 import org.opendaylight.transportpce.common.mapping.MappingUtils;
25 import org.opendaylight.transportpce.common.mapping.PortMapping;
26 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
27 import org.opendaylight.transportpce.olm.power.PowerMgmt;
28 import org.opendaylight.transportpce.olm.power.PowerMgmtImpl;
29 import org.opendaylight.transportpce.olm.util.OlmPowerServiceRpcImplUtil;
30 import org.opendaylight.transportpce.test.AbstractTest;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmInput;
32 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmOutput;
33 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerResetInput;
34 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerResetOutput;
35 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupInput;
36 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupOutput;
37 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupOutputBuilder;
38 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownInput;
39 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownOutput;
40 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownOutputBuilder;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev161014.PmNamesEnum;
43 public class OlmPowerServiceImplTest extends AbstractTest {
45 private DeviceTransactionManager deviceTransactionManager;
46 private OpenRoadmInterfaces openRoadmInterfaces;
47 private PortMapping portMapping;
48 private PowerMgmt powerMgmt;
49 private MappingUtils mappingUtils;
50 private OlmPowerService olmPowerService;
51 private DataBroker dataBroker;
55 this.dataBroker = mock(DataBroker.class);
56 this.powerMgmt = mock(PowerMgmtImpl.class);
57 this.deviceTransactionManager = mock(DeviceTransactionManager.class);
58 this.portMapping = mock(PortMapping.class);
59 this.mappingUtils = mock(MappingUtils.class);
60 this.openRoadmInterfaces = mock(OpenRoadmInterfaces.class);
61 this.olmPowerService = new OlmPowerServiceImpl(this.dataBroker, this.powerMgmt, this.deviceTransactionManager,
62 this.portMapping, this.mappingUtils, this.openRoadmInterfaces);
67 OlmPowerServiceImpl olmPowerServiceImpl = (OlmPowerServiceImpl) this.olmPowerService;
68 olmPowerServiceImpl.init();
69 olmPowerServiceImpl.close();
74 when(this.mappingUtils.getOpenRoadmVersion(anyString()))
75 .thenReturn(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1);
76 when(this.deviceTransactionManager.getDataFromDevice(anyString(), any(), any(), anyLong(), any()))
77 .thenReturn(Optional.of(OlmPowerServiceRpcImplUtil.getCurrentPmList121()));
79 GetPmInput input = OlmPowerServiceRpcImplUtil.getGetPmInput();
80 GetPmOutput result = this.olmPowerService.getPm(input);
82 org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.PmGranularity._15min,
83 result.getGranularity());
85 PmNamesEnum.OpticalPowerInput.toString(),
86 result.getMeasurements().stream().findFirst().get().getPmparameterName());
89 result.getMeasurements().stream().findFirst().get().getPmparameterValue());
92 result.getResourceIdentifier().getResourceName());
96 void testServicePowerSetupSuccess() {
97 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
98 when(this.powerMgmt.setPower(any())).thenReturn(true);
99 ServicePowerSetupOutput result = this.olmPowerService.servicePowerSetup(input);
100 assertEquals(new ServicePowerSetupOutputBuilder().setResult("Success").build(), result);
101 assertEquals("Success", result.getResult());
105 void testServicePowerSetupFailed() {
106 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
107 when(this.powerMgmt.setPower(any())).thenReturn(false);
108 ServicePowerSetupOutput output = this.olmPowerService.servicePowerSetup(input);
109 assertEquals("Failed", output.getResult());
113 void testServicePowerTurnDownSuccess() {
114 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
115 when(this.powerMgmt.powerTurnDown(any())).thenReturn(true);
116 ServicePowerTurndownOutput output = this.olmPowerService.servicePowerTurndown(input);
117 assertEquals(new ServicePowerTurndownOutputBuilder().setResult("Success").build(), output);
118 assertEquals("Success", output.getResult());
122 void testServicePowerTurnDownFailed() {
123 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
124 when(this.powerMgmt.powerTurnDown(any())).thenReturn(false);
125 ServicePowerTurndownOutput output = this.olmPowerService.servicePowerTurndown(input);
126 assertEquals(new ServicePowerTurndownOutputBuilder().setResult("Failed").build(), output);
127 assertEquals("Failed", output.getResult());
131 void testServicePowerReset() {
132 ServicePowerResetInput input = OlmPowerServiceRpcImplUtil.getServicePowerResetInput();
133 ServicePowerResetOutput output = this.olmPowerService.servicePowerReset(input);
134 assertEquals(null, output);