Update ServicehandlerImplTest 21/101621/3
authorThierry Jiao <thierry.jiao@orange.com>
Wed, 22 Jun 2022 12:51:04 +0000 (14:51 +0200)
committerThierry Jiao <thierry.jiao@orange.com>
Mon, 4 Jul 2022 07:16:03 +0000 (09:16 +0200)
- Refactor the redundant variables
- Add Unit test for service-create when service already exists in
DataStore

JIRA: TRNSPRTPCE-675
Signed-off-by: Thierry Jiao <thierry.jiao@orange.com>
Change-Id: Ifa6657e8dac0cb81d6a3c4837aac1e18f1ba00be

servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImplTest.java

index 8634966e75f984e682719f609bfe5851ecdf4f28..9c3fcacc0f95d711398c8648df9b517a536617cf 100644 (file)
@@ -8,12 +8,14 @@
 package org.opendaylight.transportpce.servicehandler.impl;
 
 import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
 import static org.opendaylight.transportpce.servicehandler.impl.ServicehandlerImpl.LogMessages;
 
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.ListeningExecutorService;
 import com.google.common.util.concurrent.MoreExecutors;
+import java.util.Optional;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Executors;
@@ -23,7 +25,6 @@ import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
-import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
 import org.opendaylight.transportpce.common.ResponseCodes;
 import org.opendaylight.transportpce.pce.service.PathComputationService;
@@ -41,7 +42,6 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.Service
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceDeleteInput;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceDeleteInputBuilder;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceDeleteOutput;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceFeasibilityCheckInput;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceFeasibilityCheckInputBuilder;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceFeasibilityCheckOutput;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceReconfigureInput;
@@ -60,9 +60,10 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempSer
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceDeleteInputBuilder;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceDeleteOutput;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.service.delete.input.ServiceDeleteReqInfoBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.service.list.ServicesBuilder;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 
-public class ServicehandlerImplTest extends AbstractTest  {
+public class ServicehandlerImplTest extends AbstractTest {
 
     @Mock
     private PathComputationService pathComputationService;
@@ -83,6 +84,11 @@ public class ServicehandlerImplTest extends AbstractTest  {
     private NetworkModelListenerImpl networkModelListenerImpl;
 
     private ServiceDataStoreOperations serviceDataStoreOperations;
+    private ServiceCreateInput serviceCreateInput;
+    private ServiceDeleteInput serviceDeleteInput;
+    private ServiceReconfigureInput serviceReconfigureInput;
+    private ServiceRestorationInput serviceRestorationInput;
+    private ServiceRerouteInput serviceRerouteInput;
     private ListeningExecutorService executorService;
     private CountDownLatch endSignal;
     private static final int NUM_THREADS = 5;
@@ -93,187 +99,152 @@ public class ServicehandlerImplTest extends AbstractTest  {
         endSignal = new CountDownLatch(1);
         MockitoAnnotations.openMocks(this);
         this.serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(getNewDataBroker());
+        serviceCreateInput = ServiceDataUtils.buildServiceCreateInput();
+        serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput();
+        serviceReconfigureInput = ServiceDataUtils.buildServiceReconfigureInput();
+        serviceRestorationInput = ServiceDataUtils.buildServiceRestorationInput();
+        serviceRerouteInput = ServiceDataUtils.buildServiceRerouteInput();
     }
 
     @Test
     public void createServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
         ServicehandlerImpl servicehandlerImpl =
-            new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
-                notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
-                serviceDataStoreOperations);
+                new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
+                        notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
+                        serviceDataStoreOperations);
         ListenableFuture<RpcResult<ServiceCreateOutput>> result =
-            servicehandlerImpl.serviceCreate(new ServiceCreateInputBuilder().build());
-        result.addListener(new Runnable() {
-            @Override
-            public void run() {
-                endSignal.countDown();
-            }
-        }, executorService);
+                servicehandlerImpl.serviceCreate(new ServiceCreateInputBuilder().build());
+        result.addListener(() -> endSignal.countDown(), executorService);
 
         endSignal.await();
-
-        RpcResult<ServiceCreateOutput> rpcResult = result.get();
         Assert.assertEquals(
-            ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
+                ResponseCodes.RESPONSE_FAILED,
+                result.get().getResult().getConfigurationResponseCommon().getResponseCode());
     }
 
     @Test
-    public void createServiceShouldBeSuccessfulWhenPreformPCESuccessful()
-        throws ExecutionException, InterruptedException {
-        ServiceCreateInput input = ServiceDataUtils.buildServiceCreateInput();
-        Mockito.when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
-        ServicehandlerImpl servicehandlerImpl =
-            new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
-                notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
-                serviceDataStoreOperations);
-        ListenableFuture<RpcResult<ServiceCreateOutput>> result =  servicehandlerImpl.serviceCreate(input);
-        result.addListener(new Runnable() {
-            @Override
-            public void run() {
-                endSignal.countDown();
-            }
-        }, executorService);
+    public void createServiceShouldBeFailedWithServiceAlreadyExist() throws ExecutionException,
+            InterruptedException {
+        final ServiceDataStoreOperations serviceDSOperations = mock(ServiceDataStoreOperations.class);
+        Mockito.when(serviceDSOperations.getService(serviceCreateInput.getServiceName()))
+                .thenReturn(Optional.of(
+                        new ServicesBuilder()
+                                .setServiceName(serviceCreateInput.getServiceName())
+                                .build()));
+        ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
+                rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
+                networkModelListenerImpl, serviceDSOperations);
+        ListenableFuture<RpcResult<ServiceCreateOutput>> result = servicehandlerImpl.serviceCreate(serviceCreateInput);
+        result.addListener(() -> endSignal.countDown(), executorService);
 
         endSignal.await();
+        Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
+                result.get().getResult().getConfigurationResponseCommon().getResponseCode());
+    }
 
-        RpcResult<ServiceCreateOutput> rpcResult = result.get();
+    @Test
+    public void createServiceShouldBeSuccessfulWhenPerformPCESuccessful()
+            throws ExecutionException, InterruptedException {
+        Mockito.when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
+        ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
+                rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
+                networkModelListenerImpl, serviceDataStoreOperations);
+        ListenableFuture<RpcResult<ServiceCreateOutput>> result = servicehandlerImpl.serviceCreate(serviceCreateInput);
+        result.addListener(() -> endSignal.countDown(), executorService);
+
+        endSignal.await();
         Assert.assertEquals(
-            ResponseCodes.RESPONSE_OK, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
+                ResponseCodes.RESPONSE_OK, result.get().getResult().getConfigurationResponseCommon().getResponseCode());
     }
 
     @Test
     public void deleteServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
-        ServicehandlerImpl servicehandlerImpl =
-            new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
-                notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
-                serviceDataStoreOperations);
-        ListenableFuture<RpcResult<ServiceDeleteOutput>> result =
-            servicehandlerImpl.serviceDelete(new ServiceDeleteInputBuilder()
-                .setServiceDeleteReqInfo(new ServiceDeleteReqInfoBuilder().setServiceName("").build()).build());
-        result.addListener(new Runnable() {
-            @Override
-            public void run() {
-                endSignal.countDown();
-            }
-        }, executorService);
+        ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
+                rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
+                networkModelListenerImpl, serviceDataStoreOperations);
+        ListenableFuture<RpcResult<ServiceDeleteOutput>> result = servicehandlerImpl.serviceDelete(
+                new ServiceDeleteInputBuilder()
+                        .setServiceDeleteReqInfo(new ServiceDeleteReqInfoBuilder()
+                                .setServiceName("")
+                                .build())
+                        .build());
+        result.addListener(() -> endSignal.countDown(), executorService);
 
         endSignal.await();
-
-        RpcResult<ServiceDeleteOutput> rpcResult = result.get();
         Assert.assertEquals(
-            ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
+                ResponseCodes.RESPONSE_FAILED,
+                result.get().getResult().getConfigurationResponseCommon().getResponseCode());
     }
 
     @Test
     public void deleteServiceShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
-        ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput();
         ServicehandlerImpl servicehandlerImpl =
-            new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
-                notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
-                serviceDataStoreOperations);
-        ListenableFuture<RpcResult<ServiceDeleteOutput>> result = servicehandlerImpl.serviceDelete(input);
-        result.addListener(new Runnable() {
-            @Override
-            public void run() {
-                endSignal.countDown();
-            }
-        }, executorService);
+                new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
+                        notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
+                        serviceDataStoreOperations);
+        ListenableFuture<RpcResult<ServiceDeleteOutput>> result = servicehandlerImpl.serviceDelete(serviceDeleteInput);
+        result.addListener(() -> endSignal.countDown(), executorService);
 
         endSignal.await();
-
-        RpcResult<ServiceDeleteOutput> rpcResult = result.get();
         Assert.assertEquals(
-            ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
+                ResponseCodes.RESPONSE_FAILED,
+                result.get().getResult().getConfigurationResponseCommon().getResponseCode());
     }
 
     @Test
     public void deleteServiceShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
-        DataBroker dataBroker = getNewDataBroker();
         Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
-        ServicehandlerImpl servicehandlerImpl =
-            new ServicehandlerImpl(dataBroker, pathComputationService, rendererServiceOperations,
-                notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
-                serviceDataStoreOperations);
-        ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
-        serviceDataStoreOperations.createService(createInput);
-        ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput();
-        ListenableFuture<RpcResult<ServiceDeleteOutput>> result = servicehandlerImpl.serviceDelete(input);
-        result.addListener(new Runnable() {
-            @Override
-            public void run() {
-                endSignal.countDown();
-            }
-        }, executorService);
+        ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
+                rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
+                networkModelListenerImpl, serviceDataStoreOperations);
+        serviceDataStoreOperations.createService(serviceCreateInput);
+        ListenableFuture<RpcResult<ServiceDeleteOutput>> result = servicehandlerImpl.serviceDelete(serviceDeleteInput);
+        result.addListener(() -> endSignal.countDown(), executorService);
 
         endSignal.await();
-
-        RpcResult<ServiceDeleteOutput> rpcResult = result.get();
         Assert.assertEquals(
-            ResponseCodes.RESPONSE_OK, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
+                ResponseCodes.RESPONSE_OK, result.get().getResult().getConfigurationResponseCommon().getResponseCode());
     }
 
 
     @Test
     public void serviceFeasibilityCheckShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
-        ServicehandlerImpl servicehandlerImpl =
-                new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
-                        notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
-                        serviceDataStoreOperations);
+        ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
+                rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
+                networkModelListenerImpl, serviceDataStoreOperations);
         ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> result =
                 servicehandlerImpl.serviceFeasibilityCheck(new ServiceFeasibilityCheckInputBuilder().build());
-        result.addListener(new Runnable() {
-            @Override
-            public void run() {
-                endSignal.countDown();
-            }
-        }, executorService);
+        result.addListener(() -> endSignal.countDown(), executorService);
 
         endSignal.await();
-
-        RpcResult<ServiceFeasibilityCheckOutput> rpcResult = result.get();
-        Assert.assertEquals(
-            ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
+        Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
+                result.get().getResult().getConfigurationResponseCommon().getResponseCode());
     }
 
     @Test
-    public void serviceFeasibilityCheckShouldBeSuccessfulWhenPreformPCESuccessful()
+    public void serviceFeasibilityCheckShouldBeSuccessfulWhenPerformPCESuccessful()
             throws ExecutionException, InterruptedException {
-        ServiceFeasibilityCheckInput input = ServiceDataUtils.buildServiceFeasibilityCheckInput();
         Mockito.when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
-        ServicehandlerImpl servicehandlerImpl =
-                new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
-                        notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
-                        serviceDataStoreOperations);
+        ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
+                rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
+                networkModelListenerImpl, serviceDataStoreOperations);
         ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> result =
-            servicehandlerImpl.serviceFeasibilityCheck(input);
-        result.addListener(new Runnable() {
-            @Override
-            public void run() {
-                endSignal.countDown();
-            }
-        }, executorService);
+                servicehandlerImpl.serviceFeasibilityCheck(ServiceDataUtils.buildServiceFeasibilityCheckInput());
+        result.addListener(() -> endSignal.countDown(), executorService);
 
         endSignal.await();
-
-        RpcResult<ServiceFeasibilityCheckOutput> rpcResult = result.get();
         Assert.assertEquals(
-                ResponseCodes.RESPONSE_OK, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
+                ResponseCodes.RESPONSE_OK, result.get().getResult().getConfigurationResponseCommon().getResponseCode());
     }
 
     @Test
     public void serviceReconfigureShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
-        ServicehandlerImpl servicehandlerImpl =
-                new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
-                        notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
-                        serviceDataStoreOperations);
+        ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
+                rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
+                networkModelListenerImpl, serviceDataStoreOperations);
         ListenableFuture<RpcResult<ServiceReconfigureOutput>> result =
                 servicehandlerImpl.serviceReconfigure(new ServiceReconfigureInputBuilder().setServiceName("").build());
-        result.addListener(new Runnable() {
-            @Override
-            public void run() {
-                endSignal.countDown();
-            }
-        }, executorService);
+        result.addListener(() -> endSignal.countDown(), executorService);
 
         endSignal.await();
     }
@@ -281,68 +252,45 @@ public class ServicehandlerImplTest extends AbstractTest  {
 
     @Test
     public void serviceReconfigureShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
-        ServiceReconfigureInput input = ServiceDataUtils.buildServiceReconfigureInput();
-
         //action -> service reconfigure
-        ServicehandlerImpl servicehandlerImpl =
-                new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
-                        notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
-                        serviceDataStoreOperations);
-        ListenableFuture<RpcResult<ServiceReconfigureOutput>> result = servicehandlerImpl.serviceReconfigure(input);
+        ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
+                rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
+                networkModelListenerImpl, serviceDataStoreOperations);
+        ListenableFuture<RpcResult<ServiceReconfigureOutput>> result = servicehandlerImpl.serviceReconfigure(
+                serviceReconfigureInput);
 
-        result.addListener(new Runnable() {
-            @Override
-            public void run() {
-                endSignal.countDown();
-            }
-        }, executorService);
+        result.addListener(() -> endSignal.countDown(), executorService);
 
         endSignal.await();
     }
 
     @Test
     public void serviceReconfigureShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
-        DataBroker dataBroker = getNewDataBroker();
-
-        //mocking
         // serviceReconfigure is calling service delete method in renderer
         Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
         //create service to reconfigure
-        ServicehandlerImpl servicehandlerImpl =
-                new ServicehandlerImpl(dataBroker, pathComputationService, rendererServiceOperations,
-                        notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
-                        serviceDataStoreOperations);
-        ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
-        serviceDataStoreOperations.createService(createInput);
+        ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
+                rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
+                networkModelListenerImpl, serviceDataStoreOperations);
+        serviceDataStoreOperations.createService(serviceCreateInput);
 
         //service reconfigure test action
-        ServiceReconfigureInput input = ServiceDataUtils.buildServiceReconfigureInput();
         //ServiceReconfigureInput is created with the same service information that is created before
-        ListenableFuture<RpcResult<ServiceReconfigureOutput>> result = servicehandlerImpl.serviceReconfigure(input);
-        result.addListener(new Runnable() {
-            @Override
-            public void run() {
-                endSignal.countDown();
-            }
-        }, executorService);
+        ListenableFuture<RpcResult<ServiceReconfigureOutput>> result = servicehandlerImpl.serviceReconfigure(
+                serviceReconfigureInput);
+        result.addListener(() -> endSignal.countDown(), executorService);
 
         endSignal.await();
     }
 
     @Test
     public void serviceReRestorationShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
-        ServicehandlerImpl servicehandlerImpl =
-                new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
-                        notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
-                        serviceDataStoreOperations);
+        ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
+                rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
+                networkModelListenerImpl, serviceDataStoreOperations);
         ListenableFuture<RpcResult<ServiceRestorationOutput>> result =
                 servicehandlerImpl.serviceRestoration(new ServiceRestorationInputBuilder().setServiceName("").build());
-        result.addListener(new Runnable() {
-            @Override
-            public void run() {
-                endSignal.countDown();
-            }
-        }, executorService);
+        result.addListener(() -> endSignal.countDown(), executorService);
 
         endSignal.await();
     }
@@ -350,248 +298,168 @@ public class ServicehandlerImplTest extends AbstractTest  {
 
     @Test
     public void serviceRestorationShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
-        ServiceRestorationInput input = ServiceDataUtils.buildServiceRestorationInput();
-
         //action -> service restore
-        ServicehandlerImpl servicehandlerImpl =
-                new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
-                        notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
-                        serviceDataStoreOperations);
-        ListenableFuture<RpcResult<ServiceRestorationOutput>> result = servicehandlerImpl.serviceRestoration(input);
+        ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
+                rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
+                networkModelListenerImpl, serviceDataStoreOperations);
+        ListenableFuture<RpcResult<ServiceRestorationOutput>> result = servicehandlerImpl.serviceRestoration(
+                serviceRestorationInput);
 
-        result.addListener(new Runnable() {
-            @Override
-            public void run() {
-                endSignal.countDown();
-            }
-        }, executorService);
+        result.addListener(() -> endSignal.countDown(), executorService);
 
         endSignal.await();
     }
 
     @Test
     public void serviceRestorationShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
-        DataBroker dataBroker = getNewDataBroker();
-
-        //mocking
         // serviceRestoration is calling service delete method in renderer
         Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
         //create service to restore
-        ServicehandlerImpl servicehandlerImpl =
-                new ServicehandlerImpl(dataBroker, pathComputationService, rendererServiceOperations,
-                        notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
-                        serviceDataStoreOperations);
-        ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
-        serviceDataStoreOperations.createService(createInput);
+        ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
+                rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
+                networkModelListenerImpl, serviceDataStoreOperations);
+        serviceDataStoreOperations.createService(serviceCreateInput);
 
         //service Restoration test action
-        ServiceRestorationInput input = ServiceDataUtils.buildServiceRestorationInput();
         //ServiceRestorationInput is created with the same service information that is created before
-        ListenableFuture<RpcResult<ServiceRestorationOutput>> result = servicehandlerImpl.serviceRestoration(input);
-        result.addListener(new Runnable() {
-            @Override
-            public void run() {
-                endSignal.countDown();
-            }
-        }, executorService);
+        ListenableFuture<RpcResult<ServiceRestorationOutput>> result = servicehandlerImpl.serviceRestoration(
+                serviceRestorationInput);
+        result.addListener(() -> endSignal.countDown(), executorService);
 
         endSignal.await();
     }
 
     @Test
     public void serviceRerouteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
-        ServicehandlerImpl servicehandlerImpl =
-                new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
-                        notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
-                        serviceDataStoreOperations);
+        ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
+                rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
+                networkModelListenerImpl, serviceDataStoreOperations);
         ListenableFuture<RpcResult<ServiceRerouteOutput>> result =
                 servicehandlerImpl.serviceReroute(new ServiceRerouteInputBuilder().setServiceName("").build());
-        result.addListener(new Runnable() {
-            @Override
-            public void run() {
-                endSignal.countDown();
-            }
-        }, executorService);
+        result.addListener(() -> endSignal.countDown(), executorService);
 
         endSignal.await();
     }
 
     @Test
     public void serviceRerouteShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
-        ServiceRerouteInput input = ServiceDataUtils.buildServiceRerouteInput();
-
         //action -> service reconfigure
-        ServicehandlerImpl servicehandlerImpl =
-                new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
-                        notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
-                        serviceDataStoreOperations);
-        ListenableFuture<RpcResult<ServiceRerouteOutput>> result = servicehandlerImpl.serviceReroute(input);
+        ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
+                rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
+                networkModelListenerImpl, serviceDataStoreOperations);
+        ListenableFuture<RpcResult<ServiceRerouteOutput>> result = servicehandlerImpl.serviceReroute(
+                serviceRerouteInput);
 
-        result.addListener(new Runnable() {
-            @Override
-            public void run() {
-                endSignal.countDown();
-            }
-        }, executorService);
+        result.addListener(() -> endSignal.countDown(), executorService);
 
         endSignal.await();
     }
 
     @Test
     public void serviceRerouteShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
-        DataBroker dataBroker = getNewDataBroker();
-
-        //mocking
         // serviceReroute is calling service delete method in renderer
         Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
         //create service to be rerouted later
-        ServicehandlerImpl servicehandlerImpl =
-                new ServicehandlerImpl(dataBroker, pathComputationService, rendererServiceOperations,
-                        notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
-                        serviceDataStoreOperations);
-        ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
-        serviceDataStoreOperations.createService(createInput);
+        ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
+                rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
+                networkModelListenerImpl, serviceDataStoreOperations);
+        serviceDataStoreOperations.createService(serviceCreateInput);
 
         //service reroute test action
-        ServiceRerouteInput input = ServiceDataUtils.buildServiceRerouteInput();
         //ServiceRerouteInput is created with the same service information that is created before
-        ListenableFuture<RpcResult<ServiceRerouteOutput>> result = servicehandlerImpl.serviceReroute(input);
-        result.addListener(new Runnable() {
-            @Override
-            public void run() {
-                endSignal.countDown();
-            }
-        }, executorService);
+        ListenableFuture<RpcResult<ServiceRerouteOutput>> result = servicehandlerImpl.serviceReroute(
+                serviceRerouteInput);
+        result.addListener(() -> endSignal.countDown(), executorService);
 
         endSignal.await();
     }
 
     @Test
     public void tempServiceDeleteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
-        ServicehandlerImpl servicehandlerImpl =
-                new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
-                        notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
-                        serviceDataStoreOperations);
+        ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
+                rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
+                networkModelListenerImpl, serviceDataStoreOperations);
         ListenableFuture<RpcResult<TempServiceDeleteOutput>> result =
-                servicehandlerImpl.tempServiceDelete(new TempServiceDeleteInputBuilder()
-                        .setCommonId("").build());
-        result.addListener(new Runnable() {
-            @Override
-            public void run() {
-                endSignal.countDown();
-            }
-        }, executorService);
+                servicehandlerImpl.tempServiceDelete(new TempServiceDeleteInputBuilder().setCommonId("").build());
+        result.addListener(() -> endSignal.countDown(), executorService);
 
         endSignal.await();
 
         RpcResult<TempServiceDeleteOutput> rpcResult = result.get();
         Assert.assertEquals(
-            ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
+                ResponseCodes.RESPONSE_FAILED,
+                rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
         Assert.assertEquals(
-            LogMessages.SERVICE_NON_COMPLIANT,
-            rpcResult.getResult().getConfigurationResponseCommon().getResponseMessage());
+                LogMessages.SERVICE_NON_COMPLIANT,
+                rpcResult.getResult().getConfigurationResponseCommon().getResponseMessage());
     }
 
     @Test
     public void tempServiceDeleteShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
-        TempServiceDeleteInput input = ServiceDataUtils.buildTempServiceDeleteInput();
-        ServicehandlerImpl servicehandlerImpl =
-                new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
-                        notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
-                        serviceDataStoreOperations);
-        ListenableFuture<RpcResult<TempServiceDeleteOutput>> result = servicehandlerImpl.tempServiceDelete(input);
-        result.addListener(new Runnable() {
-            @Override
-            public void run() {
-                endSignal.countDown();
-            }
-        }, executorService);
+        ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
+                rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
+                networkModelListenerImpl, serviceDataStoreOperations);
+        ListenableFuture<RpcResult<TempServiceDeleteOutput>> result = servicehandlerImpl.tempServiceDelete(
+                ServiceDataUtils.buildTempServiceDeleteInput());
+        result.addListener(() -> endSignal.countDown(), executorService);
 
         endSignal.await();
-
-        RpcResult<TempServiceDeleteOutput> rpcResult = result.get();
-        Assert.assertEquals(
-            ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
+        Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
+                result.get().getResult().getConfigurationResponseCommon().getResponseCode());
     }
 
     @Test
     public void tempServiceDeleteShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
-        DataBroker dataBroker = getNewDataBroker();
         Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any()));
 
         //create temp service to delete in the temp delete action
         ServicehandlerImpl servicehandlerImpl =
-                new ServicehandlerImpl(dataBroker, pathComputationService, rendererServiceOperations,
+                new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
                         notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
                         serviceDataStoreOperations);
         TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
         serviceDataStoreOperations.createTempService(createInput);
 
-
         TempServiceDeleteInput input = ServiceDataUtils.buildTempServiceDeleteInput(createInput.getCommonId());
         ListenableFuture<RpcResult<TempServiceDeleteOutput>> result = servicehandlerImpl.tempServiceDelete(input);
-        result.addListener(new Runnable() {
-            @Override
-            public void run() {
-                endSignal.countDown();
-            }
-        }, executorService);
+        result.addListener(() -> endSignal.countDown(), executorService);
 
         endSignal.await();
-
-        RpcResult<TempServiceDeleteOutput> rpcResult = result.get();
         Assert.assertEquals(
-                ResponseCodes.RESPONSE_OK, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
+                ResponseCodes.RESPONSE_OK, result.get().getResult().getConfigurationResponseCommon().getResponseCode());
     }
 
     @Test
     public void tempServiceCreateShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
-        ServicehandlerImpl servicehandlerImpl =
-                new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
-                        notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
-                        serviceDataStoreOperations);
+        ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
+                rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
+                networkModelListenerImpl, serviceDataStoreOperations);
         ListenableFuture<RpcResult<TempServiceCreateOutput>> result =
                 servicehandlerImpl.tempServiceCreate(new TempServiceCreateInputBuilder().build());
-        result.addListener(new Runnable() {
-            @Override
-            public void run() {
-                endSignal.countDown();
-            }
-        }, executorService);
+        result.addListener(() -> endSignal.countDown(), executorService);
 
         endSignal.await();
-
-        RpcResult<TempServiceCreateOutput> rpcResult = result.get();
-        Assert.assertEquals(
-            ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
+        Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
+                result.get().getResult().getConfigurationResponseCommon().getResponseCode());
     }
 
 
     @Test
-    public void tempServiceCreateShouldBeSuccessfulWhenPreformPCESuccessful()
+    public void tempServiceCreateShouldBeSuccessfulWhenPerformPCESuccessful()
             throws ExecutionException, InterruptedException {
-        TempServiceCreateInput input = ServiceDataUtils.buildTempServiceCreateInput();
         Mockito.when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
 
-        ServicehandlerImpl servicehandlerImpl =
-                new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
-                        notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl,
-                        serviceDataStoreOperations);
+        ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
+                rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
+                networkModelListenerImpl, serviceDataStoreOperations);
 
-        ListenableFuture<RpcResult<TempServiceCreateOutput>> result =  servicehandlerImpl.tempServiceCreate(input);
-        result.addListener(new Runnable() {
-            @Override
-            public void run() {
-                endSignal.countDown();
-            }
-        }, executorService);
+        ListenableFuture<RpcResult<TempServiceCreateOutput>> result = servicehandlerImpl.tempServiceCreate(
+                ServiceDataUtils.buildTempServiceCreateInput());
+        result.addListener(() -> endSignal.countDown(), executorService);
 
         endSignal.await();
-
-        RpcResult<TempServiceCreateOutput> rpcResult = result.get();
-
         Assert.assertEquals(
-                ResponseCodes.RESPONSE_OK, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
+                ResponseCodes.RESPONSE_OK, result.get().getResult().getConfigurationResponseCommon().getResponseCode());
     }
 
 }