From 296b249e512b1c677ba5dbcb57d9d9404d8f0710 Mon Sep 17 00:00:00 2001 From: Filip Gregor Date: Fri, 18 Mar 2016 15:37:19 +0100 Subject: [PATCH] Bug 3090: An AsyncDataChangeEvent instance's getCreatedData() added tests Change-Id: Icfa7d1ef72962cb96929eddcabe51d7b0037f606 Signed-off-by: Filip Gregor --- .../impl/test/Bug3090MultiKeyList.java | 62 +++++++++++++++++++ .../main/yang/opendaylight-test-bug-3090.yang | 28 +++++++++ 2 files changed, 90 insertions(+) create mode 100644 opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/Bug3090MultiKeyList.java create mode 100644 opendaylight/md-sal/sal-test-model/src/main/yang/opendaylight-test-bug-3090.yang diff --git a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/Bug3090MultiKeyList.java b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/Bug3090MultiKeyList.java new file mode 100644 index 0000000000..83bb6a4414 --- /dev/null +++ b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/Bug3090MultiKeyList.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * 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.controller.md.sal.binding.impl.test; + +import static org.opendaylight.controller.md.sal.binding.test.AssertCollections.assertContains; +import static org.opendaylight.controller.md.sal.binding.test.AssertCollections.assertEmpty; +import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION; + +import java.util.ArrayList; +import java.util.List; +import org.junit.Test; +import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction; +import org.opendaylight.controller.md.sal.binding.test.AbstractDataChangeListenerTest; +import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker; +import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.opendaylight.test.bug._3090.rev160101.Root; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.opendaylight.test.bug._3090.rev160101.RootBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.opendaylight.test.bug._3090.rev160101.root.ListInRoot; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.opendaylight.test.bug._3090.rev160101.root.ListInRootBuilder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class Bug3090MultiKeyList extends AbstractDataChangeListenerTest{ + private static final InstanceIdentifier ROOT_PATH = InstanceIdentifier.create(Root.class); + + private void write(final LogicalDatastoreType store) { + final ReadWriteTransaction readWriteTransaction = getDataBroker().newReadWriteTransaction(); + + final List listInRoots = new ArrayList<>(); + for (int i = 0; i < 10; i++) { + listInRoots.add(new ListInRootBuilder() + .setLeafA("leaf a" + i) + .setLeafC("leaf c" + i) + .setLeafB("leaf b" + i) + .build() + ); + } + final Root root = new RootBuilder().setListInRoot(listInRoots).build(); + readWriteTransaction.put(store, ROOT_PATH, root); + assertCommit(readWriteTransaction.submit()); + } + + @Test + public void listWithMultiKeyTest() { + final AbstractDataChangeListenerTest.TestListener listener = createListener(CONFIGURATION, ROOT_PATH, + AsyncDataBroker.DataChangeScope.BASE); + listener.startCapture(); + + write(CONFIGURATION); + final AsyncDataChangeEvent, DataObject> event = listener.event(); + + assertContains(event.getCreatedData(), ROOT_PATH); + assertEmpty(event.getUpdatedData()); + assertEmpty(event.getRemovedPaths()); + } +} \ No newline at end of file diff --git a/opendaylight/md-sal/sal-test-model/src/main/yang/opendaylight-test-bug-3090.yang b/opendaylight/md-sal/sal-test-model/src/main/yang/opendaylight-test-bug-3090.yang new file mode 100644 index 0000000000..9818bd8660 --- /dev/null +++ b/opendaylight/md-sal/sal-test-model/src/main/yang/opendaylight-test-bug-3090.yang @@ -0,0 +1,28 @@ +module opendaylight-test-bug-3090 { + yang-version 1; + namespace "urn:opendaylight:params:xml:ns:opendaylight-test-bug-3090"; + prefix "rpc"; + + description + "Test model for Bug 3090 - An AsyncDataChangeEvent instance's getCreatedData() method can't get data if list has multi-key"; + + revision "2016-01-01" { + description + "Bug 3090"; + } + + container root { + list list-in-root { + key "leaf-c leaf-a leaf-b"; + leaf leaf-a { + type string; + } + leaf leaf-b { + type string; + } + leaf leaf-c { + type string; + } + } + } +} \ No newline at end of file -- 2.36.6