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;
16 import org.apache.log4j.BasicConfigurator;
17 import org.junit.AfterClass;
18 import org.junit.BeforeClass;
19 import org.junit.Test;
20 import org.opendaylight.yangtools.yang.common.QName;
21 import org.opendaylight.yangtools.yang.common.QNameModule;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
23 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
25 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
26 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
27 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
28 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
29 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
30 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
31 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
32 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
33 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
34 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
35 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
36 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
37 import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContext;
38 import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefDataValidationFailedException;
39 import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefValidatation;
40 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
41 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
42 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
43 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
44 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
45 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
46 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeAttrBuilder;
47 import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
48 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
49 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
50 import org.opendaylight.yangtools.yang.model.api.Module;
51 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
52 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
53 import org.slf4j.Logger;
54 import org.slf4j.LoggerFactory;
56 public class DataTreeCandidateValidatorTest {
58 private static SchemaContext context;
59 private static Module valModule;
60 private static QNameModule valModuleQname;
61 private static LeafRefContext rootLeafRefContext;
62 public static DataTree inMemoryDataTree;
64 private static QName odl;
65 private static QName project;
66 private static QName name;
67 private static QName desc;
68 private static QName lead;
69 private static QName owner;
70 private static QName odlContributor;
71 private static QName contributor;
72 private static QName odlProjectName;
73 private static QName odlProjectDesc;
74 private static QName login;
75 private static QName contributorName;
76 private static QName l1;
77 private static QName l2;
78 private static QName con1;
79 private static QName ch1;
80 private static QName ch2;
81 private static QName leafrefInChoice;
82 private static QName listInChoice;
84 private static QName leafrefInChoiceToChoice;
85 private static QName con3;
86 private static QName list3InChoice;
87 private static QName l3;
88 private static QName choiceInCon3;
90 private static QName listInChoiceKey;
91 private static QName k;
93 private static QName leafrefLeafList;
95 private static final Logger LOG = LoggerFactory.getLogger(DataTreeCandidateValidatorTest.class);
96 private static final String NEW_LINE = System.getProperty("line.separator");
99 BasicConfigurator.configure();
103 public static void init() {
104 context = YangParserTestUtils.parseYangResourceDirectory("/leafref-validation");
106 final Set<Module> modules = context.getModules();
107 for (final Module module : modules) {
108 if (module.getName().equals("leafref-validation")) {
113 valModuleQname = valModule.getQNameModule();
114 rootLeafRefContext = LeafRefContext.create(context);
116 odl = QName.create(valModuleQname, "odl-project");
117 project = QName.create(valModuleQname, "project");
118 name = QName.create(valModuleQname, "name");
119 desc = QName.create(valModuleQname, "desc");
120 lead = QName.create(valModuleQname, "project-lead");
121 owner = QName.create(valModuleQname, "project-owner");
123 odlContributor = QName.create(valModuleQname, "odl-contributor");
124 contributor = QName.create(valModuleQname, "contributor");
125 odlProjectName = QName.create(valModuleQname, "odl-project-name");
126 login = QName.create(valModuleQname, "login");
127 contributorName = QName.create(valModuleQname, "contributor-name");
129 con1 = QName.create(valModuleQname, "con1");
130 l1 = QName.create(valModuleQname, "l1");
131 l2 = QName.create(valModuleQname, "l2");
132 odlProjectDesc = QName.create(valModuleQname, "odl-project-desc");
134 ch1 = QName.create(valModuleQname, "ch1");
135 ch2 = QName.create(valModuleQname, "ch2");
136 leafrefInChoice = QName.create(valModuleQname, "leafref-in-choice");
137 listInChoice = QName.create(valModuleQname, "list-in-choice");
139 leafrefInChoiceToChoice = QName.create(valModuleQname,
140 "leafref-in-choice-to-choice");
141 con3 = QName.create(valModuleQname, "con3");
142 list3InChoice = QName.create(valModuleQname, "list3-in-choice");
143 l3 = QName.create(valModuleQname, "l3");
144 choiceInCon3 = QName.create(valModuleQname, "choice-in-con3");
146 listInChoiceKey = QName.create(valModuleQname, "list-in-choice-key");
147 k = QName.create(valModuleQname, "k");
149 leafrefLeafList = QName.create(valModuleQname, "leafref-leaf-list");
151 inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, context);
153 final DataTreeModification initialDataTreeModification = inMemoryDataTree
154 .takeSnapshot().newModification();
156 final ContainerSchemaNode odlProjContSchemaNode = (ContainerSchemaNode) valModule
157 .getDataChildByName(odl);
159 final ContainerNode odlProjectContainer = createOdlContainer(odlProjContSchemaNode);
161 final YangInstanceIdentifier path = YangInstanceIdentifier.of(odl);
162 initialDataTreeModification.write(path, odlProjectContainer);
163 initialDataTreeModification.ready();
165 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
166 .prepare(initialDataTreeModification);
167 inMemoryDataTree.commit(writeContributorsCandidate);
171 public static void cleanup() {
172 inMemoryDataTree = null;
173 rootLeafRefContext = null;
179 public void dataTreeCanditateValidationTest() {
193 private static void writeContributors() {
195 final ContainerSchemaNode contributorContSchemaNode = (ContainerSchemaNode) valModule
196 .getDataChildByName(odlContributor);
198 final ContainerNode contributorContainer = createBasicContributorContainer(contributorContSchemaNode);
200 final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
202 final DataTreeModification writeModification = inMemoryDataTree
203 .takeSnapshot().newModification();
204 writeModification.write(contributorPath, contributorContainer);
205 writeModification.ready();
207 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
208 .prepare(writeModification);
210 LOG.debug("*************************");
211 LOG.debug("Before write of contributors: ");
212 LOG.debug("*************************");
213 LOG.debug(inMemoryDataTree.toString());
215 boolean exception = false;
217 LeafRefValidatation.validate(writeContributorsCandidate,
219 } catch (final LeafRefDataValidationFailedException e) {
220 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
221 assertEquals(3, e.getValidationsErrorsCount());
225 inMemoryDataTree.commit(writeContributorsCandidate);
227 LOG.debug("*************************");
228 LOG.debug("After write of contributors: ");
229 LOG.debug("*************************");
230 LOG.debug(inMemoryDataTree.toString());
232 assertTrue(exception);
236 private static void writeIntoMapEntry() {
238 final Map<QName, Object> keys = new HashMap<>();
239 keys.put(name, "New Project");
240 final NodeIdentifierWithPredicates mapEntryPath = new NodeIdentifierWithPredicates(
243 final YangInstanceIdentifier leaderPath = YangInstanceIdentifier
244 .of(odl).node(project).node(mapEntryPath).node(lead);
246 final LeafNode<String> leader = ImmutableNodes.leafNode(lead,
249 final DataTreeModification writeModification = inMemoryDataTree
250 .takeSnapshot().newModification();
251 writeModification.write(leaderPath, leader);
252 writeModification.ready();
254 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
255 .prepare(writeModification);
257 LOG.debug("*************************");
258 LOG.debug("Before write into map entry (update of leader name): ");
259 LOG.debug("*************************");
260 LOG.debug(inMemoryDataTree.toString());
262 boolean exception = false;
264 LeafRefValidatation.validate(writeContributorsCandidate,
266 } catch (final LeafRefDataValidationFailedException e) {
267 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
268 assertEquals(1, e.getValidationsErrorsCount());
272 inMemoryDataTree.commit(writeContributorsCandidate);
274 LOG.debug("*************************");
275 LOG.debug("After write into map entry (update of leader name): ");
276 LOG.debug("*************************");
277 LOG.debug(inMemoryDataTree.toString());
279 assertTrue(exception);
283 private static void writeMapEntry() {
285 final Map<QName, Object> keys = new HashMap<>();
286 keys.put(name, "New Project");
287 final NodeIdentifierWithPredicates mapEntryPath = new NodeIdentifierWithPredicates(
290 final YangInstanceIdentifier newOdlProjectMapEntryPath = YangInstanceIdentifier
291 .of(odl).node(project).node(mapEntryPath);
293 final ContainerSchemaNode odlProjContSchemaNode = (ContainerSchemaNode) valModule
294 .getDataChildByName(odl);
295 final ListSchemaNode projListSchemaNode = (ListSchemaNode) odlProjContSchemaNode
296 .getDataChildByName(project);
297 final MapEntryNode newProjectMapEntry = createProjectListEntry(
298 "New Project", "New Project description ...",
299 "Leader of New Project", "Owner of New Project",
302 final DataTreeModification writeModification = inMemoryDataTree
303 .takeSnapshot().newModification();
304 writeModification.write(newOdlProjectMapEntryPath, newProjectMapEntry);
305 writeModification.ready();
307 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
308 .prepare(writeModification);
310 LOG.debug("*************************");
311 LOG.debug("Before map entry write: ");
312 LOG.debug("*************************");
313 LOG.debug(inMemoryDataTree.toString());
315 boolean exception = false;
317 LeafRefValidatation.validate(writeContributorsCandidate,
319 } catch (final LeafRefDataValidationFailedException e) {
320 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
321 assertEquals(2, e.getValidationsErrorsCount());
325 inMemoryDataTree.commit(writeContributorsCandidate);
327 LOG.debug("*************************");
328 LOG.debug("After map entry write: ");
329 LOG.debug("*************************");
330 LOG.debug(inMemoryDataTree.toString());
332 assertTrue(exception);
336 private static void write() {
338 final ContainerSchemaNode contributorContSchemaNode = (ContainerSchemaNode) valModule
339 .getDataChildByName(odlContributor);
341 final ContainerNode contributorContainer = createContributorContainer(contributorContSchemaNode);
343 final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
345 final DataTreeModification writeModification = inMemoryDataTree
346 .takeSnapshot().newModification();
347 writeModification.write(contributorPath, contributorContainer);
349 writeModification.write(YangInstanceIdentifier.of(l1),
350 ImmutableNodes.leafNode(l1, "Leafref l1 under the root"));
352 .write(YangInstanceIdentifier.of(l2), ImmutableNodes.leafNode(
353 l2, "Leafref target l2 under the root"));
355 writeModification.ready();
356 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
357 .prepare(writeModification);
359 LOG.debug("*************************");
360 LOG.debug("Before write: ");
361 LOG.debug("*************************");
362 LOG.debug(inMemoryDataTree.toString());
364 boolean exception = false;
366 LeafRefValidatation.validate(writeContributorsCandidate,
368 } catch (final LeafRefDataValidationFailedException e) {
369 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
370 assertEquals(12, e.getValidationsErrorsCount());
374 inMemoryDataTree.commit(writeContributorsCandidate);
376 LOG.debug("*************************");
377 LOG.debug("After write: ");
378 LOG.debug("*************************");
379 LOG.debug(inMemoryDataTree.toString());
381 assertTrue(exception);
384 private static void write2() {
386 final ContainerSchemaNode odlCon = (ContainerSchemaNode) valModule
387 .getDataChildByName(odl);
388 final ContainerSchemaNode con1Con = (ContainerSchemaNode) odlCon
389 .getDataChildByName(con1);
390 final LeafNode<String> l1Leaf = ImmutableNodes.leafNode(l1, "l1 value");
391 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> containerBuilder = Builders
392 .containerBuilder(con1Con);
393 containerBuilder.addChild(l1Leaf);
394 final ContainerNode con1Node = containerBuilder.build();
396 final YangInstanceIdentifier con1Path = YangInstanceIdentifier.of(odl)
398 final DataTreeModification writeModification = inMemoryDataTree
399 .takeSnapshot().newModification();
400 writeModification.write(con1Path, con1Node);
402 final ChoiceNode choiceNode = createChoiceNode();
403 final YangInstanceIdentifier choicePath = YangInstanceIdentifier
405 writeModification.write(choicePath, choiceNode);
407 final ContainerNode con3Node = createCon3Node();
408 final YangInstanceIdentifier con3Path = YangInstanceIdentifier.of(odl)
410 writeModification.write(con3Path, con3Node);
412 final LeafSetNode<?> leafListNode = createLeafRefLeafListNode();
413 final YangInstanceIdentifier leafListPath = YangInstanceIdentifier.of(
414 odl).node(leafrefLeafList);
415 writeModification.write(leafListPath, leafListNode);
416 writeModification.ready();
418 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
419 .prepare(writeModification);
421 LOG.debug("*************************");
422 LOG.debug("Before write2: ");
423 LOG.debug("*************************");
424 LOG.debug(inMemoryDataTree.toString());
426 boolean exception = false;
428 LeafRefValidatation.validate(writeContributorsCandidate,
430 } catch (final LeafRefDataValidationFailedException e) {
431 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
432 assertEquals(6, e.getValidationsErrorsCount());
436 assertTrue(exception);
438 inMemoryDataTree.commit(writeContributorsCandidate);
440 LOG.debug("*************************");
441 LOG.debug("After write2: ");
442 LOG.debug("*************************");
443 LOG.debug(inMemoryDataTree.toString());
447 private static LeafSetNode<?> createLeafRefLeafListNode() {
449 final ListNodeBuilder<Object, LeafSetEntryNode<Object>> leafSetBuilder = Builders
451 leafSetBuilder.withNodeIdentifier(new NodeIdentifier(leafrefLeafList));
453 leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k1"));
454 leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k2"));
455 leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k3"));
457 return leafSetBuilder.build();
460 private static ContainerNode createCon3Node() {
462 final CollectionNodeBuilder<MapEntryNode, MapNode> mapBuilder = Builders
464 mapBuilder.withNodeIdentifier(new NodeIdentifier(list3InChoice));
466 mapBuilder.addChild(createList3Entry("k1", "val1", "valA", "valX"));
467 mapBuilder.addChild(createList3Entry("k2", "val2", "valB", "valY"));
469 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choiceBuilder = Builders
471 choiceBuilder.withNodeIdentifier(new NodeIdentifier(choiceInCon3));
473 choiceBuilder.addChild(mapBuilder.build());
475 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> containerBuilder = Builders
477 containerBuilder.withNodeIdentifier(new NodeIdentifier(con3));
479 containerBuilder.addChild(choiceBuilder.build());
481 return containerBuilder.build();
484 private static MapEntryNode createList3Entry(final String keyVal,
485 final String l3Val1, final String l3Val2, final String l3Val3) {
486 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder = Builders
488 mapEntryBuilder.withNodeIdentifier(new NodeIdentifierWithPredicates(
489 list3InChoice, k, keyVal));
491 final ListNodeBuilder<Object, LeafSetEntryNode<Object>> leafSetBuilder = Builders
493 leafSetBuilder.withNodeIdentifier(new NodeIdentifier(l3));
495 leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val1));
496 leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val2));
497 leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val3));
499 mapEntryBuilder.addChild(ImmutableNodes.leafNode(k, keyVal));
500 mapEntryBuilder.addChild(leafSetBuilder.build());
502 return mapEntryBuilder.build();
505 private static LeafSetEntryNode<Object> createLeafSetEntry(
506 final QName qname, final String val) {
507 final NormalizedNodeAttrBuilder<NodeWithValue, Object, LeafSetEntryNode<Object>> leafSetEntryBuilder = Builders
508 .leafSetEntryBuilder();
509 leafSetEntryBuilder.withNodeIdentifier(new NodeWithValue<>(qname, val));
510 leafSetEntryBuilder.withValue(val);
511 return leafSetEntryBuilder.build();
514 private static ChoiceNode createChoiceNode() {
516 final CollectionNodeBuilder<MapEntryNode, MapNode> listInChoiceBuilder = Builders
519 .withNodeIdentifier(new NodeIdentifier(listInChoice));
521 listInChoiceBuilder.addChild(createListInChoiceEntry("key1",
522 "leafref-in-choice value", "val1"));
523 listInChoiceBuilder.addChild(createListInChoiceEntry("key2",
524 "l1 value", "val2"));
525 listInChoiceBuilder.addChild(createListInChoiceEntry("key3",
526 "l1 value", "val3"));
528 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choice2Builder = Builders
530 choice2Builder.withNodeIdentifier(new NodeIdentifier(ch2));
532 choice2Builder.addChild(listInChoiceBuilder.build());
534 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choiceBuilder = Builders
536 choiceBuilder.withNodeIdentifier(new NodeIdentifier(ch1));
537 choiceBuilder.addChild(choice2Builder.build());
539 return choiceBuilder.build();
542 private static MapEntryNode createListInChoiceEntry(final String keyVal,
543 final String leafrefInChoiceVal,
544 final String leafrefInChoiceToChoiceVal) {
546 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder = Builders
549 mapEntryBuilder.withNodeIdentifier(new NodeIdentifierWithPredicates(
550 listInChoice, listInChoiceKey, keyVal));
552 mapEntryBuilder.addChild(ImmutableNodes.leafNode(listInChoiceKey,
554 mapEntryBuilder.addChild(ImmutableNodes.leafNode(leafrefInChoice,
555 leafrefInChoiceVal));
556 mapEntryBuilder.addChild(ImmutableNodes.leafNode(
557 leafrefInChoiceToChoice, leafrefInChoiceToChoiceVal));
559 return mapEntryBuilder.build();
562 private static void delete() {
564 final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
566 final DataTreeModification delete = inMemoryDataTree.takeSnapshot()
568 delete.delete(contributorPath);
571 final DataTreeCandidate deleteContributorsCanditate = inMemoryDataTree
574 LOG.debug("*************************");
575 LOG.debug("Before delete: ");
576 LOG.debug("*************************");
577 LOG.debug(inMemoryDataTree.toString());
579 boolean exception = false;
581 LeafRefValidatation.validate(deleteContributorsCanditate,
583 } catch (final LeafRefDataValidationFailedException e) {
584 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
585 assertEquals(6, e.getValidationsErrorsCount());
589 assertTrue(exception);
591 inMemoryDataTree.commit(deleteContributorsCanditate);
593 LOG.debug("*************************");
594 LOG.debug("After delete: ");
595 LOG.debug("*************************");
596 LOG.debug(inMemoryDataTree.toString());
600 private static ContainerNode createContributorContainer(
601 final ContainerSchemaNode contributorContSchemaNode) {
603 final ListSchemaNode contributorListSchemaNode = (ListSchemaNode) contributorContSchemaNode
604 .getDataChildByName(contributor);
606 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> contributorContainerBldr = Builders
607 .containerBuilder(contributorContSchemaNode);
609 final MapNode contributorMap = createContributorList(contributorListSchemaNode);
610 contributorContainerBldr.addChild(contributorMap);
612 final ContainerNode contributorContainer = contributorContainerBldr
615 return contributorContainer;
619 private static MapNode createContributorList(
620 final ListSchemaNode contributorListSchemaNode) {
622 final CollectionNodeBuilder<MapEntryNode, MapNode> contributorMapBldr = Builders
623 .mapBuilder(contributorListSchemaNode);
625 final MapEntryNode contributorMapEntry1 = createContributorListEntry(
626 "Leader of Yangtools", "Yangtools Leader name", "Yangtools",
627 "Yangtools description ...", contributorListSchemaNode);
628 final MapEntryNode contributorMapEntry2 = createContributorListEntry(
629 "Leader of MD-SAL", "MD-SAL Leader name", "MD-SAL",
630 "MD-SAL description ...", contributorListSchemaNode);
631 final MapEntryNode contributorMapEntry3 = createContributorListEntry(
632 "Leader of Controller", "Controller Leader name", "Controller",
633 "Controller description ...", contributorListSchemaNode);
635 final MapEntryNode contributorMapEntry4 = createContributorListEntry(
636 "jdoe", "John Doe", "MD-SAL", "Yangtools description ...",
637 contributorListSchemaNode);
639 final MapEntryNode contributorMapEntry5 = createContributorListEntry(
640 "foo", "foo name", "Controller", "MD-SAL description ...",
641 contributorListSchemaNode);
643 final MapEntryNode contributorMapEntry6 = createContributorListEntry(
644 "bar", "bar name", "Yangtools", "Controller description ...",
645 contributorListSchemaNode);
647 final MapEntryNode contributorMapEntry7 = createContributorListEntry(
648 "baz", "baz name", "Unknown Project",
649 "Unknown Project description ...", contributorListSchemaNode);
651 final MapEntryNode contributorMapEntry8 = createContributorListEntry(
652 "pk", "pk name", "Unknown Project 2",
653 "Controller description ...", contributorListSchemaNode);
655 contributorMapBldr.addChild(contributorMapEntry1);
656 contributorMapBldr.addChild(contributorMapEntry2);
657 contributorMapBldr.addChild(contributorMapEntry3);
658 contributorMapBldr.addChild(contributorMapEntry4);
659 contributorMapBldr.addChild(contributorMapEntry5);
660 contributorMapBldr.addChild(contributorMapEntry6);
661 contributorMapBldr.addChild(contributorMapEntry7);
662 contributorMapBldr.addChild(contributorMapEntry8);
664 final MapNode contributorMap = contributorMapBldr.build();
666 return contributorMap;
670 private static MapEntryNode createContributorListEntry(
671 final String loginVal, final String contributorNameVal,
672 final String odlProjectNameVal, final String odlProjectDescVal,
673 final ListSchemaNode contributorListSchemaNode) {
675 final LeafNode<String> loginLeaf = ImmutableNodes.leafNode(login,
677 final LeafNode<String> contributorNameLeaf = ImmutableNodes.leafNode(
678 contributorName, contributorNameVal);
679 final LeafNode<String> odlProjectNameLeafRef = ImmutableNodes.leafNode(
680 odlProjectName, odlProjectNameVal);
681 final LeafNode<String> odlProjectDescLeafRef = ImmutableNodes.leafNode(
682 odlProjectDesc, odlProjectDescVal);
684 return Builders.mapEntryBuilder(contributorListSchemaNode)
686 .addChild(contributorNameLeaf)
687 .addChild(odlProjectNameLeafRef)
688 .addChild(odlProjectDescLeafRef)
692 private static ContainerNode createOdlContainer(
693 final ContainerSchemaNode container) {
695 final ListSchemaNode projListSchemaNode = (ListSchemaNode) container
696 .getDataChildByName(project);
698 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> odlProjectContainerBldr = Builders
699 .containerBuilder(container);
701 final MapNode projectMap = createProjectList(projListSchemaNode);
702 odlProjectContainerBldr.addChild(projectMap);
704 final ContainerNode odlProjectContainer = odlProjectContainerBldr
707 return odlProjectContainer;
710 private static MapNode createProjectList(
711 final ListSchemaNode projListSchemaNode) {
713 final CollectionNodeBuilder<MapEntryNode, MapNode> projectMapBldr = Builders
714 .mapBuilder(projListSchemaNode);
716 final MapEntryNode projMapEntry1 = createProjectListEntry("Yangtools",
717 "Yangtools description ...", "Leader of Yangtools",
718 "Owner of Yangtools", projListSchemaNode);
719 final MapEntryNode projMapEntry2 = createProjectListEntry("MD-SAL",
720 "MD-SAL description ...", "Leader of MD-SAL",
721 "Owner of MD-SAL", projListSchemaNode);
722 final MapEntryNode projMapEntry3 = createProjectListEntry("Controller",
723 "Controller description ...", "Leader of Controller",
724 "Owner of Controller", projListSchemaNode);
726 projectMapBldr.addChild(projMapEntry1);
727 projectMapBldr.addChild(projMapEntry2);
728 projectMapBldr.addChild(projMapEntry3);
730 final MapNode projectMap = projectMapBldr.build();
735 private static MapEntryNode createProjectListEntry(final String nameVal,
736 final String descVal, final String leadVal, final String ownerVal,
737 final ListSchemaNode projListSchemaNode) {
739 final LeafNode<String> nameLeaf = ImmutableNodes
740 .leafNode(name, nameVal);
741 final LeafNode<String> descLeaf = ImmutableNodes
742 .leafNode(desc, descVal);
743 final LeafNode<String> leadLeafRef = ImmutableNodes.leafNode(lead,
745 final LeafNode<String> ownerLeafRef = ImmutableNodes.leafNode(owner,
748 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> projMapEntryBldr = Builders
749 .mapEntryBuilder(projListSchemaNode);
751 projMapEntryBldr.addChild(nameLeaf);
752 projMapEntryBldr.addChild(descLeaf);
753 projMapEntryBldr.addChild(leadLeafRef);
754 projMapEntryBldr.addChild(ownerLeafRef);
755 final MapEntryNode projMapEntry = projMapEntryBldr.build();
760 private static ContainerNode createBasicContributorContainer(
761 final ContainerSchemaNode contributorContSchemaNode) {
763 final ListSchemaNode contributorListSchemaNode = (ListSchemaNode) contributorContSchemaNode
764 .getDataChildByName(contributor);
766 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> contributorContainerBldr = Builders
767 .containerBuilder(contributorContSchemaNode);
769 final MapNode contributorMap = createBasicContributorList(contributorListSchemaNode);
770 contributorContainerBldr.addChild(contributorMap);
772 final ContainerNode contributorContainer = contributorContainerBldr
775 return contributorContainer;
779 private static MapNode createBasicContributorList(
780 final ListSchemaNode contributorListSchemaNode) {
782 final CollectionNodeBuilder<MapEntryNode, MapNode> contributorMapBldr = Builders
783 .mapBuilder(contributorListSchemaNode);
785 final MapEntryNode contributorMapEntry1 = createContributorListEntry(
786 "Leader of Yangtools", "Yangtools Leader name", "Yangtools",
787 "Yangtools description ...", contributorListSchemaNode);
788 final MapEntryNode contributorMapEntry2 = createContributorListEntry(
789 "Leader of MD-SAL", "MD-SAL Leader name", "MD-SAL",
790 "MD-SAL description ...", contributorListSchemaNode);
791 final MapEntryNode contributorMapEntry3 = createContributorListEntry(
792 "Leader of Controller", "Controller Leader name", "Controller",
793 "Controller description ...", contributorListSchemaNode);
795 contributorMapBldr.addChild(contributorMapEntry1);
796 contributorMapBldr.addChild(contributorMapEntry2);
797 contributorMapBldr.addChild(contributorMapEntry3);
799 final MapNode contributorMap = contributorMapBldr.build();
801 return contributorMap;