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%2FBug1418AugmentationTest.java;h=f10674226e713a8aee49ee96cd4843ea20c8661a;hp=fe32fa9d18535adc34f12fba55d3d71986757eaa;hb=97f90cb2c7865665e6f152bec1f82f4ad784b389;hpb=ed8f40c01c61ed505cb0c4d5b307a8dea0acc82f diff --git a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/Bug1418AugmentationTest.java b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/Bug1418AugmentationTest.java index fe32fa9d18..f10674226e 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/Bug1418AugmentationTest.java +++ b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/Bug1418AugmentationTest.java @@ -8,32 +8,30 @@ package org.opendaylight.controller.md.sal.binding.impl.test; +import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION; +import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.TOP_FOO_KEY; +import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.complexUsesAugment; +import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.leafOnlyUsesAugment; +import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.path; +import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.top; +import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.topLevelList; + +import com.google.common.collect.ImmutableSet; +import java.util.Set; import org.junit.Test; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; -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.controller.md.sal.binding.test.AbstractDataTreeChangeListenerTest; +import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugment; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeLeafOnlyUsesAugment; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.complex.from.grouping.ListViaUses; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.complex.from.grouping.ListViaUsesKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey; -import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.YangModuleInfo; -import static org.junit.Assert.assertTrue; -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.test.model.util.ListsBindingUtils.top; -import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.TOP_FOO_KEY; -import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.topLevelList; -import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.leafOnlyUsesAugment; -import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.complexUsesAugment; - -public class Bug1418AugmentationTest extends AbstractDataChangeListenerTest{ +public class Bug1418AugmentationTest extends AbstractDataTreeChangeListenerTest { private static final InstanceIdentifier TOP = InstanceIdentifier.create(Top.class); private static final InstanceIdentifier TOP_FOO = TOP.child(TopLevelList.class, TOP_FOO_KEY); private static final InstanceIdentifier SIMPLE_AUGMENT = @@ -45,99 +43,105 @@ public class Bug1418AugmentationTest extends AbstractDataChangeListenerTest{ private static final ListViaUsesKey LIST_VIA_USES_KEY_MOD = new ListViaUsesKey("list key modified"); + @Override + protected Set getModuleInfos() throws Exception { + return ImmutableSet.of(BindingReflections.getModuleInfo(Top.class), + BindingReflections.getModuleInfo(TreeComplexUsesAugment.class), + BindingReflections.getModuleInfo(TreeLeafOnlyUsesAugment.class)); + } + @Test public void leafOnlyAugmentationCreatedTest() { - TestListener listener = createListener(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT, - AsyncDataBroker.DataChangeScope.SUBTREE); + TreeLeafOnlyUsesAugment leafOnlyUsesAugment = leafOnlyUsesAugment("test leaf"); + final TestListener listener = createListener(CONFIGURATION, SIMPLE_AUGMENT, + added(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugment)); + WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction(); - writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP, top()); - writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY))); - writeTx.put(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugment("test leaf")); + writeTx.put(CONFIGURATION, TOP, top()); + writeTx.put(CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY))); + writeTx.put(CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugment); assertCommit(writeTx.submit()); - assertTrue(listener.hasEvent()); - AsyncDataChangeEvent, DataObject> event = listener.event(); - assertContains(event.getCreatedData(), SIMPLE_AUGMENT); - assertEmpty(event.getUpdatedData()); - assertEmpty(event.getOriginalData()); - assertEmpty(event.getRemovedPaths()); + + listener.verify(); } @Test public void leafOnlyAugmentationUpdatedTest() { WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction(); - writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP, top()); - writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY))); - writeTx.put(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugment("test leaf")); + writeTx.put(CONFIGURATION, TOP, top()); + writeTx.put(CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY))); + TreeLeafOnlyUsesAugment leafOnlyUsesAugmentBefore = leafOnlyUsesAugment("test leaf"); + writeTx.put(CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugmentBefore); assertCommit(writeTx.submit()); - TestListener listener = createListener(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT, - AsyncDataBroker.DataChangeScope.SUBTREE); + + TreeLeafOnlyUsesAugment leafOnlyUsesAugmentAfter = leafOnlyUsesAugment("test leaf changed"); + final TestListener listener = createListener(CONFIGURATION, SIMPLE_AUGMENT, + added(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugmentBefore), + replaced(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugmentBefore, + leafOnlyUsesAugmentAfter)); + writeTx = getDataBroker().newWriteOnlyTransaction(); - writeTx.put(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugment("test leaf changed")); + writeTx.put(CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugmentAfter); assertCommit(writeTx.submit()); - assertTrue(listener.hasEvent()); - AsyncDataChangeEvent, DataObject> event = listener.event(); - assertContains(event.getUpdatedData(), SIMPLE_AUGMENT); - assertContains(event.getOriginalData(), SIMPLE_AUGMENT); - assertEmpty(event.getCreatedData()); - assertEmpty(event.getRemovedPaths()); + + listener.verify(); } @Test public void leafOnlyAugmentationDeletedTest() { WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction(); - writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP, top()); - writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY))); - writeTx.put(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugment("test leaf")); + writeTx.put(CONFIGURATION, TOP, top()); + writeTx.put(CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY))); + TreeLeafOnlyUsesAugment leafOnlyUsesAugment = leafOnlyUsesAugment("test leaf"); + writeTx.put(CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugment); assertCommit(writeTx.submit()); - TestListener listener = createListener(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT, - AsyncDataBroker.DataChangeScope.SUBTREE); + + final TestListener listener = createListener(CONFIGURATION, SIMPLE_AUGMENT, + added(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugment), + deleted(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugment)); + writeTx = getDataBroker().newWriteOnlyTransaction(); - writeTx.delete(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT); + writeTx.delete(CONFIGURATION, SIMPLE_AUGMENT); assertCommit(writeTx.submit()); - assertTrue(listener.hasEvent()); - AsyncDataChangeEvent, DataObject> event = listener.event(); - assertContains(event.getRemovedPaths(), SIMPLE_AUGMENT); - assertContains(event.getOriginalData(), SIMPLE_AUGMENT); - assertEmpty(event.getCreatedData()); - assertEmpty(event.getUpdatedData()); + + listener.verify(); } @Test public void complexAugmentationCreatedTest() { - TestListener listener = createListener(LogicalDatastoreType.CONFIGURATION, COMPLEX_AUGMENT, - AsyncDataBroker.DataChangeScope.SUBTREE); + TreeComplexUsesAugment complexUsesAugment = complexUsesAugment(LIST_VIA_USES_KEY); + final TestListener listener = createListener(CONFIGURATION, COMPLEX_AUGMENT, + added(path(TOP_FOO_KEY, TreeComplexUsesAugment.class), complexUsesAugment)); + WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction(); - writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP, top()); - writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY))); - writeTx.put(LogicalDatastoreType.CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugment(LIST_VIA_USES_KEY)); + writeTx.put(CONFIGURATION, TOP, top()); + writeTx.put(CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY))); + writeTx.put(CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugment); assertCommit(writeTx.submit()); - assertTrue(listener.hasEvent()); - AsyncDataChangeEvent, DataObject> event = listener.event(); - assertContains(event.getCreatedData(), COMPLEX_AUGMENT); - assertContains(event.getCreatedData(), COMPLEX_AUGMENT.child(ListViaUses.class, LIST_VIA_USES_KEY)); - assertEmpty(event.getUpdatedData()); - assertEmpty(event.getOriginalData()); - assertEmpty(event.getRemovedPaths()); + + listener.verify(); } @Test public void complexAugmentationUpdatedTest() { WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction(); - writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP, top()); - writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY))); - writeTx.put(LogicalDatastoreType.CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugment(LIST_VIA_USES_KEY)); + writeTx.put(CONFIGURATION, TOP, top()); + writeTx.put(CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY))); + TreeComplexUsesAugment complexUsesAugmentBefore = complexUsesAugment(LIST_VIA_USES_KEY); + writeTx.put(CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugmentBefore); assertCommit(writeTx.submit()); - TestListener listener = createListener(LogicalDatastoreType.CONFIGURATION, COMPLEX_AUGMENT, - AsyncDataBroker.DataChangeScope.SUBTREE); + + TreeComplexUsesAugment complexUsesAugmentAfter = complexUsesAugment(LIST_VIA_USES_KEY_MOD); + + final TestListener listener = createListener(CONFIGURATION, COMPLEX_AUGMENT, + added(path(TOP_FOO_KEY, TreeComplexUsesAugment.class), complexUsesAugmentBefore), + replaced(path(TOP_FOO_KEY, TreeComplexUsesAugment.class), complexUsesAugmentBefore, + complexUsesAugmentAfter)); + writeTx = getDataBroker().newWriteOnlyTransaction(); - writeTx.put(LogicalDatastoreType.CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugment(LIST_VIA_USES_KEY_MOD)); + writeTx.put(CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugmentAfter); assertCommit(writeTx.submit()); - assertTrue(listener.hasEvent()); - AsyncDataChangeEvent, DataObject> event = listener.event(); - assertContains(event.getUpdatedData(), COMPLEX_AUGMENT); - assertContains(event.getCreatedData(), COMPLEX_AUGMENT.child(ListViaUses.class, LIST_VIA_USES_KEY_MOD)); - assertContains(event.getRemovedPaths(), COMPLEX_AUGMENT.child(ListViaUses.class, LIST_VIA_USES_KEY)); - assertContains(event.getOriginalData(), COMPLEX_AUGMENT); - assertContains(event.getOriginalData(), COMPLEX_AUGMENT.child(ListViaUses.class, LIST_VIA_USES_KEY)); + + listener.verify(); } }