2 * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.yangtools.yang.data.impl.schema.tree;
10 import static junit.framework.TestCase.assertFalse;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
13 import static org.junit.Assert.fail;
15 import com.google.common.collect.ImmutableMap;
16 import java.util.HashMap;
18 import java.util.Optional;
19 import org.junit.AfterClass;
20 import org.junit.Before;
21 import org.junit.BeforeClass;
22 import org.junit.Test;
23 import org.opendaylight.yangtools.util.UnmodifiableCollection;
24 import org.opendaylight.yangtools.yang.common.QName;
25 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
26 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
27 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
28 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
29 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
30 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
31 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
32 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
33 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
34 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
35 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
36 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
37 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
38 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
39 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
40 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
41 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
42 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
43 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
44 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetEntryNodeBuilder;
45 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder;
46 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder;
47 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
48 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
50 public class Bug4454Test {
52 private static final QName MASTER_CONTAINER_QNAME = QName
53 .create("urn:opendaylight:params:xml:ns:yang:list-constraints-validation-test-model", "2015-02-02",
55 private static final QName MIN_MAX_LIST_QNAME = QName.create(MASTER_CONTAINER_QNAME, "min-max-list");
56 private static final QName MIN_MAX_LEAF_LIST_QNAME = QName.create(MASTER_CONTAINER_QNAME, "min-max-leaf-list");
57 private static final QName MIN_MAX_LIST_QNAME_NO_MINMAX = QName
58 .create(MASTER_CONTAINER_QNAME, "min-max-list-no-minmax");
59 private static final QName MIN_MAX_KEY_LEAF_QNAME = QName.create(MASTER_CONTAINER_QNAME, "min-max-key-leaf");
60 private static final QName MIN_MAX_VALUE_LEAF_QNAME = QName.create(MASTER_CONTAINER_QNAME, "min-max-value-leaf");
61 private static final QName PRESENCE_QNAME = QName.create(MASTER_CONTAINER_QNAME, "presence");
63 private static final YangInstanceIdentifier MASTER_CONTAINER_PATH = YangInstanceIdentifier
64 .of(MASTER_CONTAINER_QNAME);
65 private static final YangInstanceIdentifier MIN_MAX_LIST_PATH = YangInstanceIdentifier
66 .builder(MASTER_CONTAINER_PATH)
67 .node(MIN_MAX_LIST_QNAME).build();
68 private static final YangInstanceIdentifier PRESENCE_PATH = YangInstanceIdentifier.of(PRESENCE_QNAME);
69 private static final YangInstanceIdentifier PRESENCE_MIN_MAX_LIST_PATH = PRESENCE_PATH.node(MIN_MAX_LIST_QNAME);
70 private static final YangInstanceIdentifier MIN_MAX_LIST_NO_MINMAX_PATH = YangInstanceIdentifier
71 .builder(MASTER_CONTAINER_PATH)
72 .node(MIN_MAX_LIST_QNAME_NO_MINMAX).build();
73 private static final YangInstanceIdentifier MIN_MAX_LEAF_LIST_PATH = YangInstanceIdentifier
74 .builder(MASTER_CONTAINER_PATH).node(MIN_MAX_LEAF_LIST_QNAME).build();
76 private static final Map<QName, Object> FOO_PREDICATES = ImmutableMap.of(MIN_MAX_KEY_LEAF_QNAME, "foo");
77 private static final Map<QName, Object> BAZ_PREDICATES = ImmutableMap.of(MIN_MAX_KEY_LEAF_QNAME, "baz");
79 private final MapEntryNode fooEntryNodeWithValue = ImmutableMapEntryNodeBuilder.create().withNodeIdentifier(
80 new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME, FOO_PREDICATES))
81 .withChild(ImmutableNodes.leafNode(MIN_MAX_VALUE_LEAF_QNAME, "footest")).build();
82 private final MapEntryNode bazEntryNodeWithValue = ImmutableMapEntryNodeBuilder.create().withNodeIdentifier(
83 new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME, BAZ_PREDICATES))
84 .withChild(ImmutableNodes.leafNode(MIN_MAX_VALUE_LEAF_QNAME, "baztest")).build();
85 private final MapEntryNode fooEntryNode = ImmutableNodes.mapEntry(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME,
87 private final MapEntryNode barEntryNode = ImmutableNodes.mapEntry(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME,
89 private final MapEntryNode bazEntryNode = ImmutableNodes.mapEntry(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME,
91 private final MapNode mapNodeBazFuzWithNodes = ImmutableNodes.mapNodeBuilder()
92 .withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME))
93 .withChild(bazEntryNode).withChild(bazEntryNodeWithValue).withChild(fooEntryNode)
95 private final MapNode mapNodeFooWithNodes = ImmutableNodes.mapNodeBuilder()
96 .withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME))
97 .withChild(fooEntryNode).withChild(fooEntryNodeWithValue).withChild(barEntryNode).withChild(bazEntryNode)
99 private final MapNode mapNodeBar = ImmutableNodes.mapNodeBuilder()
100 .withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME))
101 .withChild(barEntryNode).build();
102 private final MapNode mapNodeBaz = ImmutableNodes.mapNodeBuilder()
103 .withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME))
104 .withChild(bazEntryNode).build();
106 private static SchemaContext schemaContext;
108 private DataTree inMemoryDataTree;
111 public static void beforeClass() {
112 schemaContext = YangParserTestUtils.parseYangResource("/bug-4454-test.yang");
116 public static void afterClass() {
117 schemaContext = null;
121 public void prepare() {
122 inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL,
124 final DataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
125 final DataTreeModification modificationTree = initialDataTreeSnapshot.newModification();
127 modificationTree.write(MASTER_CONTAINER_PATH, ImmutableNodes.containerNode(MASTER_CONTAINER_QNAME));
128 modificationTree.ready();
129 inMemoryDataTree.commit(inMemoryDataTree.prepare(modificationTree));
133 public void minMaxListDeleteWriteTest() throws DataValidationFailedException {
134 final DataTreeModification modificationTree1 = inMemoryDataTree.takeSnapshot().newModification();
136 Map<QName, Object> key = new HashMap<>();
137 key.put(MIN_MAX_KEY_LEAF_QNAME, "foo");
139 NodeIdentifierWithPredicates mapEntryPath2 = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME , key);
141 final YangInstanceIdentifier minMaxLeafFoo = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH)
142 .node(MIN_MAX_LIST_QNAME).node(mapEntryPath2).build();
145 key.put(MIN_MAX_KEY_LEAF_QNAME, "NON-EXISTING-LEAF");
147 mapEntryPath2 = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME, key);
149 final YangInstanceIdentifier minMaxLeafNel = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH)
150 .node(MIN_MAX_LIST_QNAME).node(mapEntryPath2).build();
152 final Map<QName, Object> keyTemp = new HashMap<>();
153 keyTemp.put(MIN_MAX_KEY_LEAF_QNAME, "baz");
155 NodeIdentifierWithPredicates mapEntryPathTest = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME , keyTemp);
157 final YangInstanceIdentifier pathToBaz = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH)
158 .node(MIN_MAX_LIST_QNAME).node(mapEntryPathTest).node(MIN_MAX_VALUE_LEAF_QNAME).build();
161 keyTemp.put(MIN_MAX_KEY_LEAF_QNAME, "bar");
163 mapEntryPathTest = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME , keyTemp);
165 final YangInstanceIdentifier pathToBar = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH)
166 .node(MIN_MAX_LIST_QNAME).node(mapEntryPathTest).node(MIN_MAX_VALUE_LEAF_QNAME).build();
169 keyTemp.put(MIN_MAX_KEY_LEAF_QNAME, "foo");
171 final NodeIdentifierWithPredicates mapEntryPathTestKey = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME,
174 final YangInstanceIdentifier pathToKeyFoo = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH)
175 .node(MIN_MAX_LIST_QNAME).node(mapEntryPathTestKey).node(MIN_MAX_KEY_LEAF_QNAME).build();
177 final LeafNode<String> newNode = ImmutableNodes.leafNode(MIN_MAX_VALUE_LEAF_QNAME, "test");
178 final LeafNode<String> newNode1 = ImmutableNodes.leafNode(MIN_MAX_VALUE_LEAF_QNAME, "test1");
179 final LeafNode<String> newNode2 = ImmutableNodes.leafNode(MIN_MAX_VALUE_LEAF_QNAME, "test2");
180 final LeafNode<String> newNodekey = ImmutableNodes.leafNode(MIN_MAX_KEY_LEAF_QNAME, "foo");
182 assertFalse(inMemoryDataTree.toString().contains("list"));
184 DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
185 Optional<NormalizedNode<?, ?>> minMaxListRead = snapshotAfterCommit.readNode(MIN_MAX_LIST_PATH);
186 assertTrue(!minMaxListRead.isPresent());
188 modificationTree1.write(MIN_MAX_LIST_PATH, mapNodeFooWithNodes);
189 modificationTree1.write(MIN_MAX_LIST_PATH, mapNodeFooWithNodes);
190 modificationTree1.write(MIN_MAX_LIST_PATH, mapNodeFooWithNodes);
191 modificationTree1.merge(MIN_MAX_LIST_PATH, mapNodeBar);
192 modificationTree1.merge(MIN_MAX_LIST_PATH, mapNodeBaz);
193 modificationTree1.write(pathToKeyFoo, newNodekey);
194 modificationTree1.write(pathToBaz, newNode2);
195 modificationTree1.write(pathToBaz, newNode1);
196 modificationTree1.write(pathToBaz, newNode);
197 modificationTree1.delete(minMaxLeafFoo);
198 modificationTree1.delete(minMaxLeafNel);
200 modificationTree1.ready();
201 inMemoryDataTree.validate(modificationTree1);
202 final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree1);
203 inMemoryDataTree.commit(prepare);
205 DataTreeSnapshot test = inMemoryDataTree.takeSnapshot();
206 testLoop(test, "bar", "test");
208 DataTreeModification tempMod = test.newModification();
209 tempMod.write(pathToBaz, newNode2);
210 tempMod.write(pathToBaz, newNode1);
211 tempMod.merge(pathToBaz, newNode2);
212 tempMod.write(pathToBaz, newNode1);
215 inMemoryDataTree.validate(tempMod);
216 final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(tempMod);
217 inMemoryDataTree.commit(prepare1);
219 DataTreeSnapshot test1 = inMemoryDataTree.takeSnapshot();
220 testLoop(test1, "bar", "test1");
222 DataTreeModification tempMod1 = test1.newModification();
223 tempMod1.write(MIN_MAX_LIST_PATH, mapNodeFooWithNodes);
226 inMemoryDataTree.validate(tempMod1);
227 final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(tempMod1);
228 inMemoryDataTree.commit(prepare2);
230 DataTreeSnapshot test2 = inMemoryDataTree.takeSnapshot();
231 minMaxListRead = test2.readNode(MIN_MAX_LIST_PATH);
232 assertTrue(minMaxListRead.isPresent());
233 assertTrue(((NormalizedNodeContainer<?, ?, ?>) minMaxListRead.get()).getValue().size() == 3);
235 DataTreeModification tempMod2 = test2.newModification();
236 tempMod2.write(MIN_MAX_LIST_PATH, mapNodeBaz);
237 tempMod2.write(pathToBaz, newNode2);
240 inMemoryDataTree.validate(tempMod2);
241 final DataTreeCandidate prepare3 = inMemoryDataTree.prepare(tempMod2);
242 inMemoryDataTree.commit(prepare3);
244 DataTreeSnapshot test3 = inMemoryDataTree.takeSnapshot();
245 minMaxListRead = test3.readNode(MIN_MAX_LIST_PATH);
246 assertTrue(minMaxListRead.isPresent());
247 assertTrue(((NormalizedNodeContainer<?, ?, ?>) minMaxListRead.get()).getValue().size() == 1);
248 assertTrue(minMaxListRead.get().getValue().toString().contains("test2"));
250 DataTreeModification tempMod3 = test3.newModification();
251 tempMod3.merge(MIN_MAX_LIST_PATH, mapNodeBar);
252 tempMod3.merge(pathToBar, newNode1);
255 inMemoryDataTree.validate(tempMod3);
256 final DataTreeCandidate prepare4 = inMemoryDataTree.prepare(tempMod3);
257 inMemoryDataTree.commit(prepare4);
259 DataTreeSnapshot test4 = inMemoryDataTree.takeSnapshot();
260 testLoop(test4, "test1", "test2");
264 public void minMaxLeafListPass() throws DataValidationFailedException {
265 final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
267 final NodeWithValue<?> barPath = new NodeWithValue<>(MIN_MAX_LIST_QNAME, "bar");
268 final NodeWithValue<?> gooPath = new NodeWithValue<>(MIN_MAX_LIST_QNAME, "goo");
270 final LeafSetEntryNode<Object> barLeafSetEntry = ImmutableLeafSetEntryNodeBuilder.create()
271 .withNodeIdentifier(barPath)
272 .withValue("bar").build();
273 final LeafSetEntryNode<Object> gooLeafSetEntry = ImmutableLeafSetEntryNodeBuilder.create()
274 .withNodeIdentifier(gooPath)
275 .withValue("goo").build();
277 final LeafSetNode<Object> fooLeafSetNode = ImmutableLeafSetNodeBuilder.create()
278 .withNodeIdentifier(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME))
279 .withChildValue("foo").build();
281 modificationTree.write(MIN_MAX_LEAF_LIST_PATH, fooLeafSetNode);
282 modificationTree.write(MIN_MAX_LEAF_LIST_PATH.node(barPath), barLeafSetEntry);
283 modificationTree.ready();
285 inMemoryDataTree.validate(modificationTree);
286 final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree);
287 inMemoryDataTree.commit(prepare1);
289 DataTreeSnapshot test1 = inMemoryDataTree.takeSnapshot();
291 DataTreeModification tempMod1 = test1.newModification();
292 tempMod1.write(MIN_MAX_LEAF_LIST_PATH.node(gooPath), gooLeafSetEntry);
293 tempMod1.write(MIN_MAX_LEAF_LIST_PATH.node(barPath), barLeafSetEntry);
296 inMemoryDataTree.validate(tempMod1);
297 final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(tempMod1);
298 inMemoryDataTree.commit(prepare2);
300 final DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
301 final Optional<NormalizedNode<?, ?>> masterContainer = snapshotAfterCommit.readNode(MASTER_CONTAINER_PATH);
302 assertTrue(masterContainer.isPresent());
303 final Optional<NormalizedNodeContainer<?, ?, ?>> leafList = ((NormalizedNodeContainer) masterContainer.get())
304 .getChild(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME));
305 assertTrue(leafList.isPresent());
306 assertTrue(leafList.get().getValue().size() == 3);
310 public void minMaxListDeleteTest() throws DataValidationFailedException {
311 final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
314 NodeIdentifierWithPredicates mapEntryPath2 = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME,
315 ImmutableMap.of(MIN_MAX_KEY_LEAF_QNAME, "foo"));
317 final YangInstanceIdentifier minMaxLeafFoo = MASTER_CONTAINER_PATH
318 .node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
320 mapEntryPath2 = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME,
321 ImmutableMap.of(MIN_MAX_KEY_LEAF_QNAME, "bar"));
323 final YangInstanceIdentifier minMaxLeafBar = MASTER_CONTAINER_PATH
324 .node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
326 mapEntryPath2 = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME,
327 ImmutableMap.of(MIN_MAX_KEY_LEAF_QNAME, "baz"));
329 final YangInstanceIdentifier minMaxLeafBaz = MASTER_CONTAINER_PATH
330 .node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
332 modificationTree.write(MIN_MAX_LIST_PATH, mapNodeFooWithNodes);
333 modificationTree.merge(MIN_MAX_LIST_PATH, mapNodeBar);
334 modificationTree.merge(MIN_MAX_LIST_PATH, mapNodeBaz);
335 modificationTree.delete(minMaxLeafFoo);
336 modificationTree.delete(minMaxLeafBar);
337 modificationTree.delete(minMaxLeafBaz);
339 modificationTree.ready();
341 inMemoryDataTree.validate(modificationTree);
342 final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
343 inMemoryDataTree.commit(prepare);
345 // Empty list should have disappeared, along with the container, as we are not enforcing root
346 final NormalizedNode<?, ?> data = inMemoryDataTree.takeSnapshot().readNode(YangInstanceIdentifier.EMPTY).get();
347 assertTrue(data instanceof ContainerNode);
348 assertEquals(0, ((ContainerNode) data).getValue().size());
352 public void minMaxListDeleteExceptionTest() throws DataValidationFailedException {
353 final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
355 NodeIdentifierWithPredicates mapEntryPath2 = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME,
356 ImmutableMap.of(MIN_MAX_KEY_LEAF_QNAME, "foo"));
358 final YangInstanceIdentifier minMaxLeafFoo = PRESENCE_PATH.node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
360 mapEntryPath2 = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME,
361 ImmutableMap.of(MIN_MAX_KEY_LEAF_QNAME, "bar"));
363 final YangInstanceIdentifier minMaxLeafBar = PRESENCE_PATH.node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
365 mapEntryPath2 = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME,
366 ImmutableMap.of(MIN_MAX_KEY_LEAF_QNAME, "baz"));
368 final YangInstanceIdentifier minMaxLeafBaz = PRESENCE_PATH.node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
370 modificationTree.write(PRESENCE_PATH, ImmutableNodes.containerNode(PRESENCE_QNAME));
371 modificationTree.write(PRESENCE_MIN_MAX_LIST_PATH, mapNodeFooWithNodes);
372 modificationTree.merge(PRESENCE_MIN_MAX_LIST_PATH, mapNodeBar);
373 modificationTree.merge(PRESENCE_MIN_MAX_LIST_PATH, mapNodeBaz);
374 modificationTree.delete(minMaxLeafFoo);
375 modificationTree.delete(minMaxLeafBar);
376 modificationTree.delete(minMaxLeafBaz);
379 // Unlike minMaxListDeleteTest(), presence container enforces the list to be present
380 modificationTree.ready();
381 fail("Should have failed with IAE");
382 } catch (IllegalArgumentException e) {
383 assertEquals("Node (urn:opendaylight:params:xml:ns:yang:list-constraints-validation-test-model?"
384 + "revision=2015-02-02)presence is missing mandatory descendant "
385 + "/(urn:opendaylight:params:xml:ns:yang:list-constraints-validation-test-model?"
386 + "revision=2015-02-02)min-max-list", e.getMessage());
391 public void minMaxListNoMinMaxDeleteTest() throws DataValidationFailedException {
392 final MapEntryNode fooEntryNoMinMaxNode =
393 ImmutableNodes.mapEntry(MIN_MAX_LIST_QNAME_NO_MINMAX, MIN_MAX_KEY_LEAF_QNAME, "foo");
394 final MapNode mapNode1 = ImmutableNodes.mapNodeBuilder()
395 .withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME_NO_MINMAX))
396 .withChild(fooEntryNoMinMaxNode).build();
398 final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
400 Map<QName, Object> key = new HashMap<>();
401 key.put(MIN_MAX_KEY_LEAF_QNAME, "foo");
403 NodeIdentifierWithPredicates mapEntryPath2 = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME_NO_MINMAX,
406 final YangInstanceIdentifier minMaxLeafFoo = MASTER_CONTAINER_PATH
407 .node(MIN_MAX_LIST_QNAME_NO_MINMAX).node(mapEntryPath2);
410 key.put(MIN_MAX_KEY_LEAF_QNAME, "non-existing-leaf");
412 mapEntryPath2 = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME_NO_MINMAX, key);
414 YangInstanceIdentifier minMaxLeafNel = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH)
415 .node(MIN_MAX_LIST_QNAME_NO_MINMAX).node(mapEntryPath2).build();
417 modificationTree.write(MIN_MAX_LIST_NO_MINMAX_PATH, mapNode1);
418 modificationTree.delete(minMaxLeafFoo);
419 modificationTree.delete(minMaxLeafNel);
421 modificationTree.ready();
423 inMemoryDataTree.validate(modificationTree);
424 final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
425 inMemoryDataTree.commit(prepare);
427 final DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
428 final Optional<NormalizedNode<?, ?>> minMaxListRead = snapshotAfterCommit.readNode(MIN_MAX_LIST_NO_MINMAX_PATH);
430 // Empty list should have disappeared
431 assertFalse(minMaxListRead.isPresent());
434 private static void testLoop(final DataTreeSnapshot snapshot, final String first, final String second) {
435 Optional<NormalizedNode<?, ?>> minMaxListRead = snapshot.readNode(MIN_MAX_LIST_PATH);
436 assertTrue(minMaxListRead.isPresent());
437 assertTrue(((NormalizedNodeContainer<?, ?, ?>) minMaxListRead.get()).getValue().size() == 2);
438 UnmodifiableCollection<?> collectionChildren = (UnmodifiableCollection<?>) minMaxListRead.get().getValue();
440 for (Object collectionChild : collectionChildren) {
441 if (collectionChild.toString().contains(first)) {
442 assertTrue(collectionChild.toString().contains(first));
444 assertTrue(collectionChild.toString().contains(second));