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=a531983138f1183e4691f2106b29e8418ee7494f;hb=b1b3bafd549bb501937cea5c976d5344608b6ed3;hp=46289d95be7ea9ba040e5806952aa3edbfe6f6cb;hpb=980555a7d2dc492570012d813e5fa14253597233;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 46289d95b..a53198313 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,654 +7,601 @@ */ 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.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; +import java.util.Map; +import java.util.Optional; 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.opendaylight.mdsal.binding.api.DataBroker; +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; 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.ServiceInput; +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.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.openroadm.common.types.rev190531.RpcStatus; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateInput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateInputBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateOutput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteInput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteInputBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteOutput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceFeasibilityCheckInput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceFeasibilityCheckInputBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceFeasibilityCheckOutput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceReconfigureInput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceReconfigureInputBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceReconfigureOutput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRerouteInput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRerouteInputBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRerouteOutput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRestorationInput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRestorationInputBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRestorationOutput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceCreateInput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceCreateInputBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceCreateOutput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceDeleteInput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceDeleteInputBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceDeleteOutput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.delete.input.ServiceDeleteReqInfoBuilder; +import org.opendaylight.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.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; +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; -public class ServicehandlerImplTest extends AbstractTest { - +@ExtendWith(MockitoExtension.class) +public class ServicehandlerImplTest extends AbstractTest { + @Mock + private RpcProviderService rpcProviderService; @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; + @Mock + private PathDescription pathDescription; private ServiceDataStoreOperations serviceDataStoreOperations; + private CatalogDataStoreOperations catalogDataStoreOperations; + private ServiceCreateInput serviceCreateInput; + private ServiceDeleteInput serviceDeleteInput; + private ServiceReconfigureInput serviceReconfigureInput; + private ServiceRestorationInput serviceRestorationInput; + private ServiceRerouteInput serviceRerouteInput; private ListeningExecutorService executorService; private CountDownLatch endSignal; private static final int NUM_THREADS = 5; - private boolean callbackRan; + private PCEServiceWrapper pceServiceWrapper; + private RendererServiceWrapper rendererServiceWrapper; - @Before - public void setUp() { + @BeforeEach + void setUp() { executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS)); endSignal = new CountDownLatch(1); - callbackRan = false; - MockitoAnnotations.openMocks(this); this.serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(getNewDataBroker()); + this.catalogDataStoreOperations = + new CatalogDataStoreOperationsImpl(new NetworkTransactionImpl(getDataBroker())); + serviceCreateInput = ServiceDataUtils.buildServiceCreateInput(); + serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput(); + serviceReconfigureInput = ServiceDataUtils.buildServiceReconfigureInput(); + 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 - public void createServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { - ServicehandlerImpl servicehandlerImpl = - new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations); - ListenableFuture> result = - servicehandlerImpl.serviceCreate(new ServiceCreateInputBuilder().build()); - result.addListener(new Runnable() { - @Override - public void run() { - callbackRan = true; - endSignal.countDown(); - } - }, executorService); + void testRpcRegistration() { + new ServicehandlerImpl(rpcProviderService, serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, catalogDataStoreOperations, pathComputationService, rendererServiceOperations, + notificationPublishService); + verify(rpcProviderService, times(1)).registerRpcImplementations(any()); + } - endSignal.await(); +// @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()); +// } - RpcResult rpcResult = result.get(); - Assert.assertEquals( - ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode()); + @Test + void createServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { + ListenableFuture> result = + new ServiceCreateImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, pceServiceWrapper, notificationPublishService) + .invoke(new ServiceCreateInputBuilder().build()); + result.addListener(() -> endSignal.countDown(), executorService); + endSignal.await(); + assertEquals( + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } @Test - public void createServiceShouldBeSuccessfulWhenPreformPCESuccessful() - throws ExecutionException, InterruptedException { - ServiceCreateInput input = ServiceDataUtils.buildServiceCreateInput(); - Mockito.when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any())); - ServicehandlerImpl servicehandlerImpl = - new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations); - ListenableFuture> result = servicehandlerImpl.serviceCreate(input); - result.addListener(new Runnable() { - @Override - public void run() { - callbackRan = true; - endSignal.countDown(); - } - }, executorService); - + void createServiceShouldBeFailedWithServiceAlreadyExist() throws ExecutionException, InterruptedException { + final ServiceDataStoreOperations serviceDSOperations = mock(ServiceDataStoreOperations.class); + when(serviceDSOperations.getService(serviceCreateInput.getServiceName())) + .thenReturn(Optional.of( + new ServicesBuilder() + .setServiceName(serviceCreateInput.getServiceName()) + .build())); + ListenableFuture> result = + new ServiceCreateImpl(serviceDSOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, pceServiceWrapper, notificationPublishService) + .invoke(serviceCreateInput); + result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); + assertEquals( + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + } - RpcResult rpcResult = result.get(); - Assert.assertEquals( - ResponseCodes.RESPONSE_OK, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode()); + @Test + void createServiceShouldBeSuccessfulWhenPerformPCESuccessful() throws ExecutionException, InterruptedException { + when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any())); + ListenableFuture> result = + new ServiceCreateImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, pceServiceWrapper, notificationPublishService) + .invoke(serviceCreateInput); + result.addListener(() -> endSignal.countDown(), executorService); + endSignal.await(); + 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); + void deleteServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ListenableFuture> result = - servicehandlerImpl.serviceDelete(new ServiceDeleteInputBuilder() - .setServiceDeleteReqInfo(new ServiceDeleteReqInfoBuilder().setServiceName("").build()).build()); - result.addListener(new Runnable() { - @Override - public void run() { - callbackRan = true; - endSignal.countDown(); - } - }, executorService); - + new ServiceDeleteImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, rendererServiceWrapper, notificationPublishService) + .invoke(new ServiceDeleteInputBuilder() + .setServiceDeleteReqInfo(new ServiceDeleteReqInfoBuilder() + .setServiceName("") + .build()) + .build()); + result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); - - RpcResult rpcResult = result.get(); - Assert.assertEquals( - ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } @Test - public void deleteServiceShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { - ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput(); - ServicehandlerImpl servicehandlerImpl = - new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations); - ListenableFuture> result = servicehandlerImpl.serviceDelete(input); - result.addListener(new Runnable() { - @Override - public void run() { - callbackRan = true; - endSignal.countDown(); - } - }, executorService); - + void deleteServiceShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { + ListenableFuture> result = + new ServiceDeleteImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, rendererServiceWrapper, notificationPublishService) + .invoke(serviceDeleteInput); + result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); - - RpcResult rpcResult = result.get(); - Assert.assertEquals( - ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } @Test - public void deleteServiceShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException { - DataBroker dataBroker = getNewDataBroker(); - Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any())); - ServicehandlerImpl servicehandlerImpl = - new ServicehandlerImpl(dataBroker, pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations); - ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput(); - serviceDataStoreOperations.createService(createInput); - ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput(); - ListenableFuture> result = servicehandlerImpl.serviceDelete(input); - result.addListener(new Runnable() { - @Override - public void run() { - callbackRan = true; - endSignal.countDown(); - } - }, executorService); - + void deleteServiceShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException { + when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any())); + serviceDataStoreOperations.createService(serviceCreateInput); + ListenableFuture> result = + new ServiceDeleteImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, rendererServiceWrapper, notificationPublishService) + .invoke(serviceDeleteInput); + result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); - - RpcResult rpcResult = result.get(); - Assert.assertEquals( - ResponseCodes.RESPONSE_OK, rpcResult.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, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations); + void serviceFeasibilityCheckShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ListenableFuture> result = - servicehandlerImpl.serviceFeasibilityCheck(new ServiceFeasibilityCheckInputBuilder().build()); - result.addListener(new Runnable() { - @Override - public void run() { - callbackRan = true; - endSignal.countDown(); - } - }, executorService); - + new ServiceFeasibilityCheckImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, pceServiceWrapper) + .invoke(new ServiceFeasibilityCheckInputBuilder().build()); + result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); - - RpcResult rpcResult = result.get(); - Assert.assertEquals( - ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } @Test - public void serviceFeasibilityCheckShouldBeSuccessfulWhenPreformPCESuccessful() + void serviceFeasibilityCheckShouldBeSuccessfulWhenPerformPCESuccessful() throws ExecutionException, InterruptedException { - ServiceFeasibilityCheckInput input = ServiceDataUtils.buildServiceFeasibilityCheckInput(); - Mockito.when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any())); - ServicehandlerImpl servicehandlerImpl = - new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations); + when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any())); ListenableFuture> result = - servicehandlerImpl.serviceFeasibilityCheck(input); - result.addListener(new Runnable() { - @Override - public void run() { - callbackRan = true; - endSignal.countDown(); - } - }, executorService); - + new ServiceFeasibilityCheckImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, pceServiceWrapper) + .invoke(ServiceDataUtils.buildServiceFeasibilityCheckInput()); + result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); - - RpcResult rpcResult = result.get(); - Assert.assertEquals( - ResponseCodes.RESPONSE_OK, rpcResult.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()); - result.addListener(new Runnable() { - @Override - public void run() { - callbackRan = true; - endSignal.countDown(); - } - }, executorService); - + new ServiceReconfigureImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, rendererServiceWrapper) + .invoke(new ServiceReconfigureInputBuilder().setServiceName("").build()); + result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); - - RpcResult rpcResult = result.get(); - Assert.assertEquals( - RpcStatus.Failed, rpcResult.getResult().getStatus()); } @Test - public void serviceReconfigureShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { - ServiceReconfigureInput input = ServiceDataUtils.buildServiceReconfigureInput(); - + void serviceReconfigureShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { //action -> service reconfigure - ServicehandlerImpl servicehandlerImpl = - new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations); - ListenableFuture> result = servicehandlerImpl.serviceReconfigure(input); - - result.addListener(new Runnable() { - @Override - public void run() { - callbackRan = true; - endSignal.countDown(); - } - }, executorService); - + ListenableFuture> result = + new ServiceReconfigureImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, rendererServiceWrapper) + .invoke(serviceReconfigureInput); + result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); - - RpcResult rpcResult = result.get(); - //ServiceReconfigureOutput doesn't have ConfigurationResponseCommon but have RpcStatus directly - Assert.assertEquals( - RpcStatus.Failed, rpcResult.getResult().getStatus()); } @Test - public void serviceReconfigureShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException { - DataBroker dataBroker = getNewDataBroker(); - - //mocking + 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(dataBroker, pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations); - ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput(); - serviceDataStoreOperations.createService(createInput); - + serviceDataStoreOperations.createService(serviceCreateInput); //service reconfigure test action - ServiceReconfigureInput input = ServiceDataUtils.buildServiceReconfigureInput(); //ServiceReconfigureInput is created with the same service information that is created before - ListenableFuture> result = servicehandlerImpl.serviceReconfigure(input); - result.addListener(new Runnable() { - @Override - public void run() { - callbackRan = true; - endSignal.countDown(); - } - }, executorService); - + ListenableFuture> result = + new ServiceReconfigureImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, rendererServiceWrapper) + .invoke(serviceReconfigureInput); + result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); - - RpcResult rpcResult = result.get(); - Assert.assertEquals( - RpcStatus.Successful, rpcResult.getResult().getStatus()); } @Test - public void serviceReRestorationShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { - ServicehandlerImpl servicehandlerImpl = - new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations); + void serviceReRestorationShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ListenableFuture> result = - servicehandlerImpl.serviceRestoration(new ServiceRestorationInputBuilder().setServiceName("").build()); - result.addListener(new Runnable() { - @Override - public void run() { - callbackRan = true; - endSignal.countDown(); - } - }, executorService); - + new ServiceRestorationImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, rendererServiceWrapper) + .invoke(new ServiceRestorationInputBuilder() + .setServiceName("") + .build()); + result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); - - RpcResult rpcResult = result.get(); - Assert.assertEquals( - RpcStatus.Failed, rpcResult.getResult().getStatus()); } - @Test - public void serviceRestorationShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { - ServiceRestorationInput input = ServiceDataUtils.buildServiceRestorationInput(); - + void serviceRestorationShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { //action -> service restore - ServicehandlerImpl servicehandlerImpl = - new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations); - ListenableFuture> result = servicehandlerImpl.serviceRestoration(input); - - result.addListener(new Runnable() { - @Override - public void run() { - callbackRan = true; - endSignal.countDown(); - } - }, executorService); - + ListenableFuture> result = + new ServiceRestorationImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, rendererServiceWrapper) + .invoke(serviceRestorationInput); + result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); - - RpcResult rpcResult = result.get(); - //ServiceRestorationOutput doesn't have ConfigurationResponseCommon but have RpcStatus directly - Assert.assertEquals( - RpcStatus.Failed, rpcResult.getResult().getStatus()); } @Test - public void serviceRestorationShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException { - DataBroker dataBroker = getNewDataBroker(); - - //mocking + 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(dataBroker, pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations); - ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput(); - serviceDataStoreOperations.createService(createInput); - + serviceDataStoreOperations.createService(serviceCreateInput); //service Restoration test action - ServiceRestorationInput input = ServiceDataUtils.buildServiceRestorationInput(); //ServiceRestorationInput is created with the same service information that is created before - ListenableFuture> result = servicehandlerImpl.serviceRestoration(input); - result.addListener(new Runnable() { - @Override - public void run() { - callbackRan = true; - endSignal.countDown(); - } - }, executorService); - + ListenableFuture> result = + new ServiceRestorationImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, rendererServiceWrapper) + .invoke(serviceRestorationInput); + result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); - - RpcResult rpcResult = result.get(); - Assert.assertEquals( - RpcStatus.Successful, rpcResult.getResult().getStatus()); } @Test - public void serviceRerouteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { - ServicehandlerImpl servicehandlerImpl = - new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations); + void serviceRerouteShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { ListenableFuture> result = - servicehandlerImpl.serviceReroute(new ServiceRerouteInputBuilder().setServiceName("").build()); - result.addListener(new Runnable() { - @Override - public void run() { - callbackRan = true; - endSignal.countDown(); - } - }, executorService); - + new ServiceRerouteImpl(serviceDataStoreOperations, pceServiceWrapper) + .invoke(new ServiceRerouteInputBuilder() + .setServiceName("") + .build()); + result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); - - RpcResult rpcResult = result.get(); - Assert.assertEquals( - RpcStatus.Failed, rpcResult.getResult().getStatus()); + assertEquals( + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } @Test - public void serviceRerouteShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { - ServiceRerouteInput input = ServiceDataUtils.buildServiceRerouteInput(); - + void serviceRerouteShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { //action -> service reconfigure - ServicehandlerImpl servicehandlerImpl = - new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations); - ListenableFuture> result = servicehandlerImpl.serviceReroute(input); - - result.addListener(new Runnable() { - @Override - public void run() { - callbackRan = true; - endSignal.countDown(); - } - }, executorService); - + ListenableFuture> result = + new ServiceRerouteImpl(serviceDataStoreOperations, pceServiceWrapper) + .invoke(serviceRerouteInput); + result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); - - RpcResult rpcResult = result.get(); - //ServiceRerouteOutput doesn't have ConfigurationResponseCommon but have RpcStatus directly - Assert.assertEquals( - RpcStatus.Failed, rpcResult.getResult().getStatus()); + assertEquals( + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } @Test - public void serviceRerouteShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException { - DataBroker dataBroker = getNewDataBroker(); - - //mocking - // serviceReroute is calling service delete method in renderer - Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any())); - //create service to be rerouted later - ServicehandlerImpl servicehandlerImpl = - new ServicehandlerImpl(dataBroker, pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations); - ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput(); - serviceDataStoreOperations.createService(createInput); - - //service reroute test action - ServiceRerouteInput input = ServiceDataUtils.buildServiceRerouteInput(); - //ServiceRerouteInput is created with the same service information that is created before - ListenableFuture> result = servicehandlerImpl.serviceReroute(input); - result.addListener(new Runnable() { - @Override - public void run() { - callbackRan = true; - endSignal.countDown(); - } - }, executorService); - + 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() + .setId("0") + .setResource(new ResourceBuilder() + .setResource(new TerminationPointBuilder() + .setTpNodeId("tpNodeIdC") + .setTpId("TpIdC1") + .build()) + .setState(State.InService) + .build()) + .build(), + new AToZKey("1"), + new AToZBuilder() + .setId("1") + .setResource(new ResourceBuilder() + .setResource(new TerminationPointBuilder() + .setTpNodeId("tpNodeIdD") + .setTpId("TpIdCD") + .build()) + .setState(State.InService) + .build()) + .build(), new AToZKey("2"), + new AToZBuilder() + .setId("2") + .setResource(new ResourceBuilder() + .setResource(new TerminationPointBuilder() + .setTpNodeId("tpNodeIdA") + .setTpId("TpIdA1") + .build()) + .setState(State.InService) + .build()) + .build() + + ); + serviceDataStoreOperations.createServicePath(new ServiceInput(serviceCreateInput), + new PathComputationRequestOutputBuilder() + .setResponseParameters(new ResponseParametersBuilder() + .setPathDescription(new PathDescriptionBuilder() + .setAToZDirection(new AToZDirectionBuilder() + .setAToZ(atoz) + .setRate(Uint32.valueOf(1)) + .build()) + .setZToADirection(new ZToADirectionBuilder() + .setRate(Uint32.valueOf(1)) + .build()) + .build()) + .build()) + .build()); + serviceDataStoreOperations.createService(serviceCreateInput); + ListenableFuture> result = + new ServiceRerouteImpl(serviceDataStoreOperations, pceServiceWrapper) + .invoke(serviceRerouteInput); + result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); - - RpcResult rpcResult = result.get(); - Assert.assertEquals( - RpcStatus.Successful, rpcResult.getResult().getStatus()); + 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()); - result.addListener(new Runnable() { - @Override - public void run() { - callbackRan = true; - endSignal.countDown(); - } - }, executorService); - + new TempServiceDeleteImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + rendererServiceWrapper) + .invoke(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( + assertEquals( + ResponseCodes.RESPONSE_FAILED, + rpcResult.getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( LogMessages.SERVICE_NON_COMPLIANT, rpcResult.getResult().getConfigurationResponseCommon().getResponseMessage()); } @Test - public void tempServiceDeleteShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { - TempServiceDeleteInput input = ServiceDataUtils.buildTempServiceDeleteInput(); - ServicehandlerImpl servicehandlerImpl = - new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations); - ListenableFuture> result = servicehandlerImpl.tempServiceDelete(input); - result.addListener(new Runnable() { - @Override - public void run() { - callbackRan = true; - endSignal.countDown(); - } - }, executorService); - + void tempServiceDeleteShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { + ListenableFuture> result = + new TempServiceDeleteImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + rendererServiceWrapper) + .invoke(ServiceDataUtils.buildTempServiceDeleteInput()); + result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); - - RpcResult rpcResult = result.get(); - Assert.assertEquals( - ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode()); + assertEquals( + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } @Test - public void tempServiceDeleteShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException { - DataBroker dataBroker = getNewDataBroker(); - Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any())); - + 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(dataBroker, pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations); TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput(); - serviceDataStoreOperations.createTempService(createInput); - - - TempServiceDeleteInput input = ServiceDataUtils.buildTempServiceDeleteInput(createInput.getCommonId()); - ListenableFuture> result = servicehandlerImpl.tempServiceDelete(input); - result.addListener(new Runnable() { - @Override - public void run() { - callbackRan = true; - endSignal.countDown(); - } - }, executorService); - + serviceDataStoreOperations.createTempService(createInput, pathDescription); + ListenableFuture> result = + new TempServiceDeleteImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + rendererServiceWrapper) + .invoke(ServiceDataUtils.buildTempServiceDeleteInput(createInput.getCommonId())); + result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); + assertEquals( + ResponseCodes.RESPONSE_OK, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + } - RpcResult rpcResult = result.get(); - Assert.assertEquals( - ResponseCodes.RESPONSE_OK, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode()); + @Test + void tempServiceCreateShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { + ListenableFuture> result = + new TempServiceCreateImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, pceServiceWrapper) + .invoke(new TempServiceCreateInputBuilder().build()); + result.addListener(() -> endSignal.countDown(), executorService); + endSignal.await(); + assertEquals( + ResponseCodes.RESPONSE_FAILED, + 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 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 = - servicehandlerImpl.tempServiceCreate(new TempServiceCreateInputBuilder().build()); - result.addListener(new Runnable() { - @Override - public void run() { - callbackRan = true; - endSignal.countDown(); - } - }, executorService); + 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 TempServiceCreateImpl(serviceDataStoreOperations, pceListenerImpl, rendererListenerImpl, + networkModelListenerImpl, pceServiceWrapper) + .invoke(ServiceDataUtils.buildTempServiceCreateInput()); + result.addListener(() -> endSignal.countDown(), executorService); endSignal.await(); + assertEquals( + ResponseCodes.RESPONSE_OK, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + } - RpcResult rpcResult = result.get(); + @Test + public void addOpenroadmOperationalModesToCatalogShouldBeFailedWithEmptyInput() + throws ExecutionException, InterruptedException { + ListenableFuture> result = + new AddOpenroadmOperationalModesToCatalogImpl(catalogDataStoreOperations) + .invoke(new AddOpenroadmOperationalModesToCatalogInputBuilder().build()); Assert.assertEquals( - ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode()); + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } - @Test - public void tempServiceCreateShouldBeSuccessfulWhenPreformPCESuccessful() + public void addSpecificOperationalModesToCatalogShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { - TempServiceCreateInput input = ServiceDataUtils.buildTempServiceCreateInput(); - Mockito.when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any())); - - ServicehandlerImpl servicehandlerImpl = - new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations, - notificationPublishService, pceListenerImpl, rendererListenerImpl, networkModelListenerImpl, - serviceDataStoreOperations); - - ListenableFuture> result = servicehandlerImpl.tempServiceCreate(input); - result.addListener(new Runnable() { - @Override - public void run() { - callbackRan = true; - endSignal.countDown(); - } - }, executorService); - - endSignal.await(); - - RpcResult rpcResult = result.get(); + ListenableFuture> result = + new AddSpecificOperationalModesToCatalogImpl(catalogDataStoreOperations) + .invoke(new AddSpecificOperationalModesToCatalogInputBuilder().build()); + Assert.assertEquals( + ResponseCodes.RESPONSE_FAILED, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + } + @Test + public void addOpenroadmOperationalModesToCatalogShouldBeSuccessfulWhenAddORToCatalog() + throws ExecutionException, InterruptedException { + ListenableFuture> result = + new AddOpenroadmOperationalModesToCatalogImpl(catalogDataStoreOperations) + .invoke(CatalogDataUtils.buildAddORToCatalogInput()); Assert.assertEquals( - ResponseCodes.RESPONSE_OK, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode()); + ResponseCodes.RESPONSE_OK, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); } + @Test + public void addSpecificOperationalModesToCatalogShouldBeSuccessfulWhenAddSpecificToCatalog() + throws ExecutionException, InterruptedException { + ListenableFuture> result = + new AddSpecificOperationalModesToCatalogImpl(catalogDataStoreOperations) + .invoke(CatalogDataUtils.buildAddSpecificToCatalogInput()); + Assert.assertEquals( + ResponseCodes.RESPONSE_OK, + result.get().getResult().getConfigurationResponseCommon().getResponseCode()); + } }