From 4d7cf612a673d09132a37b2d4d3002a2f213de02 Mon Sep 17 00:00:00 2001 From: Tom Pantelis Date: Thu, 12 Apr 2018 10:19:54 -0400 Subject: [PATCH] Inject MD_SAL services directly in sal-binding-it tests This is in lieu of obtaining them via the BindingAwareBroker which is obsolete in lieu of blueprint. Also remove the CSS module checkong in AbstractIT. Change-Id: I259cec363e31759447392ee1dc940fccee46d27e Signed-off-by: Tom Pantelis --- .../test/sal/binding/it/AbstractIT.java | 19 +----- .../test/sal/binding/it/DataServiceIT.java | 14 ++--- .../test/sal/binding/it/NotificationIT.java | 61 +++++-------------- .../test/sal/binding/it/RoutedServiceIT.java | 51 ++++++---------- 4 files changed, 39 insertions(+), 106 deletions(-) diff --git a/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/AbstractIT.java b/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/AbstractIT.java index 29a336e98e..4548114ac1 100644 --- a/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/AbstractIT.java +++ b/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/AbstractIT.java @@ -9,32 +9,15 @@ package org.opendaylight.controller.test.sal.binding.it; import static org.ops4j.pax.exam.CoreOptions.maven; import static org.ops4j.pax.exam.CoreOptions.mavenBundle; -import javax.inject.Inject; + import org.junit.runner.RunWith; import org.opendaylight.controller.mdsal.it.base.AbstractMdsalTestBase; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; import org.ops4j.pax.exam.options.MavenUrlReference; -import org.ops4j.pax.exam.util.Filter; @RunWith(PaxExam.class) public abstract class AbstractIT extends AbstractMdsalTestBase { - - @Inject - @Filter(timeout=120*1000) - BindingAwareBroker broker; - - @Override - public String getModuleName() { - return "binding-broker-impl"; - } - - @Override - public String getInstanceName() { - return "binding-broker-impl"; - } - @Override public MavenUrlReference getFeatureRepo() { return maven().groupId("org.opendaylight.controller").artifactId("features-mdsal").classifier("features") diff --git a/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/DataServiceIT.java b/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/DataServiceIT.java index baa2c129b8..5a1d16634e 100644 --- a/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/DataServiceIT.java +++ b/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/DataServiceIT.java @@ -14,23 +14,26 @@ import static org.junit.Assert.assertTrue; import com.google.common.base.Optional; import java.util.concurrent.TimeUnit; +import javax.inject.Inject; import org.junit.Test; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer; 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.UnorderedListBuilder; 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.ops4j.pax.exam.util.Filter; /** * covers creating, reading and deleting of an item in dataStore */ public class DataServiceIT extends AbstractIT { - protected DataBroker dataBroker; + @Inject + @Filter(timeout = 120 * 1000) + DataBroker dataBroker; /** * @@ -42,13 +45,6 @@ public class DataServiceIT extends AbstractIT { */ @Test public void test() throws Exception { - BindingAwareConsumer consumer = session -> dataBroker = session.getSALService(DataBroker.class); - - broker.registerConsumer(consumer); - - assertNotNull(dataBroker); - - final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); assertNotNull(transaction); diff --git a/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/NotificationIT.java b/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/NotificationIT.java index db978dbeec..468fc1b1fc 100644 --- a/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/NotificationIT.java +++ b/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/NotificationIT.java @@ -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 listener1Reg; - protected ListenerRegistration 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 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 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 diff --git a/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/RoutedServiceIT.java b/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/RoutedServiceIT.java index a394bcba89..66a12edf34 100644 --- a/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/RoutedServiceIT.java +++ b/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/RoutedServiceIT.java @@ -13,14 +13,14 @@ 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; @@ -31,6 +31,7 @@ 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; @@ -45,10 +46,9 @@ public class RoutedServiceIT extends AbstractIT { protected OpendaylightTestRoutedRpcService odlRoutedService1; protected OpendaylightTestRoutedRpcService odlRoutedService2; - protected OpendaylightTestRoutedRpcService consumerService; - - protected RoutedRpcRegistration firstReg; - protected RoutedRpcRegistration secondReg; + @Inject + @Filter(timeout = 120 * 1000) + RpcProviderRegistry rpcProviderRegistry; /** * prepare mocks @@ -65,43 +65,26 @@ public class RoutedServiceIT extends AbstractIT { @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 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 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 nodeOnePath = createNodeRef("foo:node:1"); -- 2.36.6