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.md.sal.binding.impl.test;
10 import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION;
11 import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.TOP_FOO_KEY;
12 import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.USES_ONE_KEY;
13 import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.USES_TWO_KEY;
14 import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.complexUsesAugment;
15 import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.path;
16 import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.top;
17 import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.topLevelList;
19 import com.google.common.collect.ImmutableSet;
21 import org.junit.Test;
22 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
23 import org.opendaylight.controller.md.sal.binding.test.AbstractDataTreeChangeListenerTest;
24 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
25 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugment;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.complex.from.grouping.ListViaUses;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
34 * This testsuite tries to replicate bug 1333 and tests regresion of it
35 * using test-model with similar construction as one reported.
38 * See https://bugs.opendaylight.org/show_bug.cgi?id=1333 for Bug Description
41 public class Bug1333DataChangeListenerTest extends AbstractDataTreeChangeListenerTest {
43 private static final InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier.create(Top.class);
45 private static final InstanceIdentifier<TreeComplexUsesAugment> AUGMENT_WILDCARD =
46 TOP_PATH.child(TopLevelList.class).augmentation(TreeComplexUsesAugment.class);
49 protected Set<YangModuleInfo> getModuleInfos() throws Exception {
50 return ImmutableSet.of(BindingReflections.getModuleInfo(Top.class),
51 BindingReflections.getModuleInfo(TreeComplexUsesAugment.class));
54 private static Top topWithListItem() {
55 return top(topLevelList(TOP_FOO_KEY, complexUsesAugment(USES_ONE_KEY, USES_TWO_KEY)));
58 public Top writeTopWithListItem(final LogicalDatastoreType store) {
59 ReadWriteTransaction tx = getDataBroker().newReadWriteTransaction();
60 Top topItem = topWithListItem();
61 tx.put(store, TOP_PATH, topItem);
62 assertCommit(tx.submit());
66 public void deleteItem(final LogicalDatastoreType store, final InstanceIdentifier<?> path) {
67 ReadWriteTransaction tx = getDataBroker().newReadWriteTransaction();
68 tx.delete(store, path);
69 assertCommit(tx.submit());
73 public void writeTopWithListItemAugmentedListenTopSubtree() {
74 TestListener<Top> listener = createListener(CONFIGURATION, TOP_PATH, added(TOP_PATH, topWithListItem()));
76 writeTopWithListItem(CONFIGURATION);
82 public void writeTopWithListItemAugmentedListenAugmentSubtreeWildcarded() {
83 TestListener<TreeComplexUsesAugment> listener = createListener(CONFIGURATION, AUGMENT_WILDCARD,
84 added(path(TOP_FOO_KEY, TreeComplexUsesAugment.class), complexUsesAugment(USES_ONE_KEY, USES_TWO_KEY)));
86 writeTopWithListItem(CONFIGURATION);
92 public void deleteAugmentChildListenTopSubtree() {
93 Top top = writeTopWithListItem(CONFIGURATION);
95 TestListener<Top> listener = createListener(CONFIGURATION, TOP_PATH, added(TOP_PATH, top),
96 subtreeModified(TOP_PATH, top, top(topLevelList(TOP_FOO_KEY, complexUsesAugment(USES_TWO_KEY)))));
98 InstanceIdentifier<ListViaUses> deletePath = path(TOP_FOO_KEY, USES_ONE_KEY);
99 deleteItem(CONFIGURATION, deletePath);
105 public void deleteAugmentChildListenAugmentSubtreeWildcarded() {
106 writeTopWithListItem(CONFIGURATION);
108 TestListener<TreeComplexUsesAugment> listener = createListener(CONFIGURATION, AUGMENT_WILDCARD,
109 added(path(TOP_FOO_KEY, TreeComplexUsesAugment.class), complexUsesAugment(USES_ONE_KEY, USES_TWO_KEY)),
110 subtreeModified(path(TOP_FOO_KEY, TreeComplexUsesAugment.class),
111 complexUsesAugment(USES_ONE_KEY, USES_TWO_KEY), complexUsesAugment(USES_TWO_KEY)));
113 InstanceIdentifier<?> deletePath = path(TOP_FOO_KEY, USES_ONE_KEY);
114 deleteItem(CONFIGURATION, deletePath);