X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=tapi%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Ftapi%2Fconnectivity%2FTapiConnectivityImplTest.java;h=70a9adcb392808f36f877f2d889c9b10d29f6f69;hb=27070ce7114dcdb1da7203c54724fa3fe59e7cc3;hp=e4718c30e4c4f01b259082143a16757b80e8e2af;hpb=e50901c4b06c82b91f136dac09bacce01258d7b2;p=transportpce.git diff --git a/tapi/src/test/java/org/opendaylight/transportpce/tapi/connectivity/TapiConnectivityImplTest.java b/tapi/src/test/java/org/opendaylight/transportpce/tapi/connectivity/TapiConnectivityImplTest.java index e4718c30e..70a9adcb3 100644 --- a/tapi/src/test/java/org/opendaylight/transportpce/tapi/connectivity/TapiConnectivityImplTest.java +++ b/tapi/src/test/java/org/opendaylight/transportpce/tapi/connectivity/TapiConnectivityImplTest.java @@ -7,7 +7,10 @@ */ package org.opendaylight.transportpce.tapi.connectivity; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; @@ -17,23 +20,23 @@ import java.util.HashMap; 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.mdsal.binding.api.RpcProviderService; import org.opendaylight.transportpce.common.InstanceIdentifiers; import org.opendaylight.transportpce.common.network.NetworkTransactionImpl; import org.opendaylight.transportpce.common.network.NetworkTransactionService; -import org.opendaylight.transportpce.common.network.RequestProcessor; import org.opendaylight.transportpce.pce.service.PathComputationService; import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations; +import org.opendaylight.transportpce.servicehandler.catalog.CatalogDataStoreOperations; import org.opendaylight.transportpce.servicehandler.impl.ServicehandlerImpl; -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.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.tapi.listeners.TapiPceListenerImpl; @@ -44,66 +47,63 @@ import org.opendaylight.transportpce.tapi.utils.TapiConnectivityDataUtils; import org.opendaylight.transportpce.tapi.utils.TapiContext; import org.opendaylight.transportpce.tapi.utils.TapiInitialORMapping; import org.opendaylight.transportpce.tapi.utils.TapiLink; +import org.opendaylight.transportpce.tapi.utils.TapiLinkImpl; import org.opendaylight.transportpce.tapi.utils.TapiTopologyDataUtils; import org.opendaylight.transportpce.test.AbstractTest; import org.opendaylight.transportpce.test.utils.TopologyDataUtils; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.OrgOpenroadmServiceService; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.OrgOpenroadmServiceService; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceCreateInput; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.CreateConnectivityServiceInput; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.CreateConnectivityServiceInputBuilder; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.CreateConnectivityServiceOutput; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.DeleteConnectivityServiceInput; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.DeleteConnectivityServiceInputBuilder; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.DeleteConnectivityServiceOutput; -import org.opendaylight.yangtools.yang.common.RpcError; +import org.opendaylight.yangtools.yang.common.ErrorType; import org.opendaylight.yangtools.yang.common.RpcResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@ExtendWith(MockitoExtension.class) public class TapiConnectivityImplTest extends AbstractTest { @Mock private PathComputationService pathComputationService; - @Mock private RendererServiceOperations rendererServiceOperations; - @Mock private NotificationPublishService notificationPublishService; - @Mock private TapiPceListenerImpl tapipceListenerImpl; - @Mock private TapiRendererListenerImpl tapirendererListenerImpl; - @Mock private TapiServiceHandlerListenerImpl tapiserviceHandlerListenerImpl; - @Mock - private PceListenerImpl pceListenerImpl; - + private PceListener pceListenerImpl; @Mock - private RendererListenerImpl rendererListenerImpl; - + private RendererListener rendererListenerImpl; + @Mock + private NetworkListener networkModelListenerImpl; @Mock - private NetworkModelListenerImpl networkModelListenerImpl; + public CatalogDataStoreOperations catalogDataStoreOperations; + @Mock + private RpcProviderService rpcProviderService; private static final Logger LOG = LoggerFactory.getLogger(TapiConnectivityImplTest.class); - public static ServiceDataStoreOperations serviceDataStoreOperations; - public static TapiContext tapiContext; - public static TopologyUtils topologyUtils; - public static ConnectivityUtils connectivityUtils; - public static TapiInitialORMapping tapiInitialORMapping; - public static NetworkTransactionService networkTransactionService; - public static TapiLink tapilink; + private static ServiceDataStoreOperations serviceDataStoreOperations; + private static TapiContext tapiContext; + private static TopologyUtils topologyUtils; + private static ConnectivityUtils connectivityUtils; + private static TapiInitialORMapping tapiInitialORMapping; + private static NetworkTransactionService networkTransactionService; + private static TapiLink tapilink; private ListeningExecutorService executorService; private CountDownLatch endSignal; private static final int NUM_THREADS = 5; - private boolean callbackRan; - @Before - public void setUp() throws InterruptedException, ExecutionException { + @BeforeEach + void setUp() throws InterruptedException, ExecutionException { executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS)); endSignal = new CountDownLatch(1); // Need to have datastore populated to enable the mapping from TAPI to OR @@ -116,17 +116,14 @@ public class TapiConnectivityImplTest extends AbstractTest { TopologyDataUtils.writePortmappingFromFileToDatastore(getDataStoreContextUtil(), TapiTopologyDataUtils.PORTMAPPING_FILE); - callbackRan = false; - MockitoAnnotations.openMocks(this); - - networkTransactionService = new NetworkTransactionImpl( - new RequestProcessor(getDataStoreContextUtil().getDataBroker())); - tapilink = new TapiLink(networkTransactionService); + networkTransactionService = new NetworkTransactionImpl(getDataBroker()); + tapilink = new TapiLinkImpl(networkTransactionService); serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(getDataStoreContextUtil().getDataBroker()); tapiContext = new TapiContext(networkTransactionService); topologyUtils = new TopologyUtils(networkTransactionService, getDataStoreContextUtil().getDataBroker(), tapilink); - connectivityUtils = new ConnectivityUtils(serviceDataStoreOperations, new HashMap<>(), tapiContext); + connectivityUtils = new ConnectivityUtils(serviceDataStoreOperations, new HashMap<>(), tapiContext, + networkTransactionService); tapiInitialORMapping = new TapiInitialORMapping(topologyUtils, connectivityUtils, tapiContext, serviceDataStoreOperations); tapiInitialORMapping.performTopoInitialMapping(); @@ -134,20 +131,19 @@ public class TapiConnectivityImplTest extends AbstractTest { } @Test - public void createConnServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { - OrgOpenroadmServiceService serviceHandler = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, + void createConnServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { + OrgOpenroadmServiceService serviceHandler = new ServicehandlerImpl(rpcProviderService, pathComputationService, rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, - networkModelListenerImpl, serviceDataStoreOperations); + networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations); TapiConnectivityImpl tapiConnectivity = new TapiConnectivityImpl(serviceHandler, tapiContext, connectivityUtils, - tapipceListenerImpl, tapirendererListenerImpl, tapiserviceHandlerListenerImpl); + tapipceListenerImpl, tapirendererListenerImpl); ListenableFuture> result = tapiConnectivity.createConnectivityService(new CreateConnectivityServiceInputBuilder().build()); result.addListener(new Runnable() { @Override public void run() { - callbackRan = true; endSignal.countDown(); } }, executorService); @@ -155,28 +151,26 @@ public class TapiConnectivityImplTest extends AbstractTest { endSignal.await(); RpcResult rpcResult = result.get(); - Assert.assertEquals( - RpcError.ErrorType.RPC, rpcResult.getErrors().get(0).getErrorType()); + assertEquals(ErrorType.RPC, rpcResult.getErrors().get(0).getErrorType()); } @Test - public void createConnServiceShouldBeSuccessfulWhenPerformPCESuccessful() + void createConnServiceShouldBeSuccessfulWhenPerformPCESuccessful() throws ExecutionException, InterruptedException { - OrgOpenroadmServiceService serviceHandler = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, + OrgOpenroadmServiceService serviceHandler = new ServicehandlerImpl(rpcProviderService, pathComputationService, rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, - networkModelListenerImpl, serviceDataStoreOperations); + networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations); CreateConnectivityServiceInput input = TapiConnectivityDataUtils.buildConnServiceCreateInput(); - Mockito.when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any())); + when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any())); TapiConnectivityImpl tapiConnectivity = new TapiConnectivityImpl(serviceHandler, tapiContext, connectivityUtils, - tapipceListenerImpl, tapirendererListenerImpl, tapiserviceHandlerListenerImpl); + tapipceListenerImpl, tapirendererListenerImpl); ListenableFuture> result = tapiConnectivity.createConnectivityService(input); result.addListener(new Runnable() { @Override public void run() { - callbackRan = true; endSignal.countDown(); } }, executorService); @@ -184,24 +178,23 @@ public class TapiConnectivityImplTest extends AbstractTest { endSignal.await(); RpcResult rpcResult = result.get(); - Assert.assertTrue(rpcResult.isSuccessful()); + assertTrue(rpcResult.isSuccessful()); } @Test - public void deleteConnServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { - OrgOpenroadmServiceService serviceHandler = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, + void deleteConnServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException { + OrgOpenroadmServiceService serviceHandler = new ServicehandlerImpl(rpcProviderService, pathComputationService, rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, - networkModelListenerImpl, serviceDataStoreOperations); + networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations); TapiConnectivityImpl tapiConnectivity = new TapiConnectivityImpl(serviceHandler, tapiContext, connectivityUtils, - tapipceListenerImpl, tapirendererListenerImpl, tapiserviceHandlerListenerImpl); + tapipceListenerImpl, tapirendererListenerImpl); ListenableFuture> result = tapiConnectivity.deleteConnectivityService(new DeleteConnectivityServiceInputBuilder().build()); result.addListener(new Runnable() { @Override public void run() { - callbackRan = true; endSignal.countDown(); } }, executorService); @@ -209,25 +202,23 @@ public class TapiConnectivityImplTest extends AbstractTest { endSignal.await(); RpcResult rpcResult = result.get(); - Assert.assertEquals( - RpcError.ErrorType.RPC, rpcResult.getErrors().get(0).getErrorType()); + assertEquals(ErrorType.RPC, rpcResult.getErrors().get(0).getErrorType()); } @Test - public void deleteConnServiceShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { + void deleteConnServiceShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException { DeleteConnectivityServiceInput input = TapiConnectivityDataUtils.buildConnServiceDeleteInput1(); - OrgOpenroadmServiceService serviceHandler = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, + OrgOpenroadmServiceService serviceHandler = new ServicehandlerImpl(rpcProviderService, pathComputationService, rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, - networkModelListenerImpl, serviceDataStoreOperations); + networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations); TapiConnectivityImpl tapiConnectivity = new TapiConnectivityImpl(serviceHandler, tapiContext, connectivityUtils, - tapipceListenerImpl, tapirendererListenerImpl, tapiserviceHandlerListenerImpl); + tapipceListenerImpl, tapirendererListenerImpl); ListenableFuture> result = tapiConnectivity.deleteConnectivityService(input); result.addListener(new Runnable() { @Override public void run() { - callbackRan = true; endSignal.countDown(); } }, executorService); @@ -235,20 +226,19 @@ public class TapiConnectivityImplTest extends AbstractTest { endSignal.await(); RpcResult rpcResult = result.get(); - Assert.assertEquals( - RpcError.ErrorType.RPC, rpcResult.getErrors().get(0).getErrorType()); + assertEquals(ErrorType.RPC, rpcResult.getErrors().get(0).getErrorType()); } @Test - public void deleteConnServiceShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException { - Mockito.when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any())); + void deleteConnServiceShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException { + when(rendererServiceOperations.serviceDelete(any(), any())).thenReturn(Futures.immediateFuture(any())); - OrgOpenroadmServiceService serviceHandler = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, + OrgOpenroadmServiceService serviceHandler = new ServicehandlerImpl(rpcProviderService, pathComputationService, rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl, - networkModelListenerImpl, serviceDataStoreOperations); + networkModelListenerImpl, serviceDataStoreOperations, catalogDataStoreOperations); TapiConnectivityImpl tapiConnectivity = new TapiConnectivityImpl(serviceHandler, tapiContext, connectivityUtils, - tapipceListenerImpl, tapirendererListenerImpl, tapiserviceHandlerListenerImpl); + tapipceListenerImpl, tapirendererListenerImpl); ServiceCreateInput createInput = TapiConnectivityDataUtils.buildServiceCreateInput(); serviceDataStoreOperations.createService(createInput); @@ -260,7 +250,6 @@ public class TapiConnectivityImplTest extends AbstractTest { result.addListener(new Runnable() { @Override public void run() { - callbackRan = true; endSignal.countDown(); } }, executorService); @@ -268,6 +257,6 @@ public class TapiConnectivityImplTest extends AbstractTest { endSignal.await(); RpcResult rpcResult = result.get(); - Assert.assertTrue(rpcResult.isSuccessful()); + assertTrue(rpcResult.isSuccessful()); } -} +} \ No newline at end of file