*/
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.doReturn;
+import static org.mockito.Mockito.when;
-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.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.mdsal.binding.api.RpcService;
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.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.catalog.CatalogDataStoreOperations;
+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.impl.rpc.CreateConnectivityServiceImpl;
+import org.opendaylight.transportpce.tapi.impl.rpc.DeleteConnectivityServiceImpl;
+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.rev211210.OrgOpenroadmServiceService;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.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.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.ServiceCreate;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceCreateInput;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceCreateOutputBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceDelete;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.CreateConnectivityService;
+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.DeleteConnectivityService;
+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.opendaylight.yangtools.yang.common.RpcResultBuilder;
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
+ public CatalogDataStoreOperations catalogDataStoreOperations;
+ @Mock
+ private RpcProviderService rpcProviderService;
+ @Mock
+ private RpcService rpcService;
@Mock
- private NetworkModelListenerImpl networkModelListenerImpl;
+ private ServiceCreate serviceCreate;
+ @Mock
+ private ServiceDelete serviceDelete;
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;
- @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
TopologyDataUtils.writePortmappingFromFileToDatastore(getDataStoreContextUtil(),
TapiTopologyDataUtils.PORTMAPPING_FILE);
- 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(),
}
@Test
- public void createConnServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
- OrgOpenroadmServiceService serviceHandler = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
- rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
- networkModelListenerImpl, serviceDataStoreOperations);
-
- TapiConnectivityImpl tapiConnectivity = new TapiConnectivityImpl(serviceHandler, tapiContext, connectivityUtils,
- tapipceListenerImpl, tapirendererListenerImpl);
-
- ListenableFuture<RpcResult<CreateConnectivityServiceOutput>> result =
- tapiConnectivity.createConnectivityService(new CreateConnectivityServiceInputBuilder().build());
+ void createConnServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
+ when(rpcService.getRpc(any()))
+ .thenReturn(new CreateConnectivityServiceImpl(rpcService, tapiContext, connectivityUtils,
+ tapipceNotificationHandler, tapirendererNotificationHandler));
+ ListenableFuture<RpcResult<CreateConnectivityServiceOutput>> result = rpcService
+ .getRpc(CreateConnectivityService.class).invoke(new CreateConnectivityServiceInputBuilder().build());
result.addListener(new Runnable() {
@Override
public void run() {
endSignal.await();
RpcResult<CreateConnectivityServiceOutput> rpcResult = result.get();
- Assert.assertEquals(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,
- rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
- networkModelListenerImpl, serviceDataStoreOperations);
-
+ ConfigurationResponseCommon crc = new ConfigurationResponseCommonBuilder()
+ .setRequestId("request 1")
+ .setResponseCode("OK")
+ .setAckFinalIndicator("requestProcessed").build();
+ when(rpcService.getRpc(any())).thenReturn(serviceCreate);
+ doReturn(RpcResultBuilder
+ .success(new ServiceCreateOutputBuilder()
+ .setConfigurationResponseCommon(crc)
+ .build())
+ .buildFuture())
+ .when(serviceCreate).invoke(any());
CreateConnectivityServiceInput input = TapiConnectivityDataUtils.buildConnServiceCreateInput();
- Mockito.when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
- TapiConnectivityImpl tapiConnectivity = new TapiConnectivityImpl(serviceHandler, tapiContext, connectivityUtils,
- tapipceListenerImpl, tapirendererListenerImpl);
ListenableFuture<RpcResult<CreateConnectivityServiceOutput>> result =
- tapiConnectivity.createConnectivityService(input);
- result.addListener(new Runnable() {
- @Override
- public void run() {
- endSignal.countDown();
- }
- }, executorService);
-
- endSignal.await();
-
+ new CreateConnectivityServiceImpl(rpcService, tapiContext, connectivityUtils,
+ tapipceNotificationHandler, tapirendererNotificationHandler)
+ .invoke(input);
+ LOG.info("INPUT= {}", input.toString());
RpcResult<CreateConnectivityServiceOutput> rpcResult = result.get();
- Assert.assertTrue(rpcResult.isSuccessful());
+ assertTrue(rpcResult.isSuccessful());
}
@Test
- public void deleteConnServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
- OrgOpenroadmServiceService serviceHandler = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
- rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
- networkModelListenerImpl, serviceDataStoreOperations);
-
- TapiConnectivityImpl tapiConnectivity = new TapiConnectivityImpl(serviceHandler, tapiContext, connectivityUtils,
- tapipceListenerImpl, tapirendererListenerImpl);
-
- ListenableFuture<RpcResult<DeleteConnectivityServiceOutput>> result =
- tapiConnectivity.deleteConnectivityService(new DeleteConnectivityServiceInputBuilder().build());
+ void deleteConnServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
+ when(rpcService.getRpc(any()))
+ .thenReturn(new DeleteConnectivityServiceImpl(rpcService, tapiContext, networkTransactionService));
+ ListenableFuture<RpcResult<DeleteConnectivityServiceOutput>> result = rpcService
+ .getRpc(DeleteConnectivityService.class).invoke(new DeleteConnectivityServiceInputBuilder().build());
result.addListener(new Runnable() {
@Override
public void run() {
endSignal.await();
RpcResult<DeleteConnectivityServiceOutput> rpcResult = result.get();
- Assert.assertEquals(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 {
+ when(rpcService.getRpc(any()))
+ .thenReturn(new DeleteConnectivityServiceImpl(rpcService, tapiContext, networkTransactionService));
DeleteConnectivityServiceInput input = TapiConnectivityDataUtils.buildConnServiceDeleteInput1();
- OrgOpenroadmServiceService serviceHandler = new ServicehandlerImpl(getNewDataBroker(), pathComputationService,
- rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
- networkModelListenerImpl, serviceDataStoreOperations);
-
- TapiConnectivityImpl tapiConnectivity = new TapiConnectivityImpl(serviceHandler, tapiContext, connectivityUtils,
- tapipceListenerImpl, tapirendererListenerImpl);
- ListenableFuture<RpcResult<DeleteConnectivityServiceOutput>> result =
- tapiConnectivity.deleteConnectivityService(input);
+ ListenableFuture<RpcResult<DeleteConnectivityServiceOutput>> result = rpcService
+ .getRpc(DeleteConnectivityService.class).invoke(input);
result.addListener(new Runnable() {
@Override
public void run() {
endSignal.await();
RpcResult<DeleteConnectivityServiceOutput> rpcResult = result.get();
- Assert.assertEquals(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,
- rendererServiceOperations, notificationPublishService, pceListenerImpl, rendererListenerImpl,
- networkModelListenerImpl, serviceDataStoreOperations);
-
- TapiConnectivityImpl tapiConnectivity = new TapiConnectivityImpl(serviceHandler, tapiContext, connectivityUtils,
- tapipceListenerImpl, tapirendererListenerImpl);
-
+ void deleteConnServiceShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
+ ConfigurationResponseCommon crc = new ConfigurationResponseCommonBuilder()
+ .setRequestId("request 1")
+ .setResponseCode("OK")
+ .setAckFinalIndicator("requestProcessed").build();
+ when(rpcService.getRpc(any())).thenReturn(serviceDelete);
+ doReturn(RpcResultBuilder
+ .success(new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526
+ .ServiceDeleteOutputBuilder()
+ .setConfigurationResponseCommon(crc)
+ .build())
+ .buildFuture())
+ .when(serviceDelete).invoke(any());
ServiceCreateInput createInput = TapiConnectivityDataUtils.buildServiceCreateInput();
serviceDataStoreOperations.createService(createInput);
tapiContext.updateConnectivityContext(TapiConnectivityDataUtils.createConnService(), new HashMap<>());
-
DeleteConnectivityServiceInput input = TapiConnectivityDataUtils.buildConnServiceDeleteInput();
ListenableFuture<RpcResult<DeleteConnectivityServiceOutput>> result =
- tapiConnectivity.deleteConnectivityService(input);
- result.addListener(new Runnable() {
- @Override
- public void run() {
- endSignal.countDown();
- }
- }, executorService);
-
- endSignal.await();
-
+ new DeleteConnectivityServiceImpl(rpcService, tapiContext, networkTransactionService).invoke(input);
+ LOG.debug("RESULT = {}", result.toString());
RpcResult<DeleteConnectivityServiceOutput> rpcResult = result.get();
- Assert.assertTrue(rpcResult.isSuccessful());
+ assertTrue(rpcResult.isSuccessful());
}
}