BUG-1493: split off recursion tracking and rework it
[controller.git] / opendaylight / md-sal / sal-inmemory-datastore / src / test / java / org / opendaylight / controller / md / sal / dom / store / impl / WildcardedScopeBaseTest.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.dom.store.impl;
9
10 import static org.junit.Assert.assertFalse;
11 import static org.junit.Assert.assertNotNull;
12
13 import java.util.concurrent.ExecutionException;
14 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
15 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19
20 public class WildcardedScopeBaseTest extends DefaultDataChangeListenerTestSuite {
21
22     private static final YangInstanceIdentifier TOP_LEVEL_LIST_ALL = TOP_LEVEL.node(TopLevelList.QNAME).node(
23             TopLevelList.QNAME);
24
25     @Override
26     protected void customizeTask(final DatastoreTestTask task) {
27         task.changeListener(TOP_LEVEL_LIST_ALL, DataChangeScope.BASE);
28     }
29
30     @Override
31     public void putTopLevelOneNested(final DatastoreTestTask task) throws InterruptedException, ExecutionException {
32
33         AsyncDataChangeEvent<YangInstanceIdentifier, NormalizedNode<?, ?>> change = task.getChangeEvent();
34
35         assertNotNull(change);
36
37         /*
38          * Created data must not contain nested-list item, since that is two-level deep.
39          */
40         assertNotContains(change.getCreatedData(), TOP_LEVEL,path(FOO, BAR));
41         assertContains(change.getCreatedData(), path(FOO) );
42
43         assertEmpty(change.getUpdatedData());
44         assertEmpty(change.getRemovedPaths());
45
46     }
47
48     @Override
49     public void replaceTopLevelNestedChanged(final DatastoreTestTask task) throws InterruptedException,
50             ExecutionException {
51
52         AsyncDataChangeEvent<YangInstanceIdentifier, NormalizedNode<?, ?>> change = task.getChangeEvent();
53         assertNotNull(change);
54         /*
55          * Created data must NOT contain nested-list item since scope is base, and change is two
56          * level deep.
57          */
58         assertNotContains(change.getCreatedData(), path(FOO, BAZ));
59         assertContains(change.getUpdatedData(), path(FOO));
60         assertNotContains(change.getUpdatedData(), TOP_LEVEL);
61         /*
62          * Removed data must NOT contain nested-list item since scope is base, and change is two
63          * level deep.
64          */
65         assertNotContains(change.getRemovedPaths(), path(FOO, BAR));
66
67     }
68
69     @Override
70     protected void putTopLevelWithTwoNested(final DatastoreTestTask task) throws InterruptedException,
71             ExecutionException {
72
73         AsyncDataChangeEvent<YangInstanceIdentifier, NormalizedNode<?, ?>> change = task.getChangeEvent();
74         assertNotNull(change);
75         assertFalse(change.getCreatedData().isEmpty());
76
77         // Base event should contain only changed item, no details about child.
78         assertContains(change.getCreatedData(), path(FOO));
79         assertNotContains(change.getCreatedData(), TOP_LEVEL,path(FOO, BAR), path(FOO, BAZ));
80         assertEmpty(change.getUpdatedData());
81         assertEmpty(change.getRemovedPaths());
82
83     }
84
85     @Override
86     protected void twoNestedExistsOneIsDeleted(final DatastoreTestTask task) throws InterruptedException,
87             ExecutionException {
88
89         /*
90          * Base listener should be notified only and only if actual node changed its state,
91          * since deletion of child, did not result in change of node we are listening
92          * for, we should not be getting data change event
93          * and this means settable future containing receivedDataChangeEvent is not done.
94          *
95          */
96         task.verifyNoChangeEvent();
97     }
98
99     @Override
100     public void nestedListExistsRootDeleted(final DatastoreTestTask task) throws InterruptedException,
101             ExecutionException {
102
103         AsyncDataChangeEvent<YangInstanceIdentifier, NormalizedNode<?, ?>> change = task.getChangeEvent();
104
105         assertEmpty(change.getCreatedData());
106         assertEmpty(change.getUpdatedData());
107
108         assertNotContains(change.getUpdatedData(), TOP_LEVEL);
109         /*
110          *  Scope base listener event should contain top-level-list item and nested list path
111          *  and should not contain baz, bar which are two-level deep
112          */
113         assertContains(change.getRemovedPaths(), path(FOO));
114         assertNotContains(change.getRemovedPaths(),path(FOO, BAZ),path(FOO,BAR));
115     }
116
117     @Override
118     protected void existingOneNestedWriteAdditionalNested(final DatastoreTestTask task) {
119         /*
120          * One listener should be notified only and only if actual node changed its state,
121          * since deletion of nested child (in this case /nested-list/nested-list[foo],
122          * did not result in change of node we are listening
123          * for, we should not be getting data change event
124          * and this means settable future containing receivedDataChangeEvent is not done.
125          *
126          */
127         task.verifyNoChangeEvent();
128     }
129
130     @Override
131     protected void existingTopWriteTwoNested(final DatastoreTestTask task) throws InterruptedException, ExecutionException {
132         /*
133          * One listener should be notified only and only if actual node changed its state,
134          * since deletion of nested child (in this case /nested-list/nested-list[foo],
135          * did not result in change of node we are listening
136          * for, we should not be getting data change event
137          * and this means settable future containing receivedDataChangeEvent is not done.
138          *
139          */
140         task.verifyNoChangeEvent();
141     }
142
143     @Override
144     protected void existingTopWriteSibling(final DatastoreTestTask task) throws InterruptedException, ExecutionException {
145         AsyncDataChangeEvent<YangInstanceIdentifier, NormalizedNode<?, ?>> change = task.getChangeEvent();
146
147         assertContains(change.getCreatedData(), path(FOO_SIBLING));
148         assertNotContains(change.getUpdatedData(), path(FOO), TOP_LEVEL);
149         assertEmpty(change.getRemovedPaths());
150     }
151 }

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