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