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.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.impl.leafref.LeafRefContext;
37 import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefDataValidationFailedException;
38 import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefValidatation;
39 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
40 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
41 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
42 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
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.NormalizedNodeAttrBuilder;
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() {
105 initLeafRefContext();
113 private static void initSchemaContext() {
114 context = YangParserTestUtils.parseYangResourceDirectory("/leafref-validation");
116 final Set<Module> modules = context.getModules();
117 for (final Module module : modules) {
118 if (module.getName().equals("leafref-validation")) {
123 valModuleQname = valModule.getQNameModule();
126 private static void initLeafRefContext() {
127 rootLeafRefContext = LeafRefContext.create(context);
130 private static void initQnames() {
131 odl = QName.create(valModuleQname, "odl-project");
132 project = QName.create(valModuleQname, "project");
133 name = QName.create(valModuleQname, "name");
134 desc = QName.create(valModuleQname, "desc");
135 lead = QName.create(valModuleQname, "project-lead");
136 owner = QName.create(valModuleQname, "project-owner");
138 odlContributor = QName.create(valModuleQname, "odl-contributor");
139 contributor = QName.create(valModuleQname, "contributor");
140 odlProjectName = QName.create(valModuleQname, "odl-project-name");
141 login = QName.create(valModuleQname, "login");
142 contributorName = QName.create(valModuleQname, "contributor-name");
144 con1 = QName.create(valModuleQname, "con1");
145 l1 = QName.create(valModuleQname, "l1");
146 l2 = QName.create(valModuleQname, "l2");
147 odlProjectDesc = QName.create(valModuleQname, "odl-project-desc");
149 ch1 = QName.create(valModuleQname, "ch1");
150 ch2 = QName.create(valModuleQname, "ch2");
151 leafrefInChoice = QName.create(valModuleQname, "leafref-in-choice");
152 listInChoice = QName.create(valModuleQname, "list-in-choice");
154 leafrefInChoiceToChoice = QName.create(valModuleQname,
155 "leafref-in-choice-to-choice");
156 con3 = QName.create(valModuleQname, "con3");
157 list3InChoice = QName.create(valModuleQname, "list3-in-choice");
158 l3 = QName.create(valModuleQname, "l3");
159 choiceInCon3 = QName.create(valModuleQname, "choice-in-con3");
161 listInChoiceKey = QName.create(valModuleQname, "list-in-choice-key");
162 k = QName.create(valModuleQname, "k");
164 leafrefLeafList = QName.create(valModuleQname, "leafref-leaf-list");
168 private static void initDataTree() {
169 inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, context);
171 final DataTreeModification initialDataTreeModification = inMemoryDataTree
172 .takeSnapshot().newModification();
174 final ContainerSchemaNode odlProjContSchemaNode = (ContainerSchemaNode) valModule
175 .getDataChildByName(odl);
177 final ContainerNode odlProjectContainer = createOdlContainer(odlProjContSchemaNode);
179 final YangInstanceIdentifier path = YangInstanceIdentifier.of(odl);
180 initialDataTreeModification.write(path, odlProjectContainer);
181 initialDataTreeModification.ready();
183 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
184 .prepare(initialDataTreeModification);
185 inMemoryDataTree.commit(writeContributorsCandidate);
189 public void dataTreeCanditateValidationTest() {
203 private static void writeContributors() {
205 final ContainerSchemaNode contributorContSchemaNode = (ContainerSchemaNode) valModule
206 .getDataChildByName(odlContributor);
208 final ContainerNode contributorContainer = createBasicContributorContainer(contributorContSchemaNode);
210 final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
212 final DataTreeModification writeModification = inMemoryDataTree
213 .takeSnapshot().newModification();
214 writeModification.write(contributorPath, contributorContainer);
215 writeModification.ready();
217 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
218 .prepare(writeModification);
220 LOG.debug("*************************");
221 LOG.debug("Before write of contributors: ");
222 LOG.debug("*************************");
223 LOG.debug(inMemoryDataTree.toString());
225 boolean exception = false;
227 LeafRefValidatation.validate(writeContributorsCandidate,
229 } catch (final LeafRefDataValidationFailedException e) {
230 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
231 assertEquals(3, e.getValidationsErrorsCount());
235 inMemoryDataTree.commit(writeContributorsCandidate);
237 LOG.debug("*************************");
238 LOG.debug("After write of contributors: ");
239 LOG.debug("*************************");
240 LOG.debug(inMemoryDataTree.toString());
242 assertTrue(exception);
246 private static void writeIntoMapEntry() {
248 final Map<QName, Object> keys = new HashMap<>();
249 keys.put(name, "New Project");
250 final NodeIdentifierWithPredicates mapEntryPath = new NodeIdentifierWithPredicates(
253 final YangInstanceIdentifier leaderPath = YangInstanceIdentifier
254 .of(odl).node(project).node(mapEntryPath).node(lead);
256 final LeafNode<String> leader = ImmutableNodes.leafNode(lead,
259 final DataTreeModification writeModification = inMemoryDataTree
260 .takeSnapshot().newModification();
261 writeModification.write(leaderPath, leader);
262 writeModification.ready();
264 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
265 .prepare(writeModification);
267 LOG.debug("*************************");
268 LOG.debug("Before write into map entry (update of leader name): ");
269 LOG.debug("*************************");
270 LOG.debug(inMemoryDataTree.toString());
272 boolean exception = false;
274 LeafRefValidatation.validate(writeContributorsCandidate,
276 } catch (final LeafRefDataValidationFailedException e) {
277 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
278 assertEquals(1, e.getValidationsErrorsCount());
282 inMemoryDataTree.commit(writeContributorsCandidate);
284 LOG.debug("*************************");
285 LOG.debug("After write into map entry (update of leader name): ");
286 LOG.debug("*************************");
287 LOG.debug(inMemoryDataTree.toString());
289 assertTrue(exception);
293 private static void writeMapEntry() {
295 final Map<QName, Object> keys = new HashMap<>();
296 keys.put(name, "New Project");
297 final NodeIdentifierWithPredicates mapEntryPath = new NodeIdentifierWithPredicates(
300 final YangInstanceIdentifier newOdlProjectMapEntryPath = YangInstanceIdentifier
301 .of(odl).node(project).node(mapEntryPath);
303 final ContainerSchemaNode odlProjContSchemaNode = (ContainerSchemaNode) valModule
304 .getDataChildByName(odl);
305 final ListSchemaNode projListSchemaNode = (ListSchemaNode) odlProjContSchemaNode
306 .getDataChildByName(project);
307 final MapEntryNode newProjectMapEntry = createProjectListEntry(
308 "New Project", "New Project description ...",
309 "Leader of New Project", "Owner of New Project",
312 final DataTreeModification writeModification = inMemoryDataTree
313 .takeSnapshot().newModification();
314 writeModification.write(newOdlProjectMapEntryPath, newProjectMapEntry);
315 writeModification.ready();
317 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
318 .prepare(writeModification);
320 LOG.debug("*************************");
321 LOG.debug("Before map entry write: ");
322 LOG.debug("*************************");
323 LOG.debug(inMemoryDataTree.toString());
325 boolean exception = false;
327 LeafRefValidatation.validate(writeContributorsCandidate,
329 } catch (final LeafRefDataValidationFailedException e) {
330 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
331 assertEquals(2, e.getValidationsErrorsCount());
335 inMemoryDataTree.commit(writeContributorsCandidate);
337 LOG.debug("*************************");
338 LOG.debug("After map entry write: ");
339 LOG.debug("*************************");
340 LOG.debug(inMemoryDataTree.toString());
342 assertTrue(exception);
346 private static void write() {
348 final ContainerSchemaNode contributorContSchemaNode = (ContainerSchemaNode) valModule
349 .getDataChildByName(odlContributor);
351 final ContainerNode contributorContainer = createContributorContainer(contributorContSchemaNode);
353 final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
355 final DataTreeModification writeModification = inMemoryDataTree
356 .takeSnapshot().newModification();
357 writeModification.write(contributorPath, contributorContainer);
359 writeModification.write(YangInstanceIdentifier.of(l1),
360 ImmutableNodes.leafNode(l1, "Leafref l1 under the root"));
362 .write(YangInstanceIdentifier.of(l2), ImmutableNodes.leafNode(
363 l2, "Leafref target l2 under the root"));
365 writeModification.ready();
366 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
367 .prepare(writeModification);
369 LOG.debug("*************************");
370 LOG.debug("Before write: ");
371 LOG.debug("*************************");
372 LOG.debug(inMemoryDataTree.toString());
374 boolean exception = false;
376 LeafRefValidatation.validate(writeContributorsCandidate,
378 } catch (final LeafRefDataValidationFailedException e) {
379 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
380 assertEquals(12, e.getValidationsErrorsCount());
384 inMemoryDataTree.commit(writeContributorsCandidate);
386 LOG.debug("*************************");
387 LOG.debug("After write: ");
388 LOG.debug("*************************");
389 LOG.debug(inMemoryDataTree.toString());
391 assertTrue(exception);
394 private static void write2() {
396 final ContainerSchemaNode odlCon = (ContainerSchemaNode) valModule
397 .getDataChildByName(odl);
398 final ContainerSchemaNode con1Con = (ContainerSchemaNode) odlCon
399 .getDataChildByName(con1);
400 final LeafNode<String> l1Leaf = ImmutableNodes.leafNode(l1, "l1 value");
401 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> containerBuilder = Builders
402 .containerBuilder(con1Con);
403 containerBuilder.addChild(l1Leaf);
404 final ContainerNode con1Node = containerBuilder.build();
406 final YangInstanceIdentifier con1Path = YangInstanceIdentifier.of(odl)
408 final DataTreeModification writeModification = inMemoryDataTree
409 .takeSnapshot().newModification();
410 writeModification.write(con1Path, con1Node);
412 final ChoiceNode choiceNode = createChoiceNode();
413 final YangInstanceIdentifier choicePath = YangInstanceIdentifier
415 writeModification.write(choicePath, choiceNode);
417 final ContainerNode con3Node = createCon3Node();
418 final YangInstanceIdentifier con3Path = YangInstanceIdentifier.of(odl)
420 writeModification.write(con3Path, con3Node);
422 final LeafSetNode<?> leafListNode = createLeafRefLeafListNode();
423 final YangInstanceIdentifier leafListPath = YangInstanceIdentifier.of(
424 odl).node(leafrefLeafList);
425 writeModification.write(leafListPath, leafListNode);
426 writeModification.ready();
428 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
429 .prepare(writeModification);
431 LOG.debug("*************************");
432 LOG.debug("Before write2: ");
433 LOG.debug("*************************");
434 LOG.debug(inMemoryDataTree.toString());
436 boolean exception = false;
438 LeafRefValidatation.validate(writeContributorsCandidate,
440 } catch (final LeafRefDataValidationFailedException e) {
441 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
442 assertEquals(6, e.getValidationsErrorsCount());
446 assertTrue(exception);
448 inMemoryDataTree.commit(writeContributorsCandidate);
450 LOG.debug("*************************");
451 LOG.debug("After write2: ");
452 LOG.debug("*************************");
453 LOG.debug(inMemoryDataTree.toString());
457 private static LeafSetNode<?> createLeafRefLeafListNode() {
459 final ListNodeBuilder<Object, LeafSetEntryNode<Object>> leafSetBuilder = Builders
461 leafSetBuilder.withNodeIdentifier(new NodeIdentifier(leafrefLeafList));
463 leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k1"));
464 leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k2"));
465 leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k3"));
467 return leafSetBuilder.build();
470 private static ContainerNode createCon3Node() {
472 final CollectionNodeBuilder<MapEntryNode, MapNode> mapBuilder = Builders
474 mapBuilder.withNodeIdentifier(new NodeIdentifier(list3InChoice));
476 mapBuilder.addChild(createList3Entry("k1", "val1", "valA", "valX"));
477 mapBuilder.addChild(createList3Entry("k2", "val2", "valB", "valY"));
479 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choiceBuilder = Builders
481 choiceBuilder.withNodeIdentifier(new NodeIdentifier(choiceInCon3));
483 choiceBuilder.addChild(mapBuilder.build());
485 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> containerBuilder = Builders
487 containerBuilder.withNodeIdentifier(new NodeIdentifier(con3));
489 containerBuilder.addChild(choiceBuilder.build());
491 return containerBuilder.build();
494 private static MapEntryNode createList3Entry(final String keyVal,
495 final String l3Val1, final String l3Val2, final String l3Val3) {
496 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder = Builders
498 mapEntryBuilder.withNodeIdentifier(new NodeIdentifierWithPredicates(
499 list3InChoice, k, keyVal));
501 final ListNodeBuilder<Object, LeafSetEntryNode<Object>> leafSetBuilder = Builders
503 leafSetBuilder.withNodeIdentifier(new NodeIdentifier(l3));
505 leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val1));
506 leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val2));
507 leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val3));
509 mapEntryBuilder.addChild(ImmutableNodes.leafNode(k, keyVal));
510 mapEntryBuilder.addChild(leafSetBuilder.build());
512 return mapEntryBuilder.build();
515 private static LeafSetEntryNode<Object> createLeafSetEntry(
516 final QName qname, final String val) {
517 final NormalizedNodeAttrBuilder<NodeWithValue, Object, LeafSetEntryNode<Object>> leafSetEntryBuilder = Builders
518 .leafSetEntryBuilder();
519 leafSetEntryBuilder.withNodeIdentifier(new NodeWithValue<>(qname, val));
520 leafSetEntryBuilder.withValue(val);
521 return leafSetEntryBuilder.build();
524 private static ChoiceNode createChoiceNode() {
526 final CollectionNodeBuilder<MapEntryNode, MapNode> listInChoiceBuilder = Builders
529 .withNodeIdentifier(new NodeIdentifier(listInChoice));
531 listInChoiceBuilder.addChild(createListInChoiceEntry("key1",
532 "leafref-in-choice value", "val1"));
533 listInChoiceBuilder.addChild(createListInChoiceEntry("key2",
534 "l1 value", "val2"));
535 listInChoiceBuilder.addChild(createListInChoiceEntry("key3",
536 "l1 value", "val3"));
538 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choice2Builder = Builders
540 choice2Builder.withNodeIdentifier(new NodeIdentifier(ch2));
542 choice2Builder.addChild(listInChoiceBuilder.build());
544 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choiceBuilder = Builders
546 choiceBuilder.withNodeIdentifier(new NodeIdentifier(ch1));
547 choiceBuilder.addChild(choice2Builder.build());
549 return choiceBuilder.build();
552 private static MapEntryNode createListInChoiceEntry(final String keyVal,
553 final String leafrefInChoiceVal,
554 final String leafrefInChoiceToChoiceVal) {
556 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder = Builders
559 mapEntryBuilder.withNodeIdentifier(new NodeIdentifierWithPredicates(
560 listInChoice, listInChoiceKey, keyVal));
562 mapEntryBuilder.addChild(ImmutableNodes.leafNode(listInChoiceKey,
564 mapEntryBuilder.addChild(ImmutableNodes.leafNode(leafrefInChoice,
565 leafrefInChoiceVal));
566 mapEntryBuilder.addChild(ImmutableNodes.leafNode(
567 leafrefInChoiceToChoice, leafrefInChoiceToChoiceVal));
569 return mapEntryBuilder.build();
572 private static void delete() {
574 final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
576 final DataTreeModification delete = inMemoryDataTree.takeSnapshot()
578 delete.delete(contributorPath);
581 final DataTreeCandidate deleteContributorsCanditate = inMemoryDataTree
584 LOG.debug("*************************");
585 LOG.debug("Before delete: ");
586 LOG.debug("*************************");
587 LOG.debug(inMemoryDataTree.toString());
589 boolean exception = false;
591 LeafRefValidatation.validate(deleteContributorsCanditate,
593 } catch (final LeafRefDataValidationFailedException e) {
594 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
595 assertEquals(6, e.getValidationsErrorsCount());
599 assertTrue(exception);
601 inMemoryDataTree.commit(deleteContributorsCanditate);
603 LOG.debug("*************************");
604 LOG.debug("After delete: ");
605 LOG.debug("*************************");
606 LOG.debug(inMemoryDataTree.toString());
610 private static ContainerNode createContributorContainer(
611 final ContainerSchemaNode contributorContSchemaNode) {
613 final ListSchemaNode contributorListSchemaNode = (ListSchemaNode) contributorContSchemaNode
614 .getDataChildByName(contributor);
616 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> contributorContainerBldr = Builders
617 .containerBuilder(contributorContSchemaNode);
619 final MapNode contributorMap = createContributorList(contributorListSchemaNode);
620 contributorContainerBldr.addChild(contributorMap);
622 final ContainerNode contributorContainer = contributorContainerBldr
625 return contributorContainer;
629 private static MapNode createContributorList(
630 final ListSchemaNode contributorListSchemaNode) {
632 final CollectionNodeBuilder<MapEntryNode, MapNode> contributorMapBldr = Builders
633 .mapBuilder(contributorListSchemaNode);
635 final MapEntryNode contributorMapEntry1 = createContributorListEntry(
636 "Leader of Yangtools", "Yangtools Leader name", "Yangtools",
637 "Yangtools description ...", contributorListSchemaNode);
638 final MapEntryNode contributorMapEntry2 = createContributorListEntry(
639 "Leader of MD-SAL", "MD-SAL Leader name", "MD-SAL",
640 "MD-SAL description ...", contributorListSchemaNode);
641 final MapEntryNode contributorMapEntry3 = createContributorListEntry(
642 "Leader of Controller", "Controller Leader name", "Controller",
643 "Controller description ...", contributorListSchemaNode);
645 final MapEntryNode contributorMapEntry4 = createContributorListEntry(
646 "jdoe", "John Doe", "MD-SAL", "Yangtools description ...",
647 contributorListSchemaNode);
649 final MapEntryNode contributorMapEntry5 = createContributorListEntry(
650 "foo", "foo name", "Controller", "MD-SAL description ...",
651 contributorListSchemaNode);
653 final MapEntryNode contributorMapEntry6 = createContributorListEntry(
654 "bar", "bar name", "Yangtools", "Controller description ...",
655 contributorListSchemaNode);
657 final MapEntryNode contributorMapEntry7 = createContributorListEntry(
658 "baz", "baz name", "Unknown Project",
659 "Unknown Project description ...", contributorListSchemaNode);
661 final MapEntryNode contributorMapEntry8 = createContributorListEntry(
662 "pk", "pk name", "Unknown Project 2",
663 "Controller description ...", contributorListSchemaNode);
665 contributorMapBldr.addChild(contributorMapEntry1);
666 contributorMapBldr.addChild(contributorMapEntry2);
667 contributorMapBldr.addChild(contributorMapEntry3);
668 contributorMapBldr.addChild(contributorMapEntry4);
669 contributorMapBldr.addChild(contributorMapEntry5);
670 contributorMapBldr.addChild(contributorMapEntry6);
671 contributorMapBldr.addChild(contributorMapEntry7);
672 contributorMapBldr.addChild(contributorMapEntry8);
674 final MapNode contributorMap = contributorMapBldr.build();
676 return contributorMap;
680 private static MapEntryNode createContributorListEntry(
681 final String loginVal, final String contributorNameVal,
682 final String odlProjectNameVal, final String odlProjectDescVal,
683 final ListSchemaNode contributorListSchemaNode) {
685 final LeafNode<String> loginLeaf = ImmutableNodes.leafNode(login,
687 final LeafNode<String> contributorNameLeaf = ImmutableNodes.leafNode(
688 contributorName, contributorNameVal);
689 final LeafNode<String> odlProjectNameLeafRef = ImmutableNodes.leafNode(
690 odlProjectName, odlProjectNameVal);
691 final LeafNode<String> odlProjectDescLeafRef = ImmutableNodes.leafNode(
692 odlProjectDesc, odlProjectDescVal);
694 return Builders.mapEntryBuilder(contributorListSchemaNode)
696 .addChild(contributorNameLeaf)
697 .addChild(odlProjectNameLeafRef)
698 .addChild(odlProjectDescLeafRef)
702 private static ContainerNode createOdlContainer(
703 final ContainerSchemaNode container) {
705 final ListSchemaNode projListSchemaNode = (ListSchemaNode) container
706 .getDataChildByName(project);
708 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> odlProjectContainerBldr = Builders
709 .containerBuilder(container);
711 final MapNode projectMap = createProjectList(projListSchemaNode);
712 odlProjectContainerBldr.addChild(projectMap);
714 final ContainerNode odlProjectContainer = odlProjectContainerBldr
717 return odlProjectContainer;
720 private static MapNode createProjectList(
721 final ListSchemaNode projListSchemaNode) {
723 final CollectionNodeBuilder<MapEntryNode, MapNode> projectMapBldr = Builders
724 .mapBuilder(projListSchemaNode);
726 final MapEntryNode projMapEntry1 = createProjectListEntry("Yangtools",
727 "Yangtools description ...", "Leader of Yangtools",
728 "Owner of Yangtools", projListSchemaNode);
729 final MapEntryNode projMapEntry2 = createProjectListEntry("MD-SAL",
730 "MD-SAL description ...", "Leader of MD-SAL",
731 "Owner of MD-SAL", projListSchemaNode);
732 final MapEntryNode projMapEntry3 = createProjectListEntry("Controller",
733 "Controller description ...", "Leader of Controller",
734 "Owner of Controller", projListSchemaNode);
736 projectMapBldr.addChild(projMapEntry1);
737 projectMapBldr.addChild(projMapEntry2);
738 projectMapBldr.addChild(projMapEntry3);
740 final MapNode projectMap = projectMapBldr.build();
745 private static MapEntryNode createProjectListEntry(final String nameVal,
746 final String descVal, final String leadVal, final String ownerVal,
747 final ListSchemaNode projListSchemaNode) {
749 final LeafNode<String> nameLeaf = ImmutableNodes
750 .leafNode(name, nameVal);
751 final LeafNode<String> descLeaf = ImmutableNodes
752 .leafNode(desc, descVal);
753 final LeafNode<String> leadLeafRef = ImmutableNodes.leafNode(lead,
755 final LeafNode<String> ownerLeafRef = ImmutableNodes.leafNode(owner,
758 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> projMapEntryBldr = Builders
759 .mapEntryBuilder(projListSchemaNode);
761 projMapEntryBldr.addChild(nameLeaf);
762 projMapEntryBldr.addChild(descLeaf);
763 projMapEntryBldr.addChild(leadLeafRef);
764 projMapEntryBldr.addChild(ownerLeafRef);
765 final MapEntryNode projMapEntry = projMapEntryBldr.build();
770 private static ContainerNode createBasicContributorContainer(
771 final ContainerSchemaNode contributorContSchemaNode) {
773 final ListSchemaNode contributorListSchemaNode = (ListSchemaNode) contributorContSchemaNode
774 .getDataChildByName(contributor);
776 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> contributorContainerBldr = Builders
777 .containerBuilder(contributorContSchemaNode);
779 final MapNode contributorMap = createBasicContributorList(contributorListSchemaNode);
780 contributorContainerBldr.addChild(contributorMap);
782 final ContainerNode contributorContainer = contributorContainerBldr
785 return contributorContainer;
789 private static MapNode createBasicContributorList(
790 final ListSchemaNode contributorListSchemaNode) {
792 final CollectionNodeBuilder<MapEntryNode, MapNode> contributorMapBldr = Builders
793 .mapBuilder(contributorListSchemaNode);
795 final MapEntryNode contributorMapEntry1 = createContributorListEntry(
796 "Leader of Yangtools", "Yangtools Leader name", "Yangtools",
797 "Yangtools description ...", contributorListSchemaNode);
798 final MapEntryNode contributorMapEntry2 = createContributorListEntry(
799 "Leader of MD-SAL", "MD-SAL Leader name", "MD-SAL",
800 "MD-SAL description ...", contributorListSchemaNode);
801 final MapEntryNode contributorMapEntry3 = createContributorListEntry(
802 "Leader of Controller", "Controller Leader name", "Controller",
803 "Controller description ...", contributorListSchemaNode);
805 contributorMapBldr.addChild(contributorMapEntry1);
806 contributorMapBldr.addChild(contributorMapEntry2);
807 contributorMapBldr.addChild(contributorMapEntry3);
809 final MapNode contributorMap = contributorMapBldr.build();
811 return contributorMap;