2782cafaad183661bca374b2bb997221b0673fb2
[yangtools.git] / data / yang-data-tree-ri / src / test / java / org / opendaylight / yangtools / yang / data / tree / impl / Bug5968MergeTest.java
1 /*
2  * Copyright (c) 2016 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.yangtools.yang.data.tree.impl;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.fail;
12
13 import com.google.common.collect.ImmutableMap;
14 import org.junit.AfterClass;
15 import org.junit.BeforeClass;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
21 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
22 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
23 import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
24 import org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder;
25 import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder;
26 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
27 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
28 import org.opendaylight.yangtools.yang.data.tree.api.DataTree;
29 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate;
30 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeConfiguration;
31 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification;
32 import org.opendaylight.yangtools.yang.data.tree.api.DataValidationFailedException;
33 import org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory;
34 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
35 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
36
37 public class Bug5968MergeTest {
38     private static final String NS = "bug5968";
39     private static final String REV = "2016-07-28";
40     private static final QName ROOT = QName.create(NS, REV, "root");
41     private static final QName MY_LIST = QName.create(NS, REV, "my-list");
42     private static final QName LIST_ID = QName.create(NS, REV, "list-id");
43     private static final QName MANDATORY_LEAF = QName.create(NS, REV, "mandatory-leaf");
44     private static final QName COMMON_LEAF = QName.create(NS, REV, "common-leaf");
45     private static EffectiveModelContext SCHEMA_CONTEXT;
46
47     @BeforeClass
48     public static void beforeClass() {
49         SCHEMA_CONTEXT = YangParserTestUtils.parseYang("""
50             module bug5968 {
51               yang-version 1;
52               namespace bug5968;
53               prefix bug5968;
54
55               revision 2016-07-28 {
56                 description "test";
57               }
58
59               container root {
60                 list my-list {
61                   key "list-id";
62                   leaf list-id {
63                     type string;
64                   }
65                   leaf mandatory-leaf {
66                     type string;
67                     mandatory true;
68                   }
69                   leaf common-leaf {
70                     type string;
71                   }
72                 }
73               }
74             }""");
75     }
76
77     @AfterClass
78     public static void afterClass() {
79         SCHEMA_CONTEXT = null;
80     }
81
82     private static DataTree initDataTree(final EffectiveModelContext schemaContext, final boolean withMapNode)
83             throws DataValidationFailedException {
84         final DataTree inMemoryDataTree = new InMemoryDataTreeFactory().create(
85                 DataTreeConfiguration.DEFAULT_CONFIGURATION, schemaContext);
86
87         final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> root = Builders.containerBuilder()
88                 .withNodeIdentifier(new NodeIdentifier(ROOT));
89         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
90         modificationTree.merge(YangInstanceIdentifier.of(ROOT),
91             withMapNode ? root.withChild(
92                 Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(MY_LIST)).build()).build()
93                 : root.build());
94         modificationTree.ready();
95
96         inMemoryDataTree.validate(modificationTree);
97         final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
98         inMemoryDataTree.commit(prepare);
99
100         return inMemoryDataTree;
101     }
102
103     private static DataTree emptyDataTree(final EffectiveModelContext schemaContext)
104             throws DataValidationFailedException {
105         return new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION, schemaContext);
106     }
107
108     @Test
109     public void mergeInvalidContainerTest() throws DataValidationFailedException {
110         final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
111
112         final SystemMapNode myList = createMap(true);
113         final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> root = Builders.containerBuilder()
114                 .withNodeIdentifier(new NodeIdentifier(ROOT)).withChild(myList);
115
116         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
117         modificationTree.merge(YangInstanceIdentifier.of(ROOT), root.build());
118
119         try {
120             modificationTree.ready();
121             inMemoryDataTree.validate(modificationTree);
122             final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
123             inMemoryDataTree.commit(prepare);
124             fail("Should fail due to missing mandatory leaf.");
125         } catch (final IllegalArgumentException e) {
126             assertEquals("Node (bug5968?revision=2016-07-28)my-list[{(bug5968?revision=2016-07-28)list-id=1}] is "
127                 + "missing mandatory descendant /(bug5968?revision=2016-07-28)mandatory-leaf", e.getMessage());
128         }
129     }
130
131     @Test
132     public void mergeInvalidMapTest() throws DataValidationFailedException {
133         final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
134         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
135         mergeMap(modificationTree, true);
136
137         try {
138             modificationTree.ready();
139             inMemoryDataTree.validate(modificationTree);
140             final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
141             inMemoryDataTree.commit(prepare);
142             fail("Should fail due to missing mandatory leaf.");
143         } catch (final IllegalArgumentException e) {
144             assertEquals("Node (bug5968?revision=2016-07-28)my-list[{(bug5968?revision=2016-07-28)list-id=1}] is "
145                 + "missing mandatory descendant /(bug5968?revision=2016-07-28)mandatory-leaf", e.getMessage());
146         }
147     }
148
149     @Test
150     public void mergeInvalidMapEntryTest() throws DataValidationFailedException {
151         final DataTree inMemoryDataTree = initDataTree(SCHEMA_CONTEXT, true);
152         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
153
154         mergeMapEntry(modificationTree, "1", null, "common-value");
155
156         try {
157             modificationTree.ready();
158             inMemoryDataTree.validate(modificationTree);
159             final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
160             inMemoryDataTree.commit(prepare);
161             fail("Should fail due to missing mandatory leaf.");
162         } catch (final IllegalArgumentException e) {
163             assertEquals("Node (bug5968?revision=2016-07-28)my-list[{(bug5968?revision=2016-07-28)list-id=1}] is "
164                 + "missing mandatory descendant /(bug5968?revision=2016-07-28)mandatory-leaf", e.getMessage());
165         }
166     }
167
168     private static void mergeMap(final DataTreeModification modificationTree,
169             final boolean mandatoryDataMissing) throws DataValidationFailedException {
170         modificationTree.merge(YangInstanceIdentifier.of(ROOT, MY_LIST), createMap(mandatoryDataMissing));
171     }
172
173     private static SystemMapNode createMap(final boolean mandatoryDataMissing) throws DataValidationFailedException {
174         return Builders.mapBuilder()
175             .withNodeIdentifier(new NodeIdentifier(MY_LIST))
176             .withChild(mandatoryDataMissing ? createMapEntry("1", "common-value")
177                 : createMapEntry("1", "mandatory-value", "common-value"))
178             .build();
179     }
180
181     private static void mergeMapEntry(final DataTreeModification modificationTree, final Object listIdValue,
182             final Object mandatoryLeafValue, final Object commonLeafValue) throws DataValidationFailedException {
183         final MapEntryNode taskEntryNode = mandatoryLeafValue == null ? createMapEntry(listIdValue, commonLeafValue)
184                 : createMapEntry(listIdValue, mandatoryLeafValue, commonLeafValue);
185
186         modificationTree.merge(
187             YangInstanceIdentifier.of(ROOT, MY_LIST)
188                 .node(NodeIdentifierWithPredicates.of(MY_LIST, LIST_ID, listIdValue)),
189             taskEntryNode);
190     }
191
192     private static MapEntryNode createMapEntry(final Object listIdValue, final Object mandatoryLeafValue,
193             final Object commonLeafValue) throws DataValidationFailedException {
194         return Builders.mapEntryBuilder()
195                 .withNodeIdentifier(NodeIdentifierWithPredicates.of(MY_LIST, LIST_ID, listIdValue))
196                 .withChild(ImmutableNodes.leafNode(LIST_ID, listIdValue))
197                 .withChild(ImmutableNodes.leafNode(MANDATORY_LEAF, mandatoryLeafValue))
198                 .withChild(ImmutableNodes.leafNode(COMMON_LEAF, commonLeafValue)).build();
199     }
200
201     private static MapEntryNode createMapEntry(final Object listIdValue, final Object commonLeafValue)
202             throws DataValidationFailedException {
203         return Builders.mapEntryBuilder()
204                 .withNodeIdentifier(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, listIdValue)))
205                 .withChild(ImmutableNodes.leafNode(LIST_ID, listIdValue))
206                 .withChild(ImmutableNodes.leafNode(COMMON_LEAF, commonLeafValue)).build();
207     }
208
209     private static MapEntryNode createMapEntryM(final Object listIdValue, final Object mandatoryLeafValue)
210             throws DataValidationFailedException {
211         return Builders.mapEntryBuilder()
212                 .withNodeIdentifier(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, listIdValue)))
213                 .withChild(ImmutableNodes.leafNode(LIST_ID, listIdValue))
214                 .withChild(ImmutableNodes.leafNode(MANDATORY_LEAF, mandatoryLeafValue)).build();
215     }
216
217     @Test
218     public void mergeValidContainerTest() throws DataValidationFailedException {
219         final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
220
221         final SystemMapNode myList = createMap(false);
222         final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> root = Builders.containerBuilder()
223                 .withNodeIdentifier(new NodeIdentifier(ROOT)).withChild(myList);
224
225         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
226         modificationTree.merge(YangInstanceIdentifier.of(ROOT), root.build());
227         modificationTree.ready();
228         inMemoryDataTree.validate(modificationTree);
229         final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
230         inMemoryDataTree.commit(prepare);
231     }
232
233     @Test
234     public void mergeValidMapTest() throws DataValidationFailedException {
235         final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
236         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
237         mergeMap(modificationTree, false);
238
239         modificationTree.ready();
240         inMemoryDataTree.validate(modificationTree);
241         final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
242         inMemoryDataTree.commit(prepare);
243     }
244
245     @Test
246     public void mergeValidMapEntryTest() throws DataValidationFailedException {
247         final DataTree inMemoryDataTree = initDataTree(SCHEMA_CONTEXT, true);
248         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
249
250         mergeMapEntry(modificationTree, "1", "mandatory-value", "common-value");
251
252         modificationTree.ready();
253         inMemoryDataTree.validate(modificationTree);
254         final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
255         inMemoryDataTree.commit(prepare);
256     }
257
258     @Test
259     public void validMultiStepsMergeTest() throws DataValidationFailedException {
260         final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
261         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
262
263         modificationTree.merge(YangInstanceIdentifier.of(ROOT), createContainerBuilder().build());
264         modificationTree.merge(YangInstanceIdentifier.of(ROOT, MY_LIST), createMapBuilder().build());
265         modificationTree.merge(
266             YangInstanceIdentifier.of(ROOT, MY_LIST).node(NodeIdentifierWithPredicates.of(MY_LIST, LIST_ID, "1")),
267             createEmptyMapEntryBuilder("1").build());
268         modificationTree.merge(
269             YangInstanceIdentifier.of(ROOT, MY_LIST).node(NodeIdentifierWithPredicates.of(MY_LIST, LIST_ID, "1")),
270             createMapEntry("1", "mandatory-value", "common-value"));
271
272         modificationTree.ready();
273         inMemoryDataTree.validate(modificationTree);
274         final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
275         inMemoryDataTree.commit(prepare);
276     }
277
278     @Test
279     public void invalidMultiStepsMergeTest() throws DataValidationFailedException {
280         final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
281         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
282
283         modificationTree.merge(YangInstanceIdentifier.of(ROOT), createContainerBuilder().build());
284         modificationTree.merge(YangInstanceIdentifier.of(ROOT, MY_LIST), createMapBuilder().build());
285         modificationTree.merge(
286             YangInstanceIdentifier.of(ROOT, MY_LIST).node(NodeIdentifierWithPredicates.of(MY_LIST, LIST_ID, "1")),
287             createEmptyMapEntryBuilder("1").build());
288         modificationTree.merge(
289             YangInstanceIdentifier.of(ROOT, MY_LIST).node(NodeIdentifierWithPredicates.of(MY_LIST, LIST_ID, "1")),
290             createMapEntry("1", "common-value"));
291
292         try {
293             modificationTree.ready();
294             inMemoryDataTree.validate(modificationTree);
295             final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
296             inMemoryDataTree.commit(prepare);
297             fail("Should fail due to missing mandatory leaf.");
298         } catch (final IllegalArgumentException e) {
299             assertEquals("Node (bug5968?revision=2016-07-28)my-list[{(bug5968?revision=2016-07-28)list-id=1}] is "
300                 + "missing mandatory descendant /(bug5968?revision=2016-07-28)mandatory-leaf", e.getMessage());
301         }
302     }
303
304     private static DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> createEmptyMapEntryBuilder(
305             final Object listIdValue) throws DataValidationFailedException {
306         return Builders.mapEntryBuilder()
307                 .withNodeIdentifier(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, listIdValue)))
308                 .withChild(ImmutableNodes.leafNode(LIST_ID, listIdValue));
309     }
310
311     private static CollectionNodeBuilder<MapEntryNode, SystemMapNode> createMapBuilder() {
312         return Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(MY_LIST));
313     }
314
315     private static DataContainerNodeBuilder<NodeIdentifier, ContainerNode> createContainerBuilder() {
316         return Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(ROOT));
317     }
318
319     @Test
320     public void validMultiStepsWriteAndMergeTest() throws DataValidationFailedException {
321         final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
322         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
323
324         modificationTree.write(YangInstanceIdentifier.of(ROOT), createContainerBuilder().build());
325         modificationTree.merge(YangInstanceIdentifier.of(ROOT).node(MY_LIST), createMapBuilder().build());
326         modificationTree.merge(
327                 YangInstanceIdentifier.of(ROOT).node(MY_LIST)
328                         .node(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, "1"))),
329                 createEmptyMapEntryBuilder("1").build());
330         modificationTree.merge(
331                 YangInstanceIdentifier.of(ROOT).node(MY_LIST)
332                         .node(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, "1"))),
333                 createMapEntry("1", "mandatory-value", "common-value"));
334
335         modificationTree.ready();
336         inMemoryDataTree.validate(modificationTree);
337         final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
338         inMemoryDataTree.commit(prepare);
339     }
340
341     @Test
342     public void invalidMultiStepsWriteAndMergeTest() throws DataValidationFailedException {
343         final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
344         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
345
346         modificationTree.write(YangInstanceIdentifier.of(ROOT), createContainerBuilder().build());
347         modificationTree.merge(YangInstanceIdentifier.of(ROOT).node(MY_LIST), createMapBuilder().build());
348         modificationTree.merge(
349                 YangInstanceIdentifier.of(ROOT).node(MY_LIST)
350                         .node(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, "1"))),
351                 createEmptyMapEntryBuilder("1").build());
352         modificationTree.merge(
353                 YangInstanceIdentifier.of(ROOT).node(MY_LIST)
354                         .node(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, "1"))),
355                 createMapEntry("1", "common-value"));
356
357         try {
358             modificationTree.ready();
359             inMemoryDataTree.validate(modificationTree);
360             final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
361             inMemoryDataTree.commit(prepare);
362             fail("Should fail due to missing mandatory leaf.");
363         } catch (final IllegalArgumentException e) {
364             assertEquals("Node (bug5968?revision=2016-07-28)my-list[{(bug5968?revision=2016-07-28)list-id=1}] is "
365                 + "missing mandatory descendant /(bug5968?revision=2016-07-28)mandatory-leaf", e.getMessage());
366         }
367     }
368
369     @Test
370     public void validMapEntryMultiCommitMergeTest() throws DataValidationFailedException {
371         final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
372         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
373
374         modificationTree.write(YangInstanceIdentifier.of(ROOT), createContainerBuilder().build());
375         modificationTree.merge(YangInstanceIdentifier.of(ROOT).node(MY_LIST), createMapBuilder().build());
376         modificationTree.merge(
377                 YangInstanceIdentifier.of(ROOT).node(MY_LIST)
378                         .node(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, "1"))),
379                 createEmptyMapEntryBuilder("1").build());
380         modificationTree.merge(
381                 YangInstanceIdentifier.of(ROOT).node(MY_LIST)
382                         .node(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, "1"))),
383                 createMapEntryM("1", "mandatory-value"));
384
385         modificationTree.ready();
386         inMemoryDataTree.validate(modificationTree);
387         final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
388         inMemoryDataTree.commit(prepare);
389
390         final DataTreeModification modificationTree2 = inMemoryDataTree.takeSnapshot().newModification();
391         modificationTree2.merge(
392                 YangInstanceIdentifier.of(ROOT).node(MY_LIST)
393                         .node(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, "1"))),
394                 createMapEntry("1", "common-value"));
395         modificationTree2.ready();
396         inMemoryDataTree.validate(modificationTree2);
397         final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
398         inMemoryDataTree.commit(prepare2);
399     }
400
401     @Test
402     public void invalidMapEntryMultiCommitMergeTest() throws DataValidationFailedException {
403         final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
404         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
405
406         modificationTree.write(YangInstanceIdentifier.of(ROOT), createContainerBuilder().build());
407         modificationTree.merge(YangInstanceIdentifier.of(ROOT).node(MY_LIST), createMapBuilder().build());
408         modificationTree.merge(
409                 YangInstanceIdentifier.of(ROOT).node(MY_LIST)
410                         .node(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, "1"))),
411                 createEmptyMapEntryBuilder("1").build());
412         modificationTree.merge(
413                 YangInstanceIdentifier.of(ROOT).node(MY_LIST)
414                         .node(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, "1"))),
415                 createMapEntryM("1", "mandatory-value"));
416
417         modificationTree.ready();
418         inMemoryDataTree.validate(modificationTree);
419         final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
420         inMemoryDataTree.commit(prepare);
421
422         final DataTreeModification modificationTree2 = inMemoryDataTree.takeSnapshot().newModification();
423         modificationTree2.write(
424                 YangInstanceIdentifier.of(ROOT).node(MY_LIST)
425                         .node(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, "1"))),
426                 createMapEntry("1", "common-value"));
427         modificationTree2.merge(
428                 YangInstanceIdentifier.of(ROOT).node(MY_LIST)
429                         .node(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, "1"))),
430                 createMapEntryM("1", "mandatory-value"));
431         modificationTree2.merge(
432                 YangInstanceIdentifier.of(ROOT).node(MY_LIST)
433                         .node(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, "2"))),
434                 createMapEntry("2", "common-value"));
435         try {
436             modificationTree2.ready();
437             inMemoryDataTree.validate(modificationTree2);
438             final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
439             inMemoryDataTree.commit(prepare2);
440             fail("Should fail due to missing mandatory leaf.");
441         } catch (final IllegalArgumentException e) {
442             assertEquals("Node (bug5968?revision=2016-07-28)my-list[{(bug5968?revision=2016-07-28)list-id=2}] is "
443                 + "missing mandatory descendant /(bug5968?revision=2016-07-28)mandatory-leaf", e.getMessage());
444         }
445     }
446
447     /*
448      * This test consists of two transactions (i.e. data tree modifications) on
449      * empty data tree. The first one writes mandatory data and second one
450      * writes common data without any mandatory data.
451      */
452     @Test
453     public void validMapEntryMultiCommitMergeTest2() throws DataValidationFailedException {
454         final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
455         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
456         final DataTreeModification modificationTree2 = inMemoryDataTree.takeSnapshot().newModification();
457
458         modificationTree.write(YangInstanceIdentifier.of(ROOT), createContainerBuilder().build());
459         modificationTree.merge(YangInstanceIdentifier.of(ROOT).node(MY_LIST), createMapBuilder().build());
460         modificationTree.merge(
461                 YangInstanceIdentifier.of(ROOT).node(MY_LIST)
462                         .node(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, "1"))),
463                 createEmptyMapEntryBuilder("1").build());
464         modificationTree.merge(
465                 YangInstanceIdentifier.of(ROOT).node(MY_LIST)
466                         .node(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, "1"))),
467                 createMapEntryM("1", "mandatory-value"));
468
469         modificationTree.ready();
470         inMemoryDataTree.validate(modificationTree);
471         final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
472         inMemoryDataTree.commit(prepare);
473
474         modificationTree2.merge(
475                 YangInstanceIdentifier.of(ROOT).node(MY_LIST)
476                         .node(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, "1"))),
477                 createMapEntry("1", "common-value"));
478         modificationTree2.ready();
479         inMemoryDataTree.validate(modificationTree2);
480         final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
481         inMemoryDataTree.commit(prepare2);
482     }
483 }