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 / WildcardedScopeSubtreeTest.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 import static org.junit.Assert.assertTrue;
13
14 import java.util.concurrent.ExecutionException;
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 WildcardedScopeSubtreeTest 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.SUBTREE);
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         assertNotContains(change.getCreatedData(), TOP_LEVEL);
38         assertContains(change.getCreatedData(), path(FOO), path(FOO, BAR));
39         assertEmpty(change.getUpdatedData());
40         assertEmpty(change.getRemovedPaths());
41
42     }
43
44     @Override
45     public void replaceTopLevelNestedChanged(final DatastoreTestTask task) throws InterruptedException,
46             ExecutionException {
47
48         AsyncDataChangeEvent<InstanceIdentifier, NormalizedNode<?, ?>> change = task.getChangeEvent().get();
49         assertNotNull(change);
50
51         assertContains(change.getCreatedData(), path(FOO, BAZ));
52         assertContains(change.getUpdatedData(), path(FOO));
53         assertNotContains(change.getUpdatedData(), TOP_LEVEL);
54         assertContains(change.getRemovedPaths(), path(FOO, BAR));
55
56     }
57
58     @Override
59     protected void putTopLevelWithTwoNested(final DatastoreTestTask task) throws InterruptedException,
60             ExecutionException {
61
62         AsyncDataChangeEvent<InstanceIdentifier, NormalizedNode<?, ?>> change = task.getChangeEvent().get();
63         assertNotNull(change);
64         assertFalse(change.getCreatedData().isEmpty());
65
66         assertContains(change.getCreatedData(), path(FOO), path(FOO, BAR), path(FOO, BAZ));
67         assertNotContains(change.getCreatedData(), TOP_LEVEL);
68         assertEmpty(change.getUpdatedData());
69         assertEmpty(change.getRemovedPaths());
70
71     }
72
73     @Override
74     protected void twoNestedExistsOneIsDeleted(final DatastoreTestTask task) throws InterruptedException,
75             ExecutionException {
76
77         AsyncDataChangeEvent<InstanceIdentifier, NormalizedNode<?, ?>> change = task.getChangeEvent().get();
78         assertNotNull(change);
79         assertTrue(change.getCreatedData().isEmpty());
80         assertContains(change.getUpdatedData(), path(FOO));
81         assertNotContains(change.getUpdatedData(), TOP_LEVEL);
82         assertContains(change.getRemovedPaths(),path(FOO, BAZ));
83     }
84
85     @Override
86     public void nestedListExistsRootDeleted(final DatastoreTestTask task) throws InterruptedException,
87             ExecutionException {
88
89         AsyncDataChangeEvent<InstanceIdentifier, NormalizedNode<?, ?>> change = task.getChangeEvent().get();
90
91         assertEmpty(change.getCreatedData());
92         assertEmpty(change.getUpdatedData());
93
94         assertNotContains(change.getUpdatedData(), TOP_LEVEL);
95         assertContains(change.getRemovedPaths(), path(FOO),path(FOO, BAZ),path(FOO,BAR));
96     }
97
98     @Override
99     protected void existingOneNestedWriteAdditionalNested(final DatastoreTestTask task) throws InterruptedException, ExecutionException {
100         AsyncDataChangeEvent<InstanceIdentifier, NormalizedNode<?, ?>> change = task.getChangeEvent().get();
101
102         assertContains(change.getCreatedData(), path(FOO,BAZ));
103         assertNotContains(change.getCreatedData(), path(FOO,BAR));
104         assertContains(change.getUpdatedData(), path(FOO));
105         assertNotContains(change.getUpdatedData(), TOP_LEVEL);
106         assertEmpty(change.getRemovedPaths());
107     }
108
109     @Override
110     protected void existingTopWriteTwoNested(final DatastoreTestTask task) throws InterruptedException, ExecutionException {
111         AsyncDataChangeEvent<InstanceIdentifier, NormalizedNode<?, ?>> change = task.getChangeEvent().get();
112
113         assertContains(change.getCreatedData(), path(FOO,BAR),path(FOO,BAZ));
114         assertContains(change.getUpdatedData(), path(FOO));
115         assertNotContains(change.getUpdatedData(), TOP_LEVEL, path(FOO,BAR));
116         assertEmpty(change.getRemovedPaths());
117     }
118
119     @Override
120     protected void existingTopWriteSibling(final DatastoreTestTask task) throws InterruptedException, ExecutionException {
121         AsyncDataChangeEvent<InstanceIdentifier, NormalizedNode<?, ?>> change = task.getChangeEvent().get();
122
123         assertContains(change.getCreatedData(), path(FOO_SIBLING));
124         assertNotContains(change.getUpdatedData(), path(FOO), TOP_LEVEL);
125         assertEmpty(change.getRemovedPaths());
126     }
127 }

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