X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=restconf%2Frestconf-nb-rfc8040%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Frestconf%2Fnb%2Frfc8040%2Fstreams%2Flisteners%2FListenerAdapterTest.java;h=0cbf42d7f17950bd22d000a7ff63311fff9ec529;hb=1982b130c5b7b4342c1b9bb107b717f44ce4b7af;hp=a1cb417bdf8ead090e2f88aab8dd605708284053;hpb=0a95f4298a7f467b6c2eebf7904c8253cf3d5198;p=netconf.git diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenerAdapterTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenerAdapterTest.java index a1cb417bdf..0cbf42d7f1 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenerAdapterTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenerAdapterTest.java @@ -5,7 +5,6 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.restconf.nb.rfc8040.streams.listeners; import static java.time.Instant.EPOCH; @@ -18,20 +17,21 @@ import java.net.URL; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; -import java.util.Optional; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import org.json.JSONObject; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.mockito.Mockito; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; -import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; -import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService; -import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier; +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.api.WriteTransaction; +import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractConcurrentDataBrokerTest; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.mdsal.dom.api.DOMDataBroker; +import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService; +import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier; import org.opendaylight.mdsal.dom.api.DOMSchemaService; import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler; @@ -42,7 +42,7 @@ import org.opendaylight.yang.gen.v1.instance.identifier.patch.module.rev151121.p import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; import org.skyscreamer.jsonassert.JSONAssert; import org.slf4j.Logger; @@ -57,26 +57,42 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest { private static final String JSON_NOTIF_CREATE = "/listener-adapter-test/notif-create.json"; private static final String JSON_NOTIF_UPDATE = "/listener-adapter-test/notif-update.json"; private static final String JSON_NOTIF_DEL = "/listener-adapter-test/notif-del.json"; - - private static YangInstanceIdentifier PATCH_CONT_YIID = + private static final String JSON_NOTIF_WITHOUT_DATA_CREATE = + "/listener-adapter-test/notif-without-data-create.json"; + private static final String JSON_NOTIF_WITHOUT_DATA_UPDATE = + "/listener-adapter-test/notif-without-data-update.json"; + private static final String JSON_NOTIF_WITHOUT_DATA_DELETE = + "/listener-adapter-test/notif-without-data-del.json"; + + private static final YangInstanceIdentifier PATCH_CONT_YIID = YangInstanceIdentifier.create(new YangInstanceIdentifier.NodeIdentifier(PatchCont.QNAME)); + private static EffectiveModelContext SCHEMA_CONTEXT; + private DataBroker dataBroker; private DOMDataBroker domDataBroker; private TransactionChainHandler transactionChainHandler; private SchemaContextHandler schemaContextHandler; + @BeforeClass + public static void beforeClass() { + SCHEMA_CONTEXT = YangParserTestUtils.parseYangResource( + "/instanceidentifier/yang/instance-identifier-patch-module.yang"); + } + + @AfterClass + public static void afterClass() { + SCHEMA_CONTEXT = null; + } + @Before public void setUp() throws Exception { dataBroker = getDataBroker(); domDataBroker = getDomBroker(); - SchemaContext sc = YangParserTestUtils.parseYangResource( - "/instanceidentifier/yang/instance-identifier-patch-module.yang"); transactionChainHandler = new TransactionChainHandler(domDataBroker); - schemaContextHandler = SchemaContextHandler.newInstance(transactionChainHandler, - Mockito.mock(DOMSchemaService.class)); - schemaContextHandler.onGlobalContextUpdated(sc); + schemaContextHandler = new SchemaContextHandler(transactionChainHandler, Mockito.mock(DOMSchemaService.class)); + schemaContextHandler.onModelContextUpdated(SCHEMA_CONTEXT); } class ListenerAdapterTester extends ListenerAdapter { @@ -86,14 +102,14 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest { ListenerAdapterTester(final YangInstanceIdentifier path, final String streamName, final NotificationOutputTypeGrouping.NotificationOutputType outputType, - final boolean leafNodesOnly) { + final boolean leafNodesOnly, final boolean skipNotificationData) { super(path, streamName, outputType); - setQueryParams(EPOCH, Optional.empty(), Optional.empty(), leafNodesOnly); + setQueryParams(EPOCH, null, null, leafNodesOnly, skipNotificationData); } @Override - protected void post(final Event event) { - this.lastNotification = event.getData(); + protected void post(final String data) { + this.lastNotification = data; notificationLatch.countDown(); } @@ -131,11 +147,11 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest { @Test public void testJsonNotifsLeaves() throws Exception { ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", - NotificationOutputTypeGrouping.NotificationOutputType.JSON, true); + NotificationOutputTypeGrouping.NotificationOutputType.JSON, true, false); adapter.setCloseVars(transactionChainHandler, schemaContextHandler); - DOMDataTreeChangeService changeService = (DOMDataTreeChangeService) - domDataBroker.getSupportedExtensions().get(DOMDataTreeChangeService.class); + DOMDataTreeChangeService changeService = domDataBroker.getExtensions() + .getInstance(DOMDataTreeChangeService.class); DOMDataTreeIdentifier root = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, PATCH_CONT_YIID); changeService.registerDataTreeChangeListener(root, adapter); @@ -143,30 +159,30 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest { MyList1Builder builder = new MyList1Builder().setMyLeaf11("Jed").setName("Althea"); InstanceIdentifier iid = InstanceIdentifier.create(PatchCont.class) .child(MyList1.class, new MyList1Key("Althea")); - writeTransaction.put(LogicalDatastoreType.CONFIGURATION, iid, builder.build(), true); - writeTransaction.submit(); + writeTransaction.mergeParentStructurePut(LogicalDatastoreType.CONFIGURATION, iid, builder.build()); + writeTransaction.commit(); adapter.assertGot(getNotifJson(JSON_NOTIF_LEAVES_CREATE)); writeTransaction = dataBroker.newWriteOnlyTransaction(); builder = new MyList1Builder().withKey(new MyList1Key("Althea")).setMyLeaf12("Bertha"); - writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, iid, builder.build(), true); - writeTransaction.submit(); + writeTransaction.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, iid, builder.build()); + writeTransaction.commit(); adapter.assertGot(getNotifJson(JSON_NOTIF_LEAVES_UPDATE)); writeTransaction = dataBroker.newWriteOnlyTransaction(); writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, iid); - writeTransaction.submit(); + writeTransaction.commit(); adapter.assertGot(getNotifJson(JSON_NOTIF_LEAVES_DEL)); } @Test public void testJsonNotifs() throws Exception { ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", - NotificationOutputTypeGrouping.NotificationOutputType.JSON, false); + NotificationOutputTypeGrouping.NotificationOutputType.JSON, false, false); adapter.setCloseVars(transactionChainHandler, schemaContextHandler); - DOMDataTreeChangeService changeService = (DOMDataTreeChangeService) - domDataBroker.getSupportedExtensions().get(DOMDataTreeChangeService.class); + DOMDataTreeChangeService changeService = domDataBroker.getExtensions() + .getInstance(DOMDataTreeChangeService.class); DOMDataTreeIdentifier root = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, PATCH_CONT_YIID); changeService.registerDataTreeChangeListener(root, adapter); @@ -174,19 +190,49 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest { MyList1Builder builder = new MyList1Builder().setMyLeaf11("Jed").setName("Althea"); InstanceIdentifier iid = InstanceIdentifier.create(PatchCont.class) .child(MyList1.class, new MyList1Key("Althea")); - writeTransaction.put(LogicalDatastoreType.CONFIGURATION, iid, builder.build(), true); - writeTransaction.submit(); + writeTransaction.mergeParentStructurePut(LogicalDatastoreType.CONFIGURATION, iid, builder.build()); + writeTransaction.commit(); adapter.assertGot(getNotifJson(JSON_NOTIF_CREATE)); writeTransaction = dataBroker.newWriteOnlyTransaction(); builder = new MyList1Builder().withKey(new MyList1Key("Althea")).setMyLeaf12("Bertha"); - writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, iid, builder.build(), true); - writeTransaction.submit(); + writeTransaction.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, iid, builder.build()); + writeTransaction.commit(); adapter.assertGot(getNotifJson(JSON_NOTIF_UPDATE)); writeTransaction = dataBroker.newWriteOnlyTransaction(); writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, iid); - writeTransaction.submit(); + writeTransaction.commit(); adapter.assertGot(getNotifJson(JSON_NOTIF_DEL)); } + + @Test + public void testJsonNotifsWithoutData() throws Exception { + ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", + NotificationOutputTypeGrouping.NotificationOutputType.JSON, false, true); + adapter.setCloseVars(transactionChainHandler, schemaContextHandler); + + DOMDataTreeChangeService changeService = domDataBroker.getExtensions() + .getInstance(DOMDataTreeChangeService.class); + DOMDataTreeIdentifier root = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, PATCH_CONT_YIID); + changeService.registerDataTreeChangeListener(root, adapter); + WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); + MyList1Builder builder = new MyList1Builder().setMyLeaf11("Jed").setName("Althea"); + InstanceIdentifier iid = InstanceIdentifier.create(PatchCont.class) + .child(MyList1.class, new MyList1Key("Althea")); + writeTransaction.mergeParentStructurePut(LogicalDatastoreType.CONFIGURATION, iid, builder.build()); + writeTransaction.commit(); + adapter.assertGot(getNotifJson(JSON_NOTIF_WITHOUT_DATA_CREATE)); + + writeTransaction = dataBroker.newWriteOnlyTransaction(); + builder = new MyList1Builder().withKey(new MyList1Key("Althea")).setMyLeaf12("Bertha"); + writeTransaction.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, iid, builder.build()); + writeTransaction.commit(); + adapter.assertGot(getNotifJson(JSON_NOTIF_WITHOUT_DATA_UPDATE)); + + writeTransaction = dataBroker.newWriteOnlyTransaction(); + writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, iid); + writeTransaction.commit(); + adapter.assertGot(getNotifJson(JSON_NOTIF_WITHOUT_DATA_DELETE)); + } }