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=1e5639cc0f4c3c0c516194828c5e522603b20051;hb=198afc243c98aedfc5b30b93c1a5e3052d30868c;hp=be9ad142d5653888c7eac246e6889aef30030b85;hpb=82c8dcb18fd78b876fbdceb40c9f6a14259f2c98;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 be9ad142d..1e5639cc0 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 @@ -10,9 +10,12 @@ 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.times; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.opendaylight.transportpce.servicehandler.impl.ServicehandlerImpl.LogMessages; +import com.google.common.collect.ClassToInstanceMap; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; @@ -29,6 +32,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.opendaylight.mdsal.binding.api.NotificationPublishService; +import org.opendaylight.mdsal.binding.api.RpcProviderService; import org.opendaylight.transportpce.common.ResponseCodes; import org.opendaylight.transportpce.common.network.NetworkTransactionImpl; import org.opendaylight.transportpce.pce.service.PathComputationService; @@ -39,44 +43,46 @@ import org.opendaylight.transportpce.servicehandler.catalog.CatalogDataStoreOper 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.PCEServiceWrapper; +import org.opendaylight.transportpce.servicehandler.service.RendererServiceWrapper; 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.opendaylight.transportpce.pce.rev220808.service.path.rpc.result.PathDescription; -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.opendaylight.transportpce.pce.rev240205.PathComputationRequestOutputBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev240205.PathComputationRerouteRequestOutputBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev240205.service.path.rpc.result.PathDescription; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.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; -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.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; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceReconfigureInputBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceReconfigureOutput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRerouteInput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRerouteInputBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRerouteOutput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRestorationInput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRestorationInputBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRestorationOutput; -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.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.openroadm.service.rev230526.AddOpenroadmOperationalModesToCatalogInputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.AddOpenroadmOperationalModesToCatalogOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.AddSpecificOperationalModesToCatalogInputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.AddSpecificOperationalModesToCatalogOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceCreateInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceCreateInputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceCreateOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceDeleteInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceDeleteInputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceDeleteOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceFeasibilityCheckInputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceFeasibilityCheckOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceReconfigureInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceReconfigureInputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceReconfigureOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRerouteInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRerouteInputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRerouteOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRestorationInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRestorationInputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRestorationOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.TempServiceCreateInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.TempServiceCreateInputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.TempServiceCreateOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.TempServiceDeleteInputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.TempServiceDeleteOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.delete.input.ServiceDeleteReqInfoBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.list.ServicesBuilder; 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; @@ -91,7 +97,8 @@ import org.opendaylight.yangtools.yang.common.Uint32; @ExtendWith(MockitoExtension.class) public class ServicehandlerImplTest extends AbstractTest { - + @Mock + private RpcProviderService rpcProviderService; @Mock private PathComputationService pathComputationService; @Mock @@ -117,6 +124,8 @@ public class ServicehandlerImplTest extends AbstractTest { private ListeningExecutorService executorService; private CountDownLatch endSignal; private static final int NUM_THREADS = 5; + private PCEServiceWrapper pceServiceWrapper; + private RendererServiceWrapper rendererServiceWrapper; @BeforeEach void setUp() { @@ -131,16 +140,43 @@ public class ServicehandlerImplTest extends AbstractTest { serviceRestorationInput = ServiceDataUtils.buildServiceRestorationInput(); serviceRerouteInput = ServiceDataUtils.buildServiceRerouteInput(); pathDescription = ServiceDataUtils.createPathDescription(0,1,0,1); + pceServiceWrapper = new PCEServiceWrapper(pathComputationService, notificationPublishService); + this.rendererServiceWrapper = new RendererServiceWrapper(rendererServiceOperations, notificationPublishService); + } + + @Test + void testRpcRegistration() { + new ServicehandlerImpl(rpcProviderService, serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, catalogDataStoreOperations, pathComputationService, rendererServiceOperations, + notificationPublishService); + verify(rpcProviderService, times(1)).registerRpcImplementations(any(ClassToInstanceMap.class)); } +// @Test +// void testNotImplementedRpc() throws InterruptedException, ExecutionException { +// ListenableFuture> result = new ServicehandlerImpl(rpcProviderService, +// serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, +// catalogDataStoreOperations, pathComputationService, rendererServiceOperations, +// notificationPublishService) +// .serviceSrlgGet(new ServiceSrlgGetInputBuilder().build()); +// +// result.addListener(() -> endSignal.countDown(), executorService); +// endSignal.await(); +// assertNotNull(result.get()); +// assertFalse(result.get().isSuccessful()); +// assertNull(result.get().getResult()); +// assertEquals(ErrorType.RPC, result.get().getErrors().get(0).getErrorType()); +// assertEquals(ErrorSeverity.ERROR, result.get().getErrors().get(0).getSeverity()); +// assertEquals(ErrorTag.OPERATION_NOT_SUPPORTED, result.get().getErrors().get(0).getTag()); +// assertEquals("RPC not implemented yet", result.get().getErrors().get(0).getMessage()); +// } + @Test void createServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ListenableFuture> result = - new ServicehandlerImpl( - pathComputationService, rendererServiceOperations, notificationPublishService, - pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations, catalogDataStoreOperations) - .serviceCreate(new ServiceCreateInputBuilder().build()); + new ServiceCreateImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, pceServiceWrapper, notificationPublishService) + .invoke(new ServiceCreateInputBuilder().build()); result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); assertEquals( @@ -157,11 +193,9 @@ public class ServicehandlerImplTest extends AbstractTest { .setServiceName(serviceCreateInput.getServiceName()) .build())); ListenableFuture> result = - new ServicehandlerImpl( - pathComputationService, rendererServiceOperations, notificationPublishService, - pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDSOperations, catalogDataStoreOperations) - .serviceCreate(serviceCreateInput); + new ServiceCreateImpl(serviceDSOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, pceServiceWrapper, notificationPublishService) + .invoke(serviceCreateInput); result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); assertEquals( @@ -173,11 +207,9 @@ public class ServicehandlerImplTest extends AbstractTest { 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); + new ServiceCreateImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, pceServiceWrapper, notificationPublishService) + .invoke(serviceCreateInput); result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); assertEquals( @@ -188,16 +220,13 @@ public class ServicehandlerImplTest extends AbstractTest { @Test 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()); + new ServiceDeleteImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, rendererServiceWrapper, notificationPublishService) + .invoke(new ServiceDeleteInputBuilder() + .setServiceDeleteReqInfo(new ServiceDeleteReqInfoBuilder() + .setServiceName("") + .build()) + .build()); result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); assertEquals( @@ -208,11 +237,9 @@ public class ServicehandlerImplTest extends AbstractTest { @Test void deleteServiceShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { ListenableFuture> result = - new ServicehandlerImpl( - pathComputationService, rendererServiceOperations, notificationPublishService, - pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations, catalogDataStoreOperations) - .serviceDelete(serviceDeleteInput); + new ServiceDeleteImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, rendererServiceWrapper, notificationPublishService) + .invoke(serviceDeleteInput); result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); assertEquals( @@ -225,11 +252,9 @@ public class ServicehandlerImplTest extends AbstractTest { when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any())); serviceDataStoreOperations.createService(serviceCreateInput); ListenableFuture> result = - new ServicehandlerImpl( - pathComputationService, rendererServiceOperations, notificationPublishService, - pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations, catalogDataStoreOperations) - .serviceDelete(serviceDeleteInput); + new ServiceDeleteImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, rendererServiceWrapper, notificationPublishService) + .invoke(serviceDeleteInput); result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); assertEquals( @@ -239,11 +264,10 @@ public class ServicehandlerImplTest extends AbstractTest { @Test void serviceFeasibilityCheckShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { - ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(pathComputationService, - rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, - networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations); ListenableFuture> result = - servicehandlerImpl.serviceFeasibilityCheck(new ServiceFeasibilityCheckInputBuilder().build()); + new ServiceFeasibilityCheckImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, pceServiceWrapper) + .invoke(new ServiceFeasibilityCheckInputBuilder().build()); result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); assertEquals( @@ -256,11 +280,9 @@ public class ServicehandlerImplTest extends AbstractTest { throws ExecutionException, InterruptedException { when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any())); ListenableFuture> result = - new ServicehandlerImpl( - pathComputationService, rendererServiceOperations, notificationPublishService, - pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations, catalogDataStoreOperations) - .serviceFeasibilityCheck(ServiceDataUtils.buildServiceFeasibilityCheckInput()); + new ServiceFeasibilityCheckImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, pceServiceWrapper) + .invoke(ServiceDataUtils.buildServiceFeasibilityCheckInput()); result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); assertEquals( @@ -271,11 +293,9 @@ public class ServicehandlerImplTest extends AbstractTest { @Test void serviceReconfigureShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ListenableFuture> result = - new ServicehandlerImpl( - pathComputationService, rendererServiceOperations, notificationPublishService, - pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations, catalogDataStoreOperations) - .serviceReconfigure(new ServiceReconfigureInputBuilder().setServiceName("").build()); + new ServiceReconfigureImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, rendererServiceWrapper) + .invoke(new ServiceReconfigureInputBuilder().setServiceName("").build()); result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); } @@ -285,11 +305,9 @@ public class ServicehandlerImplTest extends AbstractTest { void serviceReconfigureShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { //action -> service reconfigure ListenableFuture> result = - new ServicehandlerImpl( - pathComputationService, rendererServiceOperations, notificationPublishService, - pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations, catalogDataStoreOperations) - .serviceReconfigure(serviceReconfigureInput); + new ServiceReconfigureImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, rendererServiceWrapper) + .invoke(serviceReconfigureInput); result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); } @@ -303,11 +321,9 @@ public class ServicehandlerImplTest extends AbstractTest { //service reconfigure test action //ServiceReconfigureInput is created with the same service information that is created before ListenableFuture> result = - new ServicehandlerImpl( - pathComputationService, rendererServiceOperations, notificationPublishService, - pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations, catalogDataStoreOperations) - .serviceReconfigure(serviceReconfigureInput); + new ServiceReconfigureImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, rendererServiceWrapper) + .invoke(serviceReconfigureInput); result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); } @@ -315,13 +331,11 @@ public class ServicehandlerImplTest extends AbstractTest { @Test void serviceReRestorationShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ListenableFuture> result = - new ServicehandlerImpl( - pathComputationService, rendererServiceOperations, notificationPublishService, - pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations, catalogDataStoreOperations) - .serviceRestoration(new ServiceRestorationInputBuilder() - .setServiceName("") - .build()); + new ServiceRestorationImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, rendererServiceWrapper) + .invoke(new ServiceRestorationInputBuilder() + .setServiceName("") + .build()); result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); } @@ -330,11 +344,9 @@ public class ServicehandlerImplTest extends AbstractTest { void serviceRestorationShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { //action -> service restore ListenableFuture> result = - new ServicehandlerImpl( - pathComputationService, rendererServiceOperations, notificationPublishService, - pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations, catalogDataStoreOperations) - .serviceRestoration(serviceRestorationInput); + new ServiceRestorationImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, rendererServiceWrapper) + .invoke(serviceRestorationInput); result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); } @@ -348,11 +360,9 @@ public class ServicehandlerImplTest extends AbstractTest { //service Restoration test action //ServiceRestorationInput is created with the same service information that is created before ListenableFuture> result = - new ServicehandlerImpl( - pathComputationService, rendererServiceOperations, notificationPublishService, - pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations, catalogDataStoreOperations) - .serviceRestoration(serviceRestorationInput); + new ServiceRestorationImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, rendererServiceWrapper) + .invoke(serviceRestorationInput); result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); } @@ -360,13 +370,10 @@ public class ServicehandlerImplTest extends AbstractTest { @Test void serviceRerouteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ListenableFuture> result = - new ServicehandlerImpl( - pathComputationService, rendererServiceOperations, notificationPublishService, - pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations, catalogDataStoreOperations) - .serviceReroute(new ServiceRerouteInputBuilder() - .setServiceName("") - .build()); + new ServiceRerouteImpl(serviceDataStoreOperations, pceServiceWrapper) + .invoke(new ServiceRerouteInputBuilder() + .setServiceName("") + .build()); result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); assertEquals( @@ -378,11 +385,8 @@ public class ServicehandlerImplTest extends AbstractTest { void serviceRerouteShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { //action -> service reconfigure ListenableFuture> result = - new ServicehandlerImpl( - pathComputationService, rendererServiceOperations, notificationPublishService, - pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations, catalogDataStoreOperations) - .serviceReroute(serviceRerouteInput); + new ServiceRerouteImpl(serviceDataStoreOperations, pceServiceWrapper) + .invoke(serviceRerouteInput); result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); assertEquals( @@ -449,11 +453,8 @@ public class ServicehandlerImplTest extends AbstractTest { .build()); serviceDataStoreOperations.createService(serviceCreateInput); ListenableFuture> result = - new ServicehandlerImpl( - pathComputationService, rendererServiceOperations, notificationPublishService, - pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations, catalogDataStoreOperations) - .serviceReroute(serviceRerouteInput); + new ServiceRerouteImpl(serviceDataStoreOperations, pceServiceWrapper) + .invoke(serviceRerouteInput); result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); assertEquals( @@ -464,13 +465,11 @@ public class ServicehandlerImplTest extends AbstractTest { @Test void tempServiceDeleteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ListenableFuture> result = - new ServicehandlerImpl( - pathComputationService, rendererServiceOperations, notificationPublishService, - pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations, catalogDataStoreOperations) - .tempServiceDelete(new TempServiceDeleteInputBuilder() - .setCommonId("") - .build()); + new TempServiceDeleteImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + rendererServiceWrapper) + .invoke(new TempServiceDeleteInputBuilder() + .setCommonId("") + .build()); result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); RpcResult rpcResult = result.get(); @@ -485,11 +484,9 @@ public class ServicehandlerImplTest extends AbstractTest { @Test void tempServiceDeleteShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { ListenableFuture> result = - new ServicehandlerImpl( - pathComputationService, rendererServiceOperations, notificationPublishService, - pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations, catalogDataStoreOperations) - .tempServiceDelete(ServiceDataUtils.buildTempServiceDeleteInput()); + new TempServiceDeleteImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + rendererServiceWrapper) + .invoke(ServiceDataUtils.buildTempServiceDeleteInput()); result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); assertEquals( @@ -504,11 +501,9 @@ public class ServicehandlerImplTest extends AbstractTest { TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput(); serviceDataStoreOperations.createTempService(createInput, pathDescription); ListenableFuture> result = - new ServicehandlerImpl( - pathComputationService, rendererServiceOperations, notificationPublishService, - pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations, catalogDataStoreOperations) - .tempServiceDelete(ServiceDataUtils.buildTempServiceDeleteInput(createInput.getCommonId())); + new TempServiceDeleteImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + rendererServiceWrapper) + .invoke(ServiceDataUtils.buildTempServiceDeleteInput(createInput.getCommonId())); result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); assertEquals( @@ -519,11 +514,9 @@ public class ServicehandlerImplTest extends AbstractTest { @Test void tempServiceCreateShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ListenableFuture> result = - new ServicehandlerImpl( - pathComputationService, rendererServiceOperations, notificationPublishService, - pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations, catalogDataStoreOperations) - .tempServiceCreate(new TempServiceCreateInputBuilder().build()); + new TempServiceCreateImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, pceServiceWrapper) + .invoke(new TempServiceCreateInputBuilder().build()); result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); assertEquals( @@ -531,16 +524,37 @@ public class ServicehandlerImplTest extends AbstractTest { result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } + @Test + void tempServiceCreateShouldBeFailedWithServiceAlreadyExist() throws ExecutionException, InterruptedException { + final ServiceDataStoreOperations serviceDSOperations = mock(ServiceDataStoreOperations.class); + when(serviceDSOperations.getTempService(any())) + .thenReturn(Optional.of( + new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.temp.service.list + .ServicesBuilder() + .setCommonId("bad_commonId") + .build())); + ListenableFuture> result = + new TempServiceCreateImpl(serviceDSOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, pceServiceWrapper) + .invoke(ServiceDataUtils.buildTempServiceCreateInput()); + result.addListener(() -> endSignal.countDown(), executorService); + endSignal.await(); + assertEquals( + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + "Service 'Temp (commonId)' already exists in datastore", + result.get().getResult().getConfigurationResponseCommon().getResponseMessage()); + } + @Test void tempServiceCreateShouldBeSuccessfulWhenPerformPCESuccessful() throws ExecutionException, InterruptedException { when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any())); ListenableFuture> result = - new ServicehandlerImpl( - pathComputationService, rendererServiceOperations, notificationPublishService, - pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations, catalogDataStoreOperations) - .tempServiceCreate(ServiceDataUtils.buildTempServiceCreateInput()); + new TempServiceCreateImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, pceServiceWrapper) + .invoke(ServiceDataUtils.buildTempServiceCreateInput()); result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); assertEquals( @@ -552,11 +566,8 @@ public class ServicehandlerImplTest extends AbstractTest { public void addOpenroadmOperationalModesToCatalogShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ListenableFuture> result = - new ServicehandlerImpl( - pathComputationService, rendererServiceOperations, notificationPublishService, - pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations, catalogDataStoreOperations) - .addOpenroadmOperationalModesToCatalog(new AddOpenroadmOperationalModesToCatalogInputBuilder().build()); + new AddOpenroadmOperationalModesToCatalogImpl(catalogDataStoreOperations) + .invoke(new AddOpenroadmOperationalModesToCatalogInputBuilder().build()); Assert.assertEquals( ResponseCodes.RESPONSE_FAILED, result.get().getResult().getConfigurationResponseCommon().getResponseCode()); @@ -566,11 +577,8 @@ public class ServicehandlerImplTest extends AbstractTest { public void addSpecificOperationalModesToCatalogShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ListenableFuture> result = - new ServicehandlerImpl( - pathComputationService, rendererServiceOperations, notificationPublishService, - pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations, catalogDataStoreOperations) - .addSpecificOperationalModesToCatalog(new AddSpecificOperationalModesToCatalogInputBuilder().build()); + new AddSpecificOperationalModesToCatalogImpl(catalogDataStoreOperations) + .invoke(new AddSpecificOperationalModesToCatalogInputBuilder().build()); Assert.assertEquals( ResponseCodes.RESPONSE_FAILED, result.get().getResult().getConfigurationResponseCommon().getResponseCode()); @@ -580,11 +588,8 @@ public class ServicehandlerImplTest extends AbstractTest { public void addOpenroadmOperationalModesToCatalogShouldBeSuccessfulWhenAddORToCatalog() throws ExecutionException, InterruptedException { ListenableFuture> result = - new ServicehandlerImpl( - pathComputationService, rendererServiceOperations, notificationPublishService, - pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations, catalogDataStoreOperations) - .addOpenroadmOperationalModesToCatalog(CatalogDataUtils.buildAddORToCatalogInput()); + new AddOpenroadmOperationalModesToCatalogImpl(catalogDataStoreOperations) + .invoke(CatalogDataUtils.buildAddORToCatalogInput()); Assert.assertEquals( ResponseCodes.RESPONSE_OK, result.get().getResult().getConfigurationResponseCommon().getResponseCode()); @@ -594,11 +599,8 @@ public class ServicehandlerImplTest extends AbstractTest { public void addSpecificOperationalModesToCatalogShouldBeSuccessfulWhenAddSpecificToCatalog() throws ExecutionException, InterruptedException { ListenableFuture> result = - new ServicehandlerImpl( - pathComputationService, rendererServiceOperations, notificationPublishService, - pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations, catalogDataStoreOperations) - .addSpecificOperationalModesToCatalog(CatalogDataUtils.buildAddSpecificToCatalogInput()); + new AddSpecificOperationalModesToCatalogImpl(catalogDataStoreOperations) + .invoke(CatalogDataUtils.buildAddSpecificToCatalogInput()); Assert.assertEquals( ResponseCodes.RESPONSE_OK, result.get().getResult().getConfigurationResponseCommon().getResponseCode());