d05e0b64ffebf45c874035a82017b7ea8fe16ac6
[controller.git] / opendaylight / md-sal / sal-binding-dom-it / src / test / java / org / opendaylight / controller / sal / binding / test / bugfix / WriteParentListenAugmentTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.sal.binding.test.bugfix;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL;
12
13 import com.google.common.collect.ImmutableSet;
14 import java.util.concurrent.TimeUnit;
15 import org.junit.Test;
16 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
17 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
18 import org.opendaylight.controller.md.sal.binding.test.AbstractDataTreeChangeListenerTest;
19 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugment;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugmentBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.complex.from.grouping.ContainerWithUsesBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
29
30 public class WriteParentListenAugmentTest extends AbstractDataTreeChangeListenerTest {
31
32     private static final String TLL_NAME = "foo";
33
34     private static final TopLevelListKey TLL_KEY = new TopLevelListKey(TLL_NAME);
35     private static final InstanceIdentifier<TopLevelList> TLL_INSTANCE_ID_BA = InstanceIdentifier.builder(Top.class)
36             .child(TopLevelList.class, TLL_KEY).build();
37
38     private static final InstanceIdentifier<TreeComplexUsesAugment> AUGMENT_WILDCARDED_PATH = InstanceIdentifier
39             .builder(Top.class).child(TopLevelList.class).augmentation(TreeComplexUsesAugment.class).build();
40
41     private static final InstanceIdentifier<TreeComplexUsesAugment> AUGMENT_TLL_PATH = InstanceIdentifier
42             .builder(Top.class).child(TopLevelList.class, TLL_KEY).augmentation(TreeComplexUsesAugment.class).build();
43
44     @Override
45     protected Iterable<YangModuleInfo> getModuleInfos() throws Exception {
46         return ImmutableSet.of(BindingReflections.getModuleInfo(Top.class),
47                 BindingReflections.getModuleInfo(TreeComplexUsesAugment.class));
48     }
49
50     @Test
51     public void writeNodeListenAugment() throws Exception {
52
53         DataBroker dataBroker = getDataBroker();
54
55         final TreeComplexUsesAugment treeComplexUsesAugment = treeComplexUsesAugment("one");
56
57         final TestListener<TreeComplexUsesAugment> listener = createListener(OPERATIONAL, AUGMENT_WILDCARDED_PATH,
58                 added(AUGMENT_TLL_PATH, treeComplexUsesAugment));
59
60         final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
61
62         TopLevelList tll = new TopLevelListBuilder().withKey(TLL_KEY)
63                 .addAugmentation(TreeComplexUsesAugment.class, treeComplexUsesAugment).build();
64         transaction.put(OPERATIONAL, TLL_INSTANCE_ID_BA, tll, true);
65         transaction.submit().get(5, TimeUnit.SECONDS);
66
67         listener.verify();
68
69         final WriteTransaction transaction2 = dataBroker.newWriteOnlyTransaction();
70         transaction2.put(OPERATIONAL, AUGMENT_TLL_PATH, treeComplexUsesAugment("two"));
71         transaction2.submit().get(5, TimeUnit.SECONDS);
72
73         TreeComplexUsesAugment readedAug = dataBroker.newReadOnlyTransaction().read(
74                 OPERATIONAL, AUGMENT_TLL_PATH).get(5, TimeUnit.SECONDS).get();
75         assertEquals("two", readedAug.getContainerWithUses().getLeafFromGrouping());
76     }
77
78     private static TreeComplexUsesAugment treeComplexUsesAugment(final String value) {
79         return new TreeComplexUsesAugmentBuilder()
80                 .setContainerWithUses(new ContainerWithUsesBuilder().setLeafFromGrouping(value).build())
81                 .build();
82     }
83 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.