*/
@Override
public ListenableFuture<RpcResult<GetPmOutput>> getPm(GetPmInput input) {
- if (this.olmPowerService.getPm(input).getNodeId() == null) {
- LOG.error("getPm: Error with input parameters");
+ if (input.getNodeId() == null) {
+ LOG.error("getPm: NodeId can not be null");
return RpcResultBuilder.<GetPmOutput>failed()
.withError(ErrorType.RPC, "Error with input parameters")
.buildFuture();
package org.opendaylight.transportpce.olm;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
import com.google.common.util.concurrent.ListenableFuture;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
import java.util.concurrent.ExecutionException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
-import org.opendaylight.mdsal.binding.api.MountPoint;
-import org.opendaylight.mdsal.binding.api.MountPointService;
-import org.opendaylight.transportpce.common.StringConstants;
-import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
-import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl;
-import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl121;
-import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl221;
-import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl710;
-import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
-import org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl;
-import org.opendaylight.transportpce.common.mapping.MappingUtils;
-import org.opendaylight.transportpce.common.mapping.MappingUtilsImpl;
-import org.opendaylight.transportpce.common.mapping.PortMapping;
-import org.opendaylight.transportpce.common.mapping.PortMappingImpl;
-import org.opendaylight.transportpce.common.mapping.PortMappingVersion121;
-import org.opendaylight.transportpce.common.mapping.PortMappingVersion221;
-import org.opendaylight.transportpce.common.mapping.PortMappingVersion710;
-import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
-import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
-import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl121;
-import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl221;
-import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl710;
-import org.opendaylight.transportpce.olm.power.PowerMgmt;
-import org.opendaylight.transportpce.olm.power.PowerMgmtImpl;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.opendaylight.transportpce.olm.service.OlmPowerService;
-import org.opendaylight.transportpce.olm.service.OlmPowerServiceImpl;
-import org.opendaylight.transportpce.olm.stub.MountPointServiceStub;
-import org.opendaylight.transportpce.olm.stub.MountPointStub;
import org.opendaylight.transportpce.olm.util.OlmPowerServiceRpcImplUtil;
import org.opendaylight.transportpce.test.AbstractTest;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossBaseInput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossBaseOutputBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossCurrentInput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossCurrentInputBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossCurrentOutputBuilder;
import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmInput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmInputBuilder;
import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmOutput;
import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmOutputBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerResetInput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerResetOutputBuilder;
import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupInput;
import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupOutput;
import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupOutputBuilder;
import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownInput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownOutput;
import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownOutputBuilder;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.CurrentPmlist;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.CurrentPmlistBuilder;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.current.pm.LayerRateBuilder;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.current.pm.Measurements;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.current.pm.MeasurementsBuilder;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.current.pm.measurements.MeasurementBuilder;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.currentpmlist.CurrentPm;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.currentpmlist.CurrentPmBuilder;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.currentpmlist.CurrentPmKey;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev161014.PmDataType;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev161014.PmGranularity;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev161014.PmNamesEnum;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev161014.pm.measurement.PmParameterNameBuilder;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev161014.resource.DeviceBuilder;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev161014.resource.ResourceTypeBuilder;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev161014.resource.resource.resource.CircuitPackBuilder;
import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.types.rev161014.ResourceTypeEnum;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.PmGranularity;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.olm.get.pm.input.ResourceIdentifierBuilder;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
+import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
-import org.opendaylight.yangtools.yang.common.Uint64;
-public class OlmPowerServiceRpcImplTest extends AbstractTest {
+@ExtendWith(MockitoExtension.class)
+class OlmPowerServiceRpcImplTest extends AbstractTest {
- private MountPoint mountPoint;
- private MountPointService mountPointService;
- private DeviceTransactionManager deviceTransactionManager;
- private CrossConnect crossConnect;
- private OpenRoadmInterfaces openRoadmInterfaces;
- private PortMapping portMapping;
- private PowerMgmt powerMgmt;
+ @Mock
private OlmPowerService olmPowerService;
private OlmPowerServiceRpcImpl olmPowerServiceRpc;
- private CrossConnectImpl121 crossConnectImpl121;
- private CrossConnectImpl221 crossConnectImpl22;
- private CrossConnectImpl710 crossConnectImpl710;
- private MappingUtils mappingUtils;
- private OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121;
- private OpenRoadmInterfacesImpl221 openRoadmInterfacesImpl22;
- private OpenRoadmInterfacesImpl710 openRoadmInterfacesImpl710;
- private PortMappingVersion710 portMappingVersion710;
- private PortMappingVersion221 portMappingVersion22;
- private PortMappingVersion121 portMappingVersion121;
@BeforeEach
public void setUp() {
- this.mountPoint = new MountPointStub(getDataBroker());
- this.mountPointService = new MountPointServiceStub(mountPoint);
- this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
- this.mappingUtils = Mockito.spy(new MappingUtilsImpl(getDataBroker()));
- Mockito.doReturn(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1).when(mappingUtils)
- .getOpenRoadmVersion(Mockito.anyString());
- this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
- this.crossConnectImpl121 = new CrossConnectImpl121(deviceTransactionManager);
- this.crossConnectImpl22 = new CrossConnectImpl221(deviceTransactionManager);
- this.crossConnectImpl710 = new CrossConnectImpl710(deviceTransactionManager);
- this.crossConnect = new CrossConnectImpl(deviceTransactionManager, this.mappingUtils, this.crossConnectImpl121,
- this.crossConnectImpl22, this.crossConnectImpl710);
- this.portMappingVersion710 = new PortMappingVersion710(getDataBroker(), deviceTransactionManager);
- this.portMappingVersion22 = new PortMappingVersion221(getDataBroker(), deviceTransactionManager);
- this.portMappingVersion121 = new PortMappingVersion121(getDataBroker(), deviceTransactionManager);
- this.portMapping = new PortMappingImpl(getDataBroker(), this.portMappingVersion710,
- this.portMappingVersion22, this.portMappingVersion121);
- this.openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(deviceTransactionManager);
- this.openRoadmInterfacesImpl22 = new OpenRoadmInterfacesImpl221(deviceTransactionManager, this.portMapping);
- this.openRoadmInterfacesImpl710 = new OpenRoadmInterfacesImpl710(deviceTransactionManager, this.portMapping);
- this.openRoadmInterfaces = new OpenRoadmInterfacesImpl((this.deviceTransactionManager),
- this.mappingUtils,this.openRoadmInterfacesImpl121,this.openRoadmInterfacesImpl22,
- this.openRoadmInterfacesImpl710);
- this.portMapping = Mockito.spy(this.portMapping);
- this.powerMgmt = new PowerMgmtImpl(this.openRoadmInterfaces, this.crossConnect,
- this.deviceTransactionManager, this.portMapping, 1000, 1000);
- this.olmPowerService = new OlmPowerServiceImpl(getDataBroker(), this.powerMgmt,
- this.deviceTransactionManager, this.portMapping,mappingUtils,openRoadmInterfaces);
this.olmPowerServiceRpc = new OlmPowerServiceRpcImpl(this.olmPowerService);
- //TODO
- this.olmPowerServiceRpc = Mockito.mock(OlmPowerServiceRpcImpl.class);
}
@Test
- public void pmIsNotPresentTest() throws ExecutionException, InterruptedException {
- GetPmInput input = OlmPowerServiceRpcImplUtil.getGetPmInput();
- //TODO
-// ListenableFuture<RpcResult<GetPmOutput>> output = this.olmPowerServiceRpc.getPm(input);
-// assertEquals(new GetPmOutputBuilder().build(), output.get().getResult());
-// assertEquals(null, output.get().getResult().getResourceId());
-// assertEquals(null, output.get().getResult().getMeasurements());
-// assertEquals(null, output.get().getResult().getGranularity());
-// assertEquals(null, output.get().getResult().getNodeId());
-// assertEquals(null, output.get().getResult().getResourceIdentifier());
-// assertEquals(null, output.get().getResult().getResourceType());
- }
-
- @Test
- public void testGetPm1() throws ExecutionException, InterruptedException {
- Measurements measurements = new MeasurementsBuilder().setMeasurement(
- new MeasurementBuilder()
- .setPmParameterUnit("unit")
- .setPmParameterName(new PmParameterNameBuilder()
- .setExtension("123")
- .setType(PmNamesEnum.DefectSeconds).build())
- .setPmParameterValue(new PmDataType(Uint64.valueOf(1234))).build())
- .build();
- List<Measurements> measurementsList = new ArrayList<Measurements>();
- measurementsList.add(measurements);
-
- org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev161014.resource.Resource resource =
- new org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev161014.resource.ResourceBuilder()
- .setResource(new CircuitPackBuilder().setCircuitPackName("circuit pack name").build()).build();
-
- org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.current.pm.Resource resource2 =
- new org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev161014.current.pm.ResourceBuilder()
- .setDevice(new DeviceBuilder().setNodeId("node 1").build())
- .setResourceType(new ResourceTypeBuilder()
- .setExtension("123")
- .setType(ResourceTypeEnum.Device).build())
- .setResource(resource).build();
- CurrentPm currentPm = new CurrentPmBuilder()
+ void testGetPmFailWithNodeIdNull() throws InterruptedException, ExecutionException {
+ GetPmInput input = new GetPmInputBuilder()
.setGranularity(PmGranularity._15min)
- .setId("id")
- .setLayerRate(new LayerRateBuilder().build())
- .setMeasurements(measurementsList)
- .setResource(resource2)
- .setRetrievalTime(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715
- .DateAndTime("2018-11-01T12:00:31.456449+06:00")).build();
-
- Map<CurrentPmKey, CurrentPm> currentPmList = new HashMap<>();
- currentPmList.put(currentPm.key(),currentPm);
-
- Optional<CurrentPmlist> currentPmlistOptional = Optional.of(new CurrentPmlistBuilder()
- .setCurrentPm(currentPmList).build());
-
- org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.get.pm.output.Measurements
- measurements1 = new org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.get.pm
- .output.MeasurementsBuilder().setPmparameterName("name").setPmparameterValue("1234").build();
-
-
- List<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.get.pm.output
- .Measurements> measurementsList1 = new ArrayList<>();
- measurementsList1.add(measurements1);
-
- GetPmInput input = OlmPowerServiceRpcImplUtil.getGetPmInput();
- GetPmOutputBuilder pmOutputBuilder = new GetPmOutputBuilder().setNodeId(input.getNodeId())
- .setResourceType(input.getResourceType())
- .setResourceIdentifier(input.getResourceIdentifier())
- .setGranularity(input.getGranularity())
- .setMeasurements(measurementsList1);
-
-
+ .setResourceIdentifier(new ResourceIdentifierBuilder()
+ .setResourceName("ots-deg1").build())
+ .setResourceType(ResourceTypeEnum.Interface)
+ .build();
ListenableFuture<RpcResult<GetPmOutput>> output = this.olmPowerServiceRpc.getPm(input);
- //TODO
-// assertEquals(new GetPmOutputBuilder().build(), output.get().getResult());
-// assertEquals(null, output.get().getResult().getResourceId());
+ assertFalse(output.get().isSuccessful());
+ assertNull(output.get().getResult());
+ assertEquals(ErrorType.RPC, output.get().getErrors().get(0).getErrorType());
+ assertEquals("Error with input parameters", output.get().getErrors().get(0).getMessage());
+ assertEquals(ErrorSeverity.ERROR, output.get().getErrors().get(0).getSeverity());
+ assertEquals(ErrorTag.OPERATION_FAILED, output.get().getErrors().get(0).getTag());
}
-// @Test
-// public void testGetPm2() throws ExecutionException, InterruptedException {
-// this.olmPowerService = Mockito.spy(this.olmPowerService);
-// GetPmInput input = new GetPmInputBuilder().setGranularity(PmGranularity._15min).setNodeId("node1")
-// .setResourceIdentifier(new ResourceIdentifierBuilder().setCircuitPackName("circuit pack name")
-// .setResourceName("resource name").build()).setResourceType(ResourceTypeEnum.Device).build();
-// org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.get.pm.output.Measurements
-// measurements1 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.get.pm
-// .output.MeasurementsBuilder().setPmparameterName("name").setPmparameterValue("1234").build();
-//
-//
-// List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.get.pm.output
-// .Measurements> measurementsList1 = new ArrayList<>();
-// measurementsList1.add(measurements1);
-//
-// GetPmOutputBuilder pmOutputBuilder = new GetPmOutputBuilder().setNodeId(input.getNodeId())
-// .setResourceType(input.getResourceType())
-// .setResourceIdentifier(input.getResourceIdentifier())
-// .setGranularity(input.getGranularity())
-// .setMeasurements(measurementsList1);
-//
-// Mockito.doReturn(pmOutputBuilder.build()).when(this.olmPowerService).getPm(Mockito.any());
-// ListenableFuture<RpcResult<GetPmOutput>> output = this.olmPowerServiceRpc.getPm(input);
-// assertEquals(pmOutputBuilder.build(), output.get().getResult());
-// assertEquals(true, output.get().isSuccessful());
-// }
-
@Test
- public void testGetPm3() throws ExecutionException, InterruptedException {
- GetPmInput input = OlmPowerServiceRpcImplUtil.getGetPmInput();
+ void testGetPmWithSuccess() throws InterruptedException, ExecutionException {
+ GetPmInput input = new GetPmInputBuilder()
+ .setNodeId("nodeId")
+ .build();
+ when(this.olmPowerService.getPm(any())).thenReturn(new GetPmOutputBuilder().build());
ListenableFuture<RpcResult<GetPmOutput>> output = this.olmPowerServiceRpc.getPm(input);
- //TODO
-// assertEquals(new GetPmOutputBuilder().build(), output.get().getResult());
-// assertEquals(null, output.get().getResult().getResourceId());
-// assertEquals(null, output.get().getResult().getMeasurements());
-// assertEquals(null, output.get().getResult().getGranularity());
-// assertEquals(null, output.get().getResult().getNodeId());
-// assertEquals(null, output.get().getResult().getResourceIdentifier());
-// assertEquals(null, output.get().getResult().getResourceType());
+ assertTrue(output.get().isSuccessful());
+ assertEquals(new GetPmOutputBuilder().build(), output.get().getResult());
}
@Test
- public void testServicePowerSetup1() throws ExecutionException, InterruptedException {
+ void testServicePowerSetup() throws InterruptedException, ExecutionException {
ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
- //TODO
- Mockito.when(this.olmPowerServiceRpc.servicePowerSetup(Mockito.any()))
- .thenReturn(RpcResultBuilder.success(new ServicePowerSetupOutputBuilder()
- .setResult("Success").build()).buildFuture());
+ when(this.olmPowerService.servicePowerSetup(any())).thenReturn(new ServicePowerSetupOutputBuilder().build());
ListenableFuture<RpcResult<ServicePowerSetupOutput>> output = this.olmPowerServiceRpc.servicePowerSetup(input);
- assertEquals(new ServicePowerSetupOutputBuilder().setResult("Success").build(), output.get()
- .getResult());
- assertEquals("Success", output.get().getResult().getResult());
- assertEquals(true, output.get().isSuccessful());
+ assertTrue(output.get().isSuccessful());
+ assertEquals(new ServicePowerSetupOutputBuilder().build(), output.get().getResult());
}
-
@Test
- public void testServicePowerTurndown1() throws ExecutionException, InterruptedException {
+ void testServicePowerTurndown() throws InterruptedException, ExecutionException {
ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
- //TODO
- Mockito.when(this.olmPowerServiceRpc.servicePowerTurndown(Mockito.any()))
- .thenReturn(RpcResultBuilder.success(new ServicePowerTurndownOutputBuilder()
- .setResult("Success").build()).buildFuture());
- ListenableFuture<RpcResult<ServicePowerTurndownOutput>> output = this.olmPowerServiceRpc
- .servicePowerTurndown(input);
- assertEquals(new ServicePowerTurndownOutputBuilder().setResult("Success").build(), output.get()
- .getResult());
- assertEquals("Success", output.get().getResult().getResult());
- assertEquals(true, output.get().isSuccessful());
+ when(this.olmPowerService.servicePowerTurndown(any()))
+ .thenReturn(new ServicePowerTurndownOutputBuilder().build());
+ var output = this.olmPowerServiceRpc.servicePowerTurndown(input);
+ assertTrue(output.get().isSuccessful());
+ assertEquals(new ServicePowerTurndownOutputBuilder().build(), output.get().getResult());
}
- /*
@Test
- public void testCalculateSpanlossBase1() throws ExecutionException, InterruptedException {
- CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInput();
- //TODO
- Mockito.when(this.olmPowerServiceRpc.calculateSpanlossBase(Mockito.any()))
- .thenReturn(RpcResultBuilder.success(new CalculateSpanlossBaseOutputBuilder()
- .setResult("Failed").build()).buildFuture());
- ListenableFuture<RpcResult<CalculateSpanlossBaseOutput>> output = this.olmPowerServiceRpc
- .calculateSpanlossBase(input);
- assertEquals(new CalculateSpanlossBaseOutputBuilder().setResult("Failed").build(),
- output.get().getResult());
- assertEquals("Failed", output.get().getResult().getResult());
- assertEquals(true, output.get().isSuccessful());
- }*/
+ void testCalculateSpanlossBase() throws InterruptedException, ExecutionException {
+ CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInputAll();
+ when(this.olmPowerService.calculateSpanlossBase(any()))
+ .thenReturn(new CalculateSpanlossBaseOutputBuilder().build());
+ var output = this.olmPowerServiceRpc.calculateSpanlossBase(input);
+ assertTrue(output.get().isSuccessful());
+ assertEquals(new CalculateSpanlossBaseOutputBuilder().build(), output.get().getResult());
+ }
- //TODO
-/** @Test
- public void testCalculateSpanlossCurrent1() throws ExecutionException, InterruptedException {
- CalculateSpanlossCurrentInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossCurrentInput();
- //TODO
- Mockito.when(this.olmPowerServiceRpc.calculateSpanlossCurrent(Mockito.any()))
- .thenReturn(RpcResultBuilder.success(new CalculateSpanlossCurrentOutputBuilder()
- .setResult("success").build()).buildFuture());
- ListenableFuture<RpcResult<CalculateSpanlossCurrentOutput>> output = this.olmPowerServiceRpc
- .calculateSpanlossCurrent(input);
- assertEquals(null, output.get().getResult());
- assertEquals(true, output.get().isSuccessful());
+ @Test
+ void testCalculateSpanlossCurrent() throws InterruptedException, ExecutionException {
+ CalculateSpanlossCurrentInput input = new CalculateSpanlossCurrentInputBuilder().build();
+ when(this.olmPowerService.calculateSpanlossCurrent(any()))
+ .thenReturn(new CalculateSpanlossCurrentOutputBuilder().build());
+ var output = this.olmPowerServiceRpc.calculateSpanlossCurrent(input);
+ assertTrue(output.get().isSuccessful());
+ assertEquals(new CalculateSpanlossCurrentOutputBuilder().build(), output.get().getResult());
}
@Test
- public void testServicePowerResetInput() throws ExecutionException, InterruptedException {
+ void testServicePowerReset() throws InterruptedException, ExecutionException {
ServicePowerResetInput input = OlmPowerServiceRpcImplUtil.getServicePowerResetInput();
- //TODO
- Mockito.when(this.olmPowerServiceRpc.calculateSpanlossCurrent(Mockito.any()))
- .thenReturn(RpcResultBuilder.success(new CalculateSpanlossCurrentOutputBuilder()
- .setResult(null).build()).buildFuture());
- ListenableFuture<RpcResult<ServicePowerResetOutput>> output = this.olmPowerServiceRpc
- .servicePowerReset(input);
- assertEquals(null, output.get().getResult());
- assertEquals(true, output.get().isSuccessful());
+ when(this.olmPowerService.servicePowerReset(any()))
+ .thenReturn(new ServicePowerResetOutputBuilder().build());
+ var output = this.olmPowerServiceRpc.servicePowerReset(input);
+ assertTrue(output.get().isSuccessful());
+ assertEquals(new ServicePowerResetOutputBuilder().build(), output.get().getResult());
}
-**/
}
+++ /dev/null
-/*
- * Copyright © 2019 Orange, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.transportpce.olm.power;
-
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Disabled;
-import org.junit.jupiter.api.Test;
-import org.mockito.ArgumentMatchers;
-import org.mockito.Mockito;
-import org.opendaylight.mdsal.binding.api.MountPoint;
-import org.opendaylight.mdsal.binding.api.MountPointService;
-import org.opendaylight.transportpce.common.StringConstants;
-import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
-import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl;
-import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl121;
-import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl221;
-import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl710;
-import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
-import org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl;
-import org.opendaylight.transportpce.common.mapping.MappingUtils;
-import org.opendaylight.transportpce.common.mapping.MappingUtilsImpl;
-import org.opendaylight.transportpce.common.mapping.PortMapping;
-import org.opendaylight.transportpce.common.mapping.PortMappingImpl;
-import org.opendaylight.transportpce.common.mapping.PortMappingVersion121;
-import org.opendaylight.transportpce.common.mapping.PortMappingVersion221;
-import org.opendaylight.transportpce.common.mapping.PortMappingVersion710;
-import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
-import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
-import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
-import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl121;
-import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl221;
-import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl710;
-import org.opendaylight.transportpce.olm.stub.MountPointServiceStub;
-import org.opendaylight.transportpce.olm.stub.MountPointStub;
-import org.opendaylight.transportpce.olm.util.OlmPowerServiceRpcImplUtil;
-import org.opendaylight.transportpce.olm.util.OlmUtils;
-import org.opendaylight.transportpce.test.AbstractTest;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupInput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.OpenroadmNodeVersion;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.mapping.Mapping;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.mapping.MappingBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.mapping.MappingKey;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.network.Nodes;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.network.NodesBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.network.nodes.NodeInfoBuilder;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.OpticalControlMode;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.RatioDB;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.InterfaceBuilder;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.NodeTypes;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfaces.rev161014.Interface1Builder;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfaces.rev161014.ots.container.Ots;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfaces.rev161014.ots.container.OtsBuilder;
-import org.opendaylight.yangtools.yang.common.Decimal64;
-
-@Disabled
-public class PowerMgmtPowerMockTest extends AbstractTest {
-
- private MountPoint mountPoint;
- private MountPointService mountPointService;
- private DeviceTransactionManager deviceTransactionManager;
- private CrossConnect crossConnect;
- private OpenRoadmInterfaces openRoadmInterfaces;
- private PortMapping portMapping;
- private PowerMgmt powerMgmt;
- private CrossConnectImpl121 crossConnectImpl121;
- private CrossConnectImpl221 crossConnectImpl22;
- private CrossConnectImpl710 crossConnectImpl710;
- private MappingUtils mappingUtils;
- private OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121;
- private OpenRoadmInterfacesImpl221 openRoadmInterfacesImpl22;
- private OpenRoadmInterfacesImpl710 openRoadmInterfacesImpl710;
- private PortMappingVersion710 portMappingVersion710;
- private PortMappingVersion221 portMappingVersion22;
- private PortMappingVersion121 portMappingVersion121;
-
- @BeforeEach
- void setUp() {
- this.mountPoint = new MountPointStub(getDataBroker());
- this.mountPointService = new MountPointServiceStub(mountPoint);
- this.mappingUtils = new MappingUtilsImpl(getDataBroker());
- this.mappingUtils = Mockito.spy(new MappingUtilsImpl(getDataBroker()));
- Mockito.doReturn(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1).when(mappingUtils)
- .getOpenRoadmVersion(Mockito.anyString());
- this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
- this.crossConnectImpl121 = new CrossConnectImpl121(deviceTransactionManager);
- this.crossConnectImpl22 = new CrossConnectImpl221(deviceTransactionManager);
- this.crossConnect = new CrossConnectImpl(deviceTransactionManager, this.mappingUtils, this.crossConnectImpl121,
- this.crossConnectImpl22, this.crossConnectImpl710);
- this.portMappingVersion22 = new PortMappingVersion221(getDataBroker(), deviceTransactionManager);
- this.portMappingVersion121 = new PortMappingVersion121(getDataBroker(), deviceTransactionManager);
- this.portMappingVersion710 = new PortMappingVersion710(getDataBroker(), deviceTransactionManager);
- this.portMapping = new PortMappingImpl(getDataBroker(), this.portMappingVersion710,
- this.portMappingVersion22, this.portMappingVersion121);
- this.openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(deviceTransactionManager);
- this.openRoadmInterfacesImpl22 = new OpenRoadmInterfacesImpl221(deviceTransactionManager, this.portMapping);
- this.openRoadmInterfacesImpl710 = new OpenRoadmInterfacesImpl710(deviceTransactionManager, this.portMapping);
- this.openRoadmInterfaces = new OpenRoadmInterfacesImpl((this.deviceTransactionManager),
- this.mappingUtils,this.openRoadmInterfacesImpl121,this.openRoadmInterfacesImpl22,
- this.openRoadmInterfacesImpl710);
- this.openRoadmInterfaces = Mockito.spy(this.openRoadmInterfaces);
- this.portMapping = Mockito.spy(this.portMapping);
- this.powerMgmt = new PowerMgmtImpl(this.openRoadmInterfaces, this.crossConnect,
- this.deviceTransactionManager, this.portMapping, 1000, 1000);
- }
-
- @Test
- void testSetPowerMockingUtil() {
- Mockito.mockStatic(OlmUtils.class);
- Mockito.when(this.portMapping.getNode(Mockito.anyString()))
- .thenReturn(getXpdrNodesFromNodesBuilderDeg());
- ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
- boolean output = this.powerMgmt.setPower(input);
- assertEquals(false, output);
-
- }
-
- @Test
- void testSetPowerMockingUtilNetwokType() throws OpenRoadmInterfaceException {
- Mockito.mockStatic(OlmUtils.class);
- Mockito.mockStatic(PowerMgmtVersion121.class);
- Mockito.when(this.portMapping.getNode(Mockito.anyString()))
- .thenReturn(getXpdrNodesFromNodesBuilderNetwork());
- Map<String, Double> txPowerRangeMap = new HashMap<>();
- Mockito.when(PowerMgmtVersion121.getXponderPowerRange(
- Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
- ArgumentMatchers.eq(deviceTransactionManager)))
- .thenReturn(txPowerRangeMap);
- ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
- OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121Spy = Mockito.mock(OpenRoadmInterfacesImpl121.class);
- Mockito.when(openRoadmInterfacesImpl121Spy.getInterface(Mockito.anyString(), Mockito.anyString()))
- .thenReturn(Optional.empty());
- PowerMgmtImpl powerMgmtImpl = getNewPowerMgmt(openRoadmInterfacesImpl121Spy,this.crossConnect);
- boolean output = powerMgmtImpl.setPower(input);
- assertEquals(true, output);
-
- }
-
- @Test
- void testSetPowerMockingUtilNetwokTypeMoreThanOneNode() throws OpenRoadmInterfaceException {
- Mockito.mockStatic(OlmUtils.class);
- Mockito.mockStatic(PowerMgmtVersion121.class);
- Mockito.when(this.portMapping.getNode(Mockito.anyString()))
- .thenReturn(getXpdrNodesFromNodesBuilderNetwork());
- Map<String, Double> txPowerRangeMap = new HashMap<>();
- Mockito.when(PowerMgmtVersion121
- .getXponderPowerRange(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
- ArgumentMatchers.eq(deviceTransactionManager)))
- .thenReturn(txPowerRangeMap);
- ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
- OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121Spy = Mockito.mock(OpenRoadmInterfacesImpl121.class);
- Mockito.when(openRoadmInterfacesImpl121Spy.getInterface(Mockito.anyString(), Mockito.anyString()))
- .thenReturn(Optional.empty());
- PowerMgmtImpl powerMgmtImpl = getNewPowerMgmt(openRoadmInterfacesImpl121Spy,this.crossConnect);
- boolean output = powerMgmtImpl.setPower(input);
- assertEquals(true, output);
-
- }
-
- @Test
- void testSetPowerXpdrNodes() {
- Mockito.mockStatic(OlmUtils.class);
- Mockito.when(this.portMapping.getNode(Mockito.anyString()))
- .thenReturn(getXpdrNodesFromNodesBuilderDeg());
- ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
- boolean output = this.powerMgmt.setPower(input);
- assertEquals(true, output);
-
- }
-
- @Test
- void testSetPowerRdmNodesReturnInterfaceEmpty() throws OpenRoadmInterfaceException {
- Mockito.mockStatic(OlmUtils.class);
- Mockito.when(this.portMapping.getNode(Mockito.anyString()))
- .thenReturn(getRdmNodesFromNodesBuilder());
- ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
- OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121Spy = Mockito.mock(OpenRoadmInterfacesImpl121.class);
- Mockito.when(openRoadmInterfacesImpl121Spy.getInterface(Mockito.anyString(), Mockito.anyString()))
- .thenReturn(Optional.empty());
- PowerMgmtImpl powerMgmtImpl = getNewPowerMgmt(openRoadmInterfacesImpl121Spy,this.crossConnect);
- boolean output = powerMgmtImpl.setPower(input);
- assertEquals(false, output);
- }
-
- @Test
- void testSetPowerRdmNodesThrowsException() throws OpenRoadmInterfaceException {
- Mockito.mockStatic(OlmUtils.class);
- Mockito.when(this.portMapping.getNode(Mockito.anyString()))
- .thenReturn(getRdmNodesFromNodesBuilder());
- ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
- OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121Spy = Mockito.mock(OpenRoadmInterfacesImpl121.class);
- Mockito.when(openRoadmInterfacesImpl121Spy.getInterface(Mockito.anyString(), Mockito.anyString()))
- .thenThrow(new OpenRoadmInterfaceException("error thrown by unit tests "));
- PowerMgmtImpl powerMgmtImpl = getNewPowerMgmt(openRoadmInterfacesImpl121Spy,this.crossConnect);
- boolean output = powerMgmtImpl.setPower(input);
- assertEquals(false, output);
- }
-
- @Test
- void testSetPowerRdmNodesReturnInterface() throws OpenRoadmInterfaceException {
- Mockito.mockStatic(OlmUtils.class);
- Mockito.when(this.portMapping.getNode(Mockito.anyString()))
- .thenReturn(getRdmNodesFromNodesBuilder());
- ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
- OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121Spy = Mockito.mock(OpenRoadmInterfacesImpl121.class);
-
- Ots ots = new OtsBuilder().setSpanLossTransmit(new RatioDB(Decimal64.valueOf("23"))).build();
- Interface1Builder intf1Builder = new Interface1Builder();
- Mockito.when(openRoadmInterfacesImpl121Spy.getInterface(Mockito.anyString(), Mockito.anyString())).thenReturn(
- Optional.of(new InterfaceBuilder().addAugmentation(intf1Builder.setOts(ots).build())
- .build()));
- CrossConnect crossConnectMock = Mockito.mock(CrossConnectImpl.class);
- Mockito.when(crossConnectMock
- .setPowerLevel(Mockito.anyString(), OpticalControlMode.Power.getName(), Mockito.any(),
- Mockito.anyString())).thenReturn(true);
- PowerMgmtImpl powerMgmtImpl = getNewPowerMgmt(openRoadmInterfacesImpl121Spy,crossConnectMock);
- boolean output = powerMgmtImpl.setPower(input);
- assertEquals(true, output);
- }
-
- private PowerMgmtImpl getNewPowerMgmt(OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121Spy,
- CrossConnect crossConnectMock) {
- OpenRoadmInterfacesImpl openRoadmInterfacesSpy = new OpenRoadmInterfacesImpl((this.deviceTransactionManager),
- this.mappingUtils, openRoadmInterfacesImpl121Spy, this.openRoadmInterfacesImpl22,
- this.openRoadmInterfacesImpl710);
- openRoadmInterfacesSpy = Mockito.spy(openRoadmInterfacesSpy);
- return new PowerMgmtImpl(openRoadmInterfacesSpy, crossConnectMock,
- this.deviceTransactionManager, this.portMapping, 0, 0);
- }
-
- private Nodes getXpdrNodesFromNodesBuilderDeg() {
- MappingBuilder mappingBuilder = getMappingBuilderDeg();
- Mapping mapping = mappingBuilder.build();
- return new NodesBuilder().setNodeId("node 1")
- .setNodeInfo(new NodeInfoBuilder().setNodeType(NodeTypes.Xpdr).build())
- .setMapping(Map.of(mapping.key(),mapping))
- .build();
- }
-
- private Nodes getXpdrNodesFromNodesBuilderNetwork() {
- MappingBuilder mappingBuilder = getMappingBuilderNetWork();
- Mapping mapping = mappingBuilder.build();
- return new NodesBuilder().setNodeId("node 1")
- .setNodeInfo(new NodeInfoBuilder().setNodeType(NodeTypes.Xpdr)
- .setOpenroadmVersion(OpenroadmNodeVersion._121)
- .build())
- .setMapping(Map.of(mapping.key(),mapping))
- .build();
- }
-
- private Nodes getRdmNodesFromNodesBuilder() {
- MappingBuilder mappingBuilder = getMappingBuilderDeg();
- Mapping mapping = mappingBuilder.build();
- return new NodesBuilder().setNodeId("node 1").setNodeInfo(
- new NodeInfoBuilder().setNodeType(NodeTypes.Rdm)
- .setOpenroadmVersion(OpenroadmNodeVersion._121)
- .build())
- .setMapping(Map.of(mapping.key(),mapping))
- .build();
- }
-
- private MappingBuilder getMappingBuilderDeg() {
- return new MappingBuilder()
- .withKey(new MappingKey("deg"))
- .setLogicalConnectionPoint("logicalConnPoint")
- .setSupportingOts("OTS")
- .setSupportingCircuitPackName("2/0")
- .setSupportingOms("OMS")
- .setSupportingPort("8080")
- .setSupportingCircuitPackName("circuit1");
- }
-
- private MappingBuilder getMappingBuilderNetWork() {
- return new MappingBuilder()
- .withKey(new MappingKey("network"))
- .setLogicalConnectionPoint("logicalConnPoint")
- .setSupportingOts("OTS")
- .setSupportingCircuitPackName("2/0")
- .setSupportingOms("OMS")
- .setSupportingPort("8080")
- .setSupportingCircuitPackName("circuit1");
- }
-}
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
+import static org.mockito.Mockito.when;
import java.math.BigDecimal;
import java.util.HashMap;
import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfaces.rev161014.ots.container.OtsBuilder;
import org.opendaylight.yangtools.yang.common.Decimal64;
-public class PowerMgmtTest {
+class PowerMgmtTest {
private OpenRoadmInterfaces openRoadmInterfaces;
private CrossConnect crossConnect;
private DeviceTransactionManager deviceTransactionManager;
@BeforeEach
void setUp() {
- Mockito.mock(DataBroker.class);
+ mock(DataBroker.class);
this.openRoadmInterfaces = Mockito.mock(OpenRoadmInterfaces.class);
this.crossConnect = Mockito.mock((CrossConnectImpl.class));
this.deviceTransactionManager = Mockito.mock(DeviceTransactionManager.class);
@Test
void testSetPowerWhenMappingReturnNull() {
- Mockito.when(this.portMapping.getNode(Mockito.anyString())).thenReturn(null);
+ when(this.portMapping.getNode(Mockito.anyString())).thenReturn(null);
boolean output = this.powerMgmt.setPower(OlmPowerServiceRpcImplUtil.getServicePowerSetupInput());
assertEquals(false, output);
}
@Test
void testSetPowerForTransponderAEnd() throws OpenRoadmInterfaceException {
- Mockito.when(this.portMapping.getNode("xpdr-A"))
+ when(this.portMapping.getNode("xpdr-A"))
.thenReturn(OlmPowerServiceRpcImplUtil.getMappingNodeTpdr("xpdr-A", OpenroadmNodeVersion._121,
List.of("network-A")));
- Mockito.when(this.portMapping.getNode("roadm-A"))
+ when(this.portMapping.getNode("roadm-A"))
.thenReturn(OlmPowerServiceRpcImplUtil.getMappingNodeRdm("roadm-A", OpenroadmNodeVersion._121,
List.of("srg1-A", "deg2-A")));
Interface interfOch = new InterfaceBuilder()
.setOch(new OchBuilder().build())
.build())
.build();
- Mockito.when(this.openRoadmInterfaces.getInterface(Mockito.matches("xpdr-A"), Mockito.anyString()))
+ when(this.openRoadmInterfaces.getInterface(Mockito.matches("xpdr-A"), Mockito.anyString()))
.thenReturn(Optional.of(interfOch));
Interface interfOts = new InterfaceBuilder()
.setName("interface name")
.build())
.build())
.build();
- Mockito.when(this.openRoadmInterfaces
- .getInterface(Mockito.matches("roadm-A"), Mockito.anyString()))
- .thenReturn(Optional.of(interfOts));
+ when(this.openRoadmInterfaces.getInterface(Mockito.matches("roadm-A"), Mockito.anyString()))
+ .thenReturn(Optional.of(interfOts));
MockedStatic<PowerMgmtVersion121> pmv121 = Mockito.mockStatic(PowerMgmtVersion121.class);
pmv121.when(() -> PowerMgmtVersion121.setTransponderPower(Mockito.anyString(), Mockito.anyString(),
Mockito.any(), Mockito.any(), Mockito.any()))
pmv121.when(() -> PowerMgmtVersion121.getXponderPowerRange(Mockito.anyString(), Mockito.anyString(),
Mockito.anyString(), Mockito.any()))
.thenReturn(powerRangeMap);
- Mockito.when(this.crossConnect.setPowerLevel(Mockito.anyString(), Mockito.anyString(), Mockito.any(),
- Mockito.anyString()))
- .thenReturn(true);
+ when(this.crossConnect
+ .setPowerLevel(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.anyString()))
+ .thenReturn(true);
ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInputForTransponder();
boolean result = this.powerMgmt.setPower(input);
@Test
void testSetPowerForTransponderZEnd() throws OpenRoadmInterfaceException {
- Mockito.when(this.portMapping.getNode("xpdr-C"))
- .thenReturn(OlmPowerServiceRpcImplUtil.getMappingNodeTpdr("xpdr-C", OpenroadmNodeVersion._121,
- List.of("client-C")));
+ when(this.portMapping.getNode("xpdr-C"))
+ .thenReturn(OlmPowerServiceRpcImplUtil
+ .getMappingNodeTpdr("xpdr-C", OpenroadmNodeVersion._121, List.of("client-C")));
ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil
.getServicePowerSetupInputForOneNode("xpdr-C", "network-C", "client-C");
@Test
void testSetPowerForRoadmAEnd() throws OpenRoadmInterfaceException {
- Mockito.when(this.portMapping.getNode("roadm-A"))
- .thenReturn(OlmPowerServiceRpcImplUtil.getMappingNodeRdm("roadm-A", OpenroadmNodeVersion._121,
+ when(this.portMapping.getNode("roadm-A"))
+ .thenReturn(OlmPowerServiceRpcImplUtil.getMappingNodeRdm("roadm-A", OpenroadmNodeVersion._121,
List.of("srg1-A", "deg2-A")));
- Mockito.when(this.deviceTransactionManager.getDataFromDevice(Mockito.anyString(), Mockito.any(),
- Mockito.any(), Mockito.anyLong(), Mockito.any()))
- .thenReturn(Optional.empty());
+ when(this.deviceTransactionManager
+ .getDataFromDevice(Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.anyLong(), Mockito.any()))
+ .thenReturn(Optional.empty());
Interface interfOts = new InterfaceBuilder()
.setName("interface name")
.addAugmentation(
.build())
.build())
.build();
- Mockito.when(this.openRoadmInterfaces.getInterface(Mockito.anyString(), Mockito.anyString()))
- .thenReturn(Optional.of(interfOts));
- Mockito.when(this.crossConnect.setPowerLevel(Mockito.anyString(), Mockito.anyString(), Mockito.any(),
- Mockito.anyString()))
- .thenReturn(true);
+ when(this.openRoadmInterfaces.getInterface(Mockito.anyString(), Mockito.anyString()))
+ .thenReturn(Optional.of(interfOts));
+ when(this.crossConnect
+ .setPowerLevel(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.anyString()))
+ .thenReturn(true);
ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil
.getServicePowerSetupInputForOneNode("roadm-A", "srg1-A", "deg2-A");
@Test
void testSetPowerForRoadmZEnd() throws OpenRoadmInterfaceException {
- Mockito.when(this.portMapping.getNode("roadm-C"))
- .thenReturn(OlmPowerServiceRpcImplUtil.getMappingNodeRdm("roadm-C", OpenroadmNodeVersion._121,
- List.of("deg1-C", "srg1-C")));
- Mockito.when(this.deviceTransactionManager.getDataFromDevice(Mockito.anyString(), Mockito.any(),
- Mockito.any(), Mockito.anyLong(), Mockito.any()))
- .thenReturn(Optional.empty());
- Mockito.when(this.crossConnect.setPowerLevel(Mockito.anyString(), Mockito.anyString(), Mockito.any(),
- Mockito.anyString()))
- .thenReturn(true);
+ when(this.portMapping.getNode("roadm-C"))
+ .thenReturn(OlmPowerServiceRpcImplUtil.getMappingNodeRdm("roadm-C", OpenroadmNodeVersion._121,
+ List.of("deg1-C", "srg1-C")));
+ when(this.deviceTransactionManager
+ .getDataFromDevice(Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.anyLong(), Mockito.any()))
+ .thenReturn(Optional.empty());
+ when(this.crossConnect
+ .setPowerLevel(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.anyString()))
+ .thenReturn(true);
ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil
.getServicePowerSetupInputForOneNode("roadm-C", "deg1-C", "srg1-C");
@Test
void testSetPowerForTransponderWhenNoTransponderPort() throws OpenRoadmInterfaceException {
- Mockito.when(this.portMapping.getNode("xpdr-A"))
- .thenReturn(OlmPowerServiceRpcImplUtil.getMappingNodeTpdr("xpdr-A", OpenroadmNodeVersion._121,
- List.of("network-A")));
- Mockito.when(this.portMapping.getNode("roadm-A"))
- .thenReturn(OlmPowerServiceRpcImplUtil.getMappingNodeRdm("roadm-A", OpenroadmNodeVersion._121,
- List.of("srg1-A", "deg2-A")));
+ when(this.portMapping.getNode("xpdr-A"))
+ .thenReturn(OlmPowerServiceRpcImplUtil.getMappingNodeTpdr("xpdr-A", OpenroadmNodeVersion._121,
+ List.of("network-A")));
+ when(this.portMapping.getNode("roadm-A"))
+ .thenReturn(OlmPowerServiceRpcImplUtil.getMappingNodeRdm("roadm-A", OpenroadmNodeVersion._121,
+ List.of("srg1-A", "deg2-A")));
Interface interfOch = new InterfaceBuilder()
.setName("interface name")
.addAugmentation(new Interface1Builder()
.setOch(new OchBuilder().build())
.build())
.build();
- Mockito.when(this.openRoadmInterfaces.getInterface(Mockito.matches("xpdr-A"), Mockito.anyString()))
- .thenReturn(Optional.of(interfOch));
+ when(this.openRoadmInterfaces.getInterface(Mockito.matches("xpdr-A"), Mockito.anyString()))
+ .thenReturn(Optional.of(interfOch));
Interface interfOts = new InterfaceBuilder()
.setName("interface name")
.addAugmentation(
.build())
.build())
.build();
- Mockito.when(this.openRoadmInterfaces
- .getInterface(Mockito.matches("roadm-A"), Mockito.anyString()))
- .thenReturn(Optional.of(interfOts));
+ when(this.openRoadmInterfaces.getInterface(Mockito.matches("roadm-A"), Mockito.anyString()))
+ .thenReturn(Optional.of(interfOts));
try (MockedStatic<PowerMgmtVersion121> pmv121 = Mockito.mockStatic(PowerMgmtVersion121.class)) {
pmv121.when(() -> PowerMgmtVersion121.setTransponderPower(Mockito.anyString(), Mockito.anyString(),
Mockito.any(), Mockito.any(), Mockito.any()))
Mockito.anyString(), Mockito.any()))
.thenReturn(new HashMap<>());
- Mockito.when(this.crossConnect.setPowerLevel(Mockito.anyString(), Mockito.anyString(), Mockito.any(),
- Mockito.anyString()))
- .thenReturn(true);
+ when(this.crossConnect
+ .setPowerLevel(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.anyString()))
+ .thenReturn(true);
ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInputForTransponder();
@Test
void testSetPowerForTransponderAEndWithRoadmPort() throws OpenRoadmInterfaceException {
- Mockito.when(this.portMapping.getNode("xpdr-A"))
- .thenReturn(OlmPowerServiceRpcImplUtil.getMappingNodeTpdr("xpdr-A", OpenroadmNodeVersion._121,
- List.of("network-A")));
- Mockito.when(this.portMapping.getNode("roadm-A"))
- .thenReturn(OlmPowerServiceRpcImplUtil.getMappingNodeRdm("roadm-A", OpenroadmNodeVersion._121,
- List.of("srg1-A", "deg2-A")));
+ when(this.portMapping.getNode("xpdr-A"))
+ .thenReturn(OlmPowerServiceRpcImplUtil.getMappingNodeTpdr("xpdr-A", OpenroadmNodeVersion._121,
+ List.of("network-A")));
+ when(this.portMapping.getNode("roadm-A"))
+ .thenReturn(OlmPowerServiceRpcImplUtil.getMappingNodeRdm("roadm-A", OpenroadmNodeVersion._121,
+ List.of("srg1-A", "deg2-A")));
Interface interfOch = new InterfaceBuilder()
.setName("interface name")
.addAugmentation(new Interface1Builder()
.setOch(new OchBuilder().build())
.build())
.build();
- Mockito.when(this.openRoadmInterfaces.getInterface(Mockito.matches("xpdr-A"), Mockito.anyString()))
- .thenReturn(Optional.of(interfOch));
+ when(this.openRoadmInterfaces.getInterface(Mockito.matches("xpdr-A"), Mockito.anyString()))
+ .thenReturn(Optional.of(interfOch));
Interface interfOts = new InterfaceBuilder()
.setName("interface name")
.addAugmentation(
.build())
.build())
.build();
- Mockito.when(this.openRoadmInterfaces
- .getInterface(Mockito.matches("roadm-A"), Mockito.anyString()))
- .thenReturn(Optional.of(interfOts));
+ when(this.openRoadmInterfaces.getInterface(Mockito.matches("roadm-A"), Mockito.anyString()))
+ .thenReturn(Optional.of(interfOts));
try (MockedStatic<PowerMgmtVersion121> pmv121 = Mockito.mockStatic(PowerMgmtVersion121.class)) {
pmv121.when(() -> PowerMgmtVersion121.setTransponderPower(Mockito.anyString(), Mockito.anyString(),
pmv121.when(() -> PowerMgmtVersion121.getSRGRxPowerRange(Mockito.anyString(), Mockito.anyString(),
Mockito.any(), Mockito.anyString(), Mockito.anyString()))
.thenReturn(powerRangeMapSrgRx);
- Mockito.when(this.crossConnect.setPowerLevel(Mockito.anyString(), Mockito.anyString(), Mockito.any(),
- Mockito.anyString()))
- .thenReturn(true);
+ when(this.crossConnect
+ .setPowerLevel(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.anyString()))
+ .thenReturn(true);
ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInputForTransponder();
boolean result = this.powerMgmt.setPower(input);
@Test
void testSetPowerForBadNodeType() throws OpenRoadmInterfaceException {
- Mockito.when(this.portMapping.getNode("ila node"))
- .thenReturn(OlmPowerServiceRpcImplUtil.getMappingNodeIla());
+ when(this.portMapping.getNode("ila node")).thenReturn(OlmPowerServiceRpcImplUtil.getMappingNodeIla());
ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil
.getServicePowerSetupInputForOneNode("ila node", "rx-port", "tx-port");
@Test
void testPowerTurnDownWhenSuccess() {
- Mockito.when(this.crossConnect.setPowerLevel(Mockito.anyString(), Mockito.anyString(), Mockito.any(),
- Mockito.anyString()))
- .thenReturn(true);
+ when(this.crossConnect
+ .setPowerLevel(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.anyString()))
+ .thenReturn(true);
ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
boolean result = this.powerMgmt.powerTurnDown(input);
assertEquals(true, result);
@Test
void testPowerTurnDownWhenFailure() {
- Mockito.when(this.crossConnect.setPowerLevel(Mockito.anyString(), Mockito.anyString(), Mockito.any(),
- Mockito.anyString()))
- .thenReturn(false);
+ when(this.crossConnect
+ .setPowerLevel(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.anyString()))
+ .thenReturn(false);
ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
boolean result = this.powerMgmt.powerTurnDown(input);
assertEquals(false, result);
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class OlmPowerServiceImplSpanLossBaseTest extends AbstractTest {
+class OlmPowerServiceImplSpanLossBaseTest extends AbstractTest {
private static final Logger LOG = LoggerFactory.getLogger(OlmPowerServiceImplSpanLossBaseTest.class);
private DeviceTransactionManager deviceTransactionManager;
import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownOutputBuilder;
import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev161014.PmNamesEnum;
-public class OlmPowerServiceImplTest extends AbstractTest {
+class OlmPowerServiceImplTest extends AbstractTest {
private DeviceTransactionManager deviceTransactionManager;
private OpenRoadmInterfaces openRoadmInterfaces;
+++ /dev/null
-/*
- * Copyright © 2018 Orange Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.transportpce.olm.stub;
-
-import java.util.Optional;
-import org.opendaylight.mdsal.binding.api.MountPoint;
-import org.opendaylight.mdsal.binding.api.MountPointService;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
-public class MountPointServiceStub implements MountPointService {
-
- MountPoint returnedMountPoint;
-
- public MountPointServiceStub(MountPoint usedMountPoint) {
- this.returnedMountPoint = usedMountPoint;
- }
-
- @Override
- public Optional<MountPoint> getMountPoint(InstanceIdentifier<?> mountPoint) {
- if (returnedMountPoint == null) {
- return Optional.empty();
- }
- return Optional.of(returnedMountPoint);
- }
-
- @Override
- public <T extends MountPointListener> ListenerRegistration<T> registerListener(InstanceIdentifier<?> path,
- T listener) {
- return null;
- }
-}
+++ /dev/null
-/*
- * Copyright © 2018 Orange Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.transportpce.olm.stub;
-
-import java.util.Optional;
-import org.opendaylight.mdsal.binding.api.BindingService;
-import org.opendaylight.mdsal.binding.api.DataBroker;
-import org.opendaylight.mdsal.binding.api.MountPoint;
-import org.opendaylight.mdsal.binding.api.RpcConsumerRegistry;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
-public class MountPointStub implements MountPoint {
-
- private DataBroker dataBroker;
-
- private RpcConsumerRegistry rpcConsumerRegistry;
-
- public MountPointStub(DataBroker dataBroker) {
-
- this.dataBroker = dataBroker;
- }
-
- public void setRpcConsumerRegistry(RpcConsumerRegistry rpcConsumerRegistry) {
- this.rpcConsumerRegistry = rpcConsumerRegistry;
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public <T extends BindingService> Optional<T> getService(Class<T> service) {
- if (service.isInstance(dataBroker)) {
- return Optional.ofNullable((T)dataBroker);
- }
- if (service.isInstance(rpcConsumerRegistry)) {
- return Optional.ofNullable((T)rpcConsumerRegistry);
- }
- return Optional.empty();
- }
-
- @Override
- public InstanceIdentifier<?> getIdentifier() {
- return null;
- }
-}
+++ /dev/null
-/*
- * Copyright © 2018 Orange Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.transportpce.olm.stub;
-
-import com.google.common.util.concurrent.ListenableFuture;
-import java.util.ArrayList;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossBaseInput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossBaseOutput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossCurrentInput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossCurrentOutput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmInput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmOutput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmOutputBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerResetInput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerResetOutput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupInput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupOutput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupOutputBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownInput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownOutput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownOutputBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.TransportpceOlmService;
-import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
-
-public class OlmServiceStub implements TransportpceOlmService {
-
- @Override public ListenableFuture<RpcResult<CalculateSpanlossCurrentOutput>> calculateSpanlossCurrent(
- CalculateSpanlossCurrentInput input) {
- return null;
- }
-
- @Override public ListenableFuture<RpcResult<GetPmOutput>> getPm(GetPmInput input) {
- GetPmOutput output = new GetPmOutputBuilder()
- .setNodeId("node1").setMeasurements(new ArrayList<>()).build();
- return RpcResultBuilder.success(
- output).buildFuture();
- }
-
- @Override public ListenableFuture<RpcResult<ServicePowerTurndownOutput>> servicePowerTurndown(
- ServicePowerTurndownInput input) {
- return RpcResultBuilder.success((new ServicePowerTurndownOutputBuilder())
- .setResult("Success").build()).buildFuture();
- }
-
- @Override public ListenableFuture<RpcResult<CalculateSpanlossBaseOutput>> calculateSpanlossBase(
- CalculateSpanlossBaseInput input) {
- return null;
- }
-
- @Override public ListenableFuture<RpcResult<ServicePowerResetOutput>> servicePowerReset(
- ServicePowerResetInput input) {
- return null;
- }
-
- @Override public ListenableFuture<RpcResult<ServicePowerSetupOutput>> servicePowerSetup(
- ServicePowerSetupInput input) {
- return RpcResultBuilder.success(new ServicePowerSetupOutputBuilder().build()).buildFuture();
- }
-}
import org.junit.jupiter.api.Test;
-public class OtsPmHolderTest {
+class OtsPmHolderTest {
@Test
void test() {
return true;
}
-//
-// public static boolean writeTransaction(DataBroker dataBroker, LogicalDatastoreType logicalDatastoreType,
-// InstanceIdentifier instanceIdentifier,
-// DataObject object)
-
-// public static DataObject readTransaction(DeviceTransactionManager deviceTransactionManager,
-// String nodeId,
-// LogicalDatastoreType logicalDatastoreType,
-// InstanceIdentifier<? extends DataObject> instanceIdentifier)
-// throws ExecutionException, InterruptedException {
-// Future<Optional<DeviceTransaction>> deviceTxFuture =
-// deviceTransactionManager.getDeviceTransaction(nodeId);
-// if (!deviceTxFuture.get().isPresent()) {
-// return null;
-// }
-// DeviceTransaction deviceTx = deviceTxFuture.get().get();
-// com.google.common.base.Optional<? extends DataObject> readOpt
-// = deviceTx.read(logicalDatastoreType, instanceIdentifier).get();
-// if (!readOpt.isPresent()) {
-// return null;
-// }
-// return readOpt.get();
-// }
-
public static Network1 getNullNetwork() {
Map<LinkKey, Link> nullMap = null;
Network1 network = new Network1Builder().setLink(nullMap).build();