X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-dom-it%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fbinding%2Ftest%2Fbugfix%2FWriteParentListenAugmentTest.java;h=09836147f2d6b44555493b9ff728df510c42b628;hp=591effbe03cdca28175938fd3611dbdf5e82f740;hb=97f90cb2c7865665e6f152bec1f82f4ad784b389;hpb=2d62916cb1f4b4045f4fc38fbd313f8339f9ac67 diff --git a/opendaylight/md-sal/sal-binding-dom-it/src/test/java/org/opendaylight/controller/sal/binding/test/bugfix/WriteParentListenAugmentTest.java b/opendaylight/md-sal/sal-binding-dom-it/src/test/java/org/opendaylight/controller/sal/binding/test/bugfix/WriteParentListenAugmentTest.java index 591effbe03..09836147f2 100644 --- a/opendaylight/md-sal/sal-binding-dom-it/src/test/java/org/opendaylight/controller/sal/binding/test/bugfix/WriteParentListenAugmentTest.java +++ b/opendaylight/md-sal/sal-binding-dom-it/src/test/java/org/opendaylight/controller/sal/binding/test/bugfix/WriteParentListenAugmentTest.java @@ -5,18 +5,19 @@ * 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.sal.binding.test.bugfix; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import com.google.common.util.concurrent.SettableFuture; +import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL; + +import com.google.common.collect.ImmutableSet; +import java.util.Set; import java.util.concurrent.TimeUnit; import org.junit.Test; -import org.opendaylight.controller.md.sal.common.api.data.DataChangeEvent; -import org.opendaylight.controller.sal.binding.api.data.DataChangeListener; -import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction; -import org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest; +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.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.TreeComplexUsesAugmentBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.complex.from.grouping.ContainerWithUsesBuilder; @@ -24,63 +25,60 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controll 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.TopLevelListBuilder; 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.concepts.ListenerRegistration; -import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.YangModuleInfo; -public class WriteParentListenAugmentTest extends AbstractDataServiceTest { +public class WriteParentListenAugmentTest extends AbstractDataTreeChangeListenerTest { private static final String TLL_NAME = "foo"; private static final TopLevelListKey TLL_KEY = new TopLevelListKey(TLL_NAME); - private static final InstanceIdentifier TLL_INSTANCE_ID_BA = InstanceIdentifier.builder(Top.class) // - .child(TopLevelList.class, TLL_KEY).toInstance(); + private static final InstanceIdentifier TLL_INSTANCE_ID_BA = InstanceIdentifier.builder(Top.class) + .child(TopLevelList.class, TLL_KEY).build(); private static final InstanceIdentifier AUGMENT_WILDCARDED_PATH = InstanceIdentifier - .builder(Top.class).child(TopLevelList.class).augmentation(TreeComplexUsesAugment.class).toInstance(); + .builder(Top.class).child(TopLevelList.class).augmentation(TreeComplexUsesAugment.class).build(); private static final InstanceIdentifier AUGMENT_TLL_PATH = InstanceIdentifier - .builder(Top.class).child(TopLevelList.class, TLL_KEY).augmentation(TreeComplexUsesAugment.class).toInstance(); + .builder(Top.class).child(TopLevelList.class, TLL_KEY).augmentation(TreeComplexUsesAugment.class).build(); + + @Override + protected Set getModuleInfos() throws Exception { + return ImmutableSet.of(BindingReflections.getModuleInfo(Top.class), + BindingReflections.getModuleInfo(TreeComplexUsesAugment.class)); + } @Test public void writeNodeListenAugment() throws Exception { - final SettableFuture, DataObject>> event = SettableFuture.create(); - - ListenerRegistration dclRegistration = baDataService.registerDataChangeListener( - AUGMENT_WILDCARDED_PATH, new DataChangeListener() { + DataBroker dataBroker = getDataBroker(); - @Override - public void onDataChanged(final DataChangeEvent, DataObject> change) { - event.set(change); - } - }); + final TreeComplexUsesAugment treeComplexUsesAugment = treeComplexUsesAugment("one"); - DataModificationTransaction modification = baDataService.beginTransaction(); + final TestListener listener = createListener(OPERATIONAL, AUGMENT_WILDCARDED_PATH, + added(AUGMENT_TLL_PATH, treeComplexUsesAugment)); - TopLevelList tll = new TopLevelListBuilder() // - .setKey(TLL_KEY) // - .addAugmentation(TreeComplexUsesAugment.class, treeComplexUsesAugment("one")).build(); - modification.putOperationalData(TLL_INSTANCE_ID_BA, tll); - modification.commit().get(); + final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); - DataChangeEvent, DataObject> receivedEvent = event.get(1000, TimeUnit.MILLISECONDS); - assertTrue(receivedEvent.getCreatedOperationalData().containsKey(AUGMENT_TLL_PATH)); + TopLevelList tll = new TopLevelListBuilder().withKey(TLL_KEY) + .addAugmentation(TreeComplexUsesAugment.class, treeComplexUsesAugment).build(); + transaction.put(OPERATIONAL, TLL_INSTANCE_ID_BA, tll, true); + transaction.submit().get(5, TimeUnit.SECONDS); - dclRegistration.close(); + listener.verify(); - DataModificationTransaction mod2 = baDataService.beginTransaction(); - mod2.putOperationalData(AUGMENT_TLL_PATH, treeComplexUsesAugment("two")); - mod2.commit().get(); + final WriteTransaction transaction2 = dataBroker.newWriteOnlyTransaction(); + transaction2.put(OPERATIONAL, AUGMENT_TLL_PATH, treeComplexUsesAugment("two")); + transaction2.submit().get(5, TimeUnit.SECONDS); - TreeComplexUsesAugment readedAug = (TreeComplexUsesAugment) baDataService.readOperationalData(AUGMENT_TLL_PATH); + TreeComplexUsesAugment readedAug = dataBroker.newReadOnlyTransaction().read( + OPERATIONAL, AUGMENT_TLL_PATH).get(5, TimeUnit.SECONDS).get(); assertEquals("two", readedAug.getContainerWithUses().getLeafFromGrouping()); - } - private TreeComplexUsesAugment treeComplexUsesAugment(final String value) { - return new TreeComplexUsesAugmentBuilder() // - .setContainerWithUses(new ContainerWithUsesBuilder().setLeafFromGrouping(value).build()) // + private static TreeComplexUsesAugment treeComplexUsesAugment(final String value) { + return new TreeComplexUsesAugmentBuilder() + .setContainerWithUses(new ContainerWithUsesBuilder().setLeafFromGrouping(value).build()) .build(); } -} \ No newline at end of file +}