X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=servicehandler%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fservicehandler%2Fimpl%2FServicehandlerImplTest.java;h=f023384dbdbf5a3e1d839207b107b31030c1d19c;hb=61a429b5b722d038a03c56645b0b56907203c540;hp=69cc71bd045f3c35bae562c4c871e424deb20ff6;hpb=070d949ff92a5a57c7cd46a94b913473c89a8e79;p=transportpce.git diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImplTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImplTest.java index 69cc71bd0..f023384db 100644 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImplTest.java +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImplTest.java @@ -8,39 +8,59 @@ package org.opendaylight.transportpce.servicehandler.impl; import static org.mockito.ArgumentMatchers.any; +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.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executors; - import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +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; import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations; +import org.opendaylight.transportpce.servicehandler.listeners.NetworkModelListenerImpl; import org.opendaylight.transportpce.servicehandler.listeners.PceListenerImpl; import org.opendaylight.transportpce.servicehandler.listeners.RendererListenerImpl; +import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations; import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperationsImpl; import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils; import org.opendaylight.transportpce.test.AbstractTest; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInputBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateOutput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteInput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteInputBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteOutput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.delete.input.ServiceDeleteReqInfoBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev190531.RpcStatus; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateInputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteInputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceFeasibilityCheckInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceFeasibilityCheckInputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceFeasibilityCheckOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceReconfigureInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceReconfigureInputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceReconfigureOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRerouteInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRerouteInputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRerouteOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRestorationInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRestorationInputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRestorationOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceCreateInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceCreateInputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceCreateOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceDeleteInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceDeleteInputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceDeleteOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.delete.input.ServiceDeleteReqInfoBuilder; import org.opendaylight.yangtools.yang.common.RpcResult; public class ServicehandlerImplTest extends AbstractTest { @@ -60,30 +80,33 @@ public class ServicehandlerImplTest extends AbstractTest { @Mock private RendererListenerImpl rendererListenerImpl; + @Mock + private NetworkModelListenerImpl networkModelListenerImpl; + + private ServiceDataStoreOperations serviceDataStoreOperations; private ListeningExecutorService executorService; private CountDownLatch endSignal; private static final int NUM_THREADS = 5; - private boolean callbackRan; @Before public void setUp() { executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS)); endSignal = new CountDownLatch(1); - callbackRan = false; - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); + this.serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(getNewDataBroker()); } @Test public void createServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, null); + notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations); ListenableFuture> result = servicehandlerImpl.serviceCreate(new ServiceCreateInputBuilder().build()); result.addListener(new Runnable() { @Override public void run() { - callbackRan = true; endSignal.countDown(); } }, executorService); @@ -102,12 +125,12 @@ public class ServicehandlerImplTest extends AbstractTest { Mockito.when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any())); ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, null); + notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations); ListenableFuture> result = servicehandlerImpl.serviceCreate(input); result.addListener(new Runnable() { @Override public void run() { - callbackRan = true; endSignal.countDown(); } }, executorService); @@ -123,14 +146,14 @@ public class ServicehandlerImplTest extends AbstractTest { public void deleteServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, null); + notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations); ListenableFuture> result = - servicehandlerImpl.serviceDelete(new ServiceDeleteInputBuilder() + servicehandlerImpl.serviceDelete(new ServiceDeleteInputBuilder() .setServiceDeleteReqInfo(new ServiceDeleteReqInfoBuilder().setServiceName("").build()).build()); result.addListener(new Runnable() { @Override public void run() { - callbackRan = true; endSignal.countDown(); } }, executorService); @@ -147,12 +170,12 @@ public class ServicehandlerImplTest extends AbstractTest { ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput(); ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, null); + notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations); ListenableFuture> result = servicehandlerImpl.serviceDelete(input); result.addListener(new Runnable() { @Override public void run() { - callbackRan = true; endSignal.countDown(); } }, executorService); @@ -167,11 +190,11 @@ public class ServicehandlerImplTest extends AbstractTest { @Test public void deleteServiceShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException { DataBroker dataBroker = getNewDataBroker(); - Mockito.when(rendererServiceOperations.serviceDelete(any())).thenReturn(Futures.immediateFuture(any())); + Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any())); ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(dataBroker, pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, null); - ServiceDataStoreOperationsImpl serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(dataBroker); + notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations); ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput(); serviceDataStoreOperations.createService(createInput); ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput(); @@ -179,7 +202,6 @@ public class ServicehandlerImplTest extends AbstractTest { result.addListener(new Runnable() { @Override public void run() { - callbackRan = true; endSignal.countDown(); } }, executorService); @@ -190,4 +212,426 @@ public class ServicehandlerImplTest extends AbstractTest { Assert.assertEquals( ResponseCodes.RESPONSE_OK, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode()); } + + + @Test + public void serviceFeasibilityCheckShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { + ServicehandlerImpl servicehandlerImpl = + new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, + notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations); + ListenableFuture> result = + servicehandlerImpl.serviceFeasibilityCheck(new ServiceFeasibilityCheckInputBuilder().build()); + result.addListener(new Runnable() { + @Override + public void run() { + endSignal.countDown(); + } + }, executorService); + + endSignal.await(); + + RpcResult rpcResult = result.get(); + Assert.assertEquals( + ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode()); + } + + @Test + public void serviceFeasibilityCheckShouldBeSuccessfulWhenPreformPCESuccessful() + 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); + ListenableFuture> result = + servicehandlerImpl.serviceFeasibilityCheck(input); + result.addListener(new Runnable() { + @Override + public void run() { + endSignal.countDown(); + } + }, executorService); + + endSignal.await(); + + RpcResult rpcResult = result.get(); + Assert.assertEquals( + ResponseCodes.RESPONSE_OK, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode()); + } + + @Test + public void serviceReconfigureShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { + ServicehandlerImpl servicehandlerImpl = + new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, + notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations); + ListenableFuture> result = + servicehandlerImpl.serviceReconfigure(new ServiceReconfigureInputBuilder().setServiceName("").build()); + result.addListener(new Runnable() { + @Override + public void run() { + endSignal.countDown(); + } + }, executorService); + + endSignal.await(); + + RpcResult rpcResult = result.get(); + Assert.assertEquals( + RpcStatus.Failed, rpcResult.getResult().getStatus()); + } + + + @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> result = servicehandlerImpl.serviceReconfigure(input); + + result.addListener(new Runnable() { + @Override + public void run() { + endSignal.countDown(); + } + }, executorService); + + endSignal.await(); + + RpcResult rpcResult = result.get(); + //ServiceReconfigureOutput doesn't have ConfigurationResponseCommon but have RpcStatus directly + Assert.assertEquals( + RpcStatus.Failed, rpcResult.getResult().getStatus()); + } + + @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); + + //service reconfigure test action + ServiceReconfigureInput input = ServiceDataUtils.buildServiceReconfigureInput(); + //ServiceReconfigureInput is created with the same service information that is created before + ListenableFuture> result = servicehandlerImpl.serviceReconfigure(input); + result.addListener(new Runnable() { + @Override + public void run() { + endSignal.countDown(); + } + }, executorService); + + endSignal.await(); + + RpcResult rpcResult = result.get(); + Assert.assertEquals( + RpcStatus.Successful, rpcResult.getResult().getStatus()); + } + + @Test + public void serviceReRestorationShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { + ServicehandlerImpl servicehandlerImpl = + new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, + notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations); + ListenableFuture> result = + servicehandlerImpl.serviceRestoration(new ServiceRestorationInputBuilder().setServiceName("").build()); + result.addListener(new Runnable() { + @Override + public void run() { + endSignal.countDown(); + } + }, executorService); + + endSignal.await(); + + RpcResult rpcResult = result.get(); + Assert.assertEquals( + RpcStatus.Failed, rpcResult.getResult().getStatus()); + } + + + @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> result = servicehandlerImpl.serviceRestoration(input); + + result.addListener(new Runnable() { + @Override + public void run() { + endSignal.countDown(); + } + }, executorService); + + endSignal.await(); + + RpcResult rpcResult = result.get(); + //ServiceRestorationOutput doesn't have ConfigurationResponseCommon but have RpcStatus directly + Assert.assertEquals( + RpcStatus.Failed, rpcResult.getResult().getStatus()); + } + + @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); + + //service Restoration test action + ServiceRestorationInput input = ServiceDataUtils.buildServiceRestorationInput(); + //ServiceRestorationInput is created with the same service information that is created before + ListenableFuture> result = servicehandlerImpl.serviceRestoration(input); + result.addListener(new Runnable() { + @Override + public void run() { + endSignal.countDown(); + } + }, executorService); + + endSignal.await(); + + RpcResult rpcResult = result.get(); + Assert.assertEquals( + RpcStatus.Successful, rpcResult.getResult().getStatus()); + } + + @Test + public void serviceRerouteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { + ServicehandlerImpl servicehandlerImpl = + new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, + notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations); + ListenableFuture> result = + servicehandlerImpl.serviceReroute(new ServiceRerouteInputBuilder().setServiceName("").build()); + result.addListener(new Runnable() { + @Override + public void run() { + endSignal.countDown(); + } + }, executorService); + + endSignal.await(); + + RpcResult rpcResult = result.get(); + Assert.assertEquals( + RpcStatus.Failed, rpcResult.getResult().getStatus()); + } + + @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> result = servicehandlerImpl.serviceReroute(input); + + result.addListener(new Runnable() { + @Override + public void run() { + endSignal.countDown(); + } + }, executorService); + + endSignal.await(); + + RpcResult rpcResult = result.get(); + //ServiceRerouteOutput doesn't have ConfigurationResponseCommon but have RpcStatus directly + Assert.assertEquals( + RpcStatus.Failed, rpcResult.getResult().getStatus()); + } + + @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); + + //service reroute test action + ServiceRerouteInput input = ServiceDataUtils.buildServiceRerouteInput(); + //ServiceRerouteInput is created with the same service information that is created before + ListenableFuture> result = servicehandlerImpl.serviceReroute(input); + result.addListener(new Runnable() { + @Override + public void run() { + endSignal.countDown(); + } + }, executorService); + + endSignal.await(); + + RpcResult rpcResult = result.get(); + Assert.assertEquals( + RpcStatus.Successful, rpcResult.getResult().getStatus()); + } + + @Test + public void tempServiceDeleteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { + ServicehandlerImpl servicehandlerImpl = + new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, + notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations); + ListenableFuture> result = + servicehandlerImpl.tempServiceDelete(new TempServiceDeleteInputBuilder() + .setCommonId("").build()); + result.addListener(new Runnable() { + @Override + public void run() { + endSignal.countDown(); + } + }, executorService); + + endSignal.await(); + + RpcResult rpcResult = result.get(); + Assert.assertEquals( + ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode()); + Assert.assertEquals( + 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> result = servicehandlerImpl.tempServiceDelete(input); + result.addListener(new Runnable() { + @Override + public void run() { + endSignal.countDown(); + } + }, executorService); + + endSignal.await(); + + RpcResult rpcResult = result.get(); + Assert.assertEquals( + ResponseCodes.RESPONSE_FAILED, rpcResult.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, + notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations); + TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput(); + serviceDataStoreOperations.createTempService(createInput); + + + TempServiceDeleteInput input = ServiceDataUtils.buildTempServiceDeleteInput(createInput.getCommonId()); + ListenableFuture> result = servicehandlerImpl.tempServiceDelete(input); + result.addListener(new Runnable() { + @Override + public void run() { + endSignal.countDown(); + } + }, executorService); + + endSignal.await(); + + RpcResult rpcResult = result.get(); + Assert.assertEquals( + ResponseCodes.RESPONSE_OK, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode()); + } + + @Test + public void tempServiceCreateShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { + ServicehandlerImpl servicehandlerImpl = + new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, + notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations); + ListenableFuture> result = + servicehandlerImpl.tempServiceCreate(new TempServiceCreateInputBuilder().build()); + result.addListener(new Runnable() { + @Override + public void run() { + endSignal.countDown(); + } + }, executorService); + + endSignal.await(); + + RpcResult rpcResult = result.get(); + Assert.assertEquals( + ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode()); + } + + + @Test + public void tempServiceCreateShouldBeSuccessfulWhenPreformPCESuccessful() + 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); + + ListenableFuture> result = servicehandlerImpl.tempServiceCreate(input); + result.addListener(new Runnable() { + @Override + public void run() { + endSignal.countDown(); + } + }, executorService); + + endSignal.await(); + + RpcResult rpcResult = result.get(); + + Assert.assertEquals( + ResponseCodes.RESPONSE_OK, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode()); + } + }