Fix checkstyle/spotbugs violations
[controller.git] / opendaylight / md-sal / sal-binding-it / src / test / java / org / opendaylight / controller / test / sal / binding / it / RoutedServiceIT.java
index a394bcba89e0731dae13e92f00a5be549cf3d6c5..91e53d0cc8c443af02d86bb486ae72d88a452c45 100644 (file)
@@ -13,17 +13,18 @@ import static org.junit.Assert.assertSame;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
+
 import com.google.common.util.concurrent.Futures;
+import javax.inject.Inject;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
-import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
-import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
 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;
@@ -31,11 +32,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controll
 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.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.ops4j.pax.exam.util.Filter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * covers routed rpc creation, registration, invocation, unregistration
+ * Covers routed rpc creation, registration, invocation, unregistration.
  */
 public class RoutedServiceIT extends AbstractIT {
 
@@ -45,63 +47,45 @@ public class RoutedServiceIT extends AbstractIT {
     protected OpendaylightTestRoutedRpcService odlRoutedService1;
     protected OpendaylightTestRoutedRpcService odlRoutedService2;
 
-    protected OpendaylightTestRoutedRpcService consumerService;
-
-    protected RoutedRpcRegistration<OpendaylightTestRoutedRpcService> firstReg;
-    protected RoutedRpcRegistration<OpendaylightTestRoutedRpcService> secondReg;
+    @Inject
+    @Filter(timeout = 120 * 1000)
+    RpcProviderRegistry rpcProviderRegistry;
 
     /**
-     * prepare mocks
+     * Prepare mocks.
      */
     @Before
     public void setUp() {
         odlRoutedService1 = mock(OpendaylightTestRoutedRpcService.class, "First Flow Service");
         odlRoutedService2 = mock(OpendaylightTestRoutedRpcService.class, "Second Flow Service");
         Mockito.when(odlRoutedService1.routedSimpleRoute(Mockito.<RoutedSimpleRouteInput>any()))
-            .thenReturn(Futures.<RpcResult<Void>>immediateFuture(null));
+            .thenReturn(Futures.<RpcResult<RoutedSimpleRouteOutput>>immediateFuture(null));
         Mockito.when(odlRoutedService2.routedSimpleRoute(Mockito.<RoutedSimpleRouteInput>any()))
-            .thenReturn(Futures.<RpcResult<Void>>immediateFuture(null));
+            .thenReturn(Futures.<RpcResult<RoutedSimpleRouteOutput>>immediateFuture(null));
     }
 
     @Test
     public void testServiceRegistration() {
-
-        assertNotNull(broker);
-
-        final BindingAwareProvider provider1 = new AbstractTestProvider() {
-            @Override
-            public void onSessionInitiated(final ProviderContext session) {
-                assertNotNull(session);
-                firstReg = session.addRoutedRpcImplementation(OpendaylightTestRoutedRpcService.class, odlRoutedService1);
-            }
-        };
-
         LOG.info("Register provider 1 with first implementation of routeSimpleService - service1");
-        broker.registerProvider(provider1);
+
+        RoutedRpcRegistration<OpendaylightTestRoutedRpcService> firstReg = rpcProviderRegistry
+                .addRoutedRpcImplementation(OpendaylightTestRoutedRpcService.class, odlRoutedService1);
         assertNotNull("Registration should not be null", firstReg);
         assertSame(odlRoutedService1, firstReg.getInstance());
 
-        final BindingAwareProvider provider2 = new AbstractTestProvider() {
-            @Override
-            public void onSessionInitiated(final ProviderContext session) {
-                assertNotNull(session);
-                secondReg = session.addRoutedRpcImplementation(OpendaylightTestRoutedRpcService.class, odlRoutedService2);
-            }
-        };
-
         LOG.info("Register provider 2 with second implementation of routeSimpleService - service2");
-        broker.registerProvider(provider2);
+
+        RoutedRpcRegistration<OpendaylightTestRoutedRpcService> secondReg = rpcProviderRegistry
+                .addRoutedRpcImplementation(OpendaylightTestRoutedRpcService.class, odlRoutedService2);
         assertNotNull("Registration should not be null", firstReg);
         assertSame(odlRoutedService2, secondReg.getInstance());
         assertNotSame(secondReg, firstReg);
 
-        final BindingAwareConsumer consumer =
-                session -> consumerService = session.getRpcService(OpendaylightTestRoutedRpcService.class);
-        LOG.info("Register routeService consumer");
-        broker.registerConsumer(consumer);
-
+        OpendaylightTestRoutedRpcService consumerService =
+                rpcProviderRegistry.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);
+        assertNotSame("Provider instance and consumer instance should not be same.", odlRoutedService1,
+                consumerService);
 
         final InstanceIdentifier<UnorderedList> nodeOnePath = createNodeRef("foo:node:1");
 
@@ -109,15 +93,13 @@ public class RoutedServiceIT extends AbstractIT {
         firstReg.registerPath(TestContext.class, nodeOnePath);
 
         /**
-         * Consumer creates addFlow message for node one and sends it to the
-         * MD-SAL
+         * Consumer creates addFlow message for node one and sends it to the MD-SAL.
          */
         final RoutedSimpleRouteInput simpleRouteFirstFoo = createSimpleRouteInput(nodeOnePath);
         consumerService.routedSimpleRoute(simpleRouteFirstFoo);
 
         /**
-         * Verifies that implementation of the first provider received the same
-         * message from MD-SAL.
+         * Verifies that implementation of the first provider received the same message from MD-SAL.
          */
         verify(odlRoutedService1).routedSimpleRoute(simpleRouteFirstFoo);
         /**
@@ -130,8 +112,7 @@ public class RoutedServiceIT extends AbstractIT {
         secondReg.registerPath(TestContext.class, nodeTwo);
 
         /**
-         * Consumer sends message to nodeTwo for three times. Should be
-         * processed by second instance.
+         * Consumer sends message to nodeTwo for three times. Should be processed by second instance.
          */
         final RoutedSimpleRouteInput simpleRouteSecondFoo = createSimpleRouteInput(nodeTwo);
         consumerService.routedSimpleRoute(simpleRouteSecondFoo);
@@ -139,9 +120,7 @@ public class RoutedServiceIT extends AbstractIT {
         consumerService.routedSimpleRoute(simpleRouteSecondFoo);
 
         /**
-         * Verifies that second instance was invoked 3 times with second message
-         * and first instance wasn't invoked.
-         *
+         * Verifies that second instance was invoked 3 times with second message and first instance wasn't invoked.
          */
         verify(odlRoutedService2, times(3)).routedSimpleRoute(simpleRouteSecondFoo);
         verify(odlRoutedService1, times(0)).routedSimpleRoute(simpleRouteSecondFoo);
@@ -153,43 +132,36 @@ public class RoutedServiceIT extends AbstractIT {
         secondReg.registerPath(TestContext.class, nodeOnePath);
 
         /**
-         * A consumer sends third message to node 1
+         * A consumer sends third message to node 1.
          */
         final RoutedSimpleRouteInput simpleRouteThirdFoo = createSimpleRouteInput(nodeOnePath);
         consumerService.routedSimpleRoute(simpleRouteThirdFoo);
 
         /**
-         * Verifies that provider 1 wasn't invoked and provider 2 was invoked 1
-         * time.
+         * Verifies that provider 1 wasn't invoked and provider 2 was invoked 1 time.
          * TODO: fix unregister path
          */
         //verify(odlRoutedService1, times(0)).routedSimpleRoute(simpleRouteThirdFoo);
         verify(odlRoutedService2).routedSimpleRoute(simpleRouteThirdFoo);
-
     }
 
     /**
-     * Returns node reference from string which represents path
+     * Returns node reference from string which represents path.
      *
-     * @param string
-     *            string with key(path)
+     * @param string string with key(path)
      * @return instance identifier to {@link UnorderedList}
      */
     private static InstanceIdentifier<UnorderedList> createNodeRef(final String string) {
-        final UnorderedListKey key = new UnorderedListKey(string);
-        final InstanceIdentifier<UnorderedList> path = InstanceIdentifier.builder(Lists.class)
+        return InstanceIdentifier.builder(Lists.class)
                 .child(UnorderedContainer.class)
-                .child(UnorderedList.class, key)
+                .child(UnorderedList.class, new UnorderedListKey(string))
                 .build();
-
-        return path;
     }
 
     /**
-     * Creates flow AddFlowInput for which only node and cookie are set
+     * Creates flow AddFlowInput for which only node and cookie are set.
      *
-     * @param node
-     *            NodeRef value
+     * @param node NodeRef value
      * @return simpleRouteInput instance
      */
     static RoutedSimpleRouteInput createSimpleRouteInput(final InstanceIdentifier<UnorderedList> node) {