2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.sal.binding.test.bugfix;
10 import static org.junit.Assert.assertEquals;
11 import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL;
13 import com.google.common.collect.ImmutableSet;
15 import java.util.concurrent.TimeUnit;
16 import org.junit.Test;
17 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
18 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
19 import org.opendaylight.controller.md.sal.binding.test.AbstractDataTreeChangeListenerTest;
20 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugment;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugmentBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.complex.from.grouping.ContainerWithUsesBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
31 public class WriteParentListenAugmentTest extends AbstractDataTreeChangeListenerTest {
33 private static final String TLL_NAME = "foo";
35 private static final TopLevelListKey TLL_KEY = new TopLevelListKey(TLL_NAME);
36 private static final InstanceIdentifier<TopLevelList> TLL_INSTANCE_ID_BA = InstanceIdentifier.builder(Top.class)
37 .child(TopLevelList.class, TLL_KEY).build();
39 private static final InstanceIdentifier<TreeComplexUsesAugment> AUGMENT_WILDCARDED_PATH = InstanceIdentifier
40 .builder(Top.class).child(TopLevelList.class).augmentation(TreeComplexUsesAugment.class).build();
42 private static final InstanceIdentifier<TreeComplexUsesAugment> AUGMENT_TLL_PATH = InstanceIdentifier
43 .builder(Top.class).child(TopLevelList.class, TLL_KEY).augmentation(TreeComplexUsesAugment.class).build();
46 protected Set<YangModuleInfo> getModuleInfos() throws Exception {
47 return ImmutableSet.of(BindingReflections.getModuleInfo(Top.class),
48 BindingReflections.getModuleInfo(TreeComplexUsesAugment.class));
52 public void writeNodeListenAugment() throws Exception {
54 DataBroker dataBroker = getDataBroker();
56 final TreeComplexUsesAugment treeComplexUsesAugment = treeComplexUsesAugment("one");
58 final TestListener<TreeComplexUsesAugment> listener = createListener(OPERATIONAL, AUGMENT_WILDCARDED_PATH,
59 added(AUGMENT_TLL_PATH, treeComplexUsesAugment));
61 final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
63 TopLevelList tll = new TopLevelListBuilder().withKey(TLL_KEY)
64 .addAugmentation(TreeComplexUsesAugment.class, treeComplexUsesAugment).build();
65 transaction.put(OPERATIONAL, TLL_INSTANCE_ID_BA, tll, true);
66 transaction.submit().get(5, TimeUnit.SECONDS);
70 final WriteTransaction transaction2 = dataBroker.newWriteOnlyTransaction();
71 transaction2.put(OPERATIONAL, AUGMENT_TLL_PATH, treeComplexUsesAugment("two"));
72 transaction2.submit().get(5, TimeUnit.SECONDS);
74 TreeComplexUsesAugment readedAug = dataBroker.newReadOnlyTransaction().read(
75 OPERATIONAL, AUGMENT_TLL_PATH).get(5, TimeUnit.SECONDS).get();
76 assertEquals("two", readedAug.getContainerWithUses().getLeafFromGrouping());
79 private static TreeComplexUsesAugment treeComplexUsesAugment(final String value) {
80 return new TreeComplexUsesAugmentBuilder()
81 .setContainerWithUses(new ContainerWithUsesBuilder().setLeafFromGrouping(value).build())