X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-broker%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fbinding%2Fimpl%2Ftest%2FBug3090MultiKeyList.java;h=bf6f1b288d48d552a157323c28838ee6e1bfb3eb;hp=83bb6a4414fd8264a48e65eae7ace34a321277a3;hb=97f90cb2c7865665e6f152bec1f82f4ad784b389;hpb=296b249e512b1c677ba5dbcb57d9d9404d8f0710 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 index 83bb6a4414..bf6f1b288d 100644 --- 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 @@ -7,31 +7,37 @@ */ 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 com.google.common.collect.ImmutableSet; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Objects; +import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; import org.junit.Test; +import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType; 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.binding.test.AbstractDataTreeChangeListenerTest; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections; 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; +import org.opendaylight.yangtools.yang.binding.YangModuleInfo; -public class Bug3090MultiKeyList extends AbstractDataChangeListenerTest{ +public class Bug3090MultiKeyList extends AbstractDataTreeChangeListenerTest { private static final InstanceIdentifier ROOT_PATH = InstanceIdentifier.create(Root.class); - private void write(final LogicalDatastoreType store) { - final ReadWriteTransaction readWriteTransaction = getDataBroker().newReadWriteTransaction(); + @Override + protected Set getModuleInfos() throws Exception { + return ImmutableSet.of(BindingReflections.getModuleInfo(Root.class)); + } + @Test + public void listWithMultiKeyTest() { final List listInRoots = new ArrayList<>(); for (int i = 0; i < 10; i++) { listInRoots.add(new ListInRootBuilder() @@ -41,22 +47,28 @@ public class Bug3090MultiKeyList extends AbstractDataChangeListenerTest{ .build() ); } + final Root root = new RootBuilder().setListInRoot(listInRoots).build(); - readWriteTransaction.put(store, ROOT_PATH, root); + + final TestListener listener = createListener(LogicalDatastoreType.CONFIGURATION, ROOT_PATH, + match(ModificationType.WRITE, ROOT_PATH, Objects::isNull, + (Function) dataAfter -> checkData(root, dataAfter))); + + final ReadWriteTransaction readWriteTransaction = getDataBroker().newReadWriteTransaction(); + readWriteTransaction.put(LogicalDatastoreType.CONFIGURATION, ROOT_PATH, root); assertCommit(readWriteTransaction.submit()); - } - @Test - public void listWithMultiKeyTest() { - final AbstractDataChangeListenerTest.TestListener listener = createListener(CONFIGURATION, ROOT_PATH, - AsyncDataBroker.DataChangeScope.BASE); - listener.startCapture(); + listener.verify(); + } - write(CONFIGURATION); - final AsyncDataChangeEvent, DataObject> event = listener.event(); + private static boolean checkData(final Root expected, final Root actual) { + if (actual == null) { + return false; + } - assertContains(event.getCreatedData(), ROOT_PATH); - assertEmpty(event.getUpdatedData()); - assertEmpty(event.getRemovedPaths()); + Set expListInRoot = new HashSet<>(expected.getListInRoot()); + Set actualListInRoot = actual.getListInRoot().stream() + .map(list -> new ListInRootBuilder(list).build()).collect(Collectors.toSet()); + return expListInRoot.equals(actualListInRoot); } -} \ No newline at end of file +}