2 * Copyright (c) 2016 Cisco Systems, Inc. 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.impl.leafref.context;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
13 import java.util.HashMap;
15 import org.junit.AfterClass;
16 import org.junit.BeforeClass;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.common.QNameModule;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
23 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
24 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
25 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
26 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
27 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
28 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
29 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
30 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
31 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
32 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
33 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
34 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
35 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
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.LeafRefValidation;
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.DataContainerNodeBuilder;
43 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
44 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder;
45 import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
46 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
47 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
48 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
49 import org.opendaylight.yangtools.yang.model.api.Module;
50 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
54 public class DataTreeCandidateValidatorTest {
56 private static EffectiveModelContext context;
57 private static Module valModule;
58 private static QNameModule valModuleQname;
59 private static LeafRefContext rootLeafRefContext;
60 public static DataTree inMemoryDataTree;
62 private static QName odl;
63 private static QName project;
64 private static QName name;
65 private static QName desc;
66 private static QName lead;
67 private static QName owner;
68 private static QName odlContributor;
69 private static QName contributor;
70 private static QName odlProjectName;
71 private static QName odlProjectDesc;
72 private static QName login;
73 private static QName contributorName;
74 private static QName l1;
75 private static QName l2;
76 private static QName con1;
77 private static QName ch1;
78 private static QName ch2;
79 private static QName leafrefInChoice;
80 private static QName listInChoice;
82 private static QName leafrefInChoiceToChoice;
83 private static QName con3;
84 private static QName list3InChoice;
85 private static QName l3;
86 private static QName choiceInCon3;
88 private static QName listInChoiceKey;
89 private static QName k;
91 private static QName leafrefLeafList;
93 private static final Logger LOG = LoggerFactory.getLogger(DataTreeCandidateValidatorTest.class);
94 private static final String NEW_LINE = System.getProperty("line.separator");
97 public static void init() throws DataValidationFailedException {
98 context = YangParserTestUtils.parseYangResourceDirectory("/leafref-validation");
100 for (final Module module : context.getModules()) {
101 if (module.getName().equals("leafref-validation")) {
106 valModuleQname = valModule.getQNameModule();
107 rootLeafRefContext = LeafRefContext.create(context);
109 odl = QName.create(valModuleQname, "odl-project");
110 project = QName.create(valModuleQname, "project");
111 name = QName.create(valModuleQname, "name");
112 desc = QName.create(valModuleQname, "desc");
113 lead = QName.create(valModuleQname, "project-lead");
114 owner = QName.create(valModuleQname, "project-owner");
116 odlContributor = QName.create(valModuleQname, "odl-contributor");
117 contributor = QName.create(valModuleQname, "contributor");
118 odlProjectName = QName.create(valModuleQname, "odl-project-name");
119 login = QName.create(valModuleQname, "login");
120 contributorName = QName.create(valModuleQname, "contributor-name");
122 con1 = QName.create(valModuleQname, "con1");
123 l1 = QName.create(valModuleQname, "l1");
124 l2 = QName.create(valModuleQname, "l2");
125 odlProjectDesc = QName.create(valModuleQname, "odl-project-desc");
127 ch1 = QName.create(valModuleQname, "ch1");
128 ch2 = QName.create(valModuleQname, "ch2");
129 leafrefInChoice = QName.create(valModuleQname, "leafref-in-choice");
130 listInChoice = QName.create(valModuleQname, "list-in-choice");
132 leafrefInChoiceToChoice = QName.create(valModuleQname,
133 "leafref-in-choice-to-choice");
134 con3 = QName.create(valModuleQname, "con3");
135 list3InChoice = QName.create(valModuleQname, "list3-in-choice");
136 l3 = QName.create(valModuleQname, "l3");
137 choiceInCon3 = QName.create(valModuleQname, "choice-in-con3");
139 listInChoiceKey = QName.create(valModuleQname, "list-in-choice-key");
140 k = QName.create(valModuleQname, "k");
142 leafrefLeafList = QName.create(valModuleQname, "leafref-leaf-list");
144 inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, context);
146 final DataTreeModification initialDataTreeModification = inMemoryDataTree
147 .takeSnapshot().newModification();
149 final ContainerSchemaNode odlProjContSchemaNode = (ContainerSchemaNode) valModule.findDataChildByName(odl)
152 final ContainerNode odlProjectContainer = createOdlContainer(odlProjContSchemaNode);
154 final YangInstanceIdentifier path = YangInstanceIdentifier.of(odl);
155 initialDataTreeModification.write(path, odlProjectContainer);
156 initialDataTreeModification.ready();
158 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
159 .prepare(initialDataTreeModification);
160 inMemoryDataTree.commit(writeContributorsCandidate);
164 public static void cleanup() {
165 inMemoryDataTree = null;
166 rootLeafRefContext = null;
172 public void dataTreeCanditateValidationTest() throws DataValidationFailedException {
186 private static void writeContributors() throws DataValidationFailedException {
188 final ContainerSchemaNode contributorContSchemaNode = (ContainerSchemaNode) valModule
189 .findDataChildByName(odlContributor).get();
191 final ContainerNode contributorContainer = createBasicContributorContainer(contributorContSchemaNode);
193 final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
195 final DataTreeModification writeModification = inMemoryDataTree
196 .takeSnapshot().newModification();
197 writeModification.write(contributorPath, contributorContainer);
198 writeModification.ready();
200 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
201 .prepare(writeModification);
203 LOG.debug("*************************");
204 LOG.debug("Before write of contributors: ");
205 LOG.debug("*************************");
206 LOG.debug(inMemoryDataTree.toString());
208 boolean exception = false;
210 LeafRefValidation.validate(writeContributorsCandidate,
212 } catch (final LeafRefDataValidationFailedException e) {
213 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
214 assertEquals(3, e.getValidationsErrorsCount());
218 inMemoryDataTree.commit(writeContributorsCandidate);
220 LOG.debug("*************************");
221 LOG.debug("After write of contributors: ");
222 LOG.debug("*************************");
223 LOG.debug(inMemoryDataTree.toString());
225 assertTrue(exception);
229 private static void writeIntoMapEntry() throws DataValidationFailedException {
231 final Map<QName, Object> keys = new HashMap<>();
232 keys.put(name, "New Project");
233 final NodeIdentifierWithPredicates mapEntryPath = NodeIdentifierWithPredicates.of(project, keys);
235 final YangInstanceIdentifier leaderPath = YangInstanceIdentifier
236 .of(odl).node(project).node(mapEntryPath).node(lead);
238 final LeafNode<String> leader = ImmutableNodes.leafNode(lead,
241 final DataTreeModification writeModification = inMemoryDataTree
242 .takeSnapshot().newModification();
243 writeModification.write(leaderPath, leader);
244 writeModification.ready();
246 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
247 .prepare(writeModification);
249 LOG.debug("*************************");
250 LOG.debug("Before write into map entry (update of leader name): ");
251 LOG.debug("*************************");
252 LOG.debug(inMemoryDataTree.toString());
254 boolean exception = false;
256 LeafRefValidation.validate(writeContributorsCandidate,
258 } catch (final LeafRefDataValidationFailedException e) {
259 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
260 assertEquals(1, e.getValidationsErrorsCount());
264 inMemoryDataTree.commit(writeContributorsCandidate);
266 LOG.debug("*************************");
267 LOG.debug("After write into map entry (update of leader name): ");
268 LOG.debug("*************************");
269 LOG.debug(inMemoryDataTree.toString());
271 assertTrue(exception);
275 private static void writeMapEntry() throws DataValidationFailedException {
277 final Map<QName, Object> keys = new HashMap<>();
278 keys.put(name, "New Project");
279 final NodeIdentifierWithPredicates mapEntryPath = NodeIdentifierWithPredicates.of(project, keys);
281 final YangInstanceIdentifier newOdlProjectMapEntryPath = YangInstanceIdentifier
282 .of(odl).node(project).node(mapEntryPath);
284 final ContainerSchemaNode odlProjContSchemaNode = (ContainerSchemaNode) valModule.findDataChildByName(odl)
286 final ListSchemaNode projListSchemaNode = (ListSchemaNode) odlProjContSchemaNode.findDataChildByName(project)
288 final MapEntryNode newProjectMapEntry = createProjectListEntry(
289 "New Project", "New Project description ...",
290 "Leader of New Project", "Owner of New Project",
293 final DataTreeModification writeModification = inMemoryDataTree
294 .takeSnapshot().newModification();
295 writeModification.write(newOdlProjectMapEntryPath, newProjectMapEntry);
296 writeModification.ready();
298 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
299 .prepare(writeModification);
301 LOG.debug("*************************");
302 LOG.debug("Before map entry write: ");
303 LOG.debug("*************************");
304 LOG.debug(inMemoryDataTree.toString());
306 boolean exception = false;
308 LeafRefValidation.validate(writeContributorsCandidate,
310 } catch (final LeafRefDataValidationFailedException e) {
311 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
312 assertEquals(2, e.getValidationsErrorsCount());
316 inMemoryDataTree.commit(writeContributorsCandidate);
318 LOG.debug("*************************");
319 LOG.debug("After map entry write: ");
320 LOG.debug("*************************");
321 LOG.debug(inMemoryDataTree.toString());
323 assertTrue(exception);
327 private static void write() throws DataValidationFailedException {
329 final ContainerSchemaNode contributorContSchemaNode = (ContainerSchemaNode) valModule
330 .findDataChildByName(odlContributor).get();
332 final ContainerNode contributorContainer = createContributorContainer(contributorContSchemaNode);
334 final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
336 final DataTreeModification writeModification = inMemoryDataTree
337 .takeSnapshot().newModification();
338 writeModification.write(contributorPath, contributorContainer);
340 writeModification.write(YangInstanceIdentifier.of(l1),
341 ImmutableNodes.leafNode(l1, "Leafref l1 under the root"));
343 .write(YangInstanceIdentifier.of(l2), ImmutableNodes.leafNode(
344 l2, "Leafref target l2 under the root"));
346 writeModification.ready();
347 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
348 .prepare(writeModification);
350 LOG.debug("*************************");
351 LOG.debug("Before write: ");
352 LOG.debug("*************************");
353 LOG.debug(inMemoryDataTree.toString());
355 boolean exception = false;
357 LeafRefValidation.validate(writeContributorsCandidate,
359 } catch (final LeafRefDataValidationFailedException e) {
360 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
361 assertEquals(12, e.getValidationsErrorsCount());
365 inMemoryDataTree.commit(writeContributorsCandidate);
367 LOG.debug("*************************");
368 LOG.debug("After write: ");
369 LOG.debug("*************************");
370 LOG.debug(inMemoryDataTree.toString());
372 assertTrue(exception);
375 private static void write2() throws DataValidationFailedException {
377 final ContainerSchemaNode odlCon = (ContainerSchemaNode) valModule.findDataChildByName(odl).get();
378 final ContainerSchemaNode con1Con = (ContainerSchemaNode) odlCon.findDataChildByName(con1).get();
379 final LeafNode<String> l1Leaf = ImmutableNodes.leafNode(l1, "l1 value");
380 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> containerBuilder = Builders
381 .containerBuilder(con1Con);
382 containerBuilder.addChild(l1Leaf);
383 final ContainerNode con1Node = containerBuilder.build();
385 final YangInstanceIdentifier con1Path = YangInstanceIdentifier.of(odl)
387 final DataTreeModification writeModification = inMemoryDataTree
388 .takeSnapshot().newModification();
389 writeModification.write(con1Path, con1Node);
391 final ChoiceNode choiceNode = createChoiceNode();
392 final YangInstanceIdentifier choicePath = YangInstanceIdentifier
394 writeModification.write(choicePath, choiceNode);
396 final ContainerNode con3Node = createCon3Node();
397 final YangInstanceIdentifier con3Path = YangInstanceIdentifier.of(odl)
399 writeModification.write(con3Path, con3Node);
401 final LeafSetNode<?> leafListNode = createLeafRefLeafListNode();
402 final YangInstanceIdentifier leafListPath = YangInstanceIdentifier.of(
403 odl).node(leafrefLeafList);
404 writeModification.write(leafListPath, leafListNode);
405 writeModification.ready();
407 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
408 .prepare(writeModification);
410 LOG.debug("*************************");
411 LOG.debug("Before write2: ");
412 LOG.debug("*************************");
413 LOG.debug(inMemoryDataTree.toString());
415 boolean exception = false;
417 LeafRefValidation.validate(writeContributorsCandidate,
419 } catch (final LeafRefDataValidationFailedException e) {
420 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
421 assertEquals(6, e.getValidationsErrorsCount());
425 assertTrue(exception);
427 inMemoryDataTree.commit(writeContributorsCandidate);
429 LOG.debug("*************************");
430 LOG.debug("After write2: ");
431 LOG.debug("*************************");
432 LOG.debug(inMemoryDataTree.toString());
436 private static LeafSetNode<?> createLeafRefLeafListNode() {
438 final ListNodeBuilder<Object, LeafSetEntryNode<Object>> leafSetBuilder = Builders
440 leafSetBuilder.withNodeIdentifier(new NodeIdentifier(leafrefLeafList));
442 leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k1"));
443 leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k2"));
444 leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k3"));
446 return leafSetBuilder.build();
449 private static ContainerNode createCon3Node() {
451 final CollectionNodeBuilder<MapEntryNode, MapNode> mapBuilder = Builders
453 mapBuilder.withNodeIdentifier(new NodeIdentifier(list3InChoice));
455 mapBuilder.addChild(createList3Entry("k1", "val1", "valA", "valX"));
456 mapBuilder.addChild(createList3Entry("k2", "val2", "valB", "valY"));
458 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choiceBuilder = Builders
460 choiceBuilder.withNodeIdentifier(new NodeIdentifier(choiceInCon3));
462 choiceBuilder.addChild(mapBuilder.build());
464 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> containerBuilder = Builders
466 containerBuilder.withNodeIdentifier(new NodeIdentifier(con3));
468 containerBuilder.addChild(choiceBuilder.build());
470 return containerBuilder.build();
473 private static MapEntryNode createList3Entry(final String keyVal,
474 final String l3Val1, final String l3Val2, final String l3Val3) {
475 final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder = Builders
477 mapEntryBuilder.withNodeIdentifier(NodeIdentifierWithPredicates.of(list3InChoice, k, keyVal));
479 final ListNodeBuilder<Object, LeafSetEntryNode<Object>> leafSetBuilder = Builders
481 leafSetBuilder.withNodeIdentifier(new NodeIdentifier(l3));
483 leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val1));
484 leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val2));
485 leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val3));
487 mapEntryBuilder.addChild(ImmutableNodes.leafNode(k, keyVal));
488 mapEntryBuilder.addChild(leafSetBuilder.build());
490 return mapEntryBuilder.build();
493 private static LeafSetEntryNode<Object> createLeafSetEntry(
494 final QName qname, final String val) {
495 final NormalizedNodeBuilder<NodeWithValue, Object, LeafSetEntryNode<Object>> leafSetEntryBuilder = Builders
496 .leafSetEntryBuilder();
497 leafSetEntryBuilder.withNodeIdentifier(new NodeWithValue<>(qname, val));
498 leafSetEntryBuilder.withValue(val);
499 return leafSetEntryBuilder.build();
502 private static ChoiceNode createChoiceNode() {
504 final CollectionNodeBuilder<MapEntryNode, MapNode> listInChoiceBuilder = Builders
507 .withNodeIdentifier(new NodeIdentifier(listInChoice));
509 listInChoiceBuilder.addChild(createListInChoiceEntry("key1",
510 "leafref-in-choice value", "val1"));
511 listInChoiceBuilder.addChild(createListInChoiceEntry("key2",
512 "l1 value", "val2"));
513 listInChoiceBuilder.addChild(createListInChoiceEntry("key3",
514 "l1 value", "val3"));
516 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choice2Builder = Builders
518 choice2Builder.withNodeIdentifier(new NodeIdentifier(ch2));
520 choice2Builder.addChild(listInChoiceBuilder.build());
522 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choiceBuilder = Builders
524 choiceBuilder.withNodeIdentifier(new NodeIdentifier(ch1));
525 choiceBuilder.addChild(choice2Builder.build());
527 return choiceBuilder.build();
530 private static MapEntryNode createListInChoiceEntry(final String keyVal,
531 final String leafrefInChoiceVal,
532 final String leafrefInChoiceToChoiceVal) {
534 final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder = Builders
537 mapEntryBuilder.withNodeIdentifier(NodeIdentifierWithPredicates.of(
538 listInChoice, listInChoiceKey, keyVal));
540 mapEntryBuilder.addChild(ImmutableNodes.leafNode(listInChoiceKey,
542 mapEntryBuilder.addChild(ImmutableNodes.leafNode(leafrefInChoice,
543 leafrefInChoiceVal));
544 mapEntryBuilder.addChild(ImmutableNodes.leafNode(
545 leafrefInChoiceToChoice, leafrefInChoiceToChoiceVal));
547 return mapEntryBuilder.build();
550 private static void delete() throws DataValidationFailedException {
552 final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
554 final DataTreeModification delete = inMemoryDataTree.takeSnapshot()
556 delete.delete(contributorPath);
559 final DataTreeCandidate deleteContributorsCanditate = inMemoryDataTree.prepare(delete);
561 LOG.debug("*************************");
562 LOG.debug("Before delete: ");
563 LOG.debug("*************************");
564 LOG.debug(inMemoryDataTree.toString());
566 boolean exception = false;
568 LeafRefValidation.validate(deleteContributorsCanditate,
570 } catch (final LeafRefDataValidationFailedException e) {
571 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
572 assertEquals(6, e.getValidationsErrorsCount());
576 assertTrue(exception);
578 inMemoryDataTree.commit(deleteContributorsCanditate);
580 LOG.debug("*************************");
581 LOG.debug("After delete: ");
582 LOG.debug("*************************");
583 LOG.debug(inMemoryDataTree.toString());
587 private static ContainerNode createContributorContainer(
588 final ContainerSchemaNode contributorContSchemaNode) {
590 final ListSchemaNode contributorListSchemaNode = (ListSchemaNode) contributorContSchemaNode
591 .findDataChildByName(contributor).get();
593 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> contributorContainerBldr = Builders
594 .containerBuilder(contributorContSchemaNode);
596 final MapNode contributorMap = createContributorList(contributorListSchemaNode);
597 contributorContainerBldr.addChild(contributorMap);
599 final ContainerNode contributorContainer = contributorContainerBldr
602 return contributorContainer;
606 private static MapNode createContributorList(
607 final ListSchemaNode contributorListSchemaNode) {
609 final CollectionNodeBuilder<MapEntryNode, MapNode> contributorMapBldr = Builders
610 .mapBuilder(contributorListSchemaNode);
612 final MapEntryNode contributorMapEntry1 = createContributorListEntry(
613 "Leader of Yangtools", "Yangtools Leader name", "Yangtools",
614 "Yangtools description ...", contributorListSchemaNode);
615 final MapEntryNode contributorMapEntry2 = createContributorListEntry(
616 "Leader of MD-SAL", "MD-SAL Leader name", "MD-SAL",
617 "MD-SAL description ...", contributorListSchemaNode);
618 final MapEntryNode contributorMapEntry3 = createContributorListEntry(
619 "Leader of Controller", "Controller Leader name", "Controller",
620 "Controller description ...", contributorListSchemaNode);
622 final MapEntryNode contributorMapEntry4 = createContributorListEntry(
623 "jdoe", "John Doe", "MD-SAL", "Yangtools description ...",
624 contributorListSchemaNode);
626 final MapEntryNode contributorMapEntry5 = createContributorListEntry(
627 "foo", "foo name", "Controller", "MD-SAL description ...",
628 contributorListSchemaNode);
630 final MapEntryNode contributorMapEntry6 = createContributorListEntry(
631 "bar", "bar name", "Yangtools", "Controller description ...",
632 contributorListSchemaNode);
634 final MapEntryNode contributorMapEntry7 = createContributorListEntry(
635 "baz", "baz name", "Unknown Project",
636 "Unknown Project description ...", contributorListSchemaNode);
638 final MapEntryNode contributorMapEntry8 = createContributorListEntry(
639 "pk", "pk name", "Unknown Project 2",
640 "Controller description ...", contributorListSchemaNode);
642 contributorMapBldr.addChild(contributorMapEntry1);
643 contributorMapBldr.addChild(contributorMapEntry2);
644 contributorMapBldr.addChild(contributorMapEntry3);
645 contributorMapBldr.addChild(contributorMapEntry4);
646 contributorMapBldr.addChild(contributorMapEntry5);
647 contributorMapBldr.addChild(contributorMapEntry6);
648 contributorMapBldr.addChild(contributorMapEntry7);
649 contributorMapBldr.addChild(contributorMapEntry8);
651 final MapNode contributorMap = contributorMapBldr.build();
653 return contributorMap;
657 private static MapEntryNode createContributorListEntry(
658 final String loginVal, final String contributorNameVal,
659 final String odlProjectNameVal, final String odlProjectDescVal,
660 final ListSchemaNode contributorListSchemaNode) {
662 final LeafNode<String> loginLeaf = ImmutableNodes.leafNode(login, loginVal);
663 final LeafNode<String> contributorNameLeaf = ImmutableNodes.leafNode(contributorName, contributorNameVal);
664 final LeafNode<String> odlProjectNameLeafRef = ImmutableNodes.leafNode(odlProjectName, odlProjectNameVal);
665 final LeafNode<String> odlProjectDescLeafRef = ImmutableNodes.leafNode(odlProjectDesc, odlProjectDescVal);
667 return Builders.mapEntryBuilder(contributorListSchemaNode)
669 .addChild(contributorNameLeaf)
670 .addChild(odlProjectNameLeafRef)
671 .addChild(odlProjectDescLeafRef)
675 private static ContainerNode createOdlContainer(
676 final ContainerSchemaNode container) {
678 final ListSchemaNode projListSchemaNode = (ListSchemaNode) container.findDataChildByName(project).get();
680 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> odlProjectContainerBldr = Builders
681 .containerBuilder(container);
683 final MapNode projectMap = createProjectList(projListSchemaNode);
684 odlProjectContainerBldr.addChild(projectMap);
686 final ContainerNode odlProjectContainer = odlProjectContainerBldr
689 return odlProjectContainer;
692 private static MapNode createProjectList(
693 final ListSchemaNode projListSchemaNode) {
695 final CollectionNodeBuilder<MapEntryNode, MapNode> projectMapBldr = Builders
696 .mapBuilder(projListSchemaNode);
698 final MapEntryNode projMapEntry1 = createProjectListEntry("Yangtools",
699 "Yangtools description ...", "Leader of Yangtools",
700 "Owner of Yangtools", projListSchemaNode);
701 final MapEntryNode projMapEntry2 = createProjectListEntry("MD-SAL",
702 "MD-SAL description ...", "Leader of MD-SAL",
703 "Owner of MD-SAL", projListSchemaNode);
704 final MapEntryNode projMapEntry3 = createProjectListEntry("Controller",
705 "Controller description ...", "Leader of Controller",
706 "Owner of Controller", projListSchemaNode);
708 projectMapBldr.addChild(projMapEntry1);
709 projectMapBldr.addChild(projMapEntry2);
710 projectMapBldr.addChild(projMapEntry3);
712 final MapNode projectMap = projectMapBldr.build();
717 private static MapEntryNode createProjectListEntry(final String nameVal,
718 final String descVal, final String leadVal, final String ownerVal,
719 final ListSchemaNode projListSchemaNode) {
721 final LeafNode<String> nameLeaf = ImmutableNodes
722 .leafNode(name, nameVal);
723 final LeafNode<String> descLeaf = ImmutableNodes
724 .leafNode(desc, descVal);
725 final LeafNode<String> leadLeafRef = ImmutableNodes.leafNode(lead,
727 final LeafNode<String> ownerLeafRef = ImmutableNodes.leafNode(owner,
730 final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> projMapEntryBldr = Builders
731 .mapEntryBuilder(projListSchemaNode);
733 projMapEntryBldr.addChild(nameLeaf);
734 projMapEntryBldr.addChild(descLeaf);
735 projMapEntryBldr.addChild(leadLeafRef);
736 projMapEntryBldr.addChild(ownerLeafRef);
737 final MapEntryNode projMapEntry = projMapEntryBldr.build();
742 private static ContainerNode createBasicContributorContainer(
743 final ContainerSchemaNode contributorContSchemaNode) {
745 final ListSchemaNode contributorListSchemaNode = (ListSchemaNode) contributorContSchemaNode
746 .findDataChildByName(contributor).get();
748 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> contributorContainerBldr = Builders
749 .containerBuilder(contributorContSchemaNode);
751 final MapNode contributorMap = createBasicContributorList(contributorListSchemaNode);
752 contributorContainerBldr.addChild(contributorMap);
754 final ContainerNode contributorContainer = contributorContainerBldr
757 return contributorContainer;
761 private static MapNode createBasicContributorList(
762 final ListSchemaNode contributorListSchemaNode) {
764 final CollectionNodeBuilder<MapEntryNode, MapNode> contributorMapBldr = Builders
765 .mapBuilder(contributorListSchemaNode);
767 final MapEntryNode contributorMapEntry1 = createContributorListEntry(
768 "Leader of Yangtools", "Yangtools Leader name", "Yangtools",
769 "Yangtools description ...", contributorListSchemaNode);
770 final MapEntryNode contributorMapEntry2 = createContributorListEntry(
771 "Leader of MD-SAL", "MD-SAL Leader name", "MD-SAL",
772 "MD-SAL description ...", contributorListSchemaNode);
773 final MapEntryNode contributorMapEntry3 = createContributorListEntry(
774 "Leader of Controller", "Controller Leader name", "Controller",
775 "Controller description ...", contributorListSchemaNode);
777 contributorMapBldr.addChild(contributorMapEntry1);
778 contributorMapBldr.addChild(contributorMapEntry2);
779 contributorMapBldr.addChild(contributorMapEntry3);
781 final MapNode contributorMap = contributorMapBldr.build();
783 return contributorMap;