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.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() {
103 context = YangParserTestUtils.parseYangResourceDirectory("/leafref-validation");
105 final Set<Module> modules = context.getModules();
106 for (final Module module : modules) {
107 if (module.getName().equals("leafref-validation")) {
112 valModuleQname = valModule.getQNameModule();
113 rootLeafRefContext = LeafRefContext.create(context);
115 odl = QName.create(valModuleQname, "odl-project");
116 project = QName.create(valModuleQname, "project");
117 name = QName.create(valModuleQname, "name");
118 desc = QName.create(valModuleQname, "desc");
119 lead = QName.create(valModuleQname, "project-lead");
120 owner = QName.create(valModuleQname, "project-owner");
122 odlContributor = QName.create(valModuleQname, "odl-contributor");
123 contributor = QName.create(valModuleQname, "contributor");
124 odlProjectName = QName.create(valModuleQname, "odl-project-name");
125 login = QName.create(valModuleQname, "login");
126 contributorName = QName.create(valModuleQname, "contributor-name");
128 con1 = QName.create(valModuleQname, "con1");
129 l1 = QName.create(valModuleQname, "l1");
130 l2 = QName.create(valModuleQname, "l2");
131 odlProjectDesc = QName.create(valModuleQname, "odl-project-desc");
133 ch1 = QName.create(valModuleQname, "ch1");
134 ch2 = QName.create(valModuleQname, "ch2");
135 leafrefInChoice = QName.create(valModuleQname, "leafref-in-choice");
136 listInChoice = QName.create(valModuleQname, "list-in-choice");
138 leafrefInChoiceToChoice = QName.create(valModuleQname,
139 "leafref-in-choice-to-choice");
140 con3 = QName.create(valModuleQname, "con3");
141 list3InChoice = QName.create(valModuleQname, "list3-in-choice");
142 l3 = QName.create(valModuleQname, "l3");
143 choiceInCon3 = QName.create(valModuleQname, "choice-in-con3");
145 listInChoiceKey = QName.create(valModuleQname, "list-in-choice-key");
146 k = QName.create(valModuleQname, "k");
148 leafrefLeafList = QName.create(valModuleQname, "leafref-leaf-list");
150 inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, context);
152 final DataTreeModification initialDataTreeModification = inMemoryDataTree
153 .takeSnapshot().newModification();
155 final ContainerSchemaNode odlProjContSchemaNode = (ContainerSchemaNode) valModule.findDataChildByName(odl)
158 final ContainerNode odlProjectContainer = createOdlContainer(odlProjContSchemaNode);
160 final YangInstanceIdentifier path = YangInstanceIdentifier.of(odl);
161 initialDataTreeModification.write(path, odlProjectContainer);
162 initialDataTreeModification.ready();
164 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
165 .prepare(initialDataTreeModification);
166 inMemoryDataTree.commit(writeContributorsCandidate);
170 public static void cleanup() {
171 inMemoryDataTree = null;
172 rootLeafRefContext = null;
178 public void dataTreeCanditateValidationTest() {
192 private static void writeContributors() {
194 final ContainerSchemaNode contributorContSchemaNode = (ContainerSchemaNode) valModule
195 .findDataChildByName(odlContributor).get();
197 final ContainerNode contributorContainer = createBasicContributorContainer(contributorContSchemaNode);
199 final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
201 final DataTreeModification writeModification = inMemoryDataTree
202 .takeSnapshot().newModification();
203 writeModification.write(contributorPath, contributorContainer);
204 writeModification.ready();
206 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
207 .prepare(writeModification);
209 LOG.debug("*************************");
210 LOG.debug("Before write of contributors: ");
211 LOG.debug("*************************");
212 LOG.debug(inMemoryDataTree.toString());
214 boolean exception = false;
216 LeafRefValidation.validate(writeContributorsCandidate,
218 } catch (final LeafRefDataValidationFailedException e) {
219 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
220 assertEquals(3, e.getValidationsErrorsCount());
224 inMemoryDataTree.commit(writeContributorsCandidate);
226 LOG.debug("*************************");
227 LOG.debug("After write of contributors: ");
228 LOG.debug("*************************");
229 LOG.debug(inMemoryDataTree.toString());
231 assertTrue(exception);
235 private static void writeIntoMapEntry() {
237 final Map<QName, Object> keys = new HashMap<>();
238 keys.put(name, "New Project");
239 final NodeIdentifierWithPredicates mapEntryPath = new NodeIdentifierWithPredicates(
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() {
284 final Map<QName, Object> keys = new HashMap<>();
285 keys.put(name, "New Project");
286 final NodeIdentifierWithPredicates mapEntryPath = new NodeIdentifierWithPredicates(
289 final YangInstanceIdentifier newOdlProjectMapEntryPath = YangInstanceIdentifier
290 .of(odl).node(project).node(mapEntryPath);
292 final ContainerSchemaNode odlProjContSchemaNode = (ContainerSchemaNode) valModule.findDataChildByName(odl)
294 final ListSchemaNode projListSchemaNode = (ListSchemaNode) odlProjContSchemaNode.findDataChildByName(project)
296 final MapEntryNode newProjectMapEntry = createProjectListEntry(
297 "New Project", "New Project description ...",
298 "Leader of New Project", "Owner of New Project",
301 final DataTreeModification writeModification = inMemoryDataTree
302 .takeSnapshot().newModification();
303 writeModification.write(newOdlProjectMapEntryPath, newProjectMapEntry);
304 writeModification.ready();
306 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
307 .prepare(writeModification);
309 LOG.debug("*************************");
310 LOG.debug("Before map entry write: ");
311 LOG.debug("*************************");
312 LOG.debug(inMemoryDataTree.toString());
314 boolean exception = false;
316 LeafRefValidation.validate(writeContributorsCandidate,
318 } catch (final LeafRefDataValidationFailedException e) {
319 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
320 assertEquals(2, e.getValidationsErrorsCount());
324 inMemoryDataTree.commit(writeContributorsCandidate);
326 LOG.debug("*************************");
327 LOG.debug("After map entry write: ");
328 LOG.debug("*************************");
329 LOG.debug(inMemoryDataTree.toString());
331 assertTrue(exception);
335 private static void write() {
337 final ContainerSchemaNode contributorContSchemaNode = (ContainerSchemaNode) valModule
338 .findDataChildByName(odlContributor).get();
340 final ContainerNode contributorContainer = createContributorContainer(contributorContSchemaNode);
342 final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
344 final DataTreeModification writeModification = inMemoryDataTree
345 .takeSnapshot().newModification();
346 writeModification.write(contributorPath, contributorContainer);
348 writeModification.write(YangInstanceIdentifier.of(l1),
349 ImmutableNodes.leafNode(l1, "Leafref l1 under the root"));
351 .write(YangInstanceIdentifier.of(l2), ImmutableNodes.leafNode(
352 l2, "Leafref target l2 under the root"));
354 writeModification.ready();
355 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
356 .prepare(writeModification);
358 LOG.debug("*************************");
359 LOG.debug("Before write: ");
360 LOG.debug("*************************");
361 LOG.debug(inMemoryDataTree.toString());
363 boolean exception = false;
365 LeafRefValidation.validate(writeContributorsCandidate,
367 } catch (final LeafRefDataValidationFailedException e) {
368 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
369 assertEquals(12, e.getValidationsErrorsCount());
373 inMemoryDataTree.commit(writeContributorsCandidate);
375 LOG.debug("*************************");
376 LOG.debug("After write: ");
377 LOG.debug("*************************");
378 LOG.debug(inMemoryDataTree.toString());
380 assertTrue(exception);
383 private static void write2() {
385 final ContainerSchemaNode odlCon = (ContainerSchemaNode) valModule.findDataChildByName(odl).get();
386 final ContainerSchemaNode con1Con = (ContainerSchemaNode) odlCon.findDataChildByName(con1).get();
387 final LeafNode<String> l1Leaf = ImmutableNodes.leafNode(l1, "l1 value");
388 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> containerBuilder = Builders
389 .containerBuilder(con1Con);
390 containerBuilder.addChild(l1Leaf);
391 final ContainerNode con1Node = containerBuilder.build();
393 final YangInstanceIdentifier con1Path = YangInstanceIdentifier.of(odl)
395 final DataTreeModification writeModification = inMemoryDataTree
396 .takeSnapshot().newModification();
397 writeModification.write(con1Path, con1Node);
399 final ChoiceNode choiceNode = createChoiceNode();
400 final YangInstanceIdentifier choicePath = YangInstanceIdentifier
402 writeModification.write(choicePath, choiceNode);
404 final ContainerNode con3Node = createCon3Node();
405 final YangInstanceIdentifier con3Path = YangInstanceIdentifier.of(odl)
407 writeModification.write(con3Path, con3Node);
409 final LeafSetNode<?> leafListNode = createLeafRefLeafListNode();
410 final YangInstanceIdentifier leafListPath = YangInstanceIdentifier.of(
411 odl).node(leafrefLeafList);
412 writeModification.write(leafListPath, leafListNode);
413 writeModification.ready();
415 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
416 .prepare(writeModification);
418 LOG.debug("*************************");
419 LOG.debug("Before write2: ");
420 LOG.debug("*************************");
421 LOG.debug(inMemoryDataTree.toString());
423 boolean exception = false;
425 LeafRefValidation.validate(writeContributorsCandidate,
427 } catch (final LeafRefDataValidationFailedException e) {
428 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
429 assertEquals(6, e.getValidationsErrorsCount());
433 assertTrue(exception);
435 inMemoryDataTree.commit(writeContributorsCandidate);
437 LOG.debug("*************************");
438 LOG.debug("After write2: ");
439 LOG.debug("*************************");
440 LOG.debug(inMemoryDataTree.toString());
444 private static LeafSetNode<?> createLeafRefLeafListNode() {
446 final ListNodeBuilder<Object, LeafSetEntryNode<Object>> leafSetBuilder = Builders
448 leafSetBuilder.withNodeIdentifier(new NodeIdentifier(leafrefLeafList));
450 leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k1"));
451 leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k2"));
452 leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k3"));
454 return leafSetBuilder.build();
457 private static ContainerNode createCon3Node() {
459 final CollectionNodeBuilder<MapEntryNode, MapNode> mapBuilder = Builders
461 mapBuilder.withNodeIdentifier(new NodeIdentifier(list3InChoice));
463 mapBuilder.addChild(createList3Entry("k1", "val1", "valA", "valX"));
464 mapBuilder.addChild(createList3Entry("k2", "val2", "valB", "valY"));
466 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choiceBuilder = Builders
468 choiceBuilder.withNodeIdentifier(new NodeIdentifier(choiceInCon3));
470 choiceBuilder.addChild(mapBuilder.build());
472 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> containerBuilder = Builders
474 containerBuilder.withNodeIdentifier(new NodeIdentifier(con3));
476 containerBuilder.addChild(choiceBuilder.build());
478 return containerBuilder.build();
481 private static MapEntryNode createList3Entry(final String keyVal,
482 final String l3Val1, final String l3Val2, final String l3Val3) {
483 final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder = Builders
485 mapEntryBuilder.withNodeIdentifier(new NodeIdentifierWithPredicates(
486 list3InChoice, k, keyVal));
488 final ListNodeBuilder<Object, LeafSetEntryNode<Object>> leafSetBuilder = Builders
490 leafSetBuilder.withNodeIdentifier(new NodeIdentifier(l3));
492 leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val1));
493 leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val2));
494 leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val3));
496 mapEntryBuilder.addChild(ImmutableNodes.leafNode(k, keyVal));
497 mapEntryBuilder.addChild(leafSetBuilder.build());
499 return mapEntryBuilder.build();
502 private static LeafSetEntryNode<Object> createLeafSetEntry(
503 final QName qname, final String val) {
504 final NormalizedNodeBuilder<NodeWithValue, Object, LeafSetEntryNode<Object>> leafSetEntryBuilder = Builders
505 .leafSetEntryBuilder();
506 leafSetEntryBuilder.withNodeIdentifier(new NodeWithValue<>(qname, val));
507 leafSetEntryBuilder.withValue(val);
508 return leafSetEntryBuilder.build();
511 private static ChoiceNode createChoiceNode() {
513 final CollectionNodeBuilder<MapEntryNode, MapNode> listInChoiceBuilder = Builders
516 .withNodeIdentifier(new NodeIdentifier(listInChoice));
518 listInChoiceBuilder.addChild(createListInChoiceEntry("key1",
519 "leafref-in-choice value", "val1"));
520 listInChoiceBuilder.addChild(createListInChoiceEntry("key2",
521 "l1 value", "val2"));
522 listInChoiceBuilder.addChild(createListInChoiceEntry("key3",
523 "l1 value", "val3"));
525 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choice2Builder = Builders
527 choice2Builder.withNodeIdentifier(new NodeIdentifier(ch2));
529 choice2Builder.addChild(listInChoiceBuilder.build());
531 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choiceBuilder = Builders
533 choiceBuilder.withNodeIdentifier(new NodeIdentifier(ch1));
534 choiceBuilder.addChild(choice2Builder.build());
536 return choiceBuilder.build();
539 private static MapEntryNode createListInChoiceEntry(final String keyVal,
540 final String leafrefInChoiceVal,
541 final String leafrefInChoiceToChoiceVal) {
543 final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder = Builders
546 mapEntryBuilder.withNodeIdentifier(new NodeIdentifierWithPredicates(
547 listInChoice, listInChoiceKey, keyVal));
549 mapEntryBuilder.addChild(ImmutableNodes.leafNode(listInChoiceKey,
551 mapEntryBuilder.addChild(ImmutableNodes.leafNode(leafrefInChoice,
552 leafrefInChoiceVal));
553 mapEntryBuilder.addChild(ImmutableNodes.leafNode(
554 leafrefInChoiceToChoice, leafrefInChoiceToChoiceVal));
556 return mapEntryBuilder.build();
559 private static void delete() {
561 final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
563 final DataTreeModification delete = inMemoryDataTree.takeSnapshot()
565 delete.delete(contributorPath);
568 final DataTreeCandidate deleteContributorsCanditate = inMemoryDataTree
571 LOG.debug("*************************");
572 LOG.debug("Before delete: ");
573 LOG.debug("*************************");
574 LOG.debug(inMemoryDataTree.toString());
576 boolean exception = false;
578 LeafRefValidation.validate(deleteContributorsCanditate,
580 } catch (final LeafRefDataValidationFailedException e) {
581 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
582 assertEquals(6, e.getValidationsErrorsCount());
586 assertTrue(exception);
588 inMemoryDataTree.commit(deleteContributorsCanditate);
590 LOG.debug("*************************");
591 LOG.debug("After delete: ");
592 LOG.debug("*************************");
593 LOG.debug(inMemoryDataTree.toString());
597 private static ContainerNode createContributorContainer(
598 final ContainerSchemaNode contributorContSchemaNode) {
600 final ListSchemaNode contributorListSchemaNode = (ListSchemaNode) contributorContSchemaNode
601 .findDataChildByName(contributor).get();
603 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> contributorContainerBldr = Builders
604 .containerBuilder(contributorContSchemaNode);
606 final MapNode contributorMap = createContributorList(contributorListSchemaNode);
607 contributorContainerBldr.addChild(contributorMap);
609 final ContainerNode contributorContainer = contributorContainerBldr
612 return contributorContainer;
616 private static MapNode createContributorList(
617 final ListSchemaNode contributorListSchemaNode) {
619 final CollectionNodeBuilder<MapEntryNode, MapNode> contributorMapBldr = Builders
620 .mapBuilder(contributorListSchemaNode);
622 final MapEntryNode contributorMapEntry1 = createContributorListEntry(
623 "Leader of Yangtools", "Yangtools Leader name", "Yangtools",
624 "Yangtools description ...", contributorListSchemaNode);
625 final MapEntryNode contributorMapEntry2 = createContributorListEntry(
626 "Leader of MD-SAL", "MD-SAL Leader name", "MD-SAL",
627 "MD-SAL description ...", contributorListSchemaNode);
628 final MapEntryNode contributorMapEntry3 = createContributorListEntry(
629 "Leader of Controller", "Controller Leader name", "Controller",
630 "Controller description ...", contributorListSchemaNode);
632 final MapEntryNode contributorMapEntry4 = createContributorListEntry(
633 "jdoe", "John Doe", "MD-SAL", "Yangtools description ...",
634 contributorListSchemaNode);
636 final MapEntryNode contributorMapEntry5 = createContributorListEntry(
637 "foo", "foo name", "Controller", "MD-SAL description ...",
638 contributorListSchemaNode);
640 final MapEntryNode contributorMapEntry6 = createContributorListEntry(
641 "bar", "bar name", "Yangtools", "Controller description ...",
642 contributorListSchemaNode);
644 final MapEntryNode contributorMapEntry7 = createContributorListEntry(
645 "baz", "baz name", "Unknown Project",
646 "Unknown Project description ...", contributorListSchemaNode);
648 final MapEntryNode contributorMapEntry8 = createContributorListEntry(
649 "pk", "pk name", "Unknown Project 2",
650 "Controller description ...", contributorListSchemaNode);
652 contributorMapBldr.addChild(contributorMapEntry1);
653 contributorMapBldr.addChild(contributorMapEntry2);
654 contributorMapBldr.addChild(contributorMapEntry3);
655 contributorMapBldr.addChild(contributorMapEntry4);
656 contributorMapBldr.addChild(contributorMapEntry5);
657 contributorMapBldr.addChild(contributorMapEntry6);
658 contributorMapBldr.addChild(contributorMapEntry7);
659 contributorMapBldr.addChild(contributorMapEntry8);
661 final MapNode contributorMap = contributorMapBldr.build();
663 return contributorMap;
667 private static MapEntryNode createContributorListEntry(
668 final String loginVal, final String contributorNameVal,
669 final String odlProjectNameVal, final String odlProjectDescVal,
670 final ListSchemaNode contributorListSchemaNode) {
672 final LeafNode<String> loginLeaf = ImmutableNodes.leafNode(login, loginVal);
673 final LeafNode<String> contributorNameLeaf = ImmutableNodes.leafNode(contributorName, contributorNameVal);
674 final LeafNode<String> odlProjectNameLeafRef = ImmutableNodes.leafNode(odlProjectName, odlProjectNameVal);
675 final LeafNode<String> odlProjectDescLeafRef = ImmutableNodes.leafNode(odlProjectDesc, odlProjectDescVal);
677 return Builders.mapEntryBuilder(contributorListSchemaNode)
679 .addChild(contributorNameLeaf)
680 .addChild(odlProjectNameLeafRef)
681 .addChild(odlProjectDescLeafRef)
685 private static ContainerNode createOdlContainer(
686 final ContainerSchemaNode container) {
688 final ListSchemaNode projListSchemaNode = (ListSchemaNode) container.findDataChildByName(project).get();
690 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> odlProjectContainerBldr = Builders
691 .containerBuilder(container);
693 final MapNode projectMap = createProjectList(projListSchemaNode);
694 odlProjectContainerBldr.addChild(projectMap);
696 final ContainerNode odlProjectContainer = odlProjectContainerBldr
699 return odlProjectContainer;
702 private static MapNode createProjectList(
703 final ListSchemaNode projListSchemaNode) {
705 final CollectionNodeBuilder<MapEntryNode, MapNode> projectMapBldr = Builders
706 .mapBuilder(projListSchemaNode);
708 final MapEntryNode projMapEntry1 = createProjectListEntry("Yangtools",
709 "Yangtools description ...", "Leader of Yangtools",
710 "Owner of Yangtools", projListSchemaNode);
711 final MapEntryNode projMapEntry2 = createProjectListEntry("MD-SAL",
712 "MD-SAL description ...", "Leader of MD-SAL",
713 "Owner of MD-SAL", projListSchemaNode);
714 final MapEntryNode projMapEntry3 = createProjectListEntry("Controller",
715 "Controller description ...", "Leader of Controller",
716 "Owner of Controller", projListSchemaNode);
718 projectMapBldr.addChild(projMapEntry1);
719 projectMapBldr.addChild(projMapEntry2);
720 projectMapBldr.addChild(projMapEntry3);
722 final MapNode projectMap = projectMapBldr.build();
727 private static MapEntryNode createProjectListEntry(final String nameVal,
728 final String descVal, final String leadVal, final String ownerVal,
729 final ListSchemaNode projListSchemaNode) {
731 final LeafNode<String> nameLeaf = ImmutableNodes
732 .leafNode(name, nameVal);
733 final LeafNode<String> descLeaf = ImmutableNodes
734 .leafNode(desc, descVal);
735 final LeafNode<String> leadLeafRef = ImmutableNodes.leafNode(lead,
737 final LeafNode<String> ownerLeafRef = ImmutableNodes.leafNode(owner,
740 final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> projMapEntryBldr = Builders
741 .mapEntryBuilder(projListSchemaNode);
743 projMapEntryBldr.addChild(nameLeaf);
744 projMapEntryBldr.addChild(descLeaf);
745 projMapEntryBldr.addChild(leadLeafRef);
746 projMapEntryBldr.addChild(ownerLeafRef);
747 final MapEntryNode projMapEntry = projMapEntryBldr.build();
752 private static ContainerNode createBasicContributorContainer(
753 final ContainerSchemaNode contributorContSchemaNode) {
755 final ListSchemaNode contributorListSchemaNode = (ListSchemaNode) contributorContSchemaNode
756 .findDataChildByName(contributor).get();
758 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> contributorContainerBldr = Builders
759 .containerBuilder(contributorContSchemaNode);
761 final MapNode contributorMap = createBasicContributorList(contributorListSchemaNode);
762 contributorContainerBldr.addChild(contributorMap);
764 final ContainerNode contributorContainer = contributorContainerBldr
767 return contributorContainer;
771 private static MapNode createBasicContributorList(
772 final ListSchemaNode contributorListSchemaNode) {
774 final CollectionNodeBuilder<MapEntryNode, MapNode> contributorMapBldr = Builders
775 .mapBuilder(contributorListSchemaNode);
777 final MapEntryNode contributorMapEntry1 = createContributorListEntry(
778 "Leader of Yangtools", "Yangtools Leader name", "Yangtools",
779 "Yangtools description ...", contributorListSchemaNode);
780 final MapEntryNode contributorMapEntry2 = createContributorListEntry(
781 "Leader of MD-SAL", "MD-SAL Leader name", "MD-SAL",
782 "MD-SAL description ...", contributorListSchemaNode);
783 final MapEntryNode contributorMapEntry3 = createContributorListEntry(
784 "Leader of Controller", "Controller Leader name", "Controller",
785 "Controller description ...", contributorListSchemaNode);
787 contributorMapBldr.addChild(contributorMapEntry1);
788 contributorMapBldr.addChild(contributorMapEntry2);
789 contributorMapBldr.addChild(contributorMapEntry3);
791 final MapNode contributorMap = contributorMapBldr.build();
793 return contributorMap;