Merge changes Ib0dab687,Ia7e45116,I6839ad8b
[transportpce.git] / renderer / src / test / java / org / opendaylight / transportpce / renderer / provisiondevice / RendererServiceOperationsImplTest.java
index d510e641ee86299866dfed8a5da37ee91a306195..6df33027a2248a124ebac183c2096b70d6489513 100644 (file)
  */
 package org.opendaylight.transportpce.renderer.provisiondevice;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mockito;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 import org.opendaylight.mdsal.binding.api.MountPoint;
 import org.opendaylight.mdsal.binding.api.MountPointService;
 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
 import org.opendaylight.transportpce.common.ResponseCodes;
 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.device.DeviceTransactionManager;
 import org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl;
-import org.opendaylight.transportpce.common.fixedflex.FixedFlexImpl;
-import org.opendaylight.transportpce.common.fixedflex.FixedFlexInterface;
 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.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.renderer.NetworkModelWavelengthService;
-import org.opendaylight.transportpce.renderer.NetworkModelWavelengthServiceImpl;
-import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterface121;
-import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterface221;
-import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterfaceFactory;
-import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmOtnInterface221;
-import org.opendaylight.transportpce.renderer.stub.MountPointServiceStub;
-import org.opendaylight.transportpce.renderer.stub.MountPointStub;
+import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl710;
+import org.opendaylight.transportpce.renderer.provisiondevice.notification.NotificationSender;
 import org.opendaylight.transportpce.renderer.stub.OlmServiceStub;
-import org.opendaylight.transportpce.renderer.utils.MountPointUtils;
 import org.opendaylight.transportpce.renderer.utils.NotificationPublishServiceMock;
 import org.opendaylight.transportpce.renderer.utils.ServiceDataUtils;
 import org.opendaylight.transportpce.test.AbstractTest;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.GetPmInput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.GetPmInputBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.GetPmOutput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.GetPmOutputBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.TransportpceOlmService;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.get.pm.output.Measurements;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.get.pm.output.MeasurementsBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.ServicePathOutputBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.ServiceImplementationRequestInput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.ServiceImplementationRequestOutput;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev161014.PmGranularity;
+import org.opendaylight.transportpce.test.stub.MountPointServiceStub;
+import org.opendaylight.transportpce.test.stub.MountPointStub;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePathOutputBuilder;
+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.TransportpceOlmService;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.get.pm.output.Measurements;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.get.pm.output.MeasurementsBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceImplementationRequestInput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceImplementationRequestOutput;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.types.rev161014.ResourceTypeEnum;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev200615.olm.get.pm.input.ResourceIdentifierBuilder;
+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.RpcResultBuilder;
 
 public class RendererServiceOperationsImplTest extends AbstractTest {
 
     private MountPointService mountPointService;
     private DeviceTransactionManager deviceTransactionManager;
+    private final DeviceRendererService deviceRenderer = mock(DeviceRendererService.class);
+    private final OtnDeviceRendererService otnDeviceRendererService = mock(OtnDeviceRendererService.class);
+    private final PortMapping portMapping = mock(PortMapping.class);
     private RendererServiceOperationsImpl rendererServiceOperations;
     private OpenRoadmInterfaces openRoadmInterfaces;
-    private DeviceRendererService deviceRenderer;
-    private PortMapping portMapping;
-    private OpenRoadmInterfaceFactory openRoadmInterfaceFactory;
-    private CrossConnect crossConnect;
     private TransportpceOlmService olmService;
-    private NetworkModelWavelengthService networkModelWavelengthService;
     private MappingUtils mappingUtils;
     private OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121;
     private OpenRoadmInterfacesImpl221 openRoadmInterfacesImpl221;
-    private PortMappingVersion221 portMappingVersion22;
-    private PortMappingVersion121 portMappingVersion121;
-    private CrossConnectImpl121 crossConnectImpl121;
-    private CrossConnectImpl221 crossConnectImpl221;
+    private OpenRoadmInterfacesImpl710 openRoadmInterfacesImpl710;
 
     private void setMountPoint(MountPoint mountPoint) {
         this.mountPointService = new MountPointServiceStub(mountPoint);
         this.deviceTransactionManager = new DeviceTransactionManagerImpl(this.mountPointService, 3000);
-        this.openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(deviceTransactionManager);
-        this.openRoadmInterfacesImpl221 = new OpenRoadmInterfacesImpl221(deviceTransactionManager);
         this.mappingUtils = new MappingUtilsImpl(getDataBroker());
         this.openRoadmInterfaces = new OpenRoadmInterfacesImpl(deviceTransactionManager, mappingUtils,
-            openRoadmInterfacesImpl121, openRoadmInterfacesImpl221);
-        this.openRoadmInterfaces = Mockito.spy(this.openRoadmInterfaces);
-        this.portMappingVersion22 =
-            new PortMappingVersion221(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
-        this.portMappingVersion121 =
-            new PortMappingVersion121(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
-        this.portMapping = new PortMappingImpl(getDataBroker(), this.portMappingVersion22,
-            this.portMappingVersion121);
-        FixedFlexInterface fixedFlexInterface = new FixedFlexImpl();
-        OpenRoadmInterface121 openRoadmInterface121 = new OpenRoadmInterface121(portMapping,openRoadmInterfaces);
-        OpenRoadmInterface221 openRoadmInterface221 = new OpenRoadmInterface221(portMapping,openRoadmInterfaces,
-            fixedFlexInterface);
-        OpenRoadmOtnInterface221 openRoadmOTNInterface = new OpenRoadmOtnInterface221(portMapping, openRoadmInterfaces);
-        this.openRoadmInterfaceFactory = new OpenRoadmInterfaceFactory(this.mappingUtils,openRoadmInterface121,
-            openRoadmInterface221, openRoadmOTNInterface);
-        this.crossConnectImpl121 = new CrossConnectImpl121(deviceTransactionManager);
-        this.crossConnectImpl221 = new CrossConnectImpl221(deviceTransactionManager);
-        this.crossConnect = new CrossConnectImpl(deviceTransactionManager, this.mappingUtils, this.crossConnectImpl121,
-            this.crossConnectImpl221);
+            openRoadmInterfacesImpl121, openRoadmInterfacesImpl221, openRoadmInterfacesImpl710);
+        this.openRoadmInterfaces = spy(this.openRoadmInterfaces);
     }
 
-    @Before
-    public void setUp() throws OpenRoadmInterfaceException {
+    @BeforeEach
+    void setUp() throws OpenRoadmInterfaceException {
         setMountPoint(new MountPointStub(getDataBroker()));
         this.olmService = new OlmServiceStub();
-        this.networkModelWavelengthService = new NetworkModelWavelengthServiceImpl(getDataBroker());
-        this.deviceRenderer = new DeviceRendererServiceImpl(this.getDataBroker(), this.deviceTransactionManager,
-            openRoadmInterfaceFactory, openRoadmInterfaces, crossConnect, portMapping, null);
-        Mockito.doNothing().when(this.openRoadmInterfaces).postEquipmentState(Mockito.anyString(),
-            Mockito.anyString(), Mockito.anyBoolean());
+        doNothing().when(this.openRoadmInterfaces).postEquipmentState(anyString(), anyString(), anyBoolean());
         NotificationPublishService notificationPublishService = new NotificationPublishServiceMock();
-
-        this.olmService = Mockito.spy(this.olmService);
-        this.deviceRenderer = Mockito.spy(this.deviceRenderer);
-        this.rendererServiceOperations =  new RendererServiceOperationsImpl(this.deviceRenderer, this.olmService,
-            getDataBroker(), this.networkModelWavelengthService, notificationPublishService);
-
-        ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("success")
-            .setSuccess(true);
-        Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(),
-            Mockito.any());
+        this.olmService = spy(this.olmService);
+        this.rendererServiceOperations =  new RendererServiceOperationsImpl(deviceRenderer, otnDeviceRendererService,
+                this.olmService, getDataBroker(), new NotificationSender(notificationPublishService), portMapping);
     }
 
     @Test
-    public void serviceImplementationTerminationPointAsResourceTtp() throws InterruptedException, ExecutionException {
-
+    void serviceImplementationTerminationPointAsResourceTtp() throws InterruptedException, ExecutionException {
         ServiceImplementationRequestInput input = ServiceDataUtils
             .buildServiceImplementationRequestInputTerminationPointResource(StringConstants.TTP_TOKEN);
-        writePortMapping(input, StringConstants.TTP_TOKEN);
         ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("success")
             .setSuccess(true);
-        Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(),
-            Mockito.any());
-        ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
-        Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
-
+        doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(any(), any(), any());
+        ServiceImplementationRequestOutput result =
+                this.rendererServiceOperations.serviceImplementation(input, false).get();
+        assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
     }
 
     @Test
-    public void serviceImplementationTerminationPointAsResourceTtp2() throws InterruptedException, ExecutionException {
-
+    void serviceImplementationTerminationPointAsResourceTtp2() throws InterruptedException, ExecutionException {
         ServiceImplementationRequestInput input = ServiceDataUtils
             .buildServiceImplementationRequestInputTerminationPointResource(StringConstants.TTP_TOKEN);
-        writePortMapping(input, StringConstants.TTP_TOKEN);
         ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("success")
             .setSuccess(true);
-        Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(),
-            Mockito.any());
-        Mockito.doReturn(RpcResultBuilder.failed().buildFuture()).when(this.olmService)
-            .servicePowerSetup(Mockito.any());
-        ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
-        Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());
-
+        doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(any(), any(), any());
+        doReturn(RpcResultBuilder.failed().buildFuture()).when(this.olmService).servicePowerSetup(any());
+        ServiceImplementationRequestOutput result =
+                this.rendererServiceOperations.serviceImplementation(input, false).get();
+        assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());
     }
 
     @Test
-    public void serviceImplementationTerminationPointAsResourcePp() throws InterruptedException, ExecutionException {
-
+    void serviceImplementationTerminationPointAsResourcePp() throws InterruptedException, ExecutionException {
         ServiceImplementationRequestInput input = ServiceDataUtils
             .buildServiceImplementationRequestInputTerminationPointResource(StringConstants.PP_TOKEN);
-        writePortMapping(input, StringConstants.PP_TOKEN);
         ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("success")
             .setSuccess(true);
-        Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(),
-            Mockito.any());
-        ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
-        Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
-
+        doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(any(), any(), any());
+        ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input,
+                false).get();
+        assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
     }
 
     @Test
-    public void serviceImplementationTerminationPointAsResourceNetwork()
-        throws InterruptedException, ExecutionException {
-
+    void serviceImplementationTerminationPointAsResourceNetwork() throws InterruptedException, ExecutionException {
         ServiceImplementationRequestInput input = ServiceDataUtils
             .buildServiceImplementationRequestInputTerminationPointResource(StringConstants.NETWORK_TOKEN);
-        writePortMapping(input, StringConstants.NETWORK_TOKEN);
         ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("success")
             .setSuccess(true);
-        Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(),
-            Mockito.any());
-        ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
-        Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
-
+        doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(any(), any(), any());
+        ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input,
+                false).get();
+        assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
     }
 
     @Test
-    public void serviceImplementationTerminationPointAsResourceClient()
-        throws InterruptedException, ExecutionException {
-
+    void serviceImplementationTerminationPointAsResourceClient() throws InterruptedException, ExecutionException {
         ServiceImplementationRequestInput input = ServiceDataUtils
-     //       .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.CLIENT_TOKEN);
             .buildServiceImplementationRequestInputTerminationPointResource(StringConstants.CLIENT_TOKEN);
-     //   writePortMapping(input, OpenRoadmInterfacesImpl.CLIENT_TOKEN);
-        writePortMapping(input, StringConstants.CLIENT_TOKEN);
-        ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
-        Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
+        ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("success")
+            .setSuccess(true);
+        doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(any(), any(), any());
+        ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input,
+                false).get();
+        assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
     }
 
     @Test
-    public void serviceImplementationTerminationPointAsResourceNoMapping()
-        throws InterruptedException, ExecutionException {
-
+    void serviceImplementationTerminationPointAsResourceNoMapping() throws InterruptedException, ExecutionException {
         String[] interfaceTokens = {
             StringConstants.NETWORK_TOKEN,
             StringConstants.CLIENT_TOKEN,
@@ -225,217 +168,171 @@ public class RendererServiceOperationsImplTest extends AbstractTest {
 
         ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("failed")
             .setSuccess(false);
-        Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(),
-            Mockito.any());
+        doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(any(), any(), any());
 
         for (String tpToken : interfaceTokens) {
             ServiceImplementationRequestInput input = ServiceDataUtils
                 .buildServiceImplementationRequestInputTerminationPointResource(tpToken);
-            ServiceImplementationRequestOutput result =
-                this.rendererServiceOperations.serviceImplementation(input).get();
-            Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
-                result.getConfigurationResponseCommon().getResponseCode());
+            ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input,
+                            false)
+                .get();
+            assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());
         }
     }
 
-    private void writePortMapping(ServiceImplementationRequestInput input, String tpToken) {
-        MountPointUtils.writeMapping(
-            input.getServiceAEnd().getNodeId(),
-            input.getServiceAEnd().getNodeId() + "-" + tpToken,
-            this.deviceTransactionManager
-        );
-        MountPointUtils.writeMapping(
-            input.getServiceZEnd().getNodeId(),
-            input.getServiceZEnd().getNodeId() + "-"
-                + input.getServiceAEnd().getNodeId() + "-" + tpToken,
-            this.deviceTransactionManager
-        );
-        MountPointUtils.writeMapping(
-            input.getServiceAEnd().getNodeId(),
-            input.getServiceAEnd().getNodeId() + "-"
-                + input.getServiceZEnd().getNodeId() + "-" + tpToken,
-            this.deviceTransactionManager
-        );
-        MountPointUtils.writeMapping(
-            input.getServiceZEnd().getNodeId(),
-            input.getServiceZEnd().getNodeId() + "-" + tpToken,
-            this.deviceTransactionManager
-        );
-    }
-
     @Test
-    public void serviceImplementationRollbackAllNecessary() throws InterruptedException, ExecutionException {
-
+    void serviceImplementationRollbackAllNecessary() throws InterruptedException, ExecutionException {
         ServiceImplementationRequestInput input = ServiceDataUtils
             .buildServiceImplementationRequestInputTerminationPointResource(StringConstants.NETWORK_TOKEN);
-        writePortMapping(input, StringConstants.NETWORK_TOKEN);
-        Mockito.doReturn(RpcResultBuilder.failed().buildFuture()).when(this.olmService)
-            .servicePowerSetup(Mockito.any());
-        ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
-        Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());
-
-    }
-
-    private GetPmInput createGetPmInput(String nodeId, String tp) {
-        GetPmInputBuilder getPmIpBldr = new GetPmInputBuilder();
-        getPmIpBldr.setNodeId(nodeId);
-        getPmIpBldr.setGranularity(PmGranularity._15min);
-        ResourceIdentifierBuilder rsrcBldr = new ResourceIdentifierBuilder();
-        rsrcBldr.setResourceName(tp + "-OTU");
-        getPmIpBldr.setResourceIdentifier(rsrcBldr.build());
-        getPmIpBldr.setResourceType(ResourceTypeEnum.Interface);
-        return getPmIpBldr.build();
+//        writePortMapping(input, StringConstants.NETWORK_TOKEN);
+        doReturn(RpcResultBuilder.failed().buildFuture()).when(this.olmService).servicePowerSetup(any());
+        ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input,
+                false).get();
+        assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());
     }
 
     @Test
-    public void serviceImplementationServiceInActive() throws InterruptedException, ExecutionException {
-
+    void serviceImplementationServiceInActive() throws InterruptedException, ExecutionException {
         ServiceImplementationRequestInput input = ServiceDataUtils
             .buildServiceImplementationRequestInputTerminationPointResource(StringConstants.NETWORK_TOKEN);
-        writePortMapping(input, StringConstants.NETWORK_TOKEN);
-        Measurements measurements = new MeasurementsBuilder().setPmparameterName("FECUncorrectableBlocks")
-            .setPmparameterValue("1").build();
         List<Measurements> measurementsList = new ArrayList<Measurements>();
-        measurementsList.add(measurements);
+        measurementsList.add(new MeasurementsBuilder()
+                .setPmparameterName("FECUncorrectableBlocks")
+                .setPmparameterValue("1")
+                .build());
         GetPmOutput getPmOutput = new GetPmOutputBuilder()
-            .setNodeId("node1").setMeasurements(measurementsList).build();
-        Mockito.doReturn(RpcResultBuilder.success(getPmOutput).buildFuture()).when(this.olmService)
-            .getPm(Mockito.any());
-        ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
-        Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());
-
+                .setNodeId("node1")
+                .setMeasurements(measurementsList)
+                .build();
+        doReturn(RpcResultBuilder.success(getPmOutput).buildFuture()).when(this.olmService).getPm(any());
+        ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input,
+                false).get();
+        assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());
     }
 
     @Test
-    public void serviceImplementationServiceInActive2() throws InterruptedException, ExecutionException {
-
+    void serviceImplementationServiceInActive2() throws InterruptedException, ExecutionException {
         ServiceImplementationRequestInput input = ServiceDataUtils
             .buildServiceImplementationRequestInputTerminationPointResource(StringConstants.NETWORK_TOKEN);
-        writePortMapping(input, StringConstants.NETWORK_TOKEN);
-        Measurements measurements = new MeasurementsBuilder().setPmparameterName("FECUncorrectableBlocks")
-            .setPmparameterValue("1").build();
         List<Measurements> measurementsList = new ArrayList<Measurements>();
-        measurementsList.add(measurements);
+        measurementsList.add(new MeasurementsBuilder()
+                .setPmparameterName("FECUncorrectableBlocks")
+                .setPmparameterValue("1")
+                .build());
         GetPmOutput getPmOutput = new GetPmOutputBuilder()
-            .setNodeId("node1").setMeasurements(measurementsList).build();
-        GetPmOutput getPmOutput2 = new GetPmOutputBuilder()
-            .setNodeId("node1").setMeasurements(new ArrayList<>()).build();
-
-        Mockito.when(this.olmService.getPm(Mockito.any()))
-            .thenReturn(RpcResultBuilder.success(getPmOutput).buildFuture());
-        ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
-        Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());
-
+                .setNodeId("node1")
+                .setMeasurements(measurementsList)
+                .build();
+
+        when(this.olmService.getPm(any())).thenReturn(RpcResultBuilder.success(getPmOutput).buildFuture());
+        ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input,
+                false).get();
+        assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());
     }
 
     @Test
-    public void serviceImplementationServiceInActive3() throws InterruptedException, ExecutionException {
-
+    void serviceImplementationServiceInActive3() throws InterruptedException, ExecutionException {
+        List<Measurements> measurementsList = new ArrayList<Measurements>();
+        measurementsList.add(new MeasurementsBuilder()
+                .setPmparameterName("FECUncorrectableBlocks")
+                .setPmparameterValue("1")
+                .build());
+        GetPmOutput getPmOutput = new GetPmOutputBuilder().setNodeId("node1").setMeasurements(measurementsList).build();
+        GetPmOutput getPmOutput2 = new GetPmOutputBuilder().setNodeId("node1").setMeasurements(new ArrayList<>())
+            .build();
+
+        GetPmInput getPmInputZ = createGetPmInput("XPONDER-2-3", StringConstants.NETWORK_TOKEN);
+        GetPmInput getPmInputA = createGetPmInput("XPONDER-1-2", StringConstants.NETWORK_TOKEN);
+
+        when(this.olmService.getPm(eq(getPmInputZ))).thenReturn(RpcResultBuilder.success(getPmOutput2).buildFuture());
+        when(this.olmService.getPm(eq(getPmInputA))).thenReturn(RpcResultBuilder.success(getPmOutput).buildFuture());
+        ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("success")
+            .setSuccess(true);
+        doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(any(), any(), any());
         ServiceImplementationRequestInput input = ServiceDataUtils
             .buildServiceImplementationRequestInputTerminationPointResource(StringConstants.NETWORK_TOKEN);
-        writePortMapping(input, StringConstants.NETWORK_TOKEN);
-        Measurements measurements = new MeasurementsBuilder().setPmparameterName("FECUncorrectableBlocks")
-            .setPmparameterValue("1").build();
-        List<Measurements> measurementsList = new ArrayList<Measurements>();
-        measurementsList.add(measurements);
-        GetPmOutput getPmOutput = new GetPmOutputBuilder()
-            .setNodeId("node1").setMeasurements(measurementsList).build();
-        GetPmOutput getPmOutput2 = new GetPmOutputBuilder()
-            .setNodeId("node1").setMeasurements(new ArrayList<>()).build();
-
-        GetPmInput getPmInputZ = createGetPmInput("XPONDER-2-3",
-            StringConstants.NETWORK_TOKEN);
-        GetPmInput getPmInputA = createGetPmInput("XPONDER-1-2",
-            StringConstants.NETWORK_TOKEN);
-
-        Mockito.when(this.olmService.getPm(Mockito.eq(getPmInputZ)))
-            .thenReturn(RpcResultBuilder.success(getPmOutput2).buildFuture());
-        Mockito.when(this.olmService.getPm(Mockito.eq(getPmInputA)))
-            .thenReturn(RpcResultBuilder.success(getPmOutput).buildFuture());
-        ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
-        Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());
-
+        ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input,
+                false).get();
+        assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
     }
 
     @Test
-    public void serviceImplementationServiceActive() throws InterruptedException, ExecutionException {
-
+    void serviceImplementationServiceActive() throws InterruptedException, ExecutionException {
         ServiceImplementationRequestInput input = ServiceDataUtils
             .buildServiceImplementationRequestInputTerminationPointResource(StringConstants.NETWORK_TOKEN);
-        writePortMapping(input, StringConstants.NETWORK_TOKEN);
-        GetPmOutput getPmOutput = new GetPmOutputBuilder()
-            .setNodeId("node1").setMeasurements(new ArrayList<>()).build();
         GetPmOutput getPmOutput1 = null;
-        Mockito.when(this.olmService.getPm(Mockito.any())).thenReturn(RpcResultBuilder.success(getPmOutput1)
-            .buildFuture());
+        when(this.olmService.getPm(any())).thenReturn(RpcResultBuilder.success(getPmOutput1).buildFuture());
         ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("success")
             .setSuccess(true);
-        Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(),
-            Mockito.any());
-        ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
-        Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
-
+        doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(any(), any(), any());
+        ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input,
+                false).get();
+        assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
     }
 
     @Test
-    public void serviceImplementationServiceActive2() throws InterruptedException, ExecutionException {
-
+    void serviceImplementationServiceActive2() throws InterruptedException, ExecutionException {
         ServiceImplementationRequestInput input = ServiceDataUtils
             .buildServiceImplementationRequestInputTerminationPointResource(StringConstants.NETWORK_TOKEN);
-        writePortMapping(input, StringConstants.NETWORK_TOKEN);
         GetPmOutput getPmOutput = new GetPmOutputBuilder().setMeasurements(new ArrayList<>()).build();
-        Mockito.when(this.olmService.getPm(Mockito.any())).thenReturn(RpcResultBuilder.success(getPmOutput)
-            .buildFuture());
+        when(this.olmService.getPm(any())).thenReturn(RpcResultBuilder.success(getPmOutput).buildFuture());
         ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("success")
             .setSuccess(true);
-        Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(),
-            Mockito.any());
-        ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
-        Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
-
+        doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(any(), any(), any());
+        ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input,
+                false).get();
+        assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
     }
 
     @Test
-    public void serviceImplementationServiceInActive4() throws InterruptedException, ExecutionException {
-
-        ServiceImplementationRequestInput input = ServiceDataUtils
-            .buildServiceImplementationRequestInputTerminationPointResource(StringConstants.NETWORK_TOKEN);
-        writePortMapping(input, StringConstants.NETWORK_TOKEN);
-        Measurements measurements = new MeasurementsBuilder().setPmparameterName("preFECCorrectedErrors")
-            .setPmparameterValue("1").build();
+    void serviceImplementationServiceInActive4() throws InterruptedException, ExecutionException {
         List<Measurements> measurementsList = new ArrayList<Measurements>();
-        measurementsList.add(measurements);
+        measurementsList.add(new MeasurementsBuilder()
+                .setPmparameterName("preFECCorrectedErrors")
+                .setPmparameterValue("1")
+                .build());
         GetPmOutput getPmOutput = new GetPmOutputBuilder()
-            .setNodeId("node1").setMeasurements(measurementsList).build();
+                .setNodeId("node1")
+                .setMeasurements(measurementsList)
+                .build();
 
-        Mockito.doReturn(RpcResultBuilder.success(getPmOutput).buildFuture()).when(this.olmService)
-            .getPm(Mockito.any());
+        doReturn(RpcResultBuilder.success(getPmOutput).buildFuture()).when(this.olmService).getPm(any());
         ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("success")
             .setSuccess(true);
-        Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(),
-            Mockito.any());
-        ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
-        Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
-
+        doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(any(), any(), any());
+        ServiceImplementationRequestInput input = ServiceDataUtils
+            .buildServiceImplementationRequestInputTerminationPointResource(StringConstants.NETWORK_TOKEN);
+        ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input,
+                false).get();
+        assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
     }
 
     @Test
-    public void serviceImplementationServiceInActive5() throws InterruptedException, ExecutionException {
-
+    void serviceImplementationServiceInActive5() throws InterruptedException, ExecutionException {
         ServiceImplementationRequestInput input = ServiceDataUtils
             .buildServiceImplementationRequestInputTerminationPointResource(StringConstants.NETWORK_TOKEN);
-        writePortMapping(input, StringConstants.NETWORK_TOKEN);
-        Measurements measurements = new MeasurementsBuilder().setPmparameterName("preFECCorrectedErrors")
-            .setPmparameterValue("112000000000d").build();
         List<Measurements> measurementsList = new ArrayList<Measurements>();
-        measurementsList.add(measurements);
+        measurementsList.add(new MeasurementsBuilder()
+                .setPmparameterName("preFECCorrectedErrors")
+                .setPmparameterValue("112000000000d")
+                .build());
         GetPmOutput getPmOutput = new GetPmOutputBuilder()
-            .setNodeId("node1").setMeasurements(measurementsList).build();
-
-        Mockito.doReturn(RpcResultBuilder.success(getPmOutput).buildFuture()).when(this.olmService)
-            .getPm(Mockito.any());
-        ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
-        Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());
+                .setNodeId("node1")
+                .setMeasurements(measurementsList)
+                .build();
+
+        doReturn(RpcResultBuilder.success(getPmOutput).buildFuture()).when(this.olmService).getPm(any());
+        ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input,
+                false).get();
+        assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());
+    }
 
+    private GetPmInput createGetPmInput(String nodeId, String tp) {
+        return new GetPmInputBuilder()
+                .setNodeId(nodeId)
+                .setGranularity(PmGranularity._15min)
+                .setResourceIdentifier(new ResourceIdentifierBuilder().setResourceName(tp + "-OTU").build())
+                .setResourceType(ResourceTypeEnum.Interface)
+                .build();
     }
-}
+}
\ No newline at end of file