Cache reflection operations in AbstractSchemaAwareTest
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / test / java / org / opendaylight / controller / md / sal / binding / impl / test / 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.controller.md.sal.binding.impl.test;
9
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;
18
19 import com.google.common.collect.ImmutableSet;
20 import java.util.Set;
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;
32
33 /**
34  * This testsuite tries to replicate bug 1333 and tests regresion of it
35  * using test-model with similar construction as 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
42     private static final InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier.create(Top.class);
43
44     private static final InstanceIdentifier<TreeComplexUsesAugment> AUGMENT_WILDCARD =
45             TOP_PATH.child(TopLevelList.class).augmentation(TreeComplexUsesAugment.class);
46
47     @Override
48     protected Set<YangModuleInfo> getModuleInfos() throws Exception {
49         return ImmutableSet.of(BindingReflections.getModuleInfo(Top.class),
50                 BindingReflections.getModuleInfo(TreeComplexUsesAugment.class));
51     }
52
53     private Top topWithListItem() {
54         return top(topLevelList(TOP_FOO_KEY, complexUsesAugment(USES_ONE_KEY, USES_TWO_KEY)));
55     }
56
57     public Top writeTopWithListItem(final LogicalDatastoreType store) {
58         ReadWriteTransaction tx = getDataBroker().newReadWriteTransaction();
59         Top topItem = topWithListItem();
60         tx.put(store, TOP_PATH, topItem);
61         assertCommit(tx.submit());
62         return topItem;
63     }
64
65     public void deleteItem(final LogicalDatastoreType store, final InstanceIdentifier<?> path) {
66         ReadWriteTransaction tx = getDataBroker().newReadWriteTransaction();
67         tx.delete(store, path);
68         assertCommit(tx.submit());
69     }
70
71     @Test
72     public void writeTopWithListItemAugmentedListenTopSubtree() {
73         TestListener<Top> listener = createListener(CONFIGURATION, TOP_PATH, added(TOP_PATH, topWithListItem()));
74
75         writeTopWithListItem(CONFIGURATION);
76
77         listener.verify();
78     }
79
80     @Test
81     public void writeTopWithListItemAugmentedListenAugmentSubtreeWildcarded() {
82         TestListener<TreeComplexUsesAugment> listener = createListener(CONFIGURATION, AUGMENT_WILDCARD,
83                 added(path(TOP_FOO_KEY, TreeComplexUsesAugment.class), complexUsesAugment(USES_ONE_KEY, USES_TWO_KEY)));
84
85         writeTopWithListItem(CONFIGURATION);
86
87         listener.verify();
88     }
89
90     @Test
91     public void deleteAugmentChildListenTopSubtree() {
92         Top top = writeTopWithListItem(CONFIGURATION);
93
94         TestListener<Top> listener = createListener(CONFIGURATION, TOP_PATH, added(TOP_PATH, top),
95                 subtreeModified(TOP_PATH, top, top(topLevelList(TOP_FOO_KEY, complexUsesAugment(USES_TWO_KEY)))));
96
97         InstanceIdentifier<ListViaUses> deletePath = path(TOP_FOO_KEY, USES_ONE_KEY);
98         deleteItem(CONFIGURATION, deletePath);
99
100         listener.verify();
101     }
102
103     @Test
104     public void deleteAugmentChildListenAugmentSubtreeWildcarded() {
105         writeTopWithListItem(CONFIGURATION);
106
107         TestListener<TreeComplexUsesAugment> listener = createListener(CONFIGURATION, AUGMENT_WILDCARD,
108                 added(path(TOP_FOO_KEY, TreeComplexUsesAugment.class), complexUsesAugment(USES_ONE_KEY, USES_TWO_KEY)),
109                 subtreeModified(path(TOP_FOO_KEY, TreeComplexUsesAugment.class),
110                     complexUsesAugment(USES_ONE_KEY, USES_TWO_KEY), complexUsesAugment(USES_TWO_KEY)));
111
112         InstanceIdentifier<?> deletePath = path(TOP_FOO_KEY, USES_ONE_KEY);
113         deleteItem(CONFIGURATION, deletePath);
114
115         listener.verify();
116     }
117 }

©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.