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.apache.log4j.BasicConfigurator;
16 import org.junit.AfterClass;
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.api.schema.tree.DataValidationFailedException;
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.LeafRefValidation;
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.DataContainerNodeBuilder;
44 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
45 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder;
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;
55 public class DataTreeCandidateValidatorTest {
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;
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;
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;
89 private static QName listInChoiceKey;
90 private static QName k;
92 private static QName leafrefLeafList;
94 private static final Logger LOG = LoggerFactory.getLogger(DataTreeCandidateValidatorTest.class);
95 private static final String NEW_LINE = System.getProperty("line.separator");
98 BasicConfigurator.configure();
102 public static void init() throws DataValidationFailedException {
103 context = YangParserTestUtils.parseYangResourceDirectory("/leafref-validation");
105 for (final Module module : context.getModules()) {
106 if (module.getName().equals("leafref-validation")) {
111 valModuleQname = valModule.getQNameModule();
112 rootLeafRefContext = LeafRefContext.create(context);
114 odl = QName.create(valModuleQname, "odl-project");
115 project = QName.create(valModuleQname, "project");
116 name = QName.create(valModuleQname, "name");
117 desc = QName.create(valModuleQname, "desc");
118 lead = QName.create(valModuleQname, "project-lead");
119 owner = QName.create(valModuleQname, "project-owner");
121 odlContributor = QName.create(valModuleQname, "odl-contributor");
122 contributor = QName.create(valModuleQname, "contributor");
123 odlProjectName = QName.create(valModuleQname, "odl-project-name");
124 login = QName.create(valModuleQname, "login");
125 contributorName = QName.create(valModuleQname, "contributor-name");
127 con1 = QName.create(valModuleQname, "con1");
128 l1 = QName.create(valModuleQname, "l1");
129 l2 = QName.create(valModuleQname, "l2");
130 odlProjectDesc = QName.create(valModuleQname, "odl-project-desc");
132 ch1 = QName.create(valModuleQname, "ch1");
133 ch2 = QName.create(valModuleQname, "ch2");
134 leafrefInChoice = QName.create(valModuleQname, "leafref-in-choice");
135 listInChoice = QName.create(valModuleQname, "list-in-choice");
137 leafrefInChoiceToChoice = QName.create(valModuleQname,
138 "leafref-in-choice-to-choice");
139 con3 = QName.create(valModuleQname, "con3");
140 list3InChoice = QName.create(valModuleQname, "list3-in-choice");
141 l3 = QName.create(valModuleQname, "l3");
142 choiceInCon3 = QName.create(valModuleQname, "choice-in-con3");
144 listInChoiceKey = QName.create(valModuleQname, "list-in-choice-key");
145 k = QName.create(valModuleQname, "k");
147 leafrefLeafList = QName.create(valModuleQname, "leafref-leaf-list");
149 inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, context);
151 final DataTreeModification initialDataTreeModification = inMemoryDataTree
152 .takeSnapshot().newModification();
154 final ContainerSchemaNode odlProjContSchemaNode = (ContainerSchemaNode) valModule.findDataChildByName(odl)
157 final ContainerNode odlProjectContainer = createOdlContainer(odlProjContSchemaNode);
159 final YangInstanceIdentifier path = YangInstanceIdentifier.of(odl);
160 initialDataTreeModification.write(path, odlProjectContainer);
161 initialDataTreeModification.ready();
163 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
164 .prepare(initialDataTreeModification);
165 inMemoryDataTree.commit(writeContributorsCandidate);
169 public static void cleanup() {
170 inMemoryDataTree = null;
171 rootLeafRefContext = null;
177 public void dataTreeCanditateValidationTest() throws DataValidationFailedException {
191 private static void writeContributors() throws DataValidationFailedException {
193 final ContainerSchemaNode contributorContSchemaNode = (ContainerSchemaNode) valModule
194 .findDataChildByName(odlContributor).get();
196 final ContainerNode contributorContainer = createBasicContributorContainer(contributorContSchemaNode);
198 final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
200 final DataTreeModification writeModification = inMemoryDataTree
201 .takeSnapshot().newModification();
202 writeModification.write(contributorPath, contributorContainer);
203 writeModification.ready();
205 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
206 .prepare(writeModification);
208 LOG.debug("*************************");
209 LOG.debug("Before write of contributors: ");
210 LOG.debug("*************************");
211 LOG.debug(inMemoryDataTree.toString());
213 boolean exception = false;
215 LeafRefValidation.validate(writeContributorsCandidate,
217 } catch (final LeafRefDataValidationFailedException e) {
218 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
219 assertEquals(3, e.getValidationsErrorsCount());
223 inMemoryDataTree.commit(writeContributorsCandidate);
225 LOG.debug("*************************");
226 LOG.debug("After write of contributors: ");
227 LOG.debug("*************************");
228 LOG.debug(inMemoryDataTree.toString());
230 assertTrue(exception);
234 private static void writeIntoMapEntry() throws DataValidationFailedException {
236 final Map<QName, Object> keys = new HashMap<>();
237 keys.put(name, "New Project");
238 final NodeIdentifierWithPredicates mapEntryPath = NodeIdentifierWithPredicates.of(project, keys);
240 final YangInstanceIdentifier leaderPath = YangInstanceIdentifier
241 .of(odl).node(project).node(mapEntryPath).node(lead);
243 final LeafNode<String> leader = ImmutableNodes.leafNode(lead,
246 final DataTreeModification writeModification = inMemoryDataTree
247 .takeSnapshot().newModification();
248 writeModification.write(leaderPath, leader);
249 writeModification.ready();
251 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
252 .prepare(writeModification);
254 LOG.debug("*************************");
255 LOG.debug("Before write into map entry (update of leader name): ");
256 LOG.debug("*************************");
257 LOG.debug(inMemoryDataTree.toString());
259 boolean exception = false;
261 LeafRefValidation.validate(writeContributorsCandidate,
263 } catch (final LeafRefDataValidationFailedException e) {
264 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
265 assertEquals(1, e.getValidationsErrorsCount());
269 inMemoryDataTree.commit(writeContributorsCandidate);
271 LOG.debug("*************************");
272 LOG.debug("After write into map entry (update of leader name): ");
273 LOG.debug("*************************");
274 LOG.debug(inMemoryDataTree.toString());
276 assertTrue(exception);
280 private static void writeMapEntry() throws DataValidationFailedException {
282 final Map<QName, Object> keys = new HashMap<>();
283 keys.put(name, "New Project");
284 final NodeIdentifierWithPredicates mapEntryPath = NodeIdentifierWithPredicates.of(project, keys);
286 final YangInstanceIdentifier newOdlProjectMapEntryPath = YangInstanceIdentifier
287 .of(odl).node(project).node(mapEntryPath);
289 final ContainerSchemaNode odlProjContSchemaNode = (ContainerSchemaNode) valModule.findDataChildByName(odl)
291 final ListSchemaNode projListSchemaNode = (ListSchemaNode) odlProjContSchemaNode.findDataChildByName(project)
293 final MapEntryNode newProjectMapEntry = createProjectListEntry(
294 "New Project", "New Project description ...",
295 "Leader of New Project", "Owner of New Project",
298 final DataTreeModification writeModification = inMemoryDataTree
299 .takeSnapshot().newModification();
300 writeModification.write(newOdlProjectMapEntryPath, newProjectMapEntry);
301 writeModification.ready();
303 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
304 .prepare(writeModification);
306 LOG.debug("*************************");
307 LOG.debug("Before map entry write: ");
308 LOG.debug("*************************");
309 LOG.debug(inMemoryDataTree.toString());
311 boolean exception = false;
313 LeafRefValidation.validate(writeContributorsCandidate,
315 } catch (final LeafRefDataValidationFailedException e) {
316 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
317 assertEquals(2, e.getValidationsErrorsCount());
321 inMemoryDataTree.commit(writeContributorsCandidate);
323 LOG.debug("*************************");
324 LOG.debug("After map entry write: ");
325 LOG.debug("*************************");
326 LOG.debug(inMemoryDataTree.toString());
328 assertTrue(exception);
332 private static void write() throws DataValidationFailedException {
334 final ContainerSchemaNode contributorContSchemaNode = (ContainerSchemaNode) valModule
335 .findDataChildByName(odlContributor).get();
337 final ContainerNode contributorContainer = createContributorContainer(contributorContSchemaNode);
339 final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
341 final DataTreeModification writeModification = inMemoryDataTree
342 .takeSnapshot().newModification();
343 writeModification.write(contributorPath, contributorContainer);
345 writeModification.write(YangInstanceIdentifier.of(l1),
346 ImmutableNodes.leafNode(l1, "Leafref l1 under the root"));
348 .write(YangInstanceIdentifier.of(l2), ImmutableNodes.leafNode(
349 l2, "Leafref target l2 under the root"));
351 writeModification.ready();
352 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
353 .prepare(writeModification);
355 LOG.debug("*************************");
356 LOG.debug("Before write: ");
357 LOG.debug("*************************");
358 LOG.debug(inMemoryDataTree.toString());
360 boolean exception = false;
362 LeafRefValidation.validate(writeContributorsCandidate,
364 } catch (final LeafRefDataValidationFailedException e) {
365 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
366 assertEquals(12, e.getValidationsErrorsCount());
370 inMemoryDataTree.commit(writeContributorsCandidate);
372 LOG.debug("*************************");
373 LOG.debug("After write: ");
374 LOG.debug("*************************");
375 LOG.debug(inMemoryDataTree.toString());
377 assertTrue(exception);
380 private static void write2() throws DataValidationFailedException {
382 final ContainerSchemaNode odlCon = (ContainerSchemaNode) valModule.findDataChildByName(odl).get();
383 final ContainerSchemaNode con1Con = (ContainerSchemaNode) odlCon.findDataChildByName(con1).get();
384 final LeafNode<String> l1Leaf = ImmutableNodes.leafNode(l1, "l1 value");
385 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> containerBuilder = Builders
386 .containerBuilder(con1Con);
387 containerBuilder.addChild(l1Leaf);
388 final ContainerNode con1Node = containerBuilder.build();
390 final YangInstanceIdentifier con1Path = YangInstanceIdentifier.of(odl)
392 final DataTreeModification writeModification = inMemoryDataTree
393 .takeSnapshot().newModification();
394 writeModification.write(con1Path, con1Node);
396 final ChoiceNode choiceNode = createChoiceNode();
397 final YangInstanceIdentifier choicePath = YangInstanceIdentifier
399 writeModification.write(choicePath, choiceNode);
401 final ContainerNode con3Node = createCon3Node();
402 final YangInstanceIdentifier con3Path = YangInstanceIdentifier.of(odl)
404 writeModification.write(con3Path, con3Node);
406 final LeafSetNode<?> leafListNode = createLeafRefLeafListNode();
407 final YangInstanceIdentifier leafListPath = YangInstanceIdentifier.of(
408 odl).node(leafrefLeafList);
409 writeModification.write(leafListPath, leafListNode);
410 writeModification.ready();
412 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
413 .prepare(writeModification);
415 LOG.debug("*************************");
416 LOG.debug("Before write2: ");
417 LOG.debug("*************************");
418 LOG.debug(inMemoryDataTree.toString());
420 boolean exception = false;
422 LeafRefValidation.validate(writeContributorsCandidate,
424 } catch (final LeafRefDataValidationFailedException e) {
425 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
426 assertEquals(6, e.getValidationsErrorsCount());
430 assertTrue(exception);
432 inMemoryDataTree.commit(writeContributorsCandidate);
434 LOG.debug("*************************");
435 LOG.debug("After write2: ");
436 LOG.debug("*************************");
437 LOG.debug(inMemoryDataTree.toString());
441 private static LeafSetNode<?> createLeafRefLeafListNode() {
443 final ListNodeBuilder<Object, LeafSetEntryNode<Object>> leafSetBuilder = Builders
445 leafSetBuilder.withNodeIdentifier(new NodeIdentifier(leafrefLeafList));
447 leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k1"));
448 leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k2"));
449 leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k3"));
451 return leafSetBuilder.build();
454 private static ContainerNode createCon3Node() {
456 final CollectionNodeBuilder<MapEntryNode, MapNode> mapBuilder = Builders
458 mapBuilder.withNodeIdentifier(new NodeIdentifier(list3InChoice));
460 mapBuilder.addChild(createList3Entry("k1", "val1", "valA", "valX"));
461 mapBuilder.addChild(createList3Entry("k2", "val2", "valB", "valY"));
463 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choiceBuilder = Builders
465 choiceBuilder.withNodeIdentifier(new NodeIdentifier(choiceInCon3));
467 choiceBuilder.addChild(mapBuilder.build());
469 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> containerBuilder = Builders
471 containerBuilder.withNodeIdentifier(new NodeIdentifier(con3));
473 containerBuilder.addChild(choiceBuilder.build());
475 return containerBuilder.build();
478 private static MapEntryNode createList3Entry(final String keyVal,
479 final String l3Val1, final String l3Val2, final String l3Val3) {
480 final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder = Builders
482 mapEntryBuilder.withNodeIdentifier(NodeIdentifierWithPredicates.of(list3InChoice, k, keyVal));
484 final ListNodeBuilder<Object, LeafSetEntryNode<Object>> leafSetBuilder = Builders
486 leafSetBuilder.withNodeIdentifier(new NodeIdentifier(l3));
488 leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val1));
489 leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val2));
490 leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val3));
492 mapEntryBuilder.addChild(ImmutableNodes.leafNode(k, keyVal));
493 mapEntryBuilder.addChild(leafSetBuilder.build());
495 return mapEntryBuilder.build();
498 private static LeafSetEntryNode<Object> createLeafSetEntry(
499 final QName qname, final String val) {
500 final NormalizedNodeBuilder<NodeWithValue, Object, LeafSetEntryNode<Object>> leafSetEntryBuilder = Builders
501 .leafSetEntryBuilder();
502 leafSetEntryBuilder.withNodeIdentifier(new NodeWithValue<>(qname, val));
503 leafSetEntryBuilder.withValue(val);
504 return leafSetEntryBuilder.build();
507 private static ChoiceNode createChoiceNode() {
509 final CollectionNodeBuilder<MapEntryNode, MapNode> listInChoiceBuilder = Builders
512 .withNodeIdentifier(new NodeIdentifier(listInChoice));
514 listInChoiceBuilder.addChild(createListInChoiceEntry("key1",
515 "leafref-in-choice value", "val1"));
516 listInChoiceBuilder.addChild(createListInChoiceEntry("key2",
517 "l1 value", "val2"));
518 listInChoiceBuilder.addChild(createListInChoiceEntry("key3",
519 "l1 value", "val3"));
521 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choice2Builder = Builders
523 choice2Builder.withNodeIdentifier(new NodeIdentifier(ch2));
525 choice2Builder.addChild(listInChoiceBuilder.build());
527 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choiceBuilder = Builders
529 choiceBuilder.withNodeIdentifier(new NodeIdentifier(ch1));
530 choiceBuilder.addChild(choice2Builder.build());
532 return choiceBuilder.build();
535 private static MapEntryNode createListInChoiceEntry(final String keyVal,
536 final String leafrefInChoiceVal,
537 final String leafrefInChoiceToChoiceVal) {
539 final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder = Builders
542 mapEntryBuilder.withNodeIdentifier(NodeIdentifierWithPredicates.of(
543 listInChoice, listInChoiceKey, keyVal));
545 mapEntryBuilder.addChild(ImmutableNodes.leafNode(listInChoiceKey,
547 mapEntryBuilder.addChild(ImmutableNodes.leafNode(leafrefInChoice,
548 leafrefInChoiceVal));
549 mapEntryBuilder.addChild(ImmutableNodes.leafNode(
550 leafrefInChoiceToChoice, leafrefInChoiceToChoiceVal));
552 return mapEntryBuilder.build();
555 private static void delete() throws DataValidationFailedException {
557 final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
559 final DataTreeModification delete = inMemoryDataTree.takeSnapshot()
561 delete.delete(contributorPath);
564 final DataTreeCandidate deleteContributorsCanditate = inMemoryDataTree.prepare(delete);
566 LOG.debug("*************************");
567 LOG.debug("Before delete: ");
568 LOG.debug("*************************");
569 LOG.debug(inMemoryDataTree.toString());
571 boolean exception = false;
573 LeafRefValidation.validate(deleteContributorsCanditate,
575 } catch (final LeafRefDataValidationFailedException e) {
576 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
577 assertEquals(6, e.getValidationsErrorsCount());
581 assertTrue(exception);
583 inMemoryDataTree.commit(deleteContributorsCanditate);
585 LOG.debug("*************************");
586 LOG.debug("After delete: ");
587 LOG.debug("*************************");
588 LOG.debug(inMemoryDataTree.toString());
592 private static ContainerNode createContributorContainer(
593 final ContainerSchemaNode contributorContSchemaNode) {
595 final ListSchemaNode contributorListSchemaNode = (ListSchemaNode) contributorContSchemaNode
596 .findDataChildByName(contributor).get();
598 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> contributorContainerBldr = Builders
599 .containerBuilder(contributorContSchemaNode);
601 final MapNode contributorMap = createContributorList(contributorListSchemaNode);
602 contributorContainerBldr.addChild(contributorMap);
604 final ContainerNode contributorContainer = contributorContainerBldr
607 return contributorContainer;
611 private static MapNode createContributorList(
612 final ListSchemaNode contributorListSchemaNode) {
614 final CollectionNodeBuilder<MapEntryNode, MapNode> contributorMapBldr = Builders
615 .mapBuilder(contributorListSchemaNode);
617 final MapEntryNode contributorMapEntry1 = createContributorListEntry(
618 "Leader of Yangtools", "Yangtools Leader name", "Yangtools",
619 "Yangtools description ...", contributorListSchemaNode);
620 final MapEntryNode contributorMapEntry2 = createContributorListEntry(
621 "Leader of MD-SAL", "MD-SAL Leader name", "MD-SAL",
622 "MD-SAL description ...", contributorListSchemaNode);
623 final MapEntryNode contributorMapEntry3 = createContributorListEntry(
624 "Leader of Controller", "Controller Leader name", "Controller",
625 "Controller description ...", contributorListSchemaNode);
627 final MapEntryNode contributorMapEntry4 = createContributorListEntry(
628 "jdoe", "John Doe", "MD-SAL", "Yangtools description ...",
629 contributorListSchemaNode);
631 final MapEntryNode contributorMapEntry5 = createContributorListEntry(
632 "foo", "foo name", "Controller", "MD-SAL description ...",
633 contributorListSchemaNode);
635 final MapEntryNode contributorMapEntry6 = createContributorListEntry(
636 "bar", "bar name", "Yangtools", "Controller description ...",
637 contributorListSchemaNode);
639 final MapEntryNode contributorMapEntry7 = createContributorListEntry(
640 "baz", "baz name", "Unknown Project",
641 "Unknown Project description ...", contributorListSchemaNode);
643 final MapEntryNode contributorMapEntry8 = createContributorListEntry(
644 "pk", "pk name", "Unknown Project 2",
645 "Controller description ...", contributorListSchemaNode);
647 contributorMapBldr.addChild(contributorMapEntry1);
648 contributorMapBldr.addChild(contributorMapEntry2);
649 contributorMapBldr.addChild(contributorMapEntry3);
650 contributorMapBldr.addChild(contributorMapEntry4);
651 contributorMapBldr.addChild(contributorMapEntry5);
652 contributorMapBldr.addChild(contributorMapEntry6);
653 contributorMapBldr.addChild(contributorMapEntry7);
654 contributorMapBldr.addChild(contributorMapEntry8);
656 final MapNode contributorMap = contributorMapBldr.build();
658 return contributorMap;
662 private static MapEntryNode createContributorListEntry(
663 final String loginVal, final String contributorNameVal,
664 final String odlProjectNameVal, final String odlProjectDescVal,
665 final ListSchemaNode contributorListSchemaNode) {
667 final LeafNode<String> loginLeaf = ImmutableNodes.leafNode(login, loginVal);
668 final LeafNode<String> contributorNameLeaf = ImmutableNodes.leafNode(contributorName, contributorNameVal);
669 final LeafNode<String> odlProjectNameLeafRef = ImmutableNodes.leafNode(odlProjectName, odlProjectNameVal);
670 final LeafNode<String> odlProjectDescLeafRef = ImmutableNodes.leafNode(odlProjectDesc, odlProjectDescVal);
672 return Builders.mapEntryBuilder(contributorListSchemaNode)
674 .addChild(contributorNameLeaf)
675 .addChild(odlProjectNameLeafRef)
676 .addChild(odlProjectDescLeafRef)
680 private static ContainerNode createOdlContainer(
681 final ContainerSchemaNode container) {
683 final ListSchemaNode projListSchemaNode = (ListSchemaNode) container.findDataChildByName(project).get();
685 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> odlProjectContainerBldr = Builders
686 .containerBuilder(container);
688 final MapNode projectMap = createProjectList(projListSchemaNode);
689 odlProjectContainerBldr.addChild(projectMap);
691 final ContainerNode odlProjectContainer = odlProjectContainerBldr
694 return odlProjectContainer;
697 private static MapNode createProjectList(
698 final ListSchemaNode projListSchemaNode) {
700 final CollectionNodeBuilder<MapEntryNode, MapNode> projectMapBldr = Builders
701 .mapBuilder(projListSchemaNode);
703 final MapEntryNode projMapEntry1 = createProjectListEntry("Yangtools",
704 "Yangtools description ...", "Leader of Yangtools",
705 "Owner of Yangtools", projListSchemaNode);
706 final MapEntryNode projMapEntry2 = createProjectListEntry("MD-SAL",
707 "MD-SAL description ...", "Leader of MD-SAL",
708 "Owner of MD-SAL", projListSchemaNode);
709 final MapEntryNode projMapEntry3 = createProjectListEntry("Controller",
710 "Controller description ...", "Leader of Controller",
711 "Owner of Controller", projListSchemaNode);
713 projectMapBldr.addChild(projMapEntry1);
714 projectMapBldr.addChild(projMapEntry2);
715 projectMapBldr.addChild(projMapEntry3);
717 final MapNode projectMap = projectMapBldr.build();
722 private static MapEntryNode createProjectListEntry(final String nameVal,
723 final String descVal, final String leadVal, final String ownerVal,
724 final ListSchemaNode projListSchemaNode) {
726 final LeafNode<String> nameLeaf = ImmutableNodes
727 .leafNode(name, nameVal);
728 final LeafNode<String> descLeaf = ImmutableNodes
729 .leafNode(desc, descVal);
730 final LeafNode<String> leadLeafRef = ImmutableNodes.leafNode(lead,
732 final LeafNode<String> ownerLeafRef = ImmutableNodes.leafNode(owner,
735 final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> projMapEntryBldr = Builders
736 .mapEntryBuilder(projListSchemaNode);
738 projMapEntryBldr.addChild(nameLeaf);
739 projMapEntryBldr.addChild(descLeaf);
740 projMapEntryBldr.addChild(leadLeafRef);
741 projMapEntryBldr.addChild(ownerLeafRef);
742 final MapEntryNode projMapEntry = projMapEntryBldr.build();
747 private static ContainerNode createBasicContributorContainer(
748 final ContainerSchemaNode contributorContSchemaNode) {
750 final ListSchemaNode contributorListSchemaNode = (ListSchemaNode) contributorContSchemaNode
751 .findDataChildByName(contributor).get();
753 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> contributorContainerBldr = Builders
754 .containerBuilder(contributorContSchemaNode);
756 final MapNode contributorMap = createBasicContributorList(contributorListSchemaNode);
757 contributorContainerBldr.addChild(contributorMap);
759 final ContainerNode contributorContainer = contributorContainerBldr
762 return contributorContainer;
766 private static MapNode createBasicContributorList(
767 final ListSchemaNode contributorListSchemaNode) {
769 final CollectionNodeBuilder<MapEntryNode, MapNode> contributorMapBldr = Builders
770 .mapBuilder(contributorListSchemaNode);
772 final MapEntryNode contributorMapEntry1 = createContributorListEntry(
773 "Leader of Yangtools", "Yangtools Leader name", "Yangtools",
774 "Yangtools description ...", contributorListSchemaNode);
775 final MapEntryNode contributorMapEntry2 = createContributorListEntry(
776 "Leader of MD-SAL", "MD-SAL Leader name", "MD-SAL",
777 "MD-SAL description ...", contributorListSchemaNode);
778 final MapEntryNode contributorMapEntry3 = createContributorListEntry(
779 "Leader of Controller", "Controller Leader name", "Controller",
780 "Controller description ...", contributorListSchemaNode);
782 contributorMapBldr.addChild(contributorMapEntry1);
783 contributorMapBldr.addChild(contributorMapEntry2);
784 contributorMapBldr.addChild(contributorMapEntry3);
786 final MapNode contributorMap = contributorMapBldr.build();
788 return contributorMap;