Turn NetworkTransactionImpl into a component
[transportpce.git] / tapi / src / test / java / org / opendaylight / transportpce / tapi / connectivity / TapiConnectivityImplTest.java
index 013abb37646c1dcfad153bbda66dec480f5c08c4..c01c1e153150ce3dc5328879c81be6f0b134b336 100644 (file)
@@ -27,7 +27,6 @@ import org.opendaylight.mdsal.binding.api.NotificationPublishService;
 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;
@@ -43,18 +42,19 @@ 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.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.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.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;
@@ -95,10 +95,10 @@ public class TapiConnectivityImplTest extends AbstractTest {
     public static ConnectivityUtils connectivityUtils;
     public static TapiInitialORMapping tapiInitialORMapping;
     public static NetworkTransactionService networkTransactionService;
+    public 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 {
@@ -114,15 +114,16 @@ 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 TapiLink(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();
@@ -136,14 +137,13 @@ public class TapiConnectivityImplTest extends AbstractTest {
             networkModelListenerImpl, serviceDataStoreOperations);
 
         TapiConnectivityImpl tapiConnectivity = new TapiConnectivityImpl(serviceHandler, tapiContext, connectivityUtils,
-            tapipceListenerImpl, tapirendererListenerImpl, tapiserviceHandlerListenerImpl);
+            tapipceListenerImpl, tapirendererListenerImpl);
 
         ListenableFuture<RpcResult<CreateConnectivityServiceOutput>> result =
             tapiConnectivity.createConnectivityService(new CreateConnectivityServiceInputBuilder().build());
         result.addListener(new Runnable() {
             @Override
             public void run() {
-                callbackRan = true;
                 endSignal.countDown();
             }
         }, executorService);
@@ -151,8 +151,7 @@ public class TapiConnectivityImplTest extends AbstractTest {
         endSignal.await();
 
         RpcResult<CreateConnectivityServiceOutput> rpcResult = result.get();
-        Assert.assertEquals(
-            RpcError.ErrorType.RPC, rpcResult.getErrors().get(0).getErrorType());
+        Assert.assertEquals(ErrorType.RPC, rpcResult.getErrors().get(0).getErrorType());
     }
 
     @Test
@@ -166,13 +165,12 @@ public class TapiConnectivityImplTest extends AbstractTest {
         Mockito.when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
 
         TapiConnectivityImpl tapiConnectivity = new TapiConnectivityImpl(serviceHandler, tapiContext, connectivityUtils,
-            tapipceListenerImpl, tapirendererListenerImpl, tapiserviceHandlerListenerImpl);
+            tapipceListenerImpl, tapirendererListenerImpl);
         ListenableFuture<RpcResult<CreateConnectivityServiceOutput>> result =
             tapiConnectivity.createConnectivityService(input);
         result.addListener(new Runnable() {
             @Override
             public void run() {
-                callbackRan = true;
                 endSignal.countDown();
             }
         }, executorService);
@@ -190,14 +188,13 @@ public class TapiConnectivityImplTest extends AbstractTest {
             networkModelListenerImpl, serviceDataStoreOperations);
 
         TapiConnectivityImpl tapiConnectivity = new TapiConnectivityImpl(serviceHandler, tapiContext, connectivityUtils,
-            tapipceListenerImpl, tapirendererListenerImpl, tapiserviceHandlerListenerImpl);
+            tapipceListenerImpl, tapirendererListenerImpl);
 
         ListenableFuture<RpcResult<DeleteConnectivityServiceOutput>> result =
             tapiConnectivity.deleteConnectivityService(new DeleteConnectivityServiceInputBuilder().build());
         result.addListener(new Runnable() {
             @Override
             public void run() {
-                callbackRan = true;
                 endSignal.countDown();
             }
         }, executorService);
@@ -205,8 +202,7 @@ public class TapiConnectivityImplTest extends AbstractTest {
         endSignal.await();
 
         RpcResult<DeleteConnectivityServiceOutput> rpcResult = result.get();
-        Assert.assertEquals(
-            RpcError.ErrorType.RPC, rpcResult.getErrors().get(0).getErrorType());
+        Assert.assertEquals(ErrorType.RPC, rpcResult.getErrors().get(0).getErrorType());
     }
 
     @Test
@@ -217,13 +213,12 @@ public class TapiConnectivityImplTest extends AbstractTest {
             networkModelListenerImpl, serviceDataStoreOperations);
 
         TapiConnectivityImpl tapiConnectivity = new TapiConnectivityImpl(serviceHandler, tapiContext, connectivityUtils,
-            tapipceListenerImpl, tapirendererListenerImpl, tapiserviceHandlerListenerImpl);
+            tapipceListenerImpl, tapirendererListenerImpl);
         ListenableFuture<RpcResult<DeleteConnectivityServiceOutput>> result =
             tapiConnectivity.deleteConnectivityService(input);
         result.addListener(new Runnable() {
             @Override
             public void run() {
-                callbackRan = true;
                 endSignal.countDown();
             }
         }, executorService);
@@ -231,8 +226,7 @@ public class TapiConnectivityImplTest extends AbstractTest {
         endSignal.await();
 
         RpcResult<DeleteConnectivityServiceOutput> rpcResult = result.get();
-        Assert.assertEquals(
-            RpcError.ErrorType.RPC, rpcResult.getErrors().get(0).getErrorType());
+        Assert.assertEquals(ErrorType.RPC, rpcResult.getErrors().get(0).getErrorType());
     }
 
     @Test
@@ -244,7 +238,7 @@ public class TapiConnectivityImplTest extends AbstractTest {
             networkModelListenerImpl, serviceDataStoreOperations);
 
         TapiConnectivityImpl tapiConnectivity = new TapiConnectivityImpl(serviceHandler, tapiContext, connectivityUtils,
-            tapipceListenerImpl, tapirendererListenerImpl, tapiserviceHandlerListenerImpl);
+            tapipceListenerImpl, tapirendererListenerImpl);
 
         ServiceCreateInput createInput = TapiConnectivityDataUtils.buildServiceCreateInput();
         serviceDataStoreOperations.createService(createInput);
@@ -256,7 +250,6 @@ public class TapiConnectivityImplTest extends AbstractTest {
         result.addListener(new Runnable() {
             @Override
             public void run() {
-                callbackRan = true;
                 endSignal.countDown();
             }
         }, executorService);