2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.md.sal.dom.store.impl;
10 import static org.junit.Assert.assertFalse;
11 import static org.junit.Assert.assertNotNull;
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.yangtools.yang.data.api.YangInstanceIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19 public class WildcardedScopeBaseTest extends DefaultDataChangeListenerTestSuite {
21 private static final YangInstanceIdentifier TOP_LEVEL_LIST_ALL = TOP_LEVEL.node(TopLevelList.QNAME).node(
25 protected void customizeTask(final DatastoreTestTask task) {
26 task.changeListener(TOP_LEVEL_LIST_ALL, DataChangeScope.BASE);
30 public void putTopLevelOneNested(final DatastoreTestTask task) throws Exception {
32 AsyncDataChangeEvent<YangInstanceIdentifier, NormalizedNode<?, ?>> change = task.getChangeEvent();
34 assertNotNull(change);
37 * Created data must not contain nested-list item, since that is two-level deep.
39 assertNotContains(change.getCreatedData(), TOP_LEVEL,path(FOO, BAR));
40 assertContains(change.getCreatedData(), path(FOO));
42 assertEmpty(change.getUpdatedData());
43 assertEmpty(change.getRemovedPaths());
48 public void replaceTopLevelNestedChanged(final DatastoreTestTask task) throws Exception {
50 AsyncDataChangeEvent<YangInstanceIdentifier, NormalizedNode<?, ?>> change = task.getChangeEvent();
51 assertNotNull(change);
53 * Created data must NOT contain nested-list item since scope is base, and change is two
56 assertNotContains(change.getCreatedData(), path(FOO, BAZ));
57 assertContains(change.getUpdatedData(), path(FOO));
58 assertNotContains(change.getUpdatedData(), TOP_LEVEL);
60 * Removed data must NOT contain nested-list item since scope is base, and change is two
63 assertNotContains(change.getRemovedPaths(), path(FOO, BAR));
68 protected void putTopLevelWithTwoNested(final DatastoreTestTask task) throws Exception {
70 AsyncDataChangeEvent<YangInstanceIdentifier, NormalizedNode<?, ?>> change = task.getChangeEvent();
71 assertNotNull(change);
72 assertFalse(change.getCreatedData().isEmpty());
74 // Base event should contain only changed item, no details about child.
75 assertContains(change.getCreatedData(), path(FOO));
76 assertNotContains(change.getCreatedData(), TOP_LEVEL,path(FOO, BAR), path(FOO, BAZ));
77 assertEmpty(change.getUpdatedData());
78 assertEmpty(change.getRemovedPaths());
83 protected void twoNestedExistsOneIsDeleted(final DatastoreTestTask task) throws Exception {
86 * Base listener should be notified only and only if actual node changed its state,
87 * since deletion of child, did not result in change of node we are listening
88 * for, we should not be getting data change event
89 * and this means settable future containing receivedDataChangeEvent is not done.
92 task.verifyNoChangeEvent();
96 public void nestedListExistsRootDeleted(final DatastoreTestTask task) throws Exception {
98 AsyncDataChangeEvent<YangInstanceIdentifier, NormalizedNode<?, ?>> change = task.getChangeEvent();
100 assertEmpty(change.getCreatedData());
101 assertEmpty(change.getUpdatedData());
103 assertNotContains(change.getUpdatedData(), TOP_LEVEL);
105 * Scope base listener event should contain top-level-list item and nested list path
106 * and should not contain baz, bar which are two-level deep
108 assertContains(change.getRemovedPaths(), path(FOO));
109 assertNotContains(change.getRemovedPaths(),path(FOO, BAZ),path(FOO,BAR));
113 protected void existingOneNestedWriteAdditionalNested(final DatastoreTestTask task) throws Exception {
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.
122 task.verifyNoChangeEvent();
126 protected void existingTopWriteTwoNested(final DatastoreTestTask task) throws Exception {
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.
135 task.verifyNoChangeEvent();
139 protected void existingTopWriteSibling(final DatastoreTestTask task) throws Exception {
140 AsyncDataChangeEvent<YangInstanceIdentifier, NormalizedNode<?, ?>> change = task.getChangeEvent();
142 assertContains(change.getCreatedData(), path(FOO_SIBLING));
143 assertNotContains(change.getUpdatedData(), path(FOO), TOP_LEVEL);
144 assertEmpty(change.getRemovedPaths());