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=837a61fe6d2b08dad3334f02981fe13d596e9390;hb=db87ba733190c2e59997e00e0fe9199c9c74234d;hp=013abb37646c1dcfad153bbda66dec480f5c08c4;hpb=cf3a29d3e9f11331a9cab1a4dc59b0e0d96ac9c0;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 013abb376..837a61fe6 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,91 +20,94 @@ 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; -import org.opendaylight.transportpce.tapi.listeners.TapiRendererListenerImpl; -import org.opendaylight.transportpce.tapi.listeners.TapiServiceHandlerListenerImpl; +import org.opendaylight.transportpce.tapi.listeners.TapiPceNotificationHandler; +import org.opendaylight.transportpce.tapi.listeners.TapiRendererNotificationHandler; +import org.opendaylight.transportpce.tapi.listeners.TapiServiceNotificationHandler; import org.opendaylight.transportpce.tapi.topology.TopologyUtils; 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.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.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteOutput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteOutputBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.configuration.response.common.ConfigurationResponseCommon; +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.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.rev221121.CreateConnectivityServiceInput; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.CreateConnectivityServiceInputBuilder; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.CreateConnectivityServiceOutput; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.DeleteConnectivityServiceInput; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.DeleteConnectivityServiceInputBuilder; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.DeleteConnectivityServiceOutput; +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; - + private TapiPceNotificationHandler tapipceNotificationHandler; @Mock - private TapiRendererListenerImpl tapirendererListenerImpl; - + private TapiRendererNotificationHandler tapirendererNotificationHandler; @Mock - private TapiServiceHandlerListenerImpl tapiserviceHandlerListenerImpl; - + private TapiServiceNotificationHandler tapiserviceNotificationHandler; @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; + 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 @@ -114,15 +120,14 @@ public class TapiConnectivityImplTest extends AbstractTest { TopologyDataUtils.writePortmappingFromFileToDatastore(getDataStoreContextUtil(), TapiTopologyDataUtils.PORTMAPPING_FILE); - callbackRan = false; - MockitoAnnotations.openMocks(this); - - networkTransactionService = new NetworkTransactionImpl( - new RequestProcessor(getDataStoreContextUtil().getDataBroker())); + networkTransactionService = new NetworkTransactionImpl(getDataBroker()); + tapilink = new TapiLinkImpl(networkTransactionService); serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(getDataStoreContextUtil().getDataBroker()); tapiContext = new TapiContext(networkTransactionService); - topologyUtils = new TopologyUtils(networkTransactionService, getDataStoreContextUtil().getDataBroker()); - connectivityUtils = new ConnectivityUtils(serviceDataStoreOperations, new HashMap<>(), tapiContext); + topologyUtils = new TopologyUtils(networkTransactionService, getDataStoreContextUtil().getDataBroker(), + tapilink); + connectivityUtils = new ConnectivityUtils(serviceDataStoreOperations, new HashMap<>(), tapiContext, + networkTransactionService); tapiInitialORMapping = new TapiInitialORMapping(topologyUtils, connectivityUtils, tapiContext, serviceDataStoreOperations); tapiInitialORMapping.performTopoInitialMapping(); @@ -130,20 +135,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); + tapipceNotificationHandler, tapirendererNotificationHandler, networkTransactionService); ListenableFuture> result = tapiConnectivity.createConnectivityService(new CreateConnectivityServiceInputBuilder().build()); result.addListener(new Runnable() { @Override public void run() { - callbackRan = true; endSignal.countDown(); } }, executorService); @@ -151,53 +155,51 @@ 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); + tapipceNotificationHandler, tapirendererNotificationHandler, networkTransactionService); ListenableFuture> result = tapiConnectivity.createConnectivityService(input); result.addListener(new Runnable() { @Override public void run() { - callbackRan = true; endSignal.countDown(); } }, executorService); endSignal.await(); - + LOG.info("INPUT= {}", input.toString()); 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); + tapipceNotificationHandler, tapirendererNotificationHandler, networkTransactionService); ListenableFuture> result = tapiConnectivity.deleteConnectivityService(new DeleteConnectivityServiceInputBuilder().build()); result.addListener(new Runnable() { @Override public void run() { - callbackRan = true; endSignal.countDown(); } }, executorService); @@ -205,25 +207,22 @@ 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); + tapipceNotificationHandler, tapirendererNotificationHandler, networkTransactionService); ListenableFuture> result = tapiConnectivity.deleteConnectivityService(input); result.addListener(new Runnable() { @Override public void run() { - callbackRan = true; endSignal.countDown(); } }, executorService); @@ -231,39 +230,43 @@ 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())); - - OrgOpenroadmServiceService serviceHandler = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, + void deleteConnServiceShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException { + ConfigurationResponseCommon crc = new ConfigurationResponseCommonBuilder() + .setRequestId("request 1") + .setResponseCode("OK") + .setAckFinalIndicator("requestProcessed").build(); + ServiceDeleteOutput sdo = new ServiceDeleteOutputBuilder() + .setConfigurationResponseCommon(crc) + .build(); + when(rendererServiceOperations.serviceDelete(any(), any())) + .thenReturn(Futures.immediateFuture(sdo)); + + 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); - + tapipceNotificationHandler, tapirendererNotificationHandler, networkTransactionService); ServiceCreateInput createInput = TapiConnectivityDataUtils.buildServiceCreateInput(); serviceDataStoreOperations.createService(createInput); tapiContext.updateConnectivityContext(TapiConnectivityDataUtils.createConnService(), new HashMap<>()); - DeleteConnectivityServiceInput input = TapiConnectivityDataUtils.buildConnServiceDeleteInput(); ListenableFuture> result = tapiConnectivity.deleteConnectivityService(input); result.addListener(new Runnable() { @Override public void run() { - callbackRan = true; endSignal.countDown(); } }, executorService); endSignal.await(); - + LOG.debug("RESULT = {}", result.toString()); RpcResult rpcResult = result.get(); - Assert.assertTrue(rpcResult.isSuccessful()); + assertTrue(rpcResult.isSuccessful()); } }