Fix slf4j usage errors found by checkstyle-logging
[yangtools.git] / yang / yang-data-impl / src / test / java / org / opendaylight / yangtools / yang / data / impl / leafref / context / DataTreeCandidateValidatorTest.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.leafref.context;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
12
13 import java.util.HashMap;
14 import java.util.Map;
15 import java.util.Set;
16 import org.apache.log4j.BasicConfigurator;
17 import org.junit.BeforeClass;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.common.QNameModule;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
23 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
25 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
26 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
27 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
28 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
29 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
30 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
31 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
32 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
33 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
34 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
35 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
36 import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContext;
37 import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefDataValidationFailedException;
38 import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefValidatation;
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.impl.schema.builder.api.CollectionNodeBuilder;
42 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
43 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
44 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
45 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeAttrBuilder;
46 import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
47 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
48 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
49 import org.opendaylight.yangtools.yang.model.api.Module;
50 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
51 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
52 import org.slf4j.Logger;
53 import org.slf4j.LoggerFactory;
54
55 public class DataTreeCandidateValidatorTest {
56
57     private static SchemaContext context;
58     private static Module valModule;
59     private static QNameModule valModuleQname;
60     private static LeafRefContext rootLeafRefContext;
61     public static DataTree inMemoryDataTree;
62
63     private static QName odl;
64     private static QName project;
65     private static QName name;
66     private static QName desc;
67     private static QName lead;
68     private static QName owner;
69     private static QName odlContributor;
70     private static QName contributor;
71     private static QName odlProjectName;
72     private static QName odlProjectDesc;
73     private static QName login;
74     private static QName contributorName;
75     private static QName l1;
76     private static QName l2;
77     private static QName con1;
78     private static QName ch1;
79     private static QName ch2;
80     private static QName leafrefInChoice;
81     private static QName listInChoice;
82
83     private static QName leafrefInChoiceToChoice;
84     private static QName con3;
85     private static QName list3InChoice;
86     private static QName l3;
87     private static QName choiceInCon3;
88
89     private static QName listInChoiceKey;
90     private static QName k;
91
92     private static QName leafrefLeafList;
93
94     private static final Logger LOG = LoggerFactory.getLogger(DataTreeCandidateValidatorTest.class);
95     private static final String NEW_LINE = System.getProperty("line.separator");
96
97     static {
98         BasicConfigurator.configure();
99     }
100
101     @BeforeClass
102     public static void init()  {
103         initSchemaContext();
104
105         initLeafRefContext();
106
107         initQnames();
108
109         initDataTree();
110
111     }
112
113     private static void initSchemaContext() {
114         context = YangParserTestUtils.parseYangResourceDirectory("/leafref-validation");
115
116         final Set<Module> modules = context.getModules();
117         for (final Module module : modules) {
118             if (module.getName().equals("leafref-validation")) {
119                 valModule = module;
120             }
121         }
122
123         valModuleQname = valModule.getQNameModule();
124     }
125
126     private static void initLeafRefContext() {
127         rootLeafRefContext = LeafRefContext.create(context);
128     }
129
130     private static void initQnames() {
131         odl = QName.create(valModuleQname, "odl-project");
132         project = QName.create(valModuleQname, "project");
133         name = QName.create(valModuleQname, "name");
134         desc = QName.create(valModuleQname, "desc");
135         lead = QName.create(valModuleQname, "project-lead");
136         owner = QName.create(valModuleQname, "project-owner");
137
138         odlContributor = QName.create(valModuleQname, "odl-contributor");
139         contributor = QName.create(valModuleQname, "contributor");
140         odlProjectName = QName.create(valModuleQname, "odl-project-name");
141         login = QName.create(valModuleQname, "login");
142         contributorName = QName.create(valModuleQname, "contributor-name");
143
144         con1 = QName.create(valModuleQname, "con1");
145         l1 = QName.create(valModuleQname, "l1");
146         l2 = QName.create(valModuleQname, "l2");
147         odlProjectDesc = QName.create(valModuleQname, "odl-project-desc");
148
149         ch1 = QName.create(valModuleQname, "ch1");
150         ch2 = QName.create(valModuleQname, "ch2");
151         leafrefInChoice = QName.create(valModuleQname, "leafref-in-choice");
152         listInChoice = QName.create(valModuleQname, "list-in-choice");
153
154         leafrefInChoiceToChoice = QName.create(valModuleQname,
155                 "leafref-in-choice-to-choice");
156         con3 = QName.create(valModuleQname, "con3");
157         list3InChoice = QName.create(valModuleQname, "list3-in-choice");
158         l3 = QName.create(valModuleQname, "l3");
159         choiceInCon3 = QName.create(valModuleQname, "choice-in-con3");
160
161         listInChoiceKey = QName.create(valModuleQname, "list-in-choice-key");
162         k = QName.create(valModuleQname, "k");
163
164         leafrefLeafList = QName.create(valModuleQname, "leafref-leaf-list");
165
166     }
167
168     private static void initDataTree() {
169         inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, context);
170
171         final DataTreeModification initialDataTreeModification = inMemoryDataTree
172                 .takeSnapshot().newModification();
173
174         final ContainerSchemaNode odlProjContSchemaNode = (ContainerSchemaNode) valModule
175                 .getDataChildByName(odl);
176
177         final ContainerNode odlProjectContainer = createOdlContainer(odlProjContSchemaNode);
178
179         final YangInstanceIdentifier path = YangInstanceIdentifier.of(odl);
180         initialDataTreeModification.write(path, odlProjectContainer);
181         initialDataTreeModification.ready();
182
183         final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
184                 .prepare(initialDataTreeModification);
185         inMemoryDataTree.commit(writeContributorsCandidate);
186     }
187
188     @Test
189     public void dataTreeCanditateValidationTest() {
190         write();
191
192         write2();
193
194         delete();
195
196         writeContributors();
197
198         writeMapEntry();
199
200         writeIntoMapEntry();
201     }
202
203     private static void writeContributors() {
204
205         final ContainerSchemaNode contributorContSchemaNode = (ContainerSchemaNode) valModule
206                 .getDataChildByName(odlContributor);
207
208         final ContainerNode contributorContainer = createBasicContributorContainer(contributorContSchemaNode);
209
210         final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
211                 .of(odlContributor);
212         final DataTreeModification writeModification = inMemoryDataTree
213                 .takeSnapshot().newModification();
214         writeModification.write(contributorPath, contributorContainer);
215         writeModification.ready();
216
217         final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
218                 .prepare(writeModification);
219
220         LOG.debug("*************************");
221         LOG.debug("Before write of contributors: ");
222         LOG.debug("*************************");
223         LOG.debug(inMemoryDataTree.toString());
224
225         boolean exception = false;
226         try {
227             LeafRefValidatation.validate(writeContributorsCandidate,
228                     rootLeafRefContext);
229         } catch (final LeafRefDataValidationFailedException e) {
230             LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
231             assertEquals(3, e.getValidationsErrorsCount());
232             exception = true;
233         }
234
235         inMemoryDataTree.commit(writeContributorsCandidate);
236
237         LOG.debug("*************************");
238         LOG.debug("After write of contributors: ");
239         LOG.debug("*************************");
240         LOG.debug(inMemoryDataTree.toString());
241
242         assertTrue(exception);
243
244     }
245
246     private static void writeIntoMapEntry() {
247
248         final Map<QName, Object> keys = new HashMap<>();
249         keys.put(name, "New Project");
250         final NodeIdentifierWithPredicates mapEntryPath = new NodeIdentifierWithPredicates(
251                 project, keys);
252
253         final YangInstanceIdentifier leaderPath = YangInstanceIdentifier
254                 .of(odl).node(project).node(mapEntryPath).node(lead);
255
256         final LeafNode<String> leader = ImmutableNodes.leafNode(lead,
257                 "Updated leader");
258
259         final DataTreeModification writeModification = inMemoryDataTree
260                 .takeSnapshot().newModification();
261         writeModification.write(leaderPath, leader);
262         writeModification.ready();
263
264         final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
265                 .prepare(writeModification);
266
267         LOG.debug("*************************");
268         LOG.debug("Before write into map entry (update of leader name): ");
269         LOG.debug("*************************");
270         LOG.debug(inMemoryDataTree.toString());
271
272         boolean exception = false;
273         try {
274             LeafRefValidatation.validate(writeContributorsCandidate,
275                     rootLeafRefContext);
276         } catch (final LeafRefDataValidationFailedException e) {
277             LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
278             assertEquals(1, e.getValidationsErrorsCount());
279             exception = true;
280         }
281
282         inMemoryDataTree.commit(writeContributorsCandidate);
283
284         LOG.debug("*************************");
285         LOG.debug("After write into map entry (update of leader name): ");
286         LOG.debug("*************************");
287         LOG.debug(inMemoryDataTree.toString());
288
289         assertTrue(exception);
290
291     }
292
293     private static void writeMapEntry() {
294
295         final Map<QName, Object> keys = new HashMap<>();
296         keys.put(name, "New Project");
297         final NodeIdentifierWithPredicates mapEntryPath = new NodeIdentifierWithPredicates(
298                 project, keys);
299
300         final YangInstanceIdentifier newOdlProjectMapEntryPath = YangInstanceIdentifier
301                 .of(odl).node(project).node(mapEntryPath);
302
303         final ContainerSchemaNode odlProjContSchemaNode = (ContainerSchemaNode) valModule
304                 .getDataChildByName(odl);
305         final ListSchemaNode projListSchemaNode = (ListSchemaNode) odlProjContSchemaNode
306                 .getDataChildByName(project);
307         final MapEntryNode newProjectMapEntry = createProjectListEntry(
308                 "New Project", "New Project description ...",
309                 "Leader of New Project", "Owner of New Project",
310                 projListSchemaNode);
311
312         final DataTreeModification writeModification = inMemoryDataTree
313                 .takeSnapshot().newModification();
314         writeModification.write(newOdlProjectMapEntryPath, newProjectMapEntry);
315         writeModification.ready();
316
317         final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
318                 .prepare(writeModification);
319
320         LOG.debug("*************************");
321         LOG.debug("Before map entry write: ");
322         LOG.debug("*************************");
323         LOG.debug(inMemoryDataTree.toString());
324
325         boolean exception = false;
326         try {
327             LeafRefValidatation.validate(writeContributorsCandidate,
328                     rootLeafRefContext);
329         } catch (final LeafRefDataValidationFailedException e) {
330             LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
331             assertEquals(2, e.getValidationsErrorsCount());
332             exception = true;
333         }
334
335         inMemoryDataTree.commit(writeContributorsCandidate);
336
337         LOG.debug("*************************");
338         LOG.debug("After map entry write: ");
339         LOG.debug("*************************");
340         LOG.debug(inMemoryDataTree.toString());
341
342         assertTrue(exception);
343
344     }
345
346     private static void write() {
347
348         final ContainerSchemaNode contributorContSchemaNode = (ContainerSchemaNode) valModule
349                 .getDataChildByName(odlContributor);
350
351         final ContainerNode contributorContainer = createContributorContainer(contributorContSchemaNode);
352
353         final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
354                 .of(odlContributor);
355         final DataTreeModification writeModification = inMemoryDataTree
356                 .takeSnapshot().newModification();
357         writeModification.write(contributorPath, contributorContainer);
358
359         writeModification.write(YangInstanceIdentifier.of(l1),
360                 ImmutableNodes.leafNode(l1, "Leafref l1 under the root"));
361         writeModification
362                 .write(YangInstanceIdentifier.of(l2), ImmutableNodes.leafNode(
363                         l2, "Leafref target l2 under the root"));
364
365         writeModification.ready();
366         final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
367                 .prepare(writeModification);
368
369         LOG.debug("*************************");
370         LOG.debug("Before write: ");
371         LOG.debug("*************************");
372         LOG.debug(inMemoryDataTree.toString());
373
374         boolean exception = false;
375         try {
376             LeafRefValidatation.validate(writeContributorsCandidate,
377                     rootLeafRefContext);
378         } catch (final LeafRefDataValidationFailedException e) {
379             LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
380             assertEquals(12, e.getValidationsErrorsCount());
381             exception = true;
382         }
383
384         inMemoryDataTree.commit(writeContributorsCandidate);
385
386         LOG.debug("*************************");
387         LOG.debug("After write: ");
388         LOG.debug("*************************");
389         LOG.debug(inMemoryDataTree.toString());
390
391         assertTrue(exception);
392     }
393
394     private static void write2() {
395
396         final ContainerSchemaNode odlCon = (ContainerSchemaNode) valModule
397                 .getDataChildByName(odl);
398         final ContainerSchemaNode con1Con = (ContainerSchemaNode) odlCon
399                 .getDataChildByName(con1);
400         final LeafNode<String> l1Leaf = ImmutableNodes.leafNode(l1, "l1 value");
401         final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> containerBuilder = Builders
402                 .containerBuilder(con1Con);
403         containerBuilder.addChild(l1Leaf);
404         final ContainerNode con1Node = containerBuilder.build();
405
406         final YangInstanceIdentifier con1Path = YangInstanceIdentifier.of(odl)
407                 .node(con1);
408         final DataTreeModification writeModification = inMemoryDataTree
409                 .takeSnapshot().newModification();
410         writeModification.write(con1Path, con1Node);
411
412         final ChoiceNode choiceNode = createChoiceNode();
413         final YangInstanceIdentifier choicePath = YangInstanceIdentifier
414                 .of(odl).node(ch1);
415         writeModification.write(choicePath, choiceNode);
416
417         final ContainerNode con3Node = createCon3Node();
418         final YangInstanceIdentifier con3Path = YangInstanceIdentifier.of(odl)
419                 .node(con3);
420         writeModification.write(con3Path, con3Node);
421
422         final LeafSetNode<?> leafListNode = createLeafRefLeafListNode();
423         final YangInstanceIdentifier leafListPath = YangInstanceIdentifier.of(
424                 odl).node(leafrefLeafList);
425         writeModification.write(leafListPath, leafListNode);
426         writeModification.ready();
427
428         final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
429                 .prepare(writeModification);
430
431         LOG.debug("*************************");
432         LOG.debug("Before write2: ");
433         LOG.debug("*************************");
434         LOG.debug(inMemoryDataTree.toString());
435
436         boolean exception = false;
437         try {
438             LeafRefValidatation.validate(writeContributorsCandidate,
439                     rootLeafRefContext);
440         } catch (final LeafRefDataValidationFailedException e) {
441             LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
442             assertEquals(6, e.getValidationsErrorsCount());
443             exception = true;
444         }
445
446         assertTrue(exception);
447
448         inMemoryDataTree.commit(writeContributorsCandidate);
449
450         LOG.debug("*************************");
451         LOG.debug("After write2: ");
452         LOG.debug("*************************");
453         LOG.debug(inMemoryDataTree.toString());
454
455     }
456
457     private static LeafSetNode<?> createLeafRefLeafListNode() {
458
459         final ListNodeBuilder<Object, LeafSetEntryNode<Object>> leafSetBuilder = Builders
460                 .leafSetBuilder();
461         leafSetBuilder.withNodeIdentifier(new NodeIdentifier(leafrefLeafList));
462
463         leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k1"));
464         leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k2"));
465         leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k3"));
466
467         return leafSetBuilder.build();
468     }
469
470     private static ContainerNode createCon3Node() {
471
472         final CollectionNodeBuilder<MapEntryNode, MapNode> mapBuilder = Builders
473                 .mapBuilder();
474         mapBuilder.withNodeIdentifier(new NodeIdentifier(list3InChoice));
475
476         mapBuilder.addChild(createList3Entry("k1", "val1", "valA", "valX"));
477         mapBuilder.addChild(createList3Entry("k2", "val2", "valB", "valY"));
478
479         final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choiceBuilder = Builders
480                 .choiceBuilder();
481         choiceBuilder.withNodeIdentifier(new NodeIdentifier(choiceInCon3));
482
483         choiceBuilder.addChild(mapBuilder.build());
484
485         final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> containerBuilder = Builders
486                 .containerBuilder();
487         containerBuilder.withNodeIdentifier(new NodeIdentifier(con3));
488
489         containerBuilder.addChild(choiceBuilder.build());
490
491         return containerBuilder.build();
492     }
493
494     private static MapEntryNode createList3Entry(final String keyVal,
495             final String l3Val1, final String l3Val2, final String l3Val3) {
496         final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder = Builders
497                 .mapEntryBuilder();
498         mapEntryBuilder.withNodeIdentifier(new NodeIdentifierWithPredicates(
499                 list3InChoice, k, keyVal));
500
501         final ListNodeBuilder<Object, LeafSetEntryNode<Object>> leafSetBuilder = Builders
502                 .leafSetBuilder();
503         leafSetBuilder.withNodeIdentifier(new NodeIdentifier(l3));
504
505         leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val1));
506         leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val2));
507         leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val3));
508
509         mapEntryBuilder.addChild(ImmutableNodes.leafNode(k, keyVal));
510         mapEntryBuilder.addChild(leafSetBuilder.build());
511
512         return mapEntryBuilder.build();
513     }
514
515     private static LeafSetEntryNode<Object> createLeafSetEntry(
516             final QName qname, final String val) {
517         final NormalizedNodeAttrBuilder<NodeWithValue, Object, LeafSetEntryNode<Object>> leafSetEntryBuilder = Builders
518                 .leafSetEntryBuilder();
519         leafSetEntryBuilder.withNodeIdentifier(new NodeWithValue<>(qname, val));
520         leafSetEntryBuilder.withValue(val);
521         return leafSetEntryBuilder.build();
522     }
523
524     private static ChoiceNode createChoiceNode() {
525
526         final CollectionNodeBuilder<MapEntryNode, MapNode> listInChoiceBuilder = Builders
527                 .mapBuilder();
528         listInChoiceBuilder
529                 .withNodeIdentifier(new NodeIdentifier(listInChoice));
530
531         listInChoiceBuilder.addChild(createListInChoiceEntry("key1",
532                 "leafref-in-choice value", "val1"));
533         listInChoiceBuilder.addChild(createListInChoiceEntry("key2",
534                 "l1 value", "val2"));
535         listInChoiceBuilder.addChild(createListInChoiceEntry("key3",
536                 "l1 value", "val3"));
537
538         final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choice2Builder = Builders
539                 .choiceBuilder();
540         choice2Builder.withNodeIdentifier(new NodeIdentifier(ch2));
541
542         choice2Builder.addChild(listInChoiceBuilder.build());
543
544         final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choiceBuilder = Builders
545                 .choiceBuilder();
546         choiceBuilder.withNodeIdentifier(new NodeIdentifier(ch1));
547         choiceBuilder.addChild(choice2Builder.build());
548
549         return choiceBuilder.build();
550     }
551
552     private static MapEntryNode createListInChoiceEntry(final String keyVal,
553             final String leafrefInChoiceVal,
554             final String leafrefInChoiceToChoiceVal) {
555
556         final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder = Builders
557                 .mapEntryBuilder();
558
559         mapEntryBuilder.withNodeIdentifier(new NodeIdentifierWithPredicates(
560                 listInChoice, listInChoiceKey, keyVal));
561
562         mapEntryBuilder.addChild(ImmutableNodes.leafNode(listInChoiceKey,
563                 keyVal));
564         mapEntryBuilder.addChild(ImmutableNodes.leafNode(leafrefInChoice,
565                 leafrefInChoiceVal));
566         mapEntryBuilder.addChild(ImmutableNodes.leafNode(
567                 leafrefInChoiceToChoice, leafrefInChoiceToChoiceVal));
568
569         return mapEntryBuilder.build();
570     }
571
572     private static void delete() {
573
574         final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
575                 .of(odlContributor);
576         final DataTreeModification delete = inMemoryDataTree.takeSnapshot()
577                 .newModification();
578         delete.delete(contributorPath);
579         delete.ready();
580
581         final DataTreeCandidate deleteContributorsCanditate = inMemoryDataTree
582                 .prepare(delete);
583
584         LOG.debug("*************************");
585         LOG.debug("Before delete: ");
586         LOG.debug("*************************");
587         LOG.debug(inMemoryDataTree.toString());
588
589         boolean exception = false;
590         try {
591             LeafRefValidatation.validate(deleteContributorsCanditate,
592                     rootLeafRefContext);
593         } catch (final LeafRefDataValidationFailedException e) {
594             LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
595             assertEquals(6, e.getValidationsErrorsCount());
596             exception = true;
597         }
598
599         assertTrue(exception);
600
601         inMemoryDataTree.commit(deleteContributorsCanditate);
602
603         LOG.debug("*************************");
604         LOG.debug("After delete: ");
605         LOG.debug("*************************");
606         LOG.debug(inMemoryDataTree.toString());
607
608     }
609
610     private static ContainerNode createContributorContainer(
611             final ContainerSchemaNode contributorContSchemaNode) {
612
613         final ListSchemaNode contributorListSchemaNode = (ListSchemaNode) contributorContSchemaNode
614                 .getDataChildByName(contributor);
615
616         final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> contributorContainerBldr = Builders
617                 .containerBuilder(contributorContSchemaNode);
618
619         final MapNode contributorMap = createContributorList(contributorListSchemaNode);
620         contributorContainerBldr.addChild(contributorMap);
621
622         final ContainerNode contributorContainer = contributorContainerBldr
623                 .build();
624
625         return contributorContainer;
626
627     }
628
629     private static MapNode createContributorList(
630             final ListSchemaNode contributorListSchemaNode) {
631
632         final CollectionNodeBuilder<MapEntryNode, MapNode> contributorMapBldr = Builders
633                 .mapBuilder(contributorListSchemaNode);
634
635         final MapEntryNode contributorMapEntry1 = createContributorListEntry(
636                 "Leader of Yangtools", "Yangtools Leader name", "Yangtools",
637                 "Yangtools description ...", contributorListSchemaNode);
638         final MapEntryNode contributorMapEntry2 = createContributorListEntry(
639                 "Leader of MD-SAL", "MD-SAL Leader name", "MD-SAL",
640                 "MD-SAL description ...", contributorListSchemaNode);
641         final MapEntryNode contributorMapEntry3 = createContributorListEntry(
642                 "Leader of Controller", "Controller Leader name", "Controller",
643                 "Controller description ...", contributorListSchemaNode);
644
645         final MapEntryNode contributorMapEntry4 = createContributorListEntry(
646                 "jdoe", "John Doe", "MD-SAL", "Yangtools description ...",
647                 contributorListSchemaNode);
648
649         final MapEntryNode contributorMapEntry5 = createContributorListEntry(
650                 "foo", "foo name", "Controller", "MD-SAL description ...",
651                 contributorListSchemaNode);
652
653         final MapEntryNode contributorMapEntry6 = createContributorListEntry(
654                 "bar", "bar name", "Yangtools", "Controller description ...",
655                 contributorListSchemaNode);
656
657         final MapEntryNode contributorMapEntry7 = createContributorListEntry(
658                 "baz", "baz name", "Unknown Project",
659                 "Unknown Project description ...", contributorListSchemaNode);
660
661         final MapEntryNode contributorMapEntry8 = createContributorListEntry(
662                 "pk", "pk name", "Unknown Project 2",
663                 "Controller description ...", contributorListSchemaNode);
664
665         contributorMapBldr.addChild(contributorMapEntry1);
666         contributorMapBldr.addChild(contributorMapEntry2);
667         contributorMapBldr.addChild(contributorMapEntry3);
668         contributorMapBldr.addChild(contributorMapEntry4);
669         contributorMapBldr.addChild(contributorMapEntry5);
670         contributorMapBldr.addChild(contributorMapEntry6);
671         contributorMapBldr.addChild(contributorMapEntry7);
672         contributorMapBldr.addChild(contributorMapEntry8);
673
674         final MapNode contributorMap = contributorMapBldr.build();
675
676         return contributorMap;
677
678     }
679
680     private static MapEntryNode createContributorListEntry(
681             final String loginVal, final String contributorNameVal,
682             final String odlProjectNameVal, final String odlProjectDescVal,
683             final ListSchemaNode contributorListSchemaNode) {
684
685         final LeafNode<String> loginLeaf = ImmutableNodes.leafNode(login,
686                 loginVal);
687         final LeafNode<String> contributorNameLeaf = ImmutableNodes.leafNode(
688                 contributorName, contributorNameVal);
689         final LeafNode<String> odlProjectNameLeafRef = ImmutableNodes.leafNode(
690                 odlProjectName, odlProjectNameVal);
691         final LeafNode<String> odlProjectDescLeafRef = ImmutableNodes.leafNode(
692                 odlProjectDesc, odlProjectDescVal);
693
694         return Builders.mapEntryBuilder(contributorListSchemaNode)
695                 .addChild(loginLeaf)
696                 .addChild(contributorNameLeaf)
697                 .addChild(odlProjectNameLeafRef)
698                 .addChild(odlProjectDescLeafRef)
699                 .build();
700     }
701
702     private static ContainerNode createOdlContainer(
703             final ContainerSchemaNode container) {
704
705         final ListSchemaNode projListSchemaNode = (ListSchemaNode) container
706                 .getDataChildByName(project);
707
708         final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> odlProjectContainerBldr = Builders
709                 .containerBuilder(container);
710
711         final MapNode projectMap = createProjectList(projListSchemaNode);
712         odlProjectContainerBldr.addChild(projectMap);
713
714         final ContainerNode odlProjectContainer = odlProjectContainerBldr
715                 .build();
716
717         return odlProjectContainer;
718     }
719
720     private static MapNode createProjectList(
721             final ListSchemaNode projListSchemaNode) {
722
723         final CollectionNodeBuilder<MapEntryNode, MapNode> projectMapBldr = Builders
724                 .mapBuilder(projListSchemaNode);
725
726         final MapEntryNode projMapEntry1 = createProjectListEntry("Yangtools",
727                 "Yangtools description ...", "Leader of Yangtools",
728                 "Owner of Yangtools", projListSchemaNode);
729         final MapEntryNode projMapEntry2 = createProjectListEntry("MD-SAL",
730                 "MD-SAL description ...", "Leader of MD-SAL",
731                 "Owner of MD-SAL", projListSchemaNode);
732         final MapEntryNode projMapEntry3 = createProjectListEntry("Controller",
733                 "Controller description ...", "Leader of Controller",
734                 "Owner of Controller", projListSchemaNode);
735
736         projectMapBldr.addChild(projMapEntry1);
737         projectMapBldr.addChild(projMapEntry2);
738         projectMapBldr.addChild(projMapEntry3);
739
740         final MapNode projectMap = projectMapBldr.build();
741
742         return projectMap;
743     }
744
745     private static MapEntryNode createProjectListEntry(final String nameVal,
746             final String descVal, final String leadVal, final String ownerVal,
747             final ListSchemaNode projListSchemaNode) {
748
749         final LeafNode<String> nameLeaf = ImmutableNodes
750                 .leafNode(name, nameVal);
751         final LeafNode<String> descLeaf = ImmutableNodes
752                 .leafNode(desc, descVal);
753         final LeafNode<String> leadLeafRef = ImmutableNodes.leafNode(lead,
754                 leadVal);
755         final LeafNode<String> ownerLeafRef = ImmutableNodes.leafNode(owner,
756                 ownerVal);
757
758         final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> projMapEntryBldr = Builders
759                 .mapEntryBuilder(projListSchemaNode);
760
761         projMapEntryBldr.addChild(nameLeaf);
762         projMapEntryBldr.addChild(descLeaf);
763         projMapEntryBldr.addChild(leadLeafRef);
764         projMapEntryBldr.addChild(ownerLeafRef);
765         final MapEntryNode projMapEntry = projMapEntryBldr.build();
766
767         return projMapEntry;
768     }
769
770     private static ContainerNode createBasicContributorContainer(
771             final ContainerSchemaNode contributorContSchemaNode) {
772
773         final ListSchemaNode contributorListSchemaNode = (ListSchemaNode) contributorContSchemaNode
774                 .getDataChildByName(contributor);
775
776         final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> contributorContainerBldr = Builders
777                 .containerBuilder(contributorContSchemaNode);
778
779         final MapNode contributorMap = createBasicContributorList(contributorListSchemaNode);
780         contributorContainerBldr.addChild(contributorMap);
781
782         final ContainerNode contributorContainer = contributorContainerBldr
783                 .build();
784
785         return contributorContainer;
786
787     }
788
789     private static MapNode createBasicContributorList(
790             final ListSchemaNode contributorListSchemaNode) {
791
792         final CollectionNodeBuilder<MapEntryNode, MapNode> contributorMapBldr = Builders
793                 .mapBuilder(contributorListSchemaNode);
794
795         final MapEntryNode contributorMapEntry1 = createContributorListEntry(
796                 "Leader of Yangtools", "Yangtools Leader name", "Yangtools",
797                 "Yangtools description ...", contributorListSchemaNode);
798         final MapEntryNode contributorMapEntry2 = createContributorListEntry(
799                 "Leader of MD-SAL", "MD-SAL Leader name", "MD-SAL",
800                 "MD-SAL description ...", contributorListSchemaNode);
801         final MapEntryNode contributorMapEntry3 = createContributorListEntry(
802                 "Leader of Controller", "Controller Leader name", "Controller",
803                 "Controller description ...", contributorListSchemaNode);
804
805         contributorMapBldr.addChild(contributorMapEntry1);
806         contributorMapBldr.addChild(contributorMapEntry2);
807         contributorMapBldr.addChild(contributorMapEntry3);
808
809         final MapNode contributorMap = contributorMapBldr.build();
810
811         return contributorMap;
812     }
813 }