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;
19 import org.junit.Test;
20 import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractDataTreeChangeListenerTest;
21 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TreeComplexUsesAugment;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TreeLeafOnlyUsesAugment;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.complex.from.grouping.ListViaUsesKey;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelListKey;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
31 public class Bug1418AugmentationTest extends AbstractDataTreeChangeListenerTest {
32 private static final InstanceIdentifier<Top> TOP = InstanceIdentifier.create(Top.class);
33 private static final InstanceIdentifier<TopLevelList> TOP_FOO = TOP.child(TopLevelList.class, TOP_FOO_KEY);
34 private static final InstanceIdentifier<TreeLeafOnlyUsesAugment> SIMPLE_AUGMENT =
35 TOP.child(TopLevelList.class, TOP_FOO_KEY).augmentation(TreeLeafOnlyUsesAugment.class);
36 private static final InstanceIdentifier<TreeComplexUsesAugment> COMPLEX_AUGMENT =
37 TOP.child(TopLevelList.class, TOP_FOO_KEY).augmentation(TreeComplexUsesAugment.class);
38 private static final ListViaUsesKey LIST_VIA_USES_KEY =
39 new ListViaUsesKey("list key");
40 private static final ListViaUsesKey LIST_VIA_USES_KEY_MOD =
41 new ListViaUsesKey("list key modified");
44 protected Set<YangModuleInfo> getModuleInfos() {
45 return Set.of(BindingReflections.getModuleInfo(Top.class),
46 BindingReflections.getModuleInfo(TreeComplexUsesAugment.class));
50 public void leafOnlyAugmentationCreatedTest() {
51 final var leafOnlyUsesAugment = leafOnlyUsesAugment("test leaf");
52 try (var collector = createCollector(CONFIGURATION, SIMPLE_AUGMENT)) {
53 final var writeTx = getDataBroker().newWriteOnlyTransaction();
54 writeTx.put(CONFIGURATION, TOP, top());
55 writeTx.put(CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
56 writeTx.put(CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugment);
57 assertCommit(writeTx.commit());
59 collector.assertModifications(added(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugment));
64 public void leafOnlyAugmentationUpdatedTest() {
65 var writeTx = getDataBroker().newWriteOnlyTransaction();
66 writeTx.put(CONFIGURATION, TOP, top());
67 writeTx.put(CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
68 final var leafOnlyUsesAugmentBefore = leafOnlyUsesAugment("test leaf");
69 writeTx.put(CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugmentBefore);
70 assertCommit(writeTx.commit());
72 final var leafOnlyUsesAugmentAfter = leafOnlyUsesAugment("test leaf changed");
73 try (var collector = createCollector(CONFIGURATION, SIMPLE_AUGMENT)) {
74 writeTx = getDataBroker().newWriteOnlyTransaction();
75 writeTx.put(CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugmentAfter);
76 assertCommit(writeTx.commit());
78 collector.assertModifications(
79 added(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugmentBefore),
80 replaced(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugmentBefore,
81 leafOnlyUsesAugmentAfter));
86 public void leafOnlyAugmentationDeletedTest() {
87 var writeTx = getDataBroker().newWriteOnlyTransaction();
88 writeTx.put(CONFIGURATION, TOP, top());
89 writeTx.put(CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
90 final var leafOnlyUsesAugment = leafOnlyUsesAugment("test leaf");
91 writeTx.put(CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugment);
92 assertCommit(writeTx.commit());
94 try (var collector = createCollector(CONFIGURATION, SIMPLE_AUGMENT)) {
95 writeTx = getDataBroker().newWriteOnlyTransaction();
96 writeTx.delete(CONFIGURATION, SIMPLE_AUGMENT);
97 assertCommit(writeTx.commit());
99 collector.assertModifications(
100 added(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugment),
101 deleted(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugment));
106 public void complexAugmentationCreatedTest() {
107 try (var collector = createCollector(CONFIGURATION, COMPLEX_AUGMENT)) {
108 final var complexUsesAugment = complexUsesAugment(LIST_VIA_USES_KEY);
109 final var writeTx = getDataBroker().newWriteOnlyTransaction();
110 writeTx.put(CONFIGURATION, TOP, top());
111 writeTx.put(CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
112 writeTx.put(CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugment);
113 assertCommit(writeTx.commit());
115 collector.assertModifications(added(path(TOP_FOO_KEY, TreeComplexUsesAugment.class), complexUsesAugment));
120 public void complexAugmentationUpdatedTest() {
121 var writeTx = getDataBroker().newWriteOnlyTransaction();
122 writeTx.put(CONFIGURATION, TOP, top());
123 writeTx.put(CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
124 final var complexUsesAugmentBefore = complexUsesAugment(LIST_VIA_USES_KEY);
125 writeTx.put(CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugmentBefore);
126 assertCommit(writeTx.commit());
128 try (var collector = createCollector(CONFIGURATION, COMPLEX_AUGMENT)) {
129 final var complexUsesAugmentAfter = complexUsesAugment(LIST_VIA_USES_KEY_MOD);
130 writeTx = getDataBroker().newWriteOnlyTransaction();
131 writeTx.put(CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugmentAfter);
132 assertCommit(writeTx.commit());
134 collector.assertModifications(
135 added(path(TOP_FOO_KEY, TreeComplexUsesAugment.class), complexUsesAugmentBefore),
136 // While we are overwriting the augment, at the transaction ends up replacing one child with another,
137 // so the Augmentation ends up not being overwritten, but modified
138 subtreeModified(path(TOP_FOO_KEY, TreeComplexUsesAugment.class), complexUsesAugmentBefore,
139 complexUsesAugmentAfter));