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.api.schema.tree.DataValidationFailedException;
38 import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContext;
39 import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefDataValidationFailedException;
40 import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefValidation;
41 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
42 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
43 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
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.NormalizedNodeBuilder;
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() throws DataValidationFailedException {
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.findDataChildByName(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() throws DataValidationFailedException {
193 private static void writeContributors() throws DataValidationFailedException {
195 final ContainerSchemaNode contributorContSchemaNode = (ContainerSchemaNode) valModule
196 .findDataChildByName(odlContributor).get();
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 LeafRefValidation.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() throws DataValidationFailedException {
238 final Map<QName, Object> keys = new HashMap<>();
239 keys.put(name, "New Project");
240 final NodeIdentifierWithPredicates mapEntryPath = NodeIdentifierWithPredicates.of(project, keys);
242 final YangInstanceIdentifier leaderPath = YangInstanceIdentifier
243 .of(odl).node(project).node(mapEntryPath).node(lead);
245 final LeafNode<String> leader = ImmutableNodes.leafNode(lead,
248 final DataTreeModification writeModification = inMemoryDataTree
249 .takeSnapshot().newModification();
250 writeModification.write(leaderPath, leader);
251 writeModification.ready();
253 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
254 .prepare(writeModification);
256 LOG.debug("*************************");
257 LOG.debug("Before write into map entry (update of leader name): ");
258 LOG.debug("*************************");
259 LOG.debug(inMemoryDataTree.toString());
261 boolean exception = false;
263 LeafRefValidation.validate(writeContributorsCandidate,
265 } catch (final LeafRefDataValidationFailedException e) {
266 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
267 assertEquals(1, e.getValidationsErrorsCount());
271 inMemoryDataTree.commit(writeContributorsCandidate);
273 LOG.debug("*************************");
274 LOG.debug("After write into map entry (update of leader name): ");
275 LOG.debug("*************************");
276 LOG.debug(inMemoryDataTree.toString());
278 assertTrue(exception);
282 private static void writeMapEntry() throws DataValidationFailedException {
284 final Map<QName, Object> keys = new HashMap<>();
285 keys.put(name, "New Project");
286 final NodeIdentifierWithPredicates mapEntryPath = NodeIdentifierWithPredicates.of(project, keys);
288 final YangInstanceIdentifier newOdlProjectMapEntryPath = YangInstanceIdentifier
289 .of(odl).node(project).node(mapEntryPath);
291 final ContainerSchemaNode odlProjContSchemaNode = (ContainerSchemaNode) valModule.findDataChildByName(odl)
293 final ListSchemaNode projListSchemaNode = (ListSchemaNode) odlProjContSchemaNode.findDataChildByName(project)
295 final MapEntryNode newProjectMapEntry = createProjectListEntry(
296 "New Project", "New Project description ...",
297 "Leader of New Project", "Owner of New Project",
300 final DataTreeModification writeModification = inMemoryDataTree
301 .takeSnapshot().newModification();
302 writeModification.write(newOdlProjectMapEntryPath, newProjectMapEntry);
303 writeModification.ready();
305 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
306 .prepare(writeModification);
308 LOG.debug("*************************");
309 LOG.debug("Before map entry write: ");
310 LOG.debug("*************************");
311 LOG.debug(inMemoryDataTree.toString());
313 boolean exception = false;
315 LeafRefValidation.validate(writeContributorsCandidate,
317 } catch (final LeafRefDataValidationFailedException e) {
318 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
319 assertEquals(2, e.getValidationsErrorsCount());
323 inMemoryDataTree.commit(writeContributorsCandidate);
325 LOG.debug("*************************");
326 LOG.debug("After map entry write: ");
327 LOG.debug("*************************");
328 LOG.debug(inMemoryDataTree.toString());
330 assertTrue(exception);
334 private static void write() throws DataValidationFailedException {
336 final ContainerSchemaNode contributorContSchemaNode = (ContainerSchemaNode) valModule
337 .findDataChildByName(odlContributor).get();
339 final ContainerNode contributorContainer = createContributorContainer(contributorContSchemaNode);
341 final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
343 final DataTreeModification writeModification = inMemoryDataTree
344 .takeSnapshot().newModification();
345 writeModification.write(contributorPath, contributorContainer);
347 writeModification.write(YangInstanceIdentifier.of(l1),
348 ImmutableNodes.leafNode(l1, "Leafref l1 under the root"));
350 .write(YangInstanceIdentifier.of(l2), ImmutableNodes.leafNode(
351 l2, "Leafref target l2 under the root"));
353 writeModification.ready();
354 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
355 .prepare(writeModification);
357 LOG.debug("*************************");
358 LOG.debug("Before write: ");
359 LOG.debug("*************************");
360 LOG.debug(inMemoryDataTree.toString());
362 boolean exception = false;
364 LeafRefValidation.validate(writeContributorsCandidate,
366 } catch (final LeafRefDataValidationFailedException e) {
367 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
368 assertEquals(12, e.getValidationsErrorsCount());
372 inMemoryDataTree.commit(writeContributorsCandidate);
374 LOG.debug("*************************");
375 LOG.debug("After write: ");
376 LOG.debug("*************************");
377 LOG.debug(inMemoryDataTree.toString());
379 assertTrue(exception);
382 private static void write2() throws DataValidationFailedException {
384 final ContainerSchemaNode odlCon = (ContainerSchemaNode) valModule.findDataChildByName(odl).get();
385 final ContainerSchemaNode con1Con = (ContainerSchemaNode) odlCon.findDataChildByName(con1).get();
386 final LeafNode<String> l1Leaf = ImmutableNodes.leafNode(l1, "l1 value");
387 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> containerBuilder = Builders
388 .containerBuilder(con1Con);
389 containerBuilder.addChild(l1Leaf);
390 final ContainerNode con1Node = containerBuilder.build();
392 final YangInstanceIdentifier con1Path = YangInstanceIdentifier.of(odl)
394 final DataTreeModification writeModification = inMemoryDataTree
395 .takeSnapshot().newModification();
396 writeModification.write(con1Path, con1Node);
398 final ChoiceNode choiceNode = createChoiceNode();
399 final YangInstanceIdentifier choicePath = YangInstanceIdentifier
401 writeModification.write(choicePath, choiceNode);
403 final ContainerNode con3Node = createCon3Node();
404 final YangInstanceIdentifier con3Path = YangInstanceIdentifier.of(odl)
406 writeModification.write(con3Path, con3Node);
408 final LeafSetNode<?> leafListNode = createLeafRefLeafListNode();
409 final YangInstanceIdentifier leafListPath = YangInstanceIdentifier.of(
410 odl).node(leafrefLeafList);
411 writeModification.write(leafListPath, leafListNode);
412 writeModification.ready();
414 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
415 .prepare(writeModification);
417 LOG.debug("*************************");
418 LOG.debug("Before write2: ");
419 LOG.debug("*************************");
420 LOG.debug(inMemoryDataTree.toString());
422 boolean exception = false;
424 LeafRefValidation.validate(writeContributorsCandidate,
426 } catch (final LeafRefDataValidationFailedException e) {
427 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
428 assertEquals(6, e.getValidationsErrorsCount());
432 assertTrue(exception);
434 inMemoryDataTree.commit(writeContributorsCandidate);
436 LOG.debug("*************************");
437 LOG.debug("After write2: ");
438 LOG.debug("*************************");
439 LOG.debug(inMemoryDataTree.toString());
443 private static LeafSetNode<?> createLeafRefLeafListNode() {
445 final ListNodeBuilder<Object, LeafSetEntryNode<Object>> leafSetBuilder = Builders
447 leafSetBuilder.withNodeIdentifier(new NodeIdentifier(leafrefLeafList));
449 leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k1"));
450 leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k2"));
451 leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k3"));
453 return leafSetBuilder.build();
456 private static ContainerNode createCon3Node() {
458 final CollectionNodeBuilder<MapEntryNode, MapNode> mapBuilder = Builders
460 mapBuilder.withNodeIdentifier(new NodeIdentifier(list3InChoice));
462 mapBuilder.addChild(createList3Entry("k1", "val1", "valA", "valX"));
463 mapBuilder.addChild(createList3Entry("k2", "val2", "valB", "valY"));
465 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choiceBuilder = Builders
467 choiceBuilder.withNodeIdentifier(new NodeIdentifier(choiceInCon3));
469 choiceBuilder.addChild(mapBuilder.build());
471 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> containerBuilder = Builders
473 containerBuilder.withNodeIdentifier(new NodeIdentifier(con3));
475 containerBuilder.addChild(choiceBuilder.build());
477 return containerBuilder.build();
480 private static MapEntryNode createList3Entry(final String keyVal,
481 final String l3Val1, final String l3Val2, final String l3Val3) {
482 final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder = Builders
484 mapEntryBuilder.withNodeIdentifier(NodeIdentifierWithPredicates.of(list3InChoice, k, keyVal));
486 final ListNodeBuilder<Object, LeafSetEntryNode<Object>> leafSetBuilder = Builders
488 leafSetBuilder.withNodeIdentifier(new NodeIdentifier(l3));
490 leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val1));
491 leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val2));
492 leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val3));
494 mapEntryBuilder.addChild(ImmutableNodes.leafNode(k, keyVal));
495 mapEntryBuilder.addChild(leafSetBuilder.build());
497 return mapEntryBuilder.build();
500 private static LeafSetEntryNode<Object> createLeafSetEntry(
501 final QName qname, final String val) {
502 final NormalizedNodeBuilder<NodeWithValue, Object, LeafSetEntryNode<Object>> leafSetEntryBuilder = Builders
503 .leafSetEntryBuilder();
504 leafSetEntryBuilder.withNodeIdentifier(new NodeWithValue<>(qname, val));
505 leafSetEntryBuilder.withValue(val);
506 return leafSetEntryBuilder.build();
509 private static ChoiceNode createChoiceNode() {
511 final CollectionNodeBuilder<MapEntryNode, MapNode> listInChoiceBuilder = Builders
514 .withNodeIdentifier(new NodeIdentifier(listInChoice));
516 listInChoiceBuilder.addChild(createListInChoiceEntry("key1",
517 "leafref-in-choice value", "val1"));
518 listInChoiceBuilder.addChild(createListInChoiceEntry("key2",
519 "l1 value", "val2"));
520 listInChoiceBuilder.addChild(createListInChoiceEntry("key3",
521 "l1 value", "val3"));
523 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choice2Builder = Builders
525 choice2Builder.withNodeIdentifier(new NodeIdentifier(ch2));
527 choice2Builder.addChild(listInChoiceBuilder.build());
529 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choiceBuilder = Builders
531 choiceBuilder.withNodeIdentifier(new NodeIdentifier(ch1));
532 choiceBuilder.addChild(choice2Builder.build());
534 return choiceBuilder.build();
537 private static MapEntryNode createListInChoiceEntry(final String keyVal,
538 final String leafrefInChoiceVal,
539 final String leafrefInChoiceToChoiceVal) {
541 final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder = Builders
544 mapEntryBuilder.withNodeIdentifier(NodeIdentifierWithPredicates.of(
545 listInChoice, listInChoiceKey, keyVal));
547 mapEntryBuilder.addChild(ImmutableNodes.leafNode(listInChoiceKey,
549 mapEntryBuilder.addChild(ImmutableNodes.leafNode(leafrefInChoice,
550 leafrefInChoiceVal));
551 mapEntryBuilder.addChild(ImmutableNodes.leafNode(
552 leafrefInChoiceToChoice, leafrefInChoiceToChoiceVal));
554 return mapEntryBuilder.build();
557 private static void delete() throws DataValidationFailedException {
559 final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
561 final DataTreeModification delete = inMemoryDataTree.takeSnapshot()
563 delete.delete(contributorPath);
566 final DataTreeCandidate deleteContributorsCanditate = inMemoryDataTree.prepare(delete);
568 LOG.debug("*************************");
569 LOG.debug("Before delete: ");
570 LOG.debug("*************************");
571 LOG.debug(inMemoryDataTree.toString());
573 boolean exception = false;
575 LeafRefValidation.validate(deleteContributorsCanditate,
577 } catch (final LeafRefDataValidationFailedException e) {
578 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
579 assertEquals(6, e.getValidationsErrorsCount());
583 assertTrue(exception);
585 inMemoryDataTree.commit(deleteContributorsCanditate);
587 LOG.debug("*************************");
588 LOG.debug("After delete: ");
589 LOG.debug("*************************");
590 LOG.debug(inMemoryDataTree.toString());
594 private static ContainerNode createContributorContainer(
595 final ContainerSchemaNode contributorContSchemaNode) {
597 final ListSchemaNode contributorListSchemaNode = (ListSchemaNode) contributorContSchemaNode
598 .findDataChildByName(contributor).get();
600 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> contributorContainerBldr = Builders
601 .containerBuilder(contributorContSchemaNode);
603 final MapNode contributorMap = createContributorList(contributorListSchemaNode);
604 contributorContainerBldr.addChild(contributorMap);
606 final ContainerNode contributorContainer = contributorContainerBldr
609 return contributorContainer;
613 private static MapNode createContributorList(
614 final ListSchemaNode contributorListSchemaNode) {
616 final CollectionNodeBuilder<MapEntryNode, MapNode> contributorMapBldr = Builders
617 .mapBuilder(contributorListSchemaNode);
619 final MapEntryNode contributorMapEntry1 = createContributorListEntry(
620 "Leader of Yangtools", "Yangtools Leader name", "Yangtools",
621 "Yangtools description ...", contributorListSchemaNode);
622 final MapEntryNode contributorMapEntry2 = createContributorListEntry(
623 "Leader of MD-SAL", "MD-SAL Leader name", "MD-SAL",
624 "MD-SAL description ...", contributorListSchemaNode);
625 final MapEntryNode contributorMapEntry3 = createContributorListEntry(
626 "Leader of Controller", "Controller Leader name", "Controller",
627 "Controller description ...", contributorListSchemaNode);
629 final MapEntryNode contributorMapEntry4 = createContributorListEntry(
630 "jdoe", "John Doe", "MD-SAL", "Yangtools description ...",
631 contributorListSchemaNode);
633 final MapEntryNode contributorMapEntry5 = createContributorListEntry(
634 "foo", "foo name", "Controller", "MD-SAL description ...",
635 contributorListSchemaNode);
637 final MapEntryNode contributorMapEntry6 = createContributorListEntry(
638 "bar", "bar name", "Yangtools", "Controller description ...",
639 contributorListSchemaNode);
641 final MapEntryNode contributorMapEntry7 = createContributorListEntry(
642 "baz", "baz name", "Unknown Project",
643 "Unknown Project description ...", contributorListSchemaNode);
645 final MapEntryNode contributorMapEntry8 = createContributorListEntry(
646 "pk", "pk name", "Unknown Project 2",
647 "Controller description ...", contributorListSchemaNode);
649 contributorMapBldr.addChild(contributorMapEntry1);
650 contributorMapBldr.addChild(contributorMapEntry2);
651 contributorMapBldr.addChild(contributorMapEntry3);
652 contributorMapBldr.addChild(contributorMapEntry4);
653 contributorMapBldr.addChild(contributorMapEntry5);
654 contributorMapBldr.addChild(contributorMapEntry6);
655 contributorMapBldr.addChild(contributorMapEntry7);
656 contributorMapBldr.addChild(contributorMapEntry8);
658 final MapNode contributorMap = contributorMapBldr.build();
660 return contributorMap;
664 private static MapEntryNode createContributorListEntry(
665 final String loginVal, final String contributorNameVal,
666 final String odlProjectNameVal, final String odlProjectDescVal,
667 final ListSchemaNode contributorListSchemaNode) {
669 final LeafNode<String> loginLeaf = ImmutableNodes.leafNode(login, loginVal);
670 final LeafNode<String> contributorNameLeaf = ImmutableNodes.leafNode(contributorName, contributorNameVal);
671 final LeafNode<String> odlProjectNameLeafRef = ImmutableNodes.leafNode(odlProjectName, odlProjectNameVal);
672 final LeafNode<String> odlProjectDescLeafRef = ImmutableNodes.leafNode(odlProjectDesc, odlProjectDescVal);
674 return Builders.mapEntryBuilder(contributorListSchemaNode)
676 .addChild(contributorNameLeaf)
677 .addChild(odlProjectNameLeafRef)
678 .addChild(odlProjectDescLeafRef)
682 private static ContainerNode createOdlContainer(
683 final ContainerSchemaNode container) {
685 final ListSchemaNode projListSchemaNode = (ListSchemaNode) container.findDataChildByName(project).get();
687 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> odlProjectContainerBldr = Builders
688 .containerBuilder(container);
690 final MapNode projectMap = createProjectList(projListSchemaNode);
691 odlProjectContainerBldr.addChild(projectMap);
693 final ContainerNode odlProjectContainer = odlProjectContainerBldr
696 return odlProjectContainer;
699 private static MapNode createProjectList(
700 final ListSchemaNode projListSchemaNode) {
702 final CollectionNodeBuilder<MapEntryNode, MapNode> projectMapBldr = Builders
703 .mapBuilder(projListSchemaNode);
705 final MapEntryNode projMapEntry1 = createProjectListEntry("Yangtools",
706 "Yangtools description ...", "Leader of Yangtools",
707 "Owner of Yangtools", projListSchemaNode);
708 final MapEntryNode projMapEntry2 = createProjectListEntry("MD-SAL",
709 "MD-SAL description ...", "Leader of MD-SAL",
710 "Owner of MD-SAL", projListSchemaNode);
711 final MapEntryNode projMapEntry3 = createProjectListEntry("Controller",
712 "Controller description ...", "Leader of Controller",
713 "Owner of Controller", projListSchemaNode);
715 projectMapBldr.addChild(projMapEntry1);
716 projectMapBldr.addChild(projMapEntry2);
717 projectMapBldr.addChild(projMapEntry3);
719 final MapNode projectMap = projectMapBldr.build();
724 private static MapEntryNode createProjectListEntry(final String nameVal,
725 final String descVal, final String leadVal, final String ownerVal,
726 final ListSchemaNode projListSchemaNode) {
728 final LeafNode<String> nameLeaf = ImmutableNodes
729 .leafNode(name, nameVal);
730 final LeafNode<String> descLeaf = ImmutableNodes
731 .leafNode(desc, descVal);
732 final LeafNode<String> leadLeafRef = ImmutableNodes.leafNode(lead,
734 final LeafNode<String> ownerLeafRef = ImmutableNodes.leafNode(owner,
737 final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> projMapEntryBldr = Builders
738 .mapEntryBuilder(projListSchemaNode);
740 projMapEntryBldr.addChild(nameLeaf);
741 projMapEntryBldr.addChild(descLeaf);
742 projMapEntryBldr.addChild(leadLeafRef);
743 projMapEntryBldr.addChild(ownerLeafRef);
744 final MapEntryNode projMapEntry = projMapEntryBldr.build();
749 private static ContainerNode createBasicContributorContainer(
750 final ContainerSchemaNode contributorContSchemaNode) {
752 final ListSchemaNode contributorListSchemaNode = (ListSchemaNode) contributorContSchemaNode
753 .findDataChildByName(contributor).get();
755 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> contributorContainerBldr = Builders
756 .containerBuilder(contributorContSchemaNode);
758 final MapNode contributorMap = createBasicContributorList(contributorListSchemaNode);
759 contributorContainerBldr.addChild(contributorMap);
761 final ContainerNode contributorContainer = contributorContainerBldr
764 return contributorContainer;
768 private static MapNode createBasicContributorList(
769 final ListSchemaNode contributorListSchemaNode) {
771 final CollectionNodeBuilder<MapEntryNode, MapNode> contributorMapBldr = Builders
772 .mapBuilder(contributorListSchemaNode);
774 final MapEntryNode contributorMapEntry1 = createContributorListEntry(
775 "Leader of Yangtools", "Yangtools Leader name", "Yangtools",
776 "Yangtools description ...", contributorListSchemaNode);
777 final MapEntryNode contributorMapEntry2 = createContributorListEntry(
778 "Leader of MD-SAL", "MD-SAL Leader name", "MD-SAL",
779 "MD-SAL description ...", contributorListSchemaNode);
780 final MapEntryNode contributorMapEntry3 = createContributorListEntry(
781 "Leader of Controller", "Controller Leader name", "Controller",
782 "Controller description ...", contributorListSchemaNode);
784 contributorMapBldr.addChild(contributorMapEntry1);
785 contributorMapBldr.addChild(contributorMapEntry2);
786 contributorMapBldr.addChild(contributorMapEntry3);
788 final MapNode contributorMap = contributorMapBldr.build();
790 return contributorMap;