Remove deprecated MD-SAL APIs
[controller.git] / opendaylight / md-sal / sal-binding-it / src / test / java / org / opendaylight / controller / test / sal / binding / it / RoutedServiceIT.java
index 91e53d0cc8c443af02d86bb486ae72d88a452c45..523071415df6474e9e3be50b58460f39bbc1e5c7 100644 (file)
@@ -15,21 +15,22 @@ import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
 import com.google.common.util.concurrent.Futures;
+import java.util.Set;
 import javax.inject.Inject;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
-import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.mdsal.binding.api.RpcConsumerRegistry;
+import org.opendaylight.mdsal.binding.api.RpcProviderService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.OpendaylightTestRoutedRpcService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.RoutedSimpleRouteInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.RoutedSimpleRouteInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.RoutedSimpleRouteOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.TestContext;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.Lists;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.UnorderedContainer;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unordered.container.UnorderedList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unordered.container.UnorderedListKey;
+import org.opendaylight.yangtools.concepts.ObjectRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.ops4j.pax.exam.util.Filter;
@@ -49,7 +50,11 @@ public class RoutedServiceIT extends AbstractIT {
 
     @Inject
     @Filter(timeout = 120 * 1000)
-    RpcProviderRegistry rpcProviderRegistry;
+    RpcProviderService rpcProviderService;
+
+    @Inject
+    @Filter(timeout = 120 * 1000)
+    RpcConsumerRegistry rpcConsumerRegistry;
 
     /**
      * Prepare mocks.
@@ -66,32 +71,29 @@ public class RoutedServiceIT extends AbstractIT {
 
     @Test
     public void testServiceRegistration() {
-        LOG.info("Register provider 1 with first implementation of routeSimpleService - service1");
+        LOG.info("Register provider 1 with first implementation of routeSimpleService - service1 of node 1");
+        final InstanceIdentifier<UnorderedList> nodeOnePath = createNodeRef("foo:node:1");
+        final InstanceIdentifier<UnorderedList> nodeTwo = createNodeRef("foo:node:2");
 
-        RoutedRpcRegistration<OpendaylightTestRoutedRpcService> firstReg = rpcProviderRegistry
-                .addRoutedRpcImplementation(OpendaylightTestRoutedRpcService.class, odlRoutedService1);
+        ObjectRegistration<OpendaylightTestRoutedRpcService> firstReg = rpcProviderService.registerRpcImplementation(
+            OpendaylightTestRoutedRpcService.class, odlRoutedService1,  Set.of(nodeOnePath));
         assertNotNull("Registration should not be null", firstReg);
         assertSame(odlRoutedService1, firstReg.getInstance());
 
-        LOG.info("Register provider 2 with second implementation of routeSimpleService - service2");
+        LOG.info("Register provider 2 with second implementation of routeSimpleService - service2 of node 2");
 
-        RoutedRpcRegistration<OpendaylightTestRoutedRpcService> secondReg = rpcProviderRegistry
-                .addRoutedRpcImplementation(OpendaylightTestRoutedRpcService.class, odlRoutedService2);
+        ObjectRegistration<OpendaylightTestRoutedRpcService> secondReg = rpcProviderService.registerRpcImplementation(
+            OpendaylightTestRoutedRpcService.class, odlRoutedService2, Set.of(nodeTwo));
         assertNotNull("Registration should not be null", firstReg);
         assertSame(odlRoutedService2, secondReg.getInstance());
         assertNotSame(secondReg, firstReg);
 
         OpendaylightTestRoutedRpcService consumerService =
-                rpcProviderRegistry.getRpcService(OpendaylightTestRoutedRpcService.class);
+                rpcConsumerRegistry.getRpcService(OpendaylightTestRoutedRpcService.class);
         assertNotNull("MD-SAL instance of test Service should be returned", consumerService);
         assertNotSame("Provider instance and consumer instance should not be same.", odlRoutedService1,
                 consumerService);
 
-        final InstanceIdentifier<UnorderedList> nodeOnePath = createNodeRef("foo:node:1");
-
-        LOG.info("Provider 1 registers path of node 1");
-        firstReg.registerPath(TestContext.class, nodeOnePath);
-
         /**
          * Consumer creates addFlow message for node one and sends it to the MD-SAL.
          */
@@ -107,10 +109,6 @@ public class RoutedServiceIT extends AbstractIT {
          */
         verify(odlRoutedService2, times(0)).routedSimpleRoute(simpleRouteFirstFoo);
 
-        LOG.info("Provider 2 registers path of node 2");
-        final InstanceIdentifier<UnorderedList> nodeTwo = createNodeRef("foo:node:2");
-        secondReg.registerPath(TestContext.class, nodeTwo);
-
         /**
          * Consumer sends message to nodeTwo for three times. Should be processed by second instance.
          */
@@ -126,10 +124,12 @@ public class RoutedServiceIT extends AbstractIT {
         verify(odlRoutedService1, times(0)).routedSimpleRoute(simpleRouteSecondFoo);
 
         LOG.info("Unregistration of the path for the node one in the first provider");
-        firstReg.unregisterPath(TestContext.class, nodeOnePath);
+        firstReg.close();
 
         LOG.info("Provider 2 registers path of node 1");
-        secondReg.registerPath(TestContext.class, nodeOnePath);
+        secondReg.close();
+        secondReg = rpcProviderService.registerRpcImplementation(
+            OpendaylightTestRoutedRpcService.class, odlRoutedService2, Set.of(nodeOnePath));
 
         /**
          * A consumer sends third message to node 1.
@@ -165,8 +165,6 @@ public class RoutedServiceIT extends AbstractIT {
      * @return simpleRouteInput instance
      */
     static RoutedSimpleRouteInput createSimpleRouteInput(final InstanceIdentifier<UnorderedList> node) {
-        final RoutedSimpleRouteInputBuilder ret = new RoutedSimpleRouteInputBuilder();
-        ret.setRoute(node);
-        return ret.build();
+        return new RoutedSimpleRouteInputBuilder().setRoute(node).build();
     }
 }