Correct ActionProviderService method definition
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / test / java / org / opendaylight / mdsal / binding / dom / adapter / Bug1333DataChangeListenerTest.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.mdsal.binding.dom.adapter;
9
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.USES_ONE_KEY;
12 import static org.opendaylight.mdsal.binding.test.model.util.ListsBindingUtils.USES_TWO_KEY;
13 import static org.opendaylight.mdsal.binding.test.model.util.ListsBindingUtils.complexUsesAugment;
14 import static org.opendaylight.mdsal.binding.test.model.util.ListsBindingUtils.path;
15 import static org.opendaylight.mdsal.binding.test.model.util.ListsBindingUtils.top;
16 import static org.opendaylight.mdsal.binding.test.model.util.ListsBindingUtils.topLevelList;
17 import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION;
18
19 import com.google.common.collect.ImmutableSet;
20 import java.util.Set;
21 import org.junit.Test;
22 import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
23 import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractDataTreeChangeListenerTest;
24 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
25 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TreeComplexUsesAugment;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.complex.from.grouping.ListViaUses;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
32
33 /**
34  * This testsuite tries to replicate bug 1333 and tests regresion of it  using test-model with similar construction as
35  * one reported.
36  *
37  * <p>
38  * See  https://bugs.opendaylight.org/show_bug.cgi?id=1333 for Bug Description
39  */
40 public class Bug1333DataChangeListenerTest extends AbstractDataTreeChangeListenerTest {
41     private static final InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier.create(Top.class);
42     private static final InstanceIdentifier<TreeComplexUsesAugment> AUGMENT_WILDCARD =
43             TOP_PATH.child(TopLevelList.class).augmentation(TreeComplexUsesAugment.class);
44
45     @Override
46     protected Set<YangModuleInfo> getModuleInfos() throws Exception {
47         return ImmutableSet.of(BindingReflections.getModuleInfo(Top.class),
48                 BindingReflections.getModuleInfo(TreeComplexUsesAugment.class));
49     }
50
51     private static Top topWithListItem() {
52         return top(topLevelList(TOP_FOO_KEY, complexUsesAugment(USES_ONE_KEY, USES_TWO_KEY)));
53     }
54
55     public Top writeTopWithListItem(final LogicalDatastoreType store) {
56         ReadWriteTransaction tx = getDataBroker().newReadWriteTransaction();
57         Top topItem = topWithListItem();
58         tx.put(store, TOP_PATH, topItem);
59         assertCommit(tx.commit());
60         return topItem;
61     }
62
63     public void deleteItem(final LogicalDatastoreType store, final InstanceIdentifier<?> path) {
64         ReadWriteTransaction tx = getDataBroker().newReadWriteTransaction();
65         tx.delete(store, path);
66         assertCommit(tx.commit());
67     }
68
69     @Test
70     public void writeTopWithListItemAugmentedListenTopSubtree() {
71         TestListener<Top> listener = createListener(CONFIGURATION, TOP_PATH, added(TOP_PATH, topWithListItem()));
72
73         writeTopWithListItem(CONFIGURATION);
74
75         listener.verify();
76     }
77
78     @Test
79     public void writeTopWithListItemAugmentedListenAugmentSubtreeWildcarded() {
80         TestListener<TreeComplexUsesAugment> listener = createListener(CONFIGURATION, AUGMENT_WILDCARD,
81                 added(path(TOP_FOO_KEY, TreeComplexUsesAugment.class), complexUsesAugment(USES_ONE_KEY, USES_TWO_KEY)));
82
83         writeTopWithListItem(CONFIGURATION);
84
85         listener.verify();
86     }
87
88     @Test
89     public void deleteAugmentChildListenTopSubtree() {
90         Top top = writeTopWithListItem(CONFIGURATION);
91
92         TestListener<Top> listener = createListener(CONFIGURATION, TOP_PATH, added(TOP_PATH, top),
93                 subtreeModified(TOP_PATH, top, top(topLevelList(TOP_FOO_KEY, complexUsesAugment(USES_TWO_KEY)))));
94
95         InstanceIdentifier<ListViaUses> deletePath = path(TOP_FOO_KEY, USES_ONE_KEY);
96         deleteItem(CONFIGURATION, deletePath);
97
98         listener.verify();
99     }
100
101     @Test
102     public void deleteAugmentChildListenAugmentSubtreeWildcarded() {
103         writeTopWithListItem(CONFIGURATION);
104
105         TestListener<TreeComplexUsesAugment> listener = createListener(CONFIGURATION, AUGMENT_WILDCARD,
106                 added(path(TOP_FOO_KEY, TreeComplexUsesAugment.class), complexUsesAugment(USES_ONE_KEY, USES_TWO_KEY)),
107                 subtreeModified(path(TOP_FOO_KEY, TreeComplexUsesAugment.class),
108                     complexUsesAugment(USES_ONE_KEY, USES_TWO_KEY), complexUsesAugment(USES_TWO_KEY)));
109
110         InstanceIdentifier<?> deletePath = path(TOP_FOO_KEY, USES_ONE_KEY);
111         deleteItem(CONFIGURATION, deletePath);
112
113         listener.verify();
114     }
115 }