Merge "Bug 1224, Bug 1221: Added Test case scenarios for Data Change Events."
[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 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 WildcardedScopeOneTest 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.ONE);
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          * One listener should be notified only and only if actual node changed its state,
83          * since deletion of nested child (in this case /nested-list/nested-list[foo],
84          * did not result in change of node we are listening
85          * for, we should not be getting data change event
86          * and this means settable future containing receivedDataChangeEvent is not done.
87          *
88          */
89         assertFalse(future.isDone());
90     }
91
92     @Override
93     public void nestedListExistsRootDeleted(final DatastoreTestTask task) throws InterruptedException,
94             ExecutionException {
95
96         AsyncDataChangeEvent<InstanceIdentifier, NormalizedNode<?, ?>> change = task.getChangeEvent().get();
97
98         assertEmpty(change.getCreatedData());
99         assertEmpty(change.getUpdatedData());
100
101         assertNotContains(change.getUpdatedData(), TOP_LEVEL);
102         assertContains(change.getRemovedPaths(), path(FOO),path(FOO, BAZ),path(FOO,BAR));
103     }
104
105     @Override
106     protected void existingOneNestedWriteAdditionalNested(final DatastoreTestTask task) {
107         Future<?> future = task.getChangeEvent();
108         /*
109          * One listener should be notified only and only if actual node changed its state,
110          * since deletion of nested child (in this case /nested-list/nested-list[foo],
111          * did not result in change of node we are listening
112          * for, we should not be getting data change event
113          * and this means settable future containing receivedDataChangeEvent is not done.
114          *
115          */
116         assertFalse(future.isDone());
117     }
118
119     @Override
120     protected void existingTopWriteTwoNested(final DatastoreTestTask task) throws InterruptedException, ExecutionException {
121         Future<?> future = task.getChangeEvent();
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         assertFalse(future.isDone());
131     }
132
133     @Override
134     protected void existingTopWriteSibling(final DatastoreTestTask task) throws InterruptedException, ExecutionException {
135         AsyncDataChangeEvent<InstanceIdentifier, NormalizedNode<?, ?>> change = task.getChangeEvent().get();
136
137         assertContains(change.getCreatedData(), path(FOO_SIBLING));
138         assertNotContains(change.getUpdatedData(),path(FOO), TOP_LEVEL);
139         assertEmpty(change.getRemovedPaths());
140     }
141 }

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