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=5095a93c090c8e96e5b049154213d12e18a99f20;hb=5a59a59e40a4c6d8176666965f469d0c3f6d7487;hp=63445c36d05fc948e3d13a38e9e550d2996ccc18;hpb=e2af857602888e5347f137aac70f73ad02bb6c76;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 63445c36d..5095a93c0 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 @@ -7,8 +7,10 @@ */ package org.opendaylight.transportpce.servicehandler.impl; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import static org.opendaylight.transportpce.servicehandler.impl.ServicehandlerImpl.LogMessages; import com.google.common.util.concurrent.Futures; @@ -21,27 +23,35 @@ 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.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.jupiter.MockitoExtension; import org.opendaylight.mdsal.binding.api.NotificationPublishService; import org.opendaylight.transportpce.common.ResponseCodes; +import org.opendaylight.transportpce.common.network.NetworkTransactionImpl; import org.opendaylight.transportpce.pce.service.PathComputationService; import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations; import org.opendaylight.transportpce.servicehandler.ServiceInput; -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.catalog.CatalogDataStoreOperations; +import org.opendaylight.transportpce.servicehandler.catalog.CatalogDataStoreOperationsImpl; +import org.opendaylight.transportpce.servicehandler.listeners.NetworkListener; +import org.opendaylight.transportpce.servicehandler.listeners.PceListener; +import org.opendaylight.transportpce.servicehandler.listeners.RendererListener; import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations; import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperationsImpl; +import org.opendaylight.transportpce.servicehandler.utils.CatalogDataUtils; import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils; import org.opendaylight.transportpce.test.AbstractTest; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestOutputBuilder; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRerouteRequestOutputBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.configuration.response.common.ConfigurationResponseCommonBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.AddOpenroadmOperationalModesToCatalogInputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.AddOpenroadmOperationalModesToCatalogOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.AddSpecificOperationalModesToCatalogInputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.AddSpecificOperationalModesToCatalogOutput; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceCreateInput; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceCreateInputBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceCreateOutput; @@ -62,44 +72,40 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.Service import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceCreateInput; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceCreateInputBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceCreateOutput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceDeleteInput; 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.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.AToZDirectionBuilder; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ZToADirectionBuilder; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.atoz.direction.AToZ; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.atoz.direction.AToZBuilder; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.atoz.direction.AToZKey; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.ResourceBuilder; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.resource.resource.TerminationPointBuilder; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.AToZDirectionBuilder; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.ZToADirectionBuilder; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.atoz.direction.AToZ; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.atoz.direction.AToZBuilder; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.atoz.direction.AToZKey; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.pce.resource.ResourceBuilder; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.pce.resource.resource.resource.TerminationPointBuilder; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response.parameters.sp.ResponseParametersBuilder; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response.parameters.sp.response.parameters.PathDescriptionBuilder; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.Uint32; +@ExtendWith(MockitoExtension.class) public class ServicehandlerImplTest extends AbstractTest { @Mock private PathComputationService pathComputationService; - @Mock private RendererServiceOperations rendererServiceOperations; - @Mock private NotificationPublishService notificationPublishService; - @Mock - private PceListenerImpl pceListenerImpl; - + private PceListener pceListenerImpl; @Mock - private RendererListenerImpl rendererListenerImpl; - + private RendererListener rendererListenerImpl; @Mock - private NetworkModelListenerImpl networkModelListenerImpl; + private NetworkListener networkModelListenerImpl; private ServiceDataStoreOperations serviceDataStoreOperations; + private CatalogDataStoreOperations catalogDataStoreOperations; private ServiceCreateInput serviceCreateInput; private ServiceDeleteInput serviceDeleteInput; private ServiceReconfigureInput serviceReconfigureInput; @@ -109,12 +115,13 @@ public class ServicehandlerImplTest extends AbstractTest { private CountDownLatch endSignal; private static final int NUM_THREADS = 5; - @Before - public void setUp() { + @BeforeEach + void setUp() { executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS)); endSignal = new CountDownLatch(1); - MockitoAnnotations.openMocks(this); this.serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(getNewDataBroker()); + this.catalogDataStoreOperations = + new CatalogDataStoreOperationsImpl(new NetworkTransactionImpl(getDataBroker())); serviceCreateInput = ServiceDataUtils.buildServiceCreateInput(); serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput(); serviceReconfigureInput = ServiceDataUtils.buildServiceReconfigureInput(); @@ -123,268 +130,270 @@ public class ServicehandlerImplTest extends AbstractTest { } @Test - public void createServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { - ServicehandlerImpl servicehandlerImpl = - new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations); + void createServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ListenableFuture> result = - servicehandlerImpl.serviceCreate(new ServiceCreateInputBuilder().build()); + new ServicehandlerImpl( + pathComputationService, rendererServiceOperations, notificationPublishService, + pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, catalogDataStoreOperations) + .serviceCreate(new ServiceCreateInputBuilder().build()); result.addListener(() -> endSignal.countDown(), executorService); - endSignal.await(); - Assert.assertEquals( - ResponseCodes.RESPONSE_FAILED, - result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } @Test - public void createServiceShouldBeFailedWithServiceAlreadyExist() throws ExecutionException, - InterruptedException { + void createServiceShouldBeFailedWithServiceAlreadyExist() throws ExecutionException, InterruptedException { final ServiceDataStoreOperations serviceDSOperations = mock(ServiceDataStoreOperations.class); - Mockito.when(serviceDSOperations.getService(serviceCreateInput.getServiceName())) + 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> result = servicehandlerImpl.serviceCreate(serviceCreateInput); + ListenableFuture> result = + new ServicehandlerImpl( + pathComputationService, rendererServiceOperations, notificationPublishService, + pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDSOperations, catalogDataStoreOperations) + .serviceCreate(serviceCreateInput); result.addListener(() -> endSignal.countDown(), executorService); - endSignal.await(); - Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, - result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } @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> result = servicehandlerImpl.serviceCreate(serviceCreateInput); + void createServiceShouldBeSuccessfulWhenPerformPCESuccessful() throws ExecutionException, InterruptedException { + when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any())); + ListenableFuture> result = + new ServicehandlerImpl( + pathComputationService, rendererServiceOperations, notificationPublishService, + pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, catalogDataStoreOperations) + .serviceCreate(serviceCreateInput); result.addListener(() -> endSignal.countDown(), executorService); - endSignal.await(); - Assert.assertEquals( - ResponseCodes.RESPONSE_OK, result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + 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> result = servicehandlerImpl.serviceDelete( - new ServiceDeleteInputBuilder() + void deleteServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { + ListenableFuture> result = + new ServicehandlerImpl( + pathComputationService, rendererServiceOperations, notificationPublishService, + pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, catalogDataStoreOperations) + .serviceDelete( + new ServiceDeleteInputBuilder() .setServiceDeleteReqInfo(new ServiceDeleteReqInfoBuilder() .setServiceName("") .build()) .build()); result.addListener(() -> endSignal.countDown(), executorService); - endSignal.await(); - Assert.assertEquals( - ResponseCodes.RESPONSE_FAILED, - result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } @Test - public void deleteServiceShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { - ServicehandlerImpl servicehandlerImpl = - new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations); - ListenableFuture> result = servicehandlerImpl.serviceDelete(serviceDeleteInput); + void deleteServiceShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { + ListenableFuture> result = + new ServicehandlerImpl( + pathComputationService, rendererServiceOperations, notificationPublishService, + pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, catalogDataStoreOperations) + .serviceDelete(serviceDeleteInput); result.addListener(() -> endSignal.countDown(), executorService); - endSignal.await(); - Assert.assertEquals( - ResponseCodes.RESPONSE_FAILED, - result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } @Test - public void deleteServiceShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException { - Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any())); - ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, - rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, - networkModelListenerImpl, serviceDataStoreOperations); + void deleteServiceShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException { + when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any())); serviceDataStoreOperations.createService(serviceCreateInput); - ListenableFuture> result = servicehandlerImpl.serviceDelete(serviceDeleteInput); + ListenableFuture> result = + new ServicehandlerImpl( + pathComputationService, rendererServiceOperations, notificationPublishService, + pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, catalogDataStoreOperations) + .serviceDelete(serviceDeleteInput); result.addListener(() -> endSignal.countDown(), executorService); - endSignal.await(); - Assert.assertEquals( - ResponseCodes.RESPONSE_OK, result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + ResponseCodes.RESPONSE_OK, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } - @Test - public void serviceFeasibilityCheckShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { - ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, + void serviceFeasibilityCheckShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { + ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(pathComputationService, rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, - networkModelListenerImpl, serviceDataStoreOperations); + networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations); ListenableFuture> result = servicehandlerImpl.serviceFeasibilityCheck(new ServiceFeasibilityCheckInputBuilder().build()); result.addListener(() -> endSignal.countDown(), executorService); - endSignal.await(); - Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, - result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } @Test - public void serviceFeasibilityCheckShouldBeSuccessfulWhenPerformPCESuccessful() + void serviceFeasibilityCheckShouldBeSuccessfulWhenPerformPCESuccessful() throws ExecutionException, InterruptedException { - Mockito.when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any())); - ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, - rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, - networkModelListenerImpl, serviceDataStoreOperations); + when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any())); ListenableFuture> result = - servicehandlerImpl.serviceFeasibilityCheck(ServiceDataUtils.buildServiceFeasibilityCheckInput()); + new ServicehandlerImpl( + pathComputationService, rendererServiceOperations, notificationPublishService, + pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, catalogDataStoreOperations) + .serviceFeasibilityCheck(ServiceDataUtils.buildServiceFeasibilityCheckInput()); result.addListener(() -> endSignal.countDown(), executorService); - endSignal.await(); - Assert.assertEquals( - ResponseCodes.RESPONSE_OK, result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + 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); + void serviceReconfigureShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ListenableFuture> result = - servicehandlerImpl.serviceReconfigure(new ServiceReconfigureInputBuilder().setServiceName("").build()); + new ServicehandlerImpl( + pathComputationService, rendererServiceOperations, notificationPublishService, + pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, catalogDataStoreOperations) + .serviceReconfigure(new ServiceReconfigureInputBuilder().setServiceName("").build()); result.addListener(() -> endSignal.countDown(), executorService); - endSignal.await(); } @Test - public void serviceReconfigureShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { + void serviceReconfigureShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { //action -> service reconfigure - ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, - rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, - networkModelListenerImpl, serviceDataStoreOperations); - ListenableFuture> result = servicehandlerImpl.serviceReconfigure( - serviceReconfigureInput); - + ListenableFuture> result = + new ServicehandlerImpl( + pathComputationService, rendererServiceOperations, notificationPublishService, + pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, catalogDataStoreOperations) + .serviceReconfigure(serviceReconfigureInput); result.addListener(() -> endSignal.countDown(), executorService); - endSignal.await(); } @Test - public void serviceReconfigureShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException { + void serviceReconfigureShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException { // serviceReconfigure is calling service delete method in renderer - Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any())); + when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any())); //create service to reconfigure - ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, - rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, - networkModelListenerImpl, serviceDataStoreOperations); serviceDataStoreOperations.createService(serviceCreateInput); - //service reconfigure test action //ServiceReconfigureInput is created with the same service information that is created before - ListenableFuture> result = servicehandlerImpl.serviceReconfigure( - serviceReconfigureInput); + ListenableFuture> result = + new ServicehandlerImpl( + pathComputationService, rendererServiceOperations, notificationPublishService, + pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, catalogDataStoreOperations) + .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); + void serviceReRestorationShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ListenableFuture> result = - servicehandlerImpl.serviceRestoration(new ServiceRestorationInputBuilder().setServiceName("").build()); + new ServicehandlerImpl( + pathComputationService, rendererServiceOperations, notificationPublishService, + pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, catalogDataStoreOperations) + .serviceRestoration(new ServiceRestorationInputBuilder() + .setServiceName("") + .build()); result.addListener(() -> endSignal.countDown(), executorService); - endSignal.await(); } - @Test - public void serviceRestorationShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { + void serviceRestorationShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { //action -> service restore - ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, - rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, - networkModelListenerImpl, serviceDataStoreOperations); - ListenableFuture> result = servicehandlerImpl.serviceRestoration( - serviceRestorationInput); - + ListenableFuture> result = + new ServicehandlerImpl( + pathComputationService, rendererServiceOperations, notificationPublishService, + pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, catalogDataStoreOperations) + .serviceRestoration(serviceRestorationInput); result.addListener(() -> endSignal.countDown(), executorService); - endSignal.await(); } @Test - public void serviceRestorationShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException { + void serviceRestorationShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException { // serviceRestoration is calling service delete method in renderer - Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any())); + when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any())); //create service to restore - ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, - rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, - networkModelListenerImpl, serviceDataStoreOperations); serviceDataStoreOperations.createService(serviceCreateInput); - //service Restoration test action //ServiceRestorationInput is created with the same service information that is created before - ListenableFuture> result = servicehandlerImpl.serviceRestoration( - serviceRestorationInput); + ListenableFuture> result = + new ServicehandlerImpl( + pathComputationService, rendererServiceOperations, notificationPublishService, + pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, catalogDataStoreOperations) + .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); + void serviceRerouteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ListenableFuture> result = - servicehandlerImpl.serviceReroute(new ServiceRerouteInputBuilder().setServiceName("").build()); + new ServicehandlerImpl( + pathComputationService, rendererServiceOperations, notificationPublishService, + pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, catalogDataStoreOperations) + .serviceReroute(new ServiceRerouteInputBuilder() + .setServiceName("") + .build()); result.addListener(() -> endSignal.countDown(), executorService); - endSignal.await(); - - Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, - result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } @Test - public void serviceRerouteShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { + void serviceRerouteShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { //action -> service reconfigure - ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, - rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, - networkModelListenerImpl, serviceDataStoreOperations); - ListenableFuture> result = servicehandlerImpl.serviceReroute( - serviceRerouteInput); - + ListenableFuture> result = + new ServicehandlerImpl( + pathComputationService, rendererServiceOperations, notificationPublishService, + pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, catalogDataStoreOperations) + .serviceReroute(serviceRerouteInput); result.addListener(() -> endSignal.countDown(), executorService); - endSignal.await(); - - Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, - result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } @Test - public void serviceRerouteShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException { - Mockito.when(pathComputationService.pathComputationRerouteRequest(any())) - .thenReturn(Futures.immediateFuture(new PathComputationRerouteRequestOutputBuilder() - .setConfigurationResponseCommon(new ConfigurationResponseCommonBuilder() - .setResponseCode(ResponseCodes.RESPONSE_OK) - .build()) - .build())); + void serviceRerouteShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException { + when(pathComputationService.pathComputationRerouteRequest(any())) + .thenReturn(Futures.immediateFuture(new PathComputationRerouteRequestOutputBuilder() + .setConfigurationResponseCommon(new ConfigurationResponseCommonBuilder() + .setResponseCode(ResponseCodes.RESPONSE_OK) + .build()) + .build())); Map atoz = Map.of( new AToZKey("0"), new AToZBuilder() @@ -434,106 +443,160 @@ public class ServicehandlerImplTest extends AbstractTest { .build()) .build()) .build()); - serviceDataStoreOperations.createService(serviceCreateInput); - ListenableFuture> result = new ServicehandlerImpl(getNewDataBroker(), - pathComputationService, rendererServiceOperations, notificationPublishService, pceListenerImpl, - rendererListenerImpl, networkModelListenerImpl, serviceDataStoreOperations) + ListenableFuture> result = + new ServicehandlerImpl( + pathComputationService, rendererServiceOperations, notificationPublishService, + pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, catalogDataStoreOperations) .serviceReroute(serviceRerouteInput); result.addListener(() -> endSignal.countDown(), executorService); - endSignal.await(); - - Assert.assertEquals( - ResponseCodes.RESPONSE_OK, result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + ResponseCodes.RESPONSE_OK, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } @Test - public void tempServiceDeleteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { - ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, - rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, - networkModelListenerImpl, serviceDataStoreOperations); + void tempServiceDeleteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ListenableFuture> result = - servicehandlerImpl.tempServiceDelete(new TempServiceDeleteInputBuilder().setCommonId("").build()); + new ServicehandlerImpl( + pathComputationService, rendererServiceOperations, notificationPublishService, + pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, catalogDataStoreOperations) + .tempServiceDelete(new TempServiceDeleteInputBuilder() + .setCommonId("") + .build()); result.addListener(() -> 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()); + assertEquals( + ResponseCodes.RESPONSE_FAILED, + rpcResult.getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + LogMessages.SERVICE_NON_COMPLIANT, + rpcResult.getResult().getConfigurationResponseCommon().getResponseMessage()); } @Test - public void tempServiceDeleteShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { - ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, - rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, - networkModelListenerImpl, serviceDataStoreOperations); - ListenableFuture> result = servicehandlerImpl.tempServiceDelete( - ServiceDataUtils.buildTempServiceDeleteInput()); + void tempServiceDeleteShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { + ListenableFuture> result = + new ServicehandlerImpl( + pathComputationService, rendererServiceOperations, notificationPublishService, + pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, catalogDataStoreOperations) + .tempServiceDelete(ServiceDataUtils.buildTempServiceDeleteInput()); result.addListener(() -> endSignal.countDown(), executorService); - endSignal.await(); - Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, - result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } @Test - public void tempServiceDeleteShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException { - Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any())); - + void tempServiceDeleteShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException { + when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any())); //create temp service to delete in the temp delete action - ServicehandlerImpl servicehandlerImpl = - new ServicehandlerImpl(getNewDataBroker(), 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); + ListenableFuture> result = + new ServicehandlerImpl( + pathComputationService, rendererServiceOperations, notificationPublishService, + pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, catalogDataStoreOperations) + .tempServiceDelete(ServiceDataUtils.buildTempServiceDeleteInput(createInput.getCommonId())); result.addListener(() -> endSignal.countDown(), executorService); - endSignal.await(); - Assert.assertEquals( - ResponseCodes.RESPONSE_OK, result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + 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); + void tempServiceCreateShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ListenableFuture> result = - servicehandlerImpl.tempServiceCreate(new TempServiceCreateInputBuilder().build()); + new ServicehandlerImpl( + pathComputationService, rendererServiceOperations, notificationPublishService, + pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, catalogDataStoreOperations) + .tempServiceCreate(new TempServiceCreateInputBuilder().build()); result.addListener(() -> endSignal.countDown(), executorService); - endSignal.await(); - Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, - result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } - @Test - public void tempServiceCreateShouldBeSuccessfulWhenPerformPCESuccessful() + void tempServiceCreateShouldBeSuccessfulWhenPerformPCESuccessful() throws ExecutionException, InterruptedException { - Mockito.when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any())); + when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any())); + ListenableFuture> result = + new ServicehandlerImpl( + pathComputationService, rendererServiceOperations, notificationPublishService, + pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, catalogDataStoreOperations) + .tempServiceCreate(ServiceDataUtils.buildTempServiceCreateInput()); + result.addListener(() -> endSignal.countDown(), executorService); + endSignal.await(); + assertEquals( + ResponseCodes.RESPONSE_OK, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + } - ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, - rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, - networkModelListenerImpl, serviceDataStoreOperations); + @Test + public void addOpenroadmOperationalModesToCatalogShouldBeFailedWithEmptyInput() + throws ExecutionException, InterruptedException { + ListenableFuture> result = + new ServicehandlerImpl( + pathComputationService, rendererServiceOperations, notificationPublishService, + pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, catalogDataStoreOperations) + .addOpenroadmOperationalModesToCatalog(new AddOpenroadmOperationalModesToCatalogInputBuilder().build()); + Assert.assertEquals( + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + } - ListenableFuture> result = servicehandlerImpl.tempServiceCreate( - ServiceDataUtils.buildTempServiceCreateInput()); - result.addListener(() -> endSignal.countDown(), executorService); + @Test + public void addSpecificOperationalModesToCatalogShouldBeFailedWithEmptyInput() + throws ExecutionException, InterruptedException { + ListenableFuture> result = + new ServicehandlerImpl( + pathComputationService, rendererServiceOperations, notificationPublishService, + pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, catalogDataStoreOperations) + .addSpecificOperationalModesToCatalog(new AddSpecificOperationalModesToCatalogInputBuilder().build()); + Assert.assertEquals( + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + } - endSignal.await(); + @Test + public void addOpenroadmOperationalModesToCatalogShouldBeSuccessfulWhenAddORToCatalog() + throws ExecutionException, InterruptedException { + ListenableFuture> result = + new ServicehandlerImpl( + pathComputationService, rendererServiceOperations, notificationPublishService, + pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, catalogDataStoreOperations) + .addOpenroadmOperationalModesToCatalog(CatalogDataUtils.buildAddORToCatalogInput()); Assert.assertEquals( - ResponseCodes.RESPONSE_OK, result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + ResponseCodes.RESPONSE_OK, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } + @Test + public void addSpecificOperationalModesToCatalogShouldBeSuccessfulWhenAddSpecificToCatalog() + throws ExecutionException, InterruptedException { + ListenableFuture> result = + new ServicehandlerImpl( + pathComputationService, rendererServiceOperations, notificationPublishService, + pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, + serviceDataStoreOperations, catalogDataStoreOperations) + .addSpecificOperationalModesToCatalog(CatalogDataUtils.buildAddSpecificToCatalogInput()); + Assert.assertEquals( + ResponseCodes.RESPONSE_OK, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + } }