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