Inject MD_SAL services directly in sal-binding-it tests
[controller.git] / opendaylight / md-sal / sal-binding-it / src / test / java / org / opendaylight / controller / test / sal / binding / it / NotificationIT.java
index db978dbeec8b8861441800713939bb0f6be3c531..468fc1b1fc834c60f3e924bc0dca5142853f33d5 100644 (file)
@@ -8,22 +8,18 @@
 package org.opendaylight.controller.test.sal.binding.it;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
 
 import java.util.ArrayList;
 import java.util.List;
-
+import javax.inject.Inject;
 import org.junit.Test;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
-import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
-import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
-import org.opendaylight.controller.sal.binding.api.NotificationService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.notification.rev150205.OpendaylightTestNotificationListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.notification.rev150205.OutOfPixieDustNotification;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.notification.rev150205.OutOfPixieDustNotificationBuilder;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.NotificationListener;
+import org.ops4j.pax.exam.util.Filter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -35,13 +31,9 @@ public class NotificationIT extends AbstractIT {
     private static final Logger LOG = LoggerFactory
             .getLogger(NotificationIT.class);
 
-    protected final NotificationTestListener listener1 = new NotificationTestListener();
-    protected final NotificationTestListener listener2 = new NotificationTestListener();
-
-    protected ListenerRegistration<NotificationListener> listener1Reg;
-    protected ListenerRegistration<NotificationListener> listener2Reg;
-
-    protected NotificationProviderService notifyProviderService;
+    @Inject
+    @Filter(timeout = 120 * 1000)
+    NotificationProviderService notificationService;
 
     /**
      * test of delivering of notification
@@ -49,34 +41,14 @@ public class NotificationIT extends AbstractIT {
      */
     @Test
     public void notificationTest() throws Exception {
-        LOG.info("The registration of the Provider 1.");
-        AbstractTestProvider provider1 = new AbstractTestProvider() {
-            @Override
-            public void onSessionInitiated(ProviderContext session) {
-                notifyProviderService = session.getSALService(NotificationProviderService.class);
-            }
-        };
-
-        // registerProvider method calls onSessionInitiated method above
-        broker.registerProvider(provider1);
-        assertNotNull(notifyProviderService);
-
-        LOG.info("The registration of the Consumer 1. It retrieves Notification Service "
-                + "from MD-SAL and registers OpendaylightTestNotificationListener as notification listener");
-        BindingAwareConsumer consumer1 = session -> {
-            NotificationService notificationService = session.getSALService(NotificationService.class);
-            assertNotNull(notificationService);
-            listener1Reg = notificationService.registerNotificationListener(listener1);
-        };
-        // registerConsumer method calls onSessionInitialized method above
-        broker.registerConsumer(consumer1);
-
-        assertNotNull(listener1Reg);
+        NotificationTestListener listener1 = new NotificationTestListener();
+        ListenerRegistration<NotificationListener> listener1Reg =
+                notificationService.registerNotificationListener(listener1);
 
         LOG.info("The notification of type FlowAdded with cookie ID 0 is created. The "
                 + "delay 100ms to make sure that the notification was delivered to "
                 + "listener.");
-        notifyProviderService.publish(noDustNotification("rainy day", 42));
+        notificationService.publish(noDustNotification("rainy day", 42));
         Thread.sleep(100);
 
         /**
@@ -89,16 +61,15 @@ public class NotificationIT extends AbstractIT {
 
         LOG.info("The registration of the Consumer 2. SalFlowListener is registered "
                 + "registered as notification listener.");
-        BindingAwareProvider provider = session -> listener2Reg = session.getSALService(NotificationProviderService.class).registerNotificationListener(
-                listener2);
 
-        // registerConsumer method calls onSessionInitialized method above
-        broker.registerProvider(provider);
+        NotificationTestListener listener2 = new NotificationTestListener();
+        final ListenerRegistration<NotificationListener> listener2Reg =
+                notificationService.registerNotificationListener(listener2);
 
         LOG.info("3 notifications are published");
-        notifyProviderService.publish(noDustNotification("rainy day", 5));
-        notifyProviderService.publish(noDustNotification("rainy day", 10));
-        notifyProviderService.publish(noDustNotification("tax collector", 2));
+        notificationService.publish(noDustNotification("rainy day", 5));
+        notificationService.publish(noDustNotification("rainy day", 10));
+        notificationService.publish(noDustNotification("tax collector", 2));
 
         /**
          * The delay 100ms to make sure that the notifications were delivered to
@@ -121,7 +92,7 @@ public class NotificationIT extends AbstractIT {
         listener2Reg.close();
 
         LOG.info("The notification 5 is published");
-        notifyProviderService.publish(noDustNotification("entomologist hunt", 10));
+        notificationService.publish(noDustNotification("entomologist hunt", 10));
 
         /**
          * The delay 100ms to make sure that the notification was delivered to