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=641c107a341cddf1e2e9622f8443f2d2e14c0780;hb=56ad6406faba3227e19a6f609325c8b9dbaca3fb;hp=38c2cdc14d2e762d31fb19d0a1f45917a9ecda09;hpb=f5a8fe61d265bce36b2fca393d82685a22ac326a;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 38c2cdc14..641c107a3 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,6 +8,7 @@ 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; @@ -27,8 +28,10 @@ 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; @@ -77,6 +80,10 @@ 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; @@ -87,14 +94,16 @@ public class ServicehandlerImplTest extends AbstractTest { 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, "ServiceHandler"); ListenableFuture> result = servicehandlerImpl.serviceCreate(new ServiceCreateInputBuilder().build()); result.addListener(new Runnable() { @@ -119,7 +128,8 @@ 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, "ServiceHandler"); ListenableFuture> result = servicehandlerImpl.serviceCreate(input); result.addListener(new Runnable() { @Override @@ -140,9 +150,10 @@ 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, "ServiceHandler"); ListenableFuture> result = - servicehandlerImpl.serviceDelete(new ServiceDeleteInputBuilder() + servicehandlerImpl.serviceDelete(new ServiceDeleteInputBuilder() .setServiceDeleteReqInfo(new ServiceDeleteReqInfoBuilder().setServiceName("").build()).build()); result.addListener(new Runnable() { @Override @@ -164,7 +175,8 @@ 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, "ServiceHandler"); ListenableFuture> result = servicehandlerImpl.serviceDelete(input); result.addListener(new Runnable() { @Override @@ -184,11 +196,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, "ServiceHandler"); ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput(); serviceDataStoreOperations.createService(createInput); ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput(); @@ -213,7 +225,8 @@ public class ServicehandlerImplTest extends AbstractTest { public void serviceFeasibilityCheckShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, null); + notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, "ServiceHandler"); ListenableFuture> result = servicehandlerImpl.serviceFeasibilityCheck(new ServiceFeasibilityCheckInputBuilder().build()); result.addListener(new Runnable() { @@ -238,7 +251,8 @@ 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, "ServiceHandler"); ListenableFuture> result = servicehandlerImpl.serviceFeasibilityCheck(input); result.addListener(new Runnable() { @@ -260,7 +274,8 @@ public class ServicehandlerImplTest extends AbstractTest { public void serviceReconfigureShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, null); + notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, "ServiceHandler"); ListenableFuture> result = servicehandlerImpl.serviceReconfigure(new ServiceReconfigureInputBuilder().setServiceName("").build()); result.addListener(new Runnable() { @@ -286,7 +301,8 @@ public class ServicehandlerImplTest extends AbstractTest { //action -> service reconfigure ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, null); + notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, "ServiceHandler"); ListenableFuture> result = servicehandlerImpl.serviceReconfigure(input); result.addListener(new Runnable() { @@ -311,12 +327,12 @@ public class ServicehandlerImplTest extends AbstractTest { //mocking // serviceReconfigure is calling service delete method in renderer - Mockito.when(rendererServiceOperations.serviceDelete(any())).thenReturn(Futures.immediateFuture(any())); + Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any())); //create service to reconfigure ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(dataBroker, pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, null); - ServiceDataStoreOperationsImpl serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(dataBroker); + notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, "ServiceHandler"); ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput(); serviceDataStoreOperations.createService(createInput); @@ -343,7 +359,8 @@ public class ServicehandlerImplTest extends AbstractTest { public void serviceReRestorationShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, null); + notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, "ServiceHandler"); ListenableFuture> result = servicehandlerImpl.serviceRestoration(new ServiceRestorationInputBuilder().setServiceName("").build()); result.addListener(new Runnable() { @@ -369,7 +386,8 @@ public class ServicehandlerImplTest extends AbstractTest { //action -> service restore ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, null); + notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, "ServiceHandler"); ListenableFuture> result = servicehandlerImpl.serviceRestoration(input); result.addListener(new Runnable() { @@ -394,12 +412,12 @@ public class ServicehandlerImplTest extends AbstractTest { //mocking // serviceRestoration is calling service delete method in renderer - Mockito.when(rendererServiceOperations.serviceDelete(any())).thenReturn(Futures.immediateFuture(any())); + Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any())); //create service to restore ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(dataBroker, pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, null); - ServiceDataStoreOperationsImpl serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(dataBroker); + notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, "ServiceHandler"); ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput(); serviceDataStoreOperations.createService(createInput); @@ -426,7 +444,8 @@ public class ServicehandlerImplTest extends AbstractTest { public void serviceRerouteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, null); + notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, "ServiceHandler"); ListenableFuture> result = servicehandlerImpl.serviceReroute(new ServiceRerouteInputBuilder().setServiceName("").build()); result.addListener(new Runnable() { @@ -451,7 +470,8 @@ public class ServicehandlerImplTest extends AbstractTest { //action -> service reconfigure ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, null); + notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, "ServiceHandler"); ListenableFuture> result = servicehandlerImpl.serviceReroute(input); result.addListener(new Runnable() { @@ -476,12 +496,12 @@ public class ServicehandlerImplTest extends AbstractTest { //mocking // serviceReroute is calling service delete method in renderer - Mockito.when(rendererServiceOperations.serviceDelete(any())).thenReturn(Futures.immediateFuture(any())); + 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, null); - ServiceDataStoreOperationsImpl serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(dataBroker); + notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, "ServiceHandler"); ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput(); serviceDataStoreOperations.createService(createInput); @@ -508,7 +528,8 @@ public class ServicehandlerImplTest extends AbstractTest { public void tempServiceDeleteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, null); + notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, "ServiceHandler"); ListenableFuture> result = servicehandlerImpl.tempServiceDelete(new TempServiceDeleteInputBuilder() .setCommonId("").build()); @@ -526,7 +547,8 @@ public class ServicehandlerImplTest extends AbstractTest { Assert.assertEquals( ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode()); Assert.assertEquals( - "Service not compliant !", rpcResult.getResult().getConfigurationResponseCommon().getResponseMessage()); + LogMessages.SERVICE_NON_COMPLIANT, + rpcResult.getResult().getConfigurationResponseCommon().getResponseMessage()); } @Test @@ -534,7 +556,8 @@ public class ServicehandlerImplTest extends AbstractTest { TempServiceDeleteInput input = ServiceDataUtils.buildTempServiceDeleteInput(); ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, null); + notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, "ServiceHandler"); ListenableFuture> result = servicehandlerImpl.tempServiceDelete(input); result.addListener(new Runnable() { @Override @@ -554,13 +577,13 @@ public class ServicehandlerImplTest extends AbstractTest { @Test public void tempServiceDeleteShouldBeSuccessForExistingService() 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())); //create temp service to delete in the temp delete action ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(dataBroker, pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, null); - ServiceDataStoreOperationsImpl serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(dataBroker); + notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, "ServiceHandler"); TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput(); serviceDataStoreOperations.createTempService(createInput); @@ -586,7 +609,8 @@ public class ServicehandlerImplTest extends AbstractTest { public void tempServiceCreateShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, null); + notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, "ServiceHandler"); ListenableFuture> result = servicehandlerImpl.tempServiceCreate(new TempServiceCreateInputBuilder().build()); result.addListener(new Runnable() { @@ -613,7 +637,8 @@ public class ServicehandlerImplTest extends AbstractTest { ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, null); + notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, "ServiceHandler"); ListenableFuture> result = servicehandlerImpl.tempServiceCreate(input); result.addListener(new Runnable() {