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.tree.impl;
10 import static junit.framework.TestCase.assertFalse;
11 import static org.hamcrest.CoreMatchers.containsString;
12 import static org.hamcrest.MatcherAssert.assertThat;
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertTrue;
15 import static org.junit.Assert.fail;
17 import java.util.Collection;
18 import java.util.HashMap;
20 import java.util.Optional;
21 import org.junit.AfterClass;
22 import org.junit.Before;
23 import org.junit.BeforeClass;
24 import org.junit.Test;
25 import org.opendaylight.yangtools.yang.common.QName;
26 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
27 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
28 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
29 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
30 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
31 import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
32 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
33 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
34 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
35 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
36 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
37 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
38 import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
39 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
40 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetEntryNodeBuilder;
41 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder;
42 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder;
43 import org.opendaylight.yangtools.yang.data.tree.api.DataTree;
44 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate;
45 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeConfiguration;
46 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification;
47 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot;
48 import org.opendaylight.yangtools.yang.data.tree.api.DataValidationFailedException;
49 import org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory;
50 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
51 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
53 public class Bug4454Test {
55 private static final QName MASTER_CONTAINER_QNAME = QName
56 .create("urn:opendaylight:params:xml:ns:yang:list-constraints-validation-test-model", "2015-02-02",
58 private static final QName MIN_MAX_LIST_QNAME = QName.create(MASTER_CONTAINER_QNAME, "min-max-list");
59 private static final QName MIN_MAX_LEAF_LIST_QNAME = QName.create(MASTER_CONTAINER_QNAME, "min-max-leaf-list");
60 private static final QName MIN_MAX_LIST_QNAME_NO_MINMAX = QName
61 .create(MASTER_CONTAINER_QNAME, "min-max-list-no-minmax");
62 private static final QName MIN_MAX_KEY_LEAF_QNAME = QName.create(MASTER_CONTAINER_QNAME, "min-max-key-leaf");
63 private static final QName MIN_MAX_VALUE_LEAF_QNAME = QName.create(MASTER_CONTAINER_QNAME, "min-max-value-leaf");
64 private static final QName PRESENCE_QNAME = QName.create(MASTER_CONTAINER_QNAME, "presence");
66 private static final YangInstanceIdentifier MASTER_CONTAINER_PATH = YangInstanceIdentifier
67 .of(MASTER_CONTAINER_QNAME);
68 private static final YangInstanceIdentifier MIN_MAX_LIST_PATH = YangInstanceIdentifier
69 .builder(MASTER_CONTAINER_PATH)
70 .node(MIN_MAX_LIST_QNAME).build();
71 private static final YangInstanceIdentifier PRESENCE_PATH = YangInstanceIdentifier.of(PRESENCE_QNAME);
72 private static final YangInstanceIdentifier PRESENCE_MIN_MAX_LIST_PATH = PRESENCE_PATH.node(MIN_MAX_LIST_QNAME);
73 private static final YangInstanceIdentifier MIN_MAX_LIST_NO_MINMAX_PATH = YangInstanceIdentifier
74 .builder(MASTER_CONTAINER_PATH)
75 .node(MIN_MAX_LIST_QNAME_NO_MINMAX).build();
76 private static final YangInstanceIdentifier MIN_MAX_LEAF_LIST_PATH = YangInstanceIdentifier
77 .builder(MASTER_CONTAINER_PATH).node(MIN_MAX_LEAF_LIST_QNAME).build();
79 private final MapEntryNode fooEntryNodeWithValue = ImmutableMapEntryNodeBuilder.create().withNodeIdentifier(
80 NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME, "foo"))
81 .withChild(ImmutableNodes.leafNode(MIN_MAX_VALUE_LEAF_QNAME, "footest")).build();
82 private final MapEntryNode bazEntryNodeWithValue = ImmutableMapEntryNodeBuilder.create().withNodeIdentifier(
83 NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME, "baz"))
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 SystemMapNode mapNodeBazFuzWithNodes = ImmutableNodes.mapNodeBuilder()
92 .withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME))
93 .withChild(bazEntryNode).withChild(bazEntryNodeWithValue).withChild(fooEntryNode)
95 private final SystemMapNode mapNodeFooWithNodes = ImmutableNodes.mapNodeBuilder()
96 .withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME))
97 .withChild(fooEntryNode).withChild(fooEntryNodeWithValue).withChild(barEntryNode).withChild(bazEntryNode)
99 private final SystemMapNode mapNodeBar = ImmutableNodes.mapNodeBuilder()
100 .withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME))
101 .withChild(barEntryNode).build();
102 private final SystemMapNode mapNodeBaz = ImmutableNodes.mapNodeBuilder()
103 .withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME))
104 .withChild(bazEntryNode).build();
106 private static EffectiveModelContext 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() throws DataValidationFailedException {
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 = NodeIdentifierWithPredicates.of(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 = NodeIdentifierWithPredicates.of(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 = NodeIdentifierWithPredicates.of(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 = NodeIdentifierWithPredicates.of(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 = NodeIdentifierWithPredicates.of(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 assertEquals(3, ((NormalizedNodeContainer<?>) minMaxListRead.get()).size());
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 assertEquals(1, ((NormalizedNodeContainer<?>) minMaxListRead.get()).size());
248 assertThat(minMaxListRead.get().body().toString(), containsString("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")
282 modificationTree.write(MIN_MAX_LEAF_LIST_PATH, fooLeafSetNode);
283 modificationTree.write(MIN_MAX_LEAF_LIST_PATH.node(barPath), barLeafSetEntry);
284 modificationTree.ready();
286 inMemoryDataTree.validate(modificationTree);
287 final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree);
288 inMemoryDataTree.commit(prepare1);
290 DataTreeSnapshot test1 = inMemoryDataTree.takeSnapshot();
292 DataTreeModification tempMod1 = test1.newModification();
293 tempMod1.write(MIN_MAX_LEAF_LIST_PATH.node(gooPath), gooLeafSetEntry);
294 tempMod1.write(MIN_MAX_LEAF_LIST_PATH.node(barPath), barLeafSetEntry);
297 inMemoryDataTree.validate(tempMod1);
298 final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(tempMod1);
299 inMemoryDataTree.commit(prepare2);
301 final DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
302 final Optional<NormalizedNode> masterContainer = snapshotAfterCommit.readNode(MASTER_CONTAINER_PATH);
303 assertTrue(masterContainer.isPresent());
304 final Optional<NormalizedNodeContainer<?>> leafList = ((DistinctNodeContainer) masterContainer.get())
305 .findChildByArg(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME));
306 assertTrue(leafList.isPresent());
307 assertEquals(3, leafList.get().size());
311 public void minMaxListDeleteTest() throws DataValidationFailedException {
312 final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
315 NodeIdentifierWithPredicates mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME,
316 MIN_MAX_KEY_LEAF_QNAME, "foo");
318 final YangInstanceIdentifier minMaxLeafFoo = MASTER_CONTAINER_PATH
319 .node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
321 mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME, "bar");
323 final YangInstanceIdentifier minMaxLeafBar = MASTER_CONTAINER_PATH
324 .node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
326 mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME, "baz");
328 final YangInstanceIdentifier minMaxLeafBaz = MASTER_CONTAINER_PATH
329 .node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
331 modificationTree.write(MIN_MAX_LIST_PATH, mapNodeFooWithNodes);
332 modificationTree.merge(MIN_MAX_LIST_PATH, mapNodeBar);
333 modificationTree.merge(MIN_MAX_LIST_PATH, mapNodeBaz);
334 modificationTree.delete(minMaxLeafFoo);
335 modificationTree.delete(minMaxLeafBar);
336 modificationTree.delete(minMaxLeafBaz);
338 modificationTree.ready();
340 inMemoryDataTree.validate(modificationTree);
341 final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
342 inMemoryDataTree.commit(prepare);
344 // Empty list should have disappeared, along with the container, as we are not enforcing root
345 final NormalizedNode data = inMemoryDataTree.takeSnapshot()
346 .readNode(YangInstanceIdentifier.empty()).get();
347 assertTrue(data instanceof ContainerNode);
348 assertEquals(0, ((ContainerNode) data).size());
352 public void minMaxListDeleteExceptionTest() throws DataValidationFailedException {
353 final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
355 NodeIdentifierWithPredicates mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME,
356 MIN_MAX_KEY_LEAF_QNAME, "foo");
358 final YangInstanceIdentifier minMaxLeafFoo = PRESENCE_PATH.node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
360 mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME, "bar");
362 final YangInstanceIdentifier minMaxLeafBar = PRESENCE_PATH.node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
364 mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME, "baz");
366 final YangInstanceIdentifier minMaxLeafBaz = PRESENCE_PATH.node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
368 modificationTree.write(PRESENCE_PATH, ImmutableNodes.containerNode(PRESENCE_QNAME));
369 modificationTree.write(PRESENCE_MIN_MAX_LIST_PATH, mapNodeFooWithNodes);
370 modificationTree.merge(PRESENCE_MIN_MAX_LIST_PATH, mapNodeBar);
371 modificationTree.merge(PRESENCE_MIN_MAX_LIST_PATH, mapNodeBaz);
372 modificationTree.delete(minMaxLeafFoo);
373 modificationTree.delete(minMaxLeafBar);
374 modificationTree.delete(minMaxLeafBaz);
377 // Unlike minMaxListDeleteTest(), presence container enforces the list to be present
378 modificationTree.ready();
379 fail("Should have failed with IAE");
380 } catch (IllegalArgumentException e) {
381 assertEquals("Node (urn:opendaylight:params:xml:ns:yang:list-constraints-validation-test-model?"
382 + "revision=2015-02-02)presence is missing mandatory descendant "
383 + "/(urn:opendaylight:params:xml:ns:yang:list-constraints-validation-test-model?"
384 + "revision=2015-02-02)min-max-list", e.getMessage());
389 public void minMaxListNoMinMaxDeleteTest() throws DataValidationFailedException {
390 final MapEntryNode fooEntryNoMinMaxNode =
391 ImmutableNodes.mapEntry(MIN_MAX_LIST_QNAME_NO_MINMAX, MIN_MAX_KEY_LEAF_QNAME, "foo");
392 final SystemMapNode mapNode1 = ImmutableNodes.mapNodeBuilder()
393 .withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME_NO_MINMAX))
394 .withChild(fooEntryNoMinMaxNode).build();
396 final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
398 Map<QName, Object> key = new HashMap<>();
399 key.put(MIN_MAX_KEY_LEAF_QNAME, "foo");
401 NodeIdentifierWithPredicates mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME_NO_MINMAX, key);
403 final YangInstanceIdentifier minMaxLeafFoo = MASTER_CONTAINER_PATH
404 .node(MIN_MAX_LIST_QNAME_NO_MINMAX).node(mapEntryPath2);
407 key.put(MIN_MAX_KEY_LEAF_QNAME, "non-existing-leaf");
409 mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME_NO_MINMAX, key);
411 YangInstanceIdentifier minMaxLeafNel = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH)
412 .node(MIN_MAX_LIST_QNAME_NO_MINMAX).node(mapEntryPath2).build();
414 modificationTree.write(MIN_MAX_LIST_NO_MINMAX_PATH, mapNode1);
415 modificationTree.delete(minMaxLeafFoo);
416 modificationTree.delete(minMaxLeafNel);
418 modificationTree.ready();
420 inMemoryDataTree.validate(modificationTree);
421 final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
422 inMemoryDataTree.commit(prepare);
424 final DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
425 final Optional<NormalizedNode> minMaxListRead = snapshotAfterCommit.readNode(MIN_MAX_LIST_NO_MINMAX_PATH);
427 // Empty list should have disappeared
428 assertFalse(minMaxListRead.isPresent());
431 private static void testLoop(final DataTreeSnapshot snapshot, final String first, final String second) {
432 Optional<NormalizedNode> minMaxListRead = snapshot.readNode(MIN_MAX_LIST_PATH);
433 assertTrue(minMaxListRead.isPresent());
434 assertEquals(2, ((NormalizedNodeContainer<?>) minMaxListRead.get()).size());
436 for (Object collectionChild : (Collection<?>) minMaxListRead.get().body()) {
437 if (collectionChild.toString().contains(first)) {
438 assertTrue(collectionChild.toString().contains(first));
440 assertTrue(collectionChild.toString().contains(second));