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

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