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