Merge "Re-added config.version to config-module-archetype."
[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 java.util.concurrent.Future;
15
16 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
17 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList;
19 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
21
22 public class WildcardedScopeBaseTest extends DefaultDataChangeListenerTestSuite {
23
24     private static final InstanceIdentifier TOP_LEVEL_LIST_ALL = TOP_LEVEL.node(TopLevelList.QNAME).node(
25             TopLevelList.QNAME);
26
27     @Override
28     protected void customizeTask(final DatastoreTestTask task) {
29         task.changeListener(TOP_LEVEL_LIST_ALL, DataChangeScope.BASE);
30     }
31
32     @Override
33     public void putTopLevelOneNested(final DatastoreTestTask task) throws InterruptedException, ExecutionException {
34
35         AsyncDataChangeEvent<InstanceIdentifier, NormalizedNode<?, ?>> change = task.getChangeEvent().get();
36
37         assertNotNull(change);
38
39         assertNotContains(change.getCreatedData(), TOP_LEVEL);
40         assertContains(change.getCreatedData(), path(FOO), path(FOO, BAR));
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         AsyncDataChangeEvent<InstanceIdentifier, NormalizedNode<?, ?>> change = task.getChangeEvent().get();
52         assertNotNull(change);
53
54         assertContains(change.getCreatedData(), path(FOO, BAZ));
55         assertContains(change.getUpdatedData(), path(FOO));
56         assertNotContains(change.getUpdatedData(), TOP_LEVEL);
57         assertContains(change.getRemovedPaths(), path(FOO, BAR));
58
59     }
60
61     @Override
62     protected void putTopLevelWithTwoNested(final DatastoreTestTask task) throws InterruptedException,
63             ExecutionException {
64
65         AsyncDataChangeEvent<InstanceIdentifier, NormalizedNode<?, ?>> change = task.getChangeEvent().get();
66         assertNotNull(change);
67         assertFalse(change.getCreatedData().isEmpty());
68
69         assertContains(change.getCreatedData(), path(FOO), path(FOO, BAR), path(FOO, BAZ));
70         assertNotContains(change.getCreatedData(), TOP_LEVEL);
71         assertEmpty(change.getUpdatedData());
72         assertEmpty(change.getRemovedPaths());
73
74     }
75
76     @Override
77     protected void twoNestedExistsOneIsDeleted(final DatastoreTestTask task) throws InterruptedException,
78             ExecutionException {
79
80         Future<?> future = task.getChangeEvent();
81         /*
82          * Base listener should be notified only and only if actual node changed its state,
83          * since deletion of child, did not result in change of node we are listening
84          * for, we should not be getting data change event
85          * and this means settable future containing receivedDataChangeEvent is not done.
86          *
87          */
88         assertFalse(future.isDone());
89     }
90
91     @Override
92     public void nestedListExistsRootDeleted(final DatastoreTestTask task) throws InterruptedException,
93             ExecutionException {
94
95         AsyncDataChangeEvent<InstanceIdentifier, NormalizedNode<?, ?>> change = task.getChangeEvent().get();
96
97         assertEmpty(change.getCreatedData());
98         assertEmpty(change.getUpdatedData());
99
100         assertNotContains(change.getUpdatedData(), TOP_LEVEL);
101         assertContains(change.getRemovedPaths(), path(FOO),path(FOO, BAZ),path(FOO,BAR));
102     }
103
104     @Override
105     protected void existingOneNestedWriteAdditionalNested(final DatastoreTestTask task) {
106         Future<?> future = task.getChangeEvent();
107         /*
108          * One listener should be notified only and only if actual node changed its state,
109          * since deletion of nested child (in this case /nested-list/nested-list[foo],
110          * did not result in change of node we are listening
111          * for, we should not be getting data change event
112          * and this means settable future containing receivedDataChangeEvent is not done.
113          *
114          */
115         assertFalse(future.isDone());
116     }
117
118     @Override
119     protected void existingTopWriteTwoNested(final DatastoreTestTask task) throws InterruptedException, ExecutionException {
120         Future<?> future = task.getChangeEvent();
121         /*
122          * One listener should be notified only and only if actual node changed its state,
123          * since deletion of nested child (in this case /nested-list/nested-list[foo],
124          * did not result in change of node we are listening
125          * for, we should not be getting data change event
126          * and this means settable future containing receivedDataChangeEvent is not done.
127          *
128          */
129         assertFalse(future.isDone());
130     }
131
132     @Override
133     protected void existingTopWriteSibling(final DatastoreTestTask task) throws InterruptedException, ExecutionException {
134         AsyncDataChangeEvent<InstanceIdentifier, NormalizedNode<?, ?>> change = task.getChangeEvent().get();
135
136         assertContains(change.getCreatedData(), path(FOO_SIBLING));
137         assertNotContains(change.getUpdatedData(), path(FOO), TOP_LEVEL);
138         assertEmpty(change.getRemovedPaths());
139     }
140 }