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.Builders;
40 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
41 import org.opendaylight.yangtools.yang.data.tree.api.DataTree;
42 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate;
43 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeConfiguration;
44 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification;
45 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot;
46 import org.opendaylight.yangtools.yang.data.tree.api.DataValidationFailedException;
47 import org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory;
48 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
49 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
51 public class Bug4454Test {
53 private static final QName MASTER_CONTAINER_QNAME = QName
54 .create("urn:opendaylight:params:xml:ns:yang:list-constraints-validation-test-model", "2015-02-02",
56 private static final QName MIN_MAX_LIST_QNAME = QName.create(MASTER_CONTAINER_QNAME, "min-max-list");
57 private static final QName MIN_MAX_LEAF_LIST_QNAME = QName.create(MASTER_CONTAINER_QNAME, "min-max-leaf-list");
58 private static final QName MIN_MAX_LIST_QNAME_NO_MINMAX = QName
59 .create(MASTER_CONTAINER_QNAME, "min-max-list-no-minmax");
60 private static final QName MIN_MAX_KEY_LEAF_QNAME = QName.create(MASTER_CONTAINER_QNAME, "min-max-key-leaf");
61 private static final QName MIN_MAX_VALUE_LEAF_QNAME = QName.create(MASTER_CONTAINER_QNAME, "min-max-value-leaf");
62 private static final QName PRESENCE_QNAME = QName.create(MASTER_CONTAINER_QNAME, "presence");
64 private static final YangInstanceIdentifier MASTER_CONTAINER_PATH =
65 YangInstanceIdentifier.of(MASTER_CONTAINER_QNAME);
66 private static final YangInstanceIdentifier MIN_MAX_LIST_PATH =
67 YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH).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 =
71 YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH).node(MIN_MAX_LIST_QNAME_NO_MINMAX).build();
72 private static final YangInstanceIdentifier MIN_MAX_LEAF_LIST_PATH =
73 YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH).node(MIN_MAX_LEAF_LIST_QNAME).build();
75 private final MapEntryNode fooEntryNodeWithValue = Builders.mapEntryBuilder()
76 .withNodeIdentifier(NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME, "foo"))
77 .withChild(ImmutableNodes.leafNode(MIN_MAX_VALUE_LEAF_QNAME, "footest"))
79 private final MapEntryNode bazEntryNodeWithValue = Builders.mapEntryBuilder()
80 .withNodeIdentifier(NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME, "baz"))
81 .withChild(ImmutableNodes.leafNode(MIN_MAX_VALUE_LEAF_QNAME, "baztest"))
83 private final MapEntryNode fooEntryNode = ImmutableNodes.mapEntry(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME,
85 private final MapEntryNode barEntryNode = ImmutableNodes.mapEntry(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME,
87 private final MapEntryNode bazEntryNode = ImmutableNodes.mapEntry(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME,
89 private final SystemMapNode mapNodeBazFuzWithNodes = ImmutableNodes.mapNodeBuilder()
90 .withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME))
91 .withChild(bazEntryNode).withChild(bazEntryNodeWithValue).withChild(fooEntryNode)
93 private final SystemMapNode mapNodeFooWithNodes = ImmutableNodes.mapNodeBuilder()
94 .withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME))
95 .withChild(fooEntryNode).withChild(fooEntryNodeWithValue).withChild(barEntryNode).withChild(bazEntryNode)
97 private final SystemMapNode mapNodeBar = ImmutableNodes.mapNodeBuilder()
98 .withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME))
99 .withChild(barEntryNode).build();
100 private final SystemMapNode mapNodeBaz = ImmutableNodes.mapNodeBuilder()
101 .withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME))
102 .withChild(bazEntryNode).build();
104 private static EffectiveModelContext schemaContext;
106 private DataTree inMemoryDataTree;
109 public static void beforeClass() {
110 schemaContext = YangParserTestUtils.parseYangResource("/bug-4454-test.yang");
114 public static void afterClass() {
115 schemaContext = null;
119 public void prepare() throws DataValidationFailedException {
120 inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL,
122 final DataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
123 final DataTreeModification modificationTree = initialDataTreeSnapshot.newModification();
125 modificationTree.write(MASTER_CONTAINER_PATH, ImmutableNodes.containerNode(MASTER_CONTAINER_QNAME));
126 modificationTree.ready();
127 inMemoryDataTree.commit(inMemoryDataTree.prepare(modificationTree));
131 public void minMaxListDeleteWriteTest() throws DataValidationFailedException {
132 final DataTreeModification modificationTree1 = inMemoryDataTree.takeSnapshot().newModification();
134 Map<QName, Object> key = new HashMap<>();
135 key.put(MIN_MAX_KEY_LEAF_QNAME, "foo");
137 NodeIdentifierWithPredicates mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME , key);
139 final YangInstanceIdentifier minMaxLeafFoo = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH)
140 .node(MIN_MAX_LIST_QNAME).node(mapEntryPath2).build();
143 key.put(MIN_MAX_KEY_LEAF_QNAME, "NON-EXISTING-LEAF");
145 mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, key);
147 final YangInstanceIdentifier minMaxLeafNel = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH)
148 .node(MIN_MAX_LIST_QNAME).node(mapEntryPath2).build();
150 final Map<QName, Object> keyTemp = new HashMap<>();
151 keyTemp.put(MIN_MAX_KEY_LEAF_QNAME, "baz");
153 NodeIdentifierWithPredicates mapEntryPathTest = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME , keyTemp);
155 final YangInstanceIdentifier pathToBaz = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH)
156 .node(MIN_MAX_LIST_QNAME).node(mapEntryPathTest).node(MIN_MAX_VALUE_LEAF_QNAME).build();
159 keyTemp.put(MIN_MAX_KEY_LEAF_QNAME, "bar");
161 mapEntryPathTest = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME , keyTemp);
163 final YangInstanceIdentifier pathToBar = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH)
164 .node(MIN_MAX_LIST_QNAME).node(mapEntryPathTest).node(MIN_MAX_VALUE_LEAF_QNAME).build();
167 keyTemp.put(MIN_MAX_KEY_LEAF_QNAME, "foo");
169 final NodeIdentifierWithPredicates mapEntryPathTestKey = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME,
172 final YangInstanceIdentifier pathToKeyFoo = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH)
173 .node(MIN_MAX_LIST_QNAME).node(mapEntryPathTestKey).node(MIN_MAX_KEY_LEAF_QNAME).build();
175 final LeafNode<String> newNode = ImmutableNodes.leafNode(MIN_MAX_VALUE_LEAF_QNAME, "test");
176 final LeafNode<String> newNode1 = ImmutableNodes.leafNode(MIN_MAX_VALUE_LEAF_QNAME, "test1");
177 final LeafNode<String> newNode2 = ImmutableNodes.leafNode(MIN_MAX_VALUE_LEAF_QNAME, "test2");
178 final LeafNode<String> newNodekey = ImmutableNodes.leafNode(MIN_MAX_KEY_LEAF_QNAME, "foo");
180 assertFalse(inMemoryDataTree.toString().contains("list"));
182 DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
183 Optional<NormalizedNode> minMaxListRead = snapshotAfterCommit.readNode(MIN_MAX_LIST_PATH);
184 assertTrue(!minMaxListRead.isPresent());
186 modificationTree1.write(MIN_MAX_LIST_PATH, mapNodeFooWithNodes);
187 modificationTree1.write(MIN_MAX_LIST_PATH, mapNodeFooWithNodes);
188 modificationTree1.write(MIN_MAX_LIST_PATH, mapNodeFooWithNodes);
189 modificationTree1.merge(MIN_MAX_LIST_PATH, mapNodeBar);
190 modificationTree1.merge(MIN_MAX_LIST_PATH, mapNodeBaz);
191 modificationTree1.write(pathToKeyFoo, newNodekey);
192 modificationTree1.write(pathToBaz, newNode2);
193 modificationTree1.write(pathToBaz, newNode1);
194 modificationTree1.write(pathToBaz, newNode);
195 modificationTree1.delete(minMaxLeafFoo);
196 modificationTree1.delete(minMaxLeafNel);
198 modificationTree1.ready();
199 inMemoryDataTree.validate(modificationTree1);
200 final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree1);
201 inMemoryDataTree.commit(prepare);
203 DataTreeSnapshot test = inMemoryDataTree.takeSnapshot();
204 testLoop(test, "bar", "test");
206 DataTreeModification tempMod = test.newModification();
207 tempMod.write(pathToBaz, newNode2);
208 tempMod.write(pathToBaz, newNode1);
209 tempMod.merge(pathToBaz, newNode2);
210 tempMod.write(pathToBaz, newNode1);
213 inMemoryDataTree.validate(tempMod);
214 final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(tempMod);
215 inMemoryDataTree.commit(prepare1);
217 DataTreeSnapshot test1 = inMemoryDataTree.takeSnapshot();
218 testLoop(test1, "bar", "test1");
220 DataTreeModification tempMod1 = test1.newModification();
221 tempMod1.write(MIN_MAX_LIST_PATH, mapNodeFooWithNodes);
224 inMemoryDataTree.validate(tempMod1);
225 final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(tempMod1);
226 inMemoryDataTree.commit(prepare2);
228 DataTreeSnapshot test2 = inMemoryDataTree.takeSnapshot();
229 minMaxListRead = test2.readNode(MIN_MAX_LIST_PATH);
230 assertTrue(minMaxListRead.isPresent());
231 assertEquals(3, ((NormalizedNodeContainer<?>) minMaxListRead.orElseThrow()).size());
233 DataTreeModification tempMod2 = test2.newModification();
234 tempMod2.write(MIN_MAX_LIST_PATH, mapNodeBaz);
235 tempMod2.write(pathToBaz, newNode2);
238 inMemoryDataTree.validate(tempMod2);
239 final DataTreeCandidate prepare3 = inMemoryDataTree.prepare(tempMod2);
240 inMemoryDataTree.commit(prepare3);
242 DataTreeSnapshot test3 = inMemoryDataTree.takeSnapshot();
243 minMaxListRead = test3.readNode(MIN_MAX_LIST_PATH);
244 assertTrue(minMaxListRead.isPresent());
245 assertEquals(1, ((NormalizedNodeContainer<?>) minMaxListRead.orElseThrow()).size());
246 assertThat(minMaxListRead.orElseThrow().body().toString(), containsString("test2"));
248 DataTreeModification tempMod3 = test3.newModification();
249 tempMod3.merge(MIN_MAX_LIST_PATH, mapNodeBar);
250 tempMod3.merge(pathToBar, newNode1);
253 inMemoryDataTree.validate(tempMod3);
254 final DataTreeCandidate prepare4 = inMemoryDataTree.prepare(tempMod3);
255 inMemoryDataTree.commit(prepare4);
257 DataTreeSnapshot test4 = inMemoryDataTree.takeSnapshot();
258 testLoop(test4, "test1", "test2");
262 public void minMaxLeafListPass() throws DataValidationFailedException {
263 final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
265 final NodeWithValue<?> barPath = new NodeWithValue<>(MIN_MAX_LIST_QNAME, "bar");
266 final NodeWithValue<?> gooPath = new NodeWithValue<>(MIN_MAX_LIST_QNAME, "goo");
268 final LeafSetEntryNode<Object> barLeafSetEntry = Builders.leafSetEntryBuilder()
269 .withNodeIdentifier(barPath)
270 .withValue("bar").build();
271 final LeafSetEntryNode<Object> gooLeafSetEntry = Builders.leafSetEntryBuilder()
272 .withNodeIdentifier(gooPath)
273 .withValue("goo").build();
275 final LeafSetNode<Object> fooLeafSetNode = Builders.leafSetBuilder()
276 .withNodeIdentifier(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME))
277 .withChildValue("foo")
280 modificationTree.write(MIN_MAX_LEAF_LIST_PATH, fooLeafSetNode);
281 modificationTree.write(MIN_MAX_LEAF_LIST_PATH.node(barPath), barLeafSetEntry);
282 modificationTree.ready();
284 inMemoryDataTree.validate(modificationTree);
285 final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree);
286 inMemoryDataTree.commit(prepare1);
288 DataTreeSnapshot test1 = inMemoryDataTree.takeSnapshot();
290 DataTreeModification tempMod1 = test1.newModification();
291 tempMod1.write(MIN_MAX_LEAF_LIST_PATH.node(gooPath), gooLeafSetEntry);
292 tempMod1.write(MIN_MAX_LEAF_LIST_PATH.node(barPath), barLeafSetEntry);
295 inMemoryDataTree.validate(tempMod1);
296 final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(tempMod1);
297 inMemoryDataTree.commit(prepare2);
299 final DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
300 final Optional<NormalizedNode> masterContainer = snapshotAfterCommit.readNode(MASTER_CONTAINER_PATH);
301 assertTrue(masterContainer.isPresent());
302 final Optional<NormalizedNodeContainer<?>> leafList = ((DistinctNodeContainer) masterContainer.orElseThrow())
303 .findChildByArg(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME));
304 assertTrue(leafList.isPresent());
305 assertEquals(3, leafList.orElseThrow().size());
309 public void minMaxListDeleteTest() throws DataValidationFailedException {
310 final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
313 NodeIdentifierWithPredicates mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME,
314 MIN_MAX_KEY_LEAF_QNAME, "foo");
316 final YangInstanceIdentifier minMaxLeafFoo = MASTER_CONTAINER_PATH
317 .node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
319 mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME, "bar");
321 final YangInstanceIdentifier minMaxLeafBar = MASTER_CONTAINER_PATH
322 .node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
324 mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME, "baz");
326 final YangInstanceIdentifier minMaxLeafBaz = MASTER_CONTAINER_PATH
327 .node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
329 modificationTree.write(MIN_MAX_LIST_PATH, mapNodeFooWithNodes);
330 modificationTree.merge(MIN_MAX_LIST_PATH, mapNodeBar);
331 modificationTree.merge(MIN_MAX_LIST_PATH, mapNodeBaz);
332 modificationTree.delete(minMaxLeafFoo);
333 modificationTree.delete(minMaxLeafBar);
334 modificationTree.delete(minMaxLeafBaz);
336 modificationTree.ready();
338 inMemoryDataTree.validate(modificationTree);
339 final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
340 inMemoryDataTree.commit(prepare);
342 // Empty list should have disappeared, along with the container, as we are not enforcing root
343 final NormalizedNode data = inMemoryDataTree.takeSnapshot().readNode(YangInstanceIdentifier.of()).orElseThrow();
344 assertTrue(data instanceof ContainerNode);
345 assertEquals(0, ((ContainerNode) data).size());
349 public void minMaxListDeleteExceptionTest() throws DataValidationFailedException {
350 final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
352 NodeIdentifierWithPredicates mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME,
353 MIN_MAX_KEY_LEAF_QNAME, "foo");
355 final YangInstanceIdentifier minMaxLeafFoo = PRESENCE_PATH.node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
357 mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME, "bar");
359 final YangInstanceIdentifier minMaxLeafBar = PRESENCE_PATH.node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
361 mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME, "baz");
363 final YangInstanceIdentifier minMaxLeafBaz = PRESENCE_PATH.node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
365 modificationTree.write(PRESENCE_PATH, ImmutableNodes.containerNode(PRESENCE_QNAME));
366 modificationTree.write(PRESENCE_MIN_MAX_LIST_PATH, mapNodeFooWithNodes);
367 modificationTree.merge(PRESENCE_MIN_MAX_LIST_PATH, mapNodeBar);
368 modificationTree.merge(PRESENCE_MIN_MAX_LIST_PATH, mapNodeBaz);
369 modificationTree.delete(minMaxLeafFoo);
370 modificationTree.delete(minMaxLeafBar);
371 modificationTree.delete(minMaxLeafBaz);
374 // Unlike minMaxListDeleteTest(), presence container enforces the list to be present
375 modificationTree.ready();
376 fail("Should have failed with IAE");
377 } catch (IllegalArgumentException e) {
379 Node (urn:opendaylight:params:xml:ns:yang:list-constraints-validation-test-model?revision=2015-02-02)\
380 presence is missing mandatory descendant /(urn:opendaylight:params:xml:ns:yang:list-constraints-\
381 validation-test-model?revision=2015-02-02)min-max-list""", e.getMessage());
386 public void minMaxListNoMinMaxDeleteTest() throws DataValidationFailedException {
387 final MapEntryNode fooEntryNoMinMaxNode =
388 ImmutableNodes.mapEntry(MIN_MAX_LIST_QNAME_NO_MINMAX, MIN_MAX_KEY_LEAF_QNAME, "foo");
389 final SystemMapNode mapNode1 = ImmutableNodes.mapNodeBuilder()
390 .withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME_NO_MINMAX))
391 .withChild(fooEntryNoMinMaxNode).build();
393 final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
395 Map<QName, Object> key = new HashMap<>();
396 key.put(MIN_MAX_KEY_LEAF_QNAME, "foo");
398 NodeIdentifierWithPredicates mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME_NO_MINMAX, key);
400 final YangInstanceIdentifier minMaxLeafFoo = MASTER_CONTAINER_PATH
401 .node(MIN_MAX_LIST_QNAME_NO_MINMAX).node(mapEntryPath2);
404 key.put(MIN_MAX_KEY_LEAF_QNAME, "non-existing-leaf");
406 mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME_NO_MINMAX, key);
408 YangInstanceIdentifier minMaxLeafNel = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH)
409 .node(MIN_MAX_LIST_QNAME_NO_MINMAX).node(mapEntryPath2).build();
411 modificationTree.write(MIN_MAX_LIST_NO_MINMAX_PATH, mapNode1);
412 modificationTree.delete(minMaxLeafFoo);
413 modificationTree.delete(minMaxLeafNel);
415 modificationTree.ready();
417 inMemoryDataTree.validate(modificationTree);
418 final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
419 inMemoryDataTree.commit(prepare);
421 final DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
422 final Optional<NormalizedNode> minMaxListRead = snapshotAfterCommit.readNode(MIN_MAX_LIST_NO_MINMAX_PATH);
424 // Empty list should have disappeared
425 assertFalse(minMaxListRead.isPresent());
428 private static void testLoop(final DataTreeSnapshot snapshot, final String first, final String second) {
429 Optional<NormalizedNode> minMaxListRead = snapshot.readNode(MIN_MAX_LIST_PATH);
430 assertTrue(minMaxListRead.isPresent());
431 assertEquals(2, ((NormalizedNodeContainer<?>) minMaxListRead.orElseThrow()).size());
433 for (Object collectionChild : (Collection<?>) minMaxListRead.orElseThrow().body()) {
434 if (collectionChild.toString().contains(first)) {
435 assertTrue(collectionChild.toString().contains(first));
437 assertTrue(collectionChild.toString().contains(second));