02797c27610c88a0c411f6674f4d5abda16256f2
[controller.git] / opendaylight / md-sal / sal-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.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
14 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.top.level.list.NestedList;
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(TopLevelList.QNAME).node(
23             TopLevelList.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 Exception {
32
33         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(NestedList.QNAME));
39
40         assertEmpty(change.getUpdatedData());
41         assertEmpty(change.getRemovedPaths());
42
43     }
44
45     @Override
46     public void replaceTopLevelNestedChanged(final DatastoreTestTask task) throws Exception {
47
48         AsyncDataChangeEvent<YangInstanceIdentifier, NormalizedNode<?, ?>> change = task.getChangeEvent();
49         assertNotNull(change);
50         /*
51          * Created data must NOT contain nested-list item since scope is base, and change is two
52          * level deep.
53          */
54         assertNotContains(change.getCreatedData(), path(FOO, BAZ));
55         assertContains(change.getUpdatedData(), path(FOO),path(FOO).node(NestedList.QNAME));
56         assertNotContains(change.getUpdatedData(), TOP_LEVEL);
57         /*
58          * Removed data must NOT contain nested-list item since scope is base, and change is two
59          * level deep.
60          */
61         assertNotContains(change.getRemovedPaths(), path(FOO, BAR));
62
63     }
64
65     @Override
66     protected void putTopLevelWithTwoNested(final DatastoreTestTask task) throws Exception {
67
68         AsyncDataChangeEvent<YangInstanceIdentifier, NormalizedNode<?, ?>> change = task.getChangeEvent();
69         assertNotNull(change);
70         assertFalse(change.getCreatedData().isEmpty());
71
72         // Base event should contain only changed item, and details about immediate child.
73         assertContains(change.getCreatedData(), path(FOO),path(FOO).node(NestedList.QNAME));
74         assertNotContains(change.getCreatedData(), TOP_LEVEL,path(FOO, BAR), path(FOO, BAZ));
75         assertEmpty(change.getUpdatedData());
76         assertEmpty(change.getRemovedPaths());
77
78     }
79
80     @Override
81     protected void twoNestedExistsOneIsDeleted(final DatastoreTestTask task) throws Exception {
82
83         /*
84          * One listener should be notified only and only if actual node changed its state,
85          * since deletion of nested child (in this case /nested-list/nested-list[foo],
86          * did not result in change of node we are listening
87          * for, we should not be getting data change event
88          * and this means settable future containing receivedDataChangeEvent is not done.
89          *
90          */
91         task.verifyNoChangeEvent();
92     }
93
94     @Override
95     public void nestedListExistsRootDeleted(final DatastoreTestTask task) throws Exception {
96
97         AsyncDataChangeEvent<YangInstanceIdentifier, NormalizedNode<?, ?>> change = task.getChangeEvent();
98
99         assertEmpty(change.getCreatedData());
100         assertEmpty(change.getUpdatedData());
101
102         assertNotContains(change.getUpdatedData(), TOP_LEVEL);
103         assertContains(change.getRemovedPaths(), path(FOO),path(FOO).node(NestedList.QNAME));
104         assertNotContains(change.getRemovedPaths(), path(FOO, BAZ),path(FOO,BAR));
105     }
106
107     @Override
108     protected void existingOneNestedWriteAdditionalNested(final DatastoreTestTask task) throws Exception {
109         /*
110          * One listener should be notified only and only if actual node changed its state,
111          * since deletion of nested child (in this case /nested-list/nested-list[foo],
112          * did not result in change of node we are listening
113          * for, we should not be getting data change event
114          * and this means settable future containing receivedDataChangeEvent is not done.
115          *
116          */
117         task.verifyNoChangeEvent();
118     }
119
120     @Override
121     protected void existingTopWriteTwoNested(final DatastoreTestTask task) throws Exception {
122         /*
123          * One listener should be notified only and only if actual node changed its state,
124          * since deletion of nested child (in this case /nested-list/nested-list[foo],
125          * did not result in change of node we are listening
126          * for, we should not be getting data change event
127          * and this means settable future containing receivedDataChangeEvent is not done.
128          *
129          */
130         task.verifyNoChangeEvent();
131     }
132
133     @Override
134     protected void existingTopWriteSibling(final DatastoreTestTask task) throws Exception {
135         AsyncDataChangeEvent<YangInstanceIdentifier, NormalizedNode<?, ?>> change = task.getChangeEvent();
136
137         assertContains(change.getCreatedData(), path(FOO_SIBLING));
138         assertNotContains(change.getUpdatedData(),path(FOO), TOP_LEVEL);
139         assertEmpty(change.getRemovedPaths());
140     }
141 }