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