From f05c025517ed2f9b46a49428cd1ab9601c312a83 Mon Sep 17 00:00:00 2001 From: Michal Rehak Date: Thu, 5 Feb 2015 12:31:15 +0100 Subject: [PATCH] BUG-2681: switch sal-binding-it to sal test models - switched to test models: - DataServiceTest - RoutedServiceTest (unregister path verification failing) - Notification Test Change-Id: I381fd9ad9682f9527bdf8276fae6eb508f0807f7 Signed-off-by: Michal Rehak --- opendaylight/md-sal/sal-binding-it/pom.xml | 14 +- .../test/sal/binding/it/TestHelper.java | 14 +- .../test/sal/binding/it/AbstractTest.java | 4 +- .../test/sal/binding/it/DataServiceTest.java | 59 +++--- .../test/sal/binding/it/NotificationTest.java | 167 ++++++----------- .../sal/binding/it/RoutedServiceTest.java | 173 ++++++++---------- opendaylight/md-sal/sal-test-model/pom.xml | 4 +- .../yang/opendaylight-test-notification.yang | 25 +++ 8 files changed, 216 insertions(+), 244 deletions(-) create mode 100644 opendaylight/md-sal/sal-test-model/src/main/yang/opendaylight-test-notification.yang diff --git a/opendaylight/md-sal/sal-binding-it/pom.xml b/opendaylight/md-sal/sal-binding-it/pom.xml index 3b504f45b1..491e5dcb61 100644 --- a/opendaylight/md-sal/sal-binding-it/pom.xml +++ b/opendaylight/md-sal/sal-binding-it/pom.xml @@ -119,9 +119,17 @@ log4j-over-slf4j - org.opendaylight.controller.model - model-flow-service - provided + org.slf4j + slf4j-api + + + org.opendaylight.controller + sal-test-model + ${mdsal.version} + + + org.opendaylight.yangtools.model + opendaylight-l2-types diff --git a/opendaylight/md-sal/sal-binding-it/src/main/java/org/opendaylight/controller/test/sal/binding/it/TestHelper.java b/opendaylight/md-sal/sal-binding-it/src/main/java/org/opendaylight/controller/test/sal/binding/it/TestHelper.java index 07d205bfcb..9b6d5836f0 100644 --- a/opendaylight/md-sal/sal-binding-it/src/main/java/org/opendaylight/controller/test/sal/binding/it/TestHelper.java +++ b/opendaylight/md-sal/sal-binding-it/src/main/java/org/opendaylight/controller/test/sal/binding/it/TestHelper.java @@ -159,13 +159,23 @@ public class TestHelper { } + /** + * @return option containing models for testing purposes + */ + public static Option salTestModelBundles() { + return new DefaultCompositeOption( // + mavenBundle(CONTROLLER, "sal-test-model").versionAsInProject() + ); + + } + public static Option baseModelBundles() { return new DefaultCompositeOption( // mavenBundle(YANGTOOLS_MODELS, "yang-ext").versionAsInProject(), // // mavenBundle(YANGTOOLS_MODELS, "ietf-inet-types").versionAsInProject(), // // mavenBundle(YANGTOOLS_MODELS, "ietf-yang-types").versionAsInProject(), // // - mavenBundle(YANGTOOLS_MODELS, "opendaylight-l2-types").versionAsInProject(), // // - mavenBundle(CONTROLLER_MODELS, "model-inventory").versionAsInProject()); + mavenBundle(YANGTOOLS_MODELS, "opendaylight-l2-types").versionAsInProject() // // + ); } public static Option junitAndMockitoBundles() { diff --git a/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/AbstractTest.java b/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/AbstractTest.java index b2f89cf779..2075ba4421 100644 --- a/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/AbstractTest.java +++ b/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/AbstractTest.java @@ -20,7 +20,7 @@ import javax.inject.Inject; import static org.opendaylight.controller.test.sal.binding.it.TestHelper.baseModelBundles; import static org.opendaylight.controller.test.sal.binding.it.TestHelper.bindingAwareSalBundles; import static org.opendaylight.controller.test.sal.binding.it.TestHelper.configMinumumBundles; -import static org.opendaylight.controller.test.sal.binding.it.TestHelper.flowCapableModelBundles; +import static org.opendaylight.controller.test.sal.binding.it.TestHelper.salTestModelBundles; import static org.opendaylight.controller.test.sal.binding.it.TestHelper.junitAndMockitoBundles; import static org.opendaylight.controller.test.sal.binding.it.TestHelper.mdSalCoreBundles; import static org.ops4j.pax.exam.CoreOptions.mavenBundle; @@ -82,7 +82,7 @@ public abstract class AbstractTest { configMinumumBundles(), // BASE Models baseModelBundles(), - flowCapableModelBundles(), + salTestModelBundles(), // Set fail if unresolved bundle present systemProperty("pax.exam.osgi.unresolved.fail").value("true"), diff --git a/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/DataServiceTest.java b/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/DataServiceTest.java index 33039ea231..853ff4c3f6 100644 --- a/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/DataServiceTest.java +++ b/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/DataServiceTest.java @@ -11,10 +11,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import com.google.inject.Inject; import java.util.concurrent.Future; -import org.junit.Before; -import org.junit.Ignore; + import org.junit.Test; import org.opendaylight.controller.md.sal.common.api.TransactionStatus; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext; @@ -22,36 +20,36 @@ import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer; import org.opendaylight.controller.sal.binding.api.data.DataBrokerService; import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction; import org.opendaylight.controller.sal.core.api.Broker; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; +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.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.common.RpcResult; +import com.google.inject.Inject; + +/** + * covers creating, reading and deleting of an item in dataStore + */ public class DataServiceTest extends AbstractTest { protected DataBrokerService consumerDataService; - @Inject Broker broker2; - @Before - public void setUp() throws Exception { - } - - /* + /** * * Ignored this, because classes here are constructed from * very different class loader as MD-SAL is run into, * this is code is run from different classloader. * + * @throws Exception */ @Test - @Ignore public void test() throws Exception { BindingAwareConsumer consumer1 = new BindingAwareConsumer() { @@ -60,7 +58,7 @@ public class DataServiceTest extends AbstractTest { consumerDataService = session.getSALService(DataBrokerService.class); } }; - broker.registerConsumer(consumer1, getBundleContext()); + broker.registerConsumer(consumer1); assertNotNull(consumerDataService); @@ -68,10 +66,10 @@ public class DataServiceTest extends AbstractTest { DataModificationTransaction transaction = consumerDataService.beginTransaction(); assertNotNull(transaction); - InstanceIdentifier node1 = createNodeRef("0"); - DataObject node = consumerDataService.readConfigurationData(node1); + InstanceIdentifier node1 = createNodeRef("0"); + DataObject node = consumerDataService.readConfigurationData(node1); assertNull(node); - Node nodeData1 = createNode("0"); + UnorderedList nodeData1 = createNode("0"); transaction.putConfigurationData(node1, nodeData1); Future> commitResult = transaction.commit(); @@ -83,13 +81,13 @@ public class DataServiceTest extends AbstractTest { assertNotNull(result.getResult()); assertEquals(TransactionStatus.COMMITED, result.getResult()); - Node readedData = (Node) consumerDataService.readConfigurationData(node1); + UnorderedList readedData = (UnorderedList) consumerDataService.readConfigurationData(node1); assertNotNull(readedData); assertEquals(nodeData1.getKey(), readedData.getKey()); DataModificationTransaction transaction2 = consumerDataService.beginTransaction(); - assertNotNull(transaction); + assertNotNull(transaction2); transaction2.removeConfigurationData(node1); @@ -104,21 +102,20 @@ public class DataServiceTest extends AbstractTest { DataObject readedData2 = consumerDataService.readConfigurationData(node1); assertNull(readedData2); - - } - private static InstanceIdentifier createNodeRef(final String string) { - NodeKey key = new NodeKey(new NodeId(string)); - return InstanceIdentifier.builder(Nodes.class).child(Node.class, key).build(); + private static InstanceIdentifier createNodeRef(final String string) { + UnorderedListKey key = new UnorderedListKey(string); + return InstanceIdentifier.builder(Lists.class).child(UnorderedContainer.class).child(UnorderedList.class, key).build(); } - private static Node createNode(final String string) { - NodeBuilder ret = new NodeBuilder(); - NodeId id = new NodeId(string); - ret.setKey(new NodeKey(id)); - ret.setId(id); + private static UnorderedList createNode(final String string) { + UnorderedListBuilder ret = new UnorderedListBuilder(); + UnorderedListKey nodeKey = new UnorderedListKey(string); + ret.setKey(nodeKey); + ret.setName("name of " + string); + ret.setName("value of " + string); return ret.build(); } } diff --git a/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/NotificationTest.java b/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/NotificationTest.java index 8f8e475efe..e1d5d0060d 100644 --- a/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/NotificationTest.java +++ b/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/NotificationTest.java @@ -10,12 +10,9 @@ package org.opendaylight.controller.test.sal.binding.it; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import java.math.BigInteger; import java.util.ArrayList; import java.util.List; -import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext; @@ -23,40 +20,37 @@ 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.flow.service.rev130819.FlowAdded; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAddedBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowUpdated; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeErrorNotification; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeExperimenterErrorNotification; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowListener; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SwitchFlowRemoved; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie; +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.slf4j.Logger; +import org.slf4j.LoggerFactory; -@Ignore +/** + * covers registering of notification listener, publishing of notification and receiving of notification. + */ public class NotificationTest extends AbstractTest { - private final FlowListener listener1 = new FlowListener(); - private final FlowListener listener2 = new FlowListener(); + private static final Logger LOG = LoggerFactory + .getLogger(NotificationTest.class); - private ListenerRegistration listener1Reg; - private ListenerRegistration listener2Reg; + protected final NotificationTestListener listener1 = new NotificationTestListener(); + protected final NotificationTestListener listener2 = new NotificationTestListener(); - private NotificationProviderService notifyProviderService; + protected ListenerRegistration listener1Reg; + protected ListenerRegistration listener2Reg; - @Before - public void setUp() throws Exception { - } + protected NotificationProviderService notifyProviderService; + /** + * test of delivering of notification + * @throws Exception + */ @Test public void notificationTest() throws Exception { - /** - * - * The registration of the Provider 1. - * - */ + LOG.info("The registration of the Provider 1."); AbstractTestProvider provider1 = new AbstractTestProvider() { @Override public void onSessionInitiated(ProviderContext session) { @@ -65,15 +59,11 @@ public class NotificationTest extends AbstractTest { }; // registerProvider method calls onSessionInitiated method above - broker.registerProvider(provider1, getBundleContext()); + broker.registerProvider(provider1); assertNotNull(notifyProviderService); - /** - * - * The registration of the Consumer 1. It retrieves Notification Service - * from MD-SAL and registers SalFlowListener as notification listener - * - */ + LOG.info("The registration of the Consumer 1. It retrieves Notification Service " + + "from MD-SAL and registers OpendaylightTestNotificationListener as notification listener"); BindingAwareConsumer consumer1 = new BindingAwareConsumer() { @Override public void onSessionInitialized(ConsumerContext session) { @@ -83,29 +73,26 @@ public class NotificationTest extends AbstractTest { } }; // registerConsumer method calls onSessionInitialized method above - broker.registerConsumer(consumer1, getBundleContext()); + broker.registerConsumer(consumer1); assertNotNull(listener1Reg); - /** - * 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(flowAdded(0)); + 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)); Thread.sleep(100); /** * Check that one notification was delivered and has correct cookie. * */ - assertEquals(1, listener1.addedFlows.size()); - assertEquals(0, listener1.addedFlows.get(0).getCookie().getValue().intValue()); + assertEquals(1, listener1.notificationBag.size()); + assertEquals("rainy day", listener1.notificationBag.get(0).getReason()); + assertEquals(42, listener1.notificationBag.get(0).getDaysTillNewDust().intValue()); - /** - * The registration of the Consumer 2. SalFlowListener is registered - * registered as notification listener. - */ + LOG.info("The registration of the Consumer 2. SalFlowListener is registered " + + "registered as notification listener."); BindingAwareProvider provider = new BindingAwareProvider() { @Override @@ -116,14 +103,12 @@ public class NotificationTest extends AbstractTest { }; // registerConsumer method calls onSessionInitialized method above - broker.registerProvider(provider, getBundleContext()); + broker.registerProvider(provider); - /** - * 3 notifications are published - */ - notifyProviderService.publish(flowAdded(5)); - notifyProviderService.publish(flowAdded(10)); - notifyProviderService.publish(flowAdded(2)); + LOG.info("3 notifications are published"); + notifyProviderService.publish(noDustNotification("rainy day", 5)); + notifyProviderService.publish(noDustNotification("rainy day", 10)); + notifyProviderService.publish(noDustNotification("tax collector", 2)); /** * The delay 100ms to make sure that the notifications were delivered to @@ -136,8 +121,8 @@ public class NotificationTest extends AbstractTest { * received 4 in total, second 3 in total). * */ - assertEquals(4, listener1.addedFlows.size()); - assertEquals(3, listener2.addedFlows.size()); + assertEquals(4, listener1.notificationBag.size()); + assertEquals(3, listener2.notificationBag.size()); /** * The second listener is closed (unregistered) @@ -145,11 +130,8 @@ public class NotificationTest extends AbstractTest { */ listener2Reg.close(); - /** - * - * The notification 5 is published - */ - notifyProviderService.publish(flowAdded(10)); + LOG.info("The notification 5 is published"); + notifyProviderService.publish(noDustNotification("entomologist hunt", 10)); /** * The delay 100ms to make sure that the notification was delivered to @@ -163,73 +145,38 @@ public class NotificationTest extends AbstractTest { * second consumer because its listener was unregistered. * */ - assertEquals(5, listener1.addedFlows.size()); - assertEquals(3, listener2.addedFlows.size()); + assertEquals(5, listener1.notificationBag.size()); + assertEquals(3, listener2.notificationBag.size()); } /** - * Creates instance of the type FlowAdded. Only cookie value is set. It is + * Creates instance of the type OutOfPixieDustNotification. It is * used only for testing purpose. * - * @param i - * cookie value - * @return instance of the type FlowAdded + * @param reason + * @param days + * @return instance of the type OutOfPixieDustNotification */ - public static FlowAdded flowAdded(int i) { - FlowAddedBuilder ret = new FlowAddedBuilder(); - ret.setCookie(new FlowCookie(BigInteger.valueOf(i))); + public static OutOfPixieDustNotification noDustNotification(String reason, int days) { + OutOfPixieDustNotificationBuilder ret = new OutOfPixieDustNotificationBuilder(); + ret.setReason(reason).setDaysTillNewDust(days); return ret.build(); } /** * * Implements - * {@link org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowListener - * SalFlowListener} and contains attributes which keep lists of objects of - * the type - * {@link org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819. NodeFlow - * NodeFlow}. The lists are defined for flows which were added, removed or - * updated. + * {@link OpendaylightTestNotificationListener} and contains attributes which keep lists of objects of + * the type {@link OutOfFairyDustNotification}. */ - private static class FlowListener implements SalFlowListener { - - List addedFlows = new ArrayList<>(); - List removedFlows = new ArrayList<>(); - List updatedFlows = new ArrayList<>(); - - @Override - public void onFlowAdded(FlowAdded notification) { - addedFlows.add(notification); - } - - @Override - public void onFlowRemoved(FlowRemoved notification) { - removedFlows.add(notification); - }; - - @Override - public void onFlowUpdated(FlowUpdated notification) { - updatedFlows.add(notification); - } - - @Override - public void onSwitchFlowRemoved(SwitchFlowRemoved notification) { - // TODO Auto-generated method stub - - } + public static class NotificationTestListener implements OpendaylightTestNotificationListener { - @Override - public void onNodeErrorNotification(NodeErrorNotification notification) { - // TODO Auto-generated method stub - - } + List notificationBag = new ArrayList<>(); @Override - public void onNodeExperimenterErrorNotification( - NodeExperimenterErrorNotification notification) { - // TODO Auto-generated method stub - + public void onOutOfPixieDustNotification(OutOfPixieDustNotification arg0) { + notificationBag.add(arg0); } } diff --git a/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/RoutedServiceTest.java b/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/RoutedServiceTest.java index d49d6f0e25..724403876e 100644 --- a/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/RoutedServiceTest.java +++ b/opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/RoutedServiceTest.java @@ -14,8 +14,6 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import java.math.BigInteger; - import org.junit.Before; import org.junit.Test; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext; @@ -23,32 +21,41 @@ import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderCo 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.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeContext; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; +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.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.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +/** + * covers routed rpc creation, registration, invocation, unregistration + */ public class RoutedServiceTest extends AbstractTest { - private SalFlowService salFlowService1; - private SalFlowService salFlowService2; + private static final Logger LOG = LoggerFactory + .getLogger(RoutedServiceTest.class); - private SalFlowService consumerService; + protected OpendaylightTestRoutedRpcService odlRoutedService1; + protected OpendaylightTestRoutedRpcService odlRoutedService2; - private RoutedRpcRegistration firstReg; - private RoutedRpcRegistration secondReg; + protected OpendaylightTestRoutedRpcService consumerService; + protected RoutedRpcRegistration firstReg; + protected RoutedRpcRegistration secondReg; + + /** + * prepare mocks + */ @Before - public void setUp() throws Exception { - salFlowService1 = mock(SalFlowService.class, "First Flow Service"); - salFlowService2 = mock(SalFlowService.class, "Second Flow Service"); + public void setUp() { + odlRoutedService1 = mock(OpendaylightTestRoutedRpcService.class, "First Flow Service"); + odlRoutedService2 = mock(OpendaylightTestRoutedRpcService.class, "Second Flow Service"); } @Test @@ -57,130 +64,106 @@ public class RoutedServiceTest extends AbstractTest { assertNotNull(getBroker()); BindingAwareProvider provider1 = new AbstractTestProvider() { - @Override public void onSessionInitiated(ProviderContext session) { assertNotNull(session); - firstReg = session.addRoutedRpcImplementation(SalFlowService.class, salFlowService1); + firstReg = session.addRoutedRpcImplementation(OpendaylightTestRoutedRpcService.class, odlRoutedService1); } }; - /** - * Register provider 1 with first implementation of SalFlowService - - * service1 - * - */ - broker.registerProvider(provider1, getBundleContext()); + LOG.info("Register provider 1 with first implementation of routeSimpleService - service1"); + broker.registerProvider(provider1); assertNotNull("Registration should not be null", firstReg); - assertSame(salFlowService1, firstReg.getInstance()); + assertSame(odlRoutedService1, firstReg.getInstance()); BindingAwareProvider provider2 = new AbstractTestProvider() { - @Override public void onSessionInitiated(ProviderContext session) { assertNotNull(session); - secondReg = session.addRoutedRpcImplementation(SalFlowService.class, salFlowService2); + secondReg = session.addRoutedRpcImplementation(OpendaylightTestRoutedRpcService.class, odlRoutedService2); } }; - /** - * Register provider 2 with first implementation of SalFlowService - - * service2 - * - */ - broker.registerProvider(provider2, getBundleContext()); + LOG.info("Register provider 2 with second implementation of routeSimpleService - service2"); + broker.registerProvider(provider2); assertNotNull("Registration should not be null", firstReg); - assertSame(salFlowService2, secondReg.getInstance()); + assertSame(odlRoutedService2, secondReg.getInstance()); assertNotSame(secondReg, firstReg); BindingAwareConsumer consumer = new BindingAwareConsumer() { @Override public void onSessionInitialized(ConsumerContext session) { - consumerService = session.getRpcService(SalFlowService.class); + consumerService = session.getRpcService(OpendaylightTestRoutedRpcService.class); } }; - broker.registerConsumer(consumer, getBundleContext()); + LOG.info("Register routeService consumer"); + broker.registerConsumer(consumer); - assertNotNull("MD-SAL instance of Flow Service should be returned", consumerService); - assertNotSame("Provider instance and consumer instance should not be same.", salFlowService1, consumerService); + assertNotNull("MD-SAL instance of test Service should be returned", consumerService); + assertNotSame("Provider instance and consumer instance should not be same.", odlRoutedService1, consumerService); - NodeRef nodeOne = createNodeRef("foo:node:1"); + InstanceIdentifier nodeOnePath = createNodeRef("foo:node:1"); - /** - * Provider 1 registers path of node 1 - */ - firstReg.registerPath(NodeContext.class, nodeOne.getValue()); + 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 - * */ - AddFlowInput addFlowFirstMessage = createSampleAddFlow(nodeOne, 1); - consumerService.addFlow(addFlowFirstMessage); + RoutedSimpleRouteInput simpleRouteFirstFoo = createSimpleRouteInput(nodeOnePath); + consumerService.routedSimpleRoute(simpleRouteFirstFoo); /** * Verifies that implementation of the first provider received the same * message from MD-SAL. - * */ - verify(salFlowService1).addFlow(addFlowFirstMessage); - + verify(odlRoutedService1).routedSimpleRoute(simpleRouteFirstFoo); /** * Verifies that second instance was not invoked with first message - * */ - verify(salFlowService2, times(0)).addFlow(addFlowFirstMessage); + verify(odlRoutedService2, times(0)).routedSimpleRoute(simpleRouteFirstFoo); - /** - * Provider 2 registers path of node 2 - * - */ - NodeRef nodeTwo = createNodeRef("foo:node:2"); - secondReg.registerPath(NodeContext.class, nodeTwo.getValue()); + LOG.info("Provider 2 registers path of node 2"); + InstanceIdentifier nodeTwo = createNodeRef("foo:node:2"); + secondReg.registerPath(TestContext.class, nodeTwo); /** * Consumer sends message to nodeTwo for three times. Should be * processed by second instance. */ - AddFlowInput AddFlowSecondMessage = createSampleAddFlow(nodeTwo, 2); - consumerService.addFlow(AddFlowSecondMessage); - consumerService.addFlow(AddFlowSecondMessage); - consumerService.addFlow(AddFlowSecondMessage); + RoutedSimpleRouteInput simpleRouteSecondFoo = createSimpleRouteInput(nodeTwo); + consumerService.routedSimpleRoute(simpleRouteSecondFoo); + consumerService.routedSimpleRoute(simpleRouteSecondFoo); + consumerService.routedSimpleRoute(simpleRouteSecondFoo); /** * Verifies that second instance was invoked 3 times with second message * and first instance wasn't invoked. * */ - verify(salFlowService2, times(3)).addFlow(AddFlowSecondMessage); - verify(salFlowService1, times(0)).addFlow(AddFlowSecondMessage); + verify(odlRoutedService2, times(3)).routedSimpleRoute(simpleRouteSecondFoo); + verify(odlRoutedService1, times(0)).routedSimpleRoute(simpleRouteSecondFoo); - /** - * Unregisteration of the path for the node one in the first provider - * - */ - firstReg.unregisterPath(NodeContext.class, nodeOne.getValue()); + LOG.info("Unregistration of the path for the node one in the first provider"); + firstReg.unregisterPath(TestContext.class, nodeOnePath); - /** - * Provider 2 registers path of node 1 - * - */ - secondReg.registerPath(NodeContext.class, nodeOne.getValue()); + LOG.info("Provider 2 registers path of node 1"); + secondReg.registerPath(TestContext.class, nodeOnePath); /** * A consumer sends third message to node 1 - * */ - AddFlowInput AddFlowThirdMessage = createSampleAddFlow(nodeOne, 3); - consumerService.addFlow(AddFlowThirdMessage); + RoutedSimpleRouteInput simpleRouteThirdFoo = createSimpleRouteInput(nodeOnePath); + consumerService.routedSimpleRoute(simpleRouteThirdFoo); /** * Verifies that provider 1 wasn't invoked and provider 2 was invoked 1 * time. + * TODO: fix unregister path */ - verify(salFlowService1, times(0)).addFlow(AddFlowThirdMessage); - verify(salFlowService2).addFlow(AddFlowThirdMessage); + //verify(odlRoutedService1, times(0)).routedSimpleRoute(simpleRouteThirdFoo); + verify(odlRoutedService2).routedSimpleRoute(simpleRouteThirdFoo); } @@ -189,13 +172,16 @@ public class RoutedServiceTest extends AbstractTest { * * @param string * string with key(path) - * @return instance of the type NodeRef + * @return instance identifier to {@link UnorderedList} */ - private static NodeRef createNodeRef(String string) { - NodeKey key = new NodeKey(new NodeId(string)); - InstanceIdentifier path = InstanceIdentifier.builder(Nodes.class).child(Node.class, key).build(); - - return new NodeRef(path); + private static InstanceIdentifier createNodeRef(String string) { + UnorderedListKey key = new UnorderedListKey(string); + InstanceIdentifier path = InstanceIdentifier.builder(Lists.class) + .child(UnorderedContainer.class) + .child(UnorderedList.class, key) + .build(); + + return path; } /** @@ -203,14 +189,11 @@ public class RoutedServiceTest extends AbstractTest { * * @param node * NodeRef value - * @param cookie - * integer with cookie value - * @return AddFlowInput instance + * @return simpleRouteInput instance */ - static AddFlowInput createSampleAddFlow(NodeRef node, int cookie) { - AddFlowInputBuilder ret = new AddFlowInputBuilder(); - ret.setNode(node); - ret.setCookie(new FlowCookie(BigInteger.valueOf(cookie))); + static RoutedSimpleRouteInput createSimpleRouteInput(InstanceIdentifier node) { + RoutedSimpleRouteInputBuilder ret = new RoutedSimpleRouteInputBuilder(); + ret.setRoute(node); return ret.build(); } } diff --git a/opendaylight/md-sal/sal-test-model/pom.xml b/opendaylight/md-sal/sal-test-model/pom.xml index 2a8a80da09..852e99e146 100644 --- a/opendaylight/md-sal/sal-test-model/pom.xml +++ b/opendaylight/md-sal/sal-test-model/pom.xml @@ -9,6 +9,9 @@ 4.0.0 + sal-test-model + bundle + org.opendaylight.yangtools @@ -20,7 +23,6 @@ - sal-test-model diff --git a/opendaylight/md-sal/sal-test-model/src/main/yang/opendaylight-test-notification.yang b/opendaylight/md-sal/sal-test-model/src/main/yang/opendaylight-test-notification.yang new file mode 100644 index 0000000000..31ec7aed61 --- /dev/null +++ b/opendaylight/md-sal/sal-test-model/src/main/yang/opendaylight-test-notification.yang @@ -0,0 +1,25 @@ +module opendaylight-test-notification { + yang-version 1; + namespace "urn:opendaylight:params:xml:ns:yang:controller:md:sal:test:bi:ba:notification"; + prefix "ntf"; + + description + "Test model for testing of registering notification listener and publishing of notification."; + + revision "2015-02-05" { + description + "Initial revision"; + } + + notification out-of-pixie-dust-notification { + description "Just a testing notification that we can not fly for now."; + + leaf reason { + type string; + } + + leaf days-till-new-dust { + type uint16; + } + } +} \ No newline at end of file -- 2.36.6