2 * Copyright (c) 2014, 2015 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.mdsal.binding.dom.adapter;
10 import static org.opendaylight.mdsal.binding.test.model.util.ListsBindingUtils.TOP_FOO_KEY;
11 import static org.opendaylight.mdsal.binding.test.model.util.ListsBindingUtils.complexUsesAugment;
12 import static org.opendaylight.mdsal.binding.test.model.util.ListsBindingUtils.leafOnlyUsesAugment;
13 import static org.opendaylight.mdsal.binding.test.model.util.ListsBindingUtils.path;
14 import static org.opendaylight.mdsal.binding.test.model.util.ListsBindingUtils.top;
15 import static org.opendaylight.mdsal.binding.test.model.util.ListsBindingUtils.topLevelList;
16 import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION;
18 import com.google.common.collect.ImmutableSet;
20 import org.junit.Test;
21 import org.opendaylight.mdsal.binding.api.WriteTransaction;
22 import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractDataTreeChangeListenerTest;
23 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TreeComplexUsesAugment;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TreeLeafOnlyUsesAugment;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.complex.from.grouping.ListViaUsesKey;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelListKey;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
33 public class Bug1418AugmentationTest extends AbstractDataTreeChangeListenerTest {
34 private static final InstanceIdentifier<Top> TOP = InstanceIdentifier.create(Top.class);
35 private static final InstanceIdentifier<TopLevelList> TOP_FOO = TOP.child(TopLevelList.class, TOP_FOO_KEY);
36 private static final InstanceIdentifier<TreeLeafOnlyUsesAugment> SIMPLE_AUGMENT =
37 TOP.child(TopLevelList.class, TOP_FOO_KEY).augmentation(TreeLeafOnlyUsesAugment.class);
38 private static final InstanceIdentifier<TreeComplexUsesAugment> COMPLEX_AUGMENT =
39 TOP.child(TopLevelList.class, TOP_FOO_KEY).augmentation(TreeComplexUsesAugment.class);
40 private static final ListViaUsesKey LIST_VIA_USES_KEY =
41 new ListViaUsesKey("list key");
42 private static final ListViaUsesKey LIST_VIA_USES_KEY_MOD =
43 new ListViaUsesKey("list key modified");
46 protected Set<YangModuleInfo> getModuleInfos() throws Exception {
47 return ImmutableSet.of(BindingReflections.getModuleInfo(Top.class),
48 BindingReflections.getModuleInfo(TreeComplexUsesAugment.class),
49 BindingReflections.getModuleInfo(TreeLeafOnlyUsesAugment.class));
53 public void leafOnlyAugmentationCreatedTest() {
54 TreeLeafOnlyUsesAugment leafOnlyUsesAugment = leafOnlyUsesAugment("test leaf");
55 final TestListener<TreeLeafOnlyUsesAugment> listener = createListener(CONFIGURATION, SIMPLE_AUGMENT,
56 added(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugment));
58 WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
59 writeTx.put(CONFIGURATION, TOP, top());
60 writeTx.put(CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
61 writeTx.put(CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugment);
62 assertCommit(writeTx.commit());
68 public void leafOnlyAugmentationUpdatedTest() {
69 WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
70 writeTx.put(CONFIGURATION, TOP, top());
71 writeTx.put(CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
72 TreeLeafOnlyUsesAugment leafOnlyUsesAugmentBefore = leafOnlyUsesAugment("test leaf");
73 writeTx.put(CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugmentBefore);
74 assertCommit(writeTx.commit());
76 TreeLeafOnlyUsesAugment leafOnlyUsesAugmentAfter = leafOnlyUsesAugment("test leaf changed");
77 final TestListener<TreeLeafOnlyUsesAugment> listener = createListener(CONFIGURATION, SIMPLE_AUGMENT,
78 added(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugmentBefore),
79 replaced(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugmentBefore,
80 leafOnlyUsesAugmentAfter));
82 writeTx = getDataBroker().newWriteOnlyTransaction();
83 writeTx.put(CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugmentAfter);
84 assertCommit(writeTx.commit());
90 public void leafOnlyAugmentationDeletedTest() {
91 WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
92 writeTx.put(CONFIGURATION, TOP, top());
93 writeTx.put(CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
94 TreeLeafOnlyUsesAugment leafOnlyUsesAugment = leafOnlyUsesAugment("test leaf");
95 writeTx.put(CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugment);
96 assertCommit(writeTx.commit());
98 final TestListener<TreeLeafOnlyUsesAugment> listener = createListener(CONFIGURATION, SIMPLE_AUGMENT,
99 added(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugment),
100 deleted(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugment));
102 writeTx = getDataBroker().newWriteOnlyTransaction();
103 writeTx.delete(CONFIGURATION, SIMPLE_AUGMENT);
104 assertCommit(writeTx.commit());
110 public void complexAugmentationCreatedTest() {
111 TreeComplexUsesAugment complexUsesAugment = complexUsesAugment(LIST_VIA_USES_KEY);
112 final TestListener<TreeComplexUsesAugment> listener = createListener(CONFIGURATION, COMPLEX_AUGMENT,
113 added(path(TOP_FOO_KEY, TreeComplexUsesAugment.class), complexUsesAugment));
115 WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
116 writeTx.put(CONFIGURATION, TOP, top());
117 writeTx.put(CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
118 writeTx.put(CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugment);
119 assertCommit(writeTx.commit());
125 public void complexAugmentationUpdatedTest() {
126 WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
127 writeTx.put(CONFIGURATION, TOP, top());
128 writeTx.put(CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
129 TreeComplexUsesAugment complexUsesAugmentBefore = complexUsesAugment(LIST_VIA_USES_KEY);
130 writeTx.put(CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugmentBefore);
131 assertCommit(writeTx.commit());
133 TreeComplexUsesAugment complexUsesAugmentAfter = complexUsesAugment(LIST_VIA_USES_KEY_MOD);
135 final TestListener<TreeComplexUsesAugment> listener = createListener(CONFIGURATION, COMPLEX_AUGMENT,
136 added(path(TOP_FOO_KEY, TreeComplexUsesAugment.class), complexUsesAugmentBefore),
137 replaced(path(TOP_FOO_KEY, TreeComplexUsesAugment.class), complexUsesAugmentBefore,
138 complexUsesAugmentAfter));
140 writeTx = getDataBroker().newWriteOnlyTransaction();
141 writeTx.put(CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugmentAfter);
142 assertCommit(writeTx.commit());