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.io.FileNotFoundException;
14 import java.net.URISyntaxException;
15 import java.util.HashMap;
18 import org.apache.log4j.BasicConfigurator;
19 import org.junit.BeforeClass;
20 import org.junit.Test;
21 import org.opendaylight.yangtools.yang.common.QName;
22 import org.opendaylight.yangtools.yang.common.QNameModule;
23 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
25 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
26 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
27 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
28 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
29 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
30 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
31 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
32 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
33 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
34 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
35 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
36 import org.opendaylight.yangtools.yang.data.api.schema.tree.TipProducingDataTree;
37 import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
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.LeafRefValidatation;
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.DataContainerNodeAttrBuilder;
45 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
46 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
47 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeAttrBuilder;
48 import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
49 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
50 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
51 import org.opendaylight.yangtools.yang.model.api.Module;
52 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
53 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
54 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
55 import org.slf4j.Logger;
56 import org.slf4j.LoggerFactory;
58 public class DataTreeCandidateValidatorTest {
60 private static SchemaContext context;
61 private static Module valModule;
62 private static QNameModule valModuleQname;
63 private static LeafRefContext rootLeafRefContext;
64 public static TipProducingDataTree inMemoryDataTree;
66 private static QName odl;
67 private static QName project;
68 private static QName name;
69 private static QName desc;
70 private static QName lead;
71 private static QName owner;
72 private static QName odlContributor;
73 private static QName contributor;
74 private static QName odlProjectName;
75 private static QName odlProjectDesc;
76 private static QName login;
77 private static QName contributorName;
78 private static QName l1;
79 private static QName l2;
80 private static QName con1;
81 private static QName ch1;
82 private static QName ch2;
83 private static QName leafrefInChoice;
84 private static QName listInChoice;
86 private static QName leafrefInChoiceToChoice;
87 private static QName con3;
88 private static QName list3InChoice;
89 private static QName l3;
90 private static QName choiceInCon3;
92 private static QName listInChoiceKey;
93 private static QName k;
95 private static QName leafrefLeafList;
97 private static final Logger LOG = LoggerFactory.getLogger(DataTreeCandidateValidatorTest.class);
98 private static final String NEW_LINE = System.getProperty("line.separator");
101 BasicConfigurator.configure();
105 public static void init() throws FileNotFoundException, ReactorException,
109 initLeafRefContext();
117 private static void initSchemaContext() {
118 context = YangParserTestUtils.parseYangResourceDirectory("/leafref-validation");
120 final Set<Module> modules = context.getModules();
121 for (final Module module : modules) {
122 if (module.getName().equals("leafref-validation")) {
127 valModuleQname = valModule.getQNameModule();
130 private static void initLeafRefContext() {
131 rootLeafRefContext = LeafRefContext.create(context);
134 private static void initQnames() {
135 odl = QName.create(valModuleQname, "odl-project");
136 project = QName.create(valModuleQname, "project");
137 name = QName.create(valModuleQname, "name");
138 desc = QName.create(valModuleQname, "desc");
139 lead = QName.create(valModuleQname, "project-lead");
140 owner = QName.create(valModuleQname, "project-owner");
142 odlContributor = QName.create(valModuleQname, "odl-contributor");
143 contributor = QName.create(valModuleQname, "contributor");
144 odlProjectName = QName.create(valModuleQname, "odl-project-name");
145 login = QName.create(valModuleQname, "login");
146 contributorName = QName.create(valModuleQname, "contributor-name");
148 con1 = QName.create(valModuleQname, "con1");
149 l1 = QName.create(valModuleQname, "l1");
150 l2 = QName.create(valModuleQname, "l2");
151 odlProjectDesc = QName.create(valModuleQname, "odl-project-desc");
153 ch1 = QName.create(valModuleQname, "ch1");
154 ch2 = QName.create(valModuleQname, "ch2");
155 leafrefInChoice = QName.create(valModuleQname, "leafref-in-choice");
156 listInChoice = QName.create(valModuleQname, "list-in-choice");
158 leafrefInChoiceToChoice = QName.create(valModuleQname,
159 "leafref-in-choice-to-choice");
160 con3 = QName.create(valModuleQname, "con3");
161 list3InChoice = QName.create(valModuleQname, "list3-in-choice");
162 l3 = QName.create(valModuleQname, "l3");
163 choiceInCon3 = QName.create(valModuleQname, "choice-in-con3");
165 listInChoiceKey = QName.create(valModuleQname, "list-in-choice-key");
166 k = QName.create(valModuleQname, "k");
168 leafrefLeafList = QName.create(valModuleQname, "leafref-leaf-list");
172 private static void initDataTree() {
173 inMemoryDataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
174 inMemoryDataTree.setSchemaContext(context);
176 final DataTreeModification initialDataTreeModification = inMemoryDataTree
177 .takeSnapshot().newModification();
179 final ContainerSchemaNode odlProjContSchemaNode = (ContainerSchemaNode) valModule
180 .getDataChildByName(odl);
182 final ContainerNode odlProjectContainer = createOdlContainer(odlProjContSchemaNode);
184 final YangInstanceIdentifier path = YangInstanceIdentifier.of(odl);
185 initialDataTreeModification.write(path, odlProjectContainer);
186 initialDataTreeModification.ready();
188 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
189 .prepare(initialDataTreeModification);
190 inMemoryDataTree.commit(writeContributorsCandidate);
195 public void dataTreeCanditateValidationTest() {
209 private static void writeContributors() {
211 final ContainerSchemaNode contributorContSchemaNode = (ContainerSchemaNode) valModule
212 .getDataChildByName(odlContributor);
214 final ContainerNode contributorContainer = createBasicContributorContainer(contributorContSchemaNode);
216 final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
218 final DataTreeModification writeModification = inMemoryDataTree
219 .takeSnapshot().newModification();
220 writeModification.write(contributorPath, contributorContainer);
221 writeModification.ready();
223 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
224 .prepare(writeModification);
226 LOG.debug("*************************");
227 LOG.debug("Before write of contributors: ");
228 LOG.debug("*************************");
229 LOG.debug(inMemoryDataTree.toString());
231 boolean exception = false;
233 LeafRefValidatation.validate(writeContributorsCandidate,
235 } catch (final LeafRefDataValidationFailedException e) {
236 LOG.debug("All validation errors:" + NEW_LINE + e.getMessage());
237 assertEquals(3, e.getValidationsErrorsCount());
241 inMemoryDataTree.commit(writeContributorsCandidate);
243 LOG.debug("*************************");
244 LOG.debug("After write of contributors: ");
245 LOG.debug("*************************");
246 LOG.debug(inMemoryDataTree.toString());
248 assertTrue(exception);
252 private static void writeIntoMapEntry() {
254 final Map<QName, Object> keys = new HashMap<>();
255 keys.put(name, "New Project");
256 final NodeIdentifierWithPredicates mapEntryPath = new NodeIdentifierWithPredicates(
259 final YangInstanceIdentifier leaderPath = YangInstanceIdentifier
260 .of(odl).node(project).node(mapEntryPath).node(lead);
262 final LeafNode<String> leader = ImmutableNodes.leafNode(lead,
265 final DataTreeModification writeModification = inMemoryDataTree
266 .takeSnapshot().newModification();
267 writeModification.write(leaderPath, leader);
268 writeModification.ready();
270 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
271 .prepare(writeModification);
273 LOG.debug("*************************");
274 LOG.debug("Before write into map entry (update of leader name): ");
275 LOG.debug("*************************");
276 LOG.debug(inMemoryDataTree.toString());
278 boolean exception = false;
280 LeafRefValidatation.validate(writeContributorsCandidate,
282 } catch (final LeafRefDataValidationFailedException e) {
283 LOG.debug("All validation errors:" + NEW_LINE + e.getMessage());
284 assertEquals(1, e.getValidationsErrorsCount());
288 inMemoryDataTree.commit(writeContributorsCandidate);
290 LOG.debug("*************************");
291 LOG.debug("After write into map entry (update of leader name): ");
292 LOG.debug("*************************");
293 LOG.debug(inMemoryDataTree.toString());
295 assertTrue(exception);
299 private static void writeMapEntry() {
301 final Map<QName, Object> keys = new HashMap<>();
302 keys.put(name, "New Project");
303 final NodeIdentifierWithPredicates mapEntryPath = new NodeIdentifierWithPredicates(
306 final YangInstanceIdentifier newOdlProjectMapEntryPath = YangInstanceIdentifier
307 .of(odl).node(project).node(mapEntryPath);
309 final ContainerSchemaNode odlProjContSchemaNode = (ContainerSchemaNode) valModule
310 .getDataChildByName(odl);
311 final ListSchemaNode projListSchemaNode = (ListSchemaNode) odlProjContSchemaNode
312 .getDataChildByName(project);
313 final MapEntryNode newProjectMapEntry = createProjectListEntry(
314 "New Project", "New Project description ...",
315 "Leader of New Project", "Owner of New Project",
318 final DataTreeModification writeModification = inMemoryDataTree
319 .takeSnapshot().newModification();
320 writeModification.write(newOdlProjectMapEntryPath, newProjectMapEntry);
321 writeModification.ready();
323 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
324 .prepare(writeModification);
326 LOG.debug("*************************");
327 LOG.debug("Before map entry write: ");
328 LOG.debug("*************************");
329 LOG.debug(inMemoryDataTree.toString());
331 boolean exception = false;
333 LeafRefValidatation.validate(writeContributorsCandidate,
335 } catch (final LeafRefDataValidationFailedException e) {
336 LOG.debug("All validation errors:" + NEW_LINE + e.getMessage());
337 assertEquals(2, e.getValidationsErrorsCount());
341 inMemoryDataTree.commit(writeContributorsCandidate);
343 LOG.debug("*************************");
344 LOG.debug("After map entry write: ");
345 LOG.debug("*************************");
346 LOG.debug(inMemoryDataTree.toString());
348 assertTrue(exception);
352 private static void write() {
354 final ContainerSchemaNode contributorContSchemaNode = (ContainerSchemaNode) valModule
355 .getDataChildByName(odlContributor);
357 final ContainerNode contributorContainer = createContributorContainer(contributorContSchemaNode);
359 final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
361 final DataTreeModification writeModification = inMemoryDataTree
362 .takeSnapshot().newModification();
363 writeModification.write(contributorPath, contributorContainer);
365 writeModification.write(YangInstanceIdentifier.of(l1),
366 ImmutableNodes.leafNode(l1, "Leafref l1 under the root"));
368 .write(YangInstanceIdentifier.of(l2), ImmutableNodes.leafNode(
369 l2, "Leafref target l2 under the root"));
371 writeModification.ready();
372 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
373 .prepare(writeModification);
375 LOG.debug("*************************");
376 LOG.debug("Before write: ");
377 LOG.debug("*************************");
378 LOG.debug(inMemoryDataTree.toString());
380 boolean exception = false;
382 LeafRefValidatation.validate(writeContributorsCandidate,
384 } catch (final LeafRefDataValidationFailedException e) {
385 LOG.debug("All validation errors:" + NEW_LINE + e.getMessage());
386 assertEquals(12, e.getValidationsErrorsCount());
390 inMemoryDataTree.commit(writeContributorsCandidate);
392 LOG.debug("*************************");
393 LOG.debug("After write: ");
394 LOG.debug("*************************");
395 LOG.debug(inMemoryDataTree.toString());
397 assertTrue(exception);
400 private static void write2() {
402 final ContainerSchemaNode odlCon = (ContainerSchemaNode) valModule
403 .getDataChildByName(odl);
404 final ContainerSchemaNode con1Con = (ContainerSchemaNode) odlCon
405 .getDataChildByName(con1);
406 final LeafNode<String> l1Leaf = ImmutableNodes.leafNode(l1, "l1 value");
407 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> containerBuilder = Builders
408 .containerBuilder(con1Con);
409 containerBuilder.addChild(l1Leaf);
410 final ContainerNode con1Node = containerBuilder.build();
412 final YangInstanceIdentifier con1Path = YangInstanceIdentifier.of(odl)
414 final DataTreeModification writeModification = inMemoryDataTree
415 .takeSnapshot().newModification();
416 writeModification.write(con1Path, con1Node);
418 final ChoiceNode choiceNode = createChoiceNode();
419 final YangInstanceIdentifier choicePath = YangInstanceIdentifier
421 writeModification.write(choicePath, choiceNode);
423 final ContainerNode con3Node = createCon3Node();
424 final YangInstanceIdentifier con3Path = YangInstanceIdentifier.of(odl)
426 writeModification.write(con3Path, con3Node);
428 final LeafSetNode<?> leafListNode = createLeafRefLeafListNode();
429 final YangInstanceIdentifier leafListPath = YangInstanceIdentifier.of(
430 odl).node(leafrefLeafList);
431 writeModification.write(leafListPath, leafListNode);
432 writeModification.ready();
434 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
435 .prepare(writeModification);
437 LOG.debug("*************************");
438 LOG.debug("Before write2: ");
439 LOG.debug("*************************");
440 LOG.debug(inMemoryDataTree.toString());
442 boolean exception = false;
444 LeafRefValidatation.validate(writeContributorsCandidate,
446 } catch (final LeafRefDataValidationFailedException e) {
447 LOG.debug("All validation errors:" + NEW_LINE + e.getMessage());
448 assertEquals(6, e.getValidationsErrorsCount());
452 assertTrue(exception);
454 inMemoryDataTree.commit(writeContributorsCandidate);
456 LOG.debug("*************************");
457 LOG.debug("After write2: ");
458 LOG.debug("*************************");
459 LOG.debug(inMemoryDataTree.toString());
463 private static LeafSetNode<?> createLeafRefLeafListNode() {
465 final ListNodeBuilder<Object, LeafSetEntryNode<Object>> leafSetBuilder = Builders
467 leafSetBuilder.withNodeIdentifier(new NodeIdentifier(leafrefLeafList));
469 leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k1"));
470 leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k2"));
471 leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k3"));
473 return leafSetBuilder.build();
476 private static ContainerNode createCon3Node() {
478 final CollectionNodeBuilder<MapEntryNode, MapNode> mapBuilder = Builders
480 mapBuilder.withNodeIdentifier(new NodeIdentifier(list3InChoice));
482 mapBuilder.addChild(createList3Entry("k1", "val1", "valA", "valX"));
483 mapBuilder.addChild(createList3Entry("k2", "val2", "valB", "valY"));
485 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choiceBuilder = Builders
487 choiceBuilder.withNodeIdentifier(new NodeIdentifier(choiceInCon3));
489 choiceBuilder.addChild(mapBuilder.build());
491 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> containerBuilder = Builders
493 containerBuilder.withNodeIdentifier(new NodeIdentifier(con3));
495 containerBuilder.addChild(choiceBuilder.build());
497 return containerBuilder.build();
500 private static MapEntryNode createList3Entry(final String kVal,
501 final String l3Val1, final String l3Val2, final String l3Val3) {
502 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder = Builders
504 mapEntryBuilder.withNodeIdentifier(new NodeIdentifierWithPredicates(
505 list3InChoice, k, kVal));
507 final ListNodeBuilder<Object, LeafSetEntryNode<Object>> leafSetBuilder = Builders
509 leafSetBuilder.withNodeIdentifier(new NodeIdentifier(l3));
511 leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val1));
512 leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val2));
513 leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val3));
515 mapEntryBuilder.addChild(ImmutableNodes.leafNode(k, kVal));
516 mapEntryBuilder.addChild(leafSetBuilder.build());
518 return mapEntryBuilder.build();
521 private static LeafSetEntryNode<Object> createLeafSetEntry(
522 final QName qname, final String val) {
523 final NormalizedNodeAttrBuilder<NodeWithValue, Object, LeafSetEntryNode<Object>> leafSetEntryBuilder = Builders
524 .leafSetEntryBuilder();
525 leafSetEntryBuilder.withNodeIdentifier(new NodeWithValue<>(qname, val));
526 leafSetEntryBuilder.withValue(val);
527 return leafSetEntryBuilder.build();
530 private static ChoiceNode createChoiceNode() {
532 final CollectionNodeBuilder<MapEntryNode, MapNode> listInChoiceBuilder = Builders
535 .withNodeIdentifier(new NodeIdentifier(listInChoice));
537 listInChoiceBuilder.addChild(createListInChoiceEntry("key1",
538 "leafref-in-choice value", "val1"));
539 listInChoiceBuilder.addChild(createListInChoiceEntry("key2",
540 "l1 value", "val2"));
541 listInChoiceBuilder.addChild(createListInChoiceEntry("key3",
542 "l1 value", "val3"));
544 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choice2Builder = Builders
546 choice2Builder.withNodeIdentifier(new NodeIdentifier(ch2));
548 choice2Builder.addChild(listInChoiceBuilder.build());
550 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choiceBuilder = Builders
552 choiceBuilder.withNodeIdentifier(new NodeIdentifier(ch1));
553 choiceBuilder.addChild(choice2Builder.build());
555 return choiceBuilder.build();
558 private static MapEntryNode createListInChoiceEntry(final String keyVal,
559 final String leafrefInChoiceVal,
560 final String leafrefInChoiceToChoiceVal) {
562 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder = Builders
565 mapEntryBuilder.withNodeIdentifier(new NodeIdentifierWithPredicates(
566 listInChoice, listInChoiceKey, keyVal));
568 mapEntryBuilder.addChild(ImmutableNodes.leafNode(listInChoiceKey,
570 mapEntryBuilder.addChild(ImmutableNodes.leafNode(leafrefInChoice,
571 leafrefInChoiceVal));
572 mapEntryBuilder.addChild(ImmutableNodes.leafNode(
573 leafrefInChoiceToChoice, leafrefInChoiceToChoiceVal));
575 return mapEntryBuilder.build();
578 private static void delete() {
580 final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
582 final DataTreeModification delete = inMemoryDataTree.takeSnapshot()
584 delete.delete(contributorPath);
587 final DataTreeCandidate deleteContributorsCanditate = inMemoryDataTree
590 LOG.debug("*************************");
591 LOG.debug("Before delete: ");
592 LOG.debug("*************************");
593 LOG.debug(inMemoryDataTree.toString());
595 boolean exception = false;
597 LeafRefValidatation.validate(deleteContributorsCanditate,
599 } catch (final LeafRefDataValidationFailedException e) {
600 LOG.debug("All validation errors:" + NEW_LINE + e.getMessage());
601 assertEquals(6, e.getValidationsErrorsCount());
605 assertTrue(exception);
607 inMemoryDataTree.commit(deleteContributorsCanditate);
609 LOG.debug("*************************");
610 LOG.debug("After delete: ");
611 LOG.debug("*************************");
612 LOG.debug(inMemoryDataTree.toString());
616 private static ContainerNode createContributorContainer(
617 final ContainerSchemaNode contributorContSchemaNode) {
619 final ListSchemaNode contributorListSchemaNode = (ListSchemaNode) contributorContSchemaNode
620 .getDataChildByName(contributor);
622 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> contributorContainerBldr = Builders
623 .containerBuilder(contributorContSchemaNode);
625 final MapNode contributorMap = createContributorList(contributorListSchemaNode);
626 contributorContainerBldr.addChild(contributorMap);
628 final ContainerNode contributorContainer = contributorContainerBldr
631 return contributorContainer;
635 private static MapNode createContributorList(
636 final ListSchemaNode contributorListSchemaNode) {
638 final CollectionNodeBuilder<MapEntryNode, MapNode> contributorMapBldr = Builders
639 .mapBuilder(contributorListSchemaNode);
641 final MapEntryNode contributorMapEntry1 = createContributorListEntry(
642 "Leader of Yangtools", "Yangtools Leader name", "Yangtools",
643 "Yangtools description ...", contributorListSchemaNode);
644 final MapEntryNode contributorMapEntry2 = createContributorListEntry(
645 "Leader of MD-SAL", "MD-SAL Leader name", "MD-SAL",
646 "MD-SAL description ...", contributorListSchemaNode);
647 final MapEntryNode contributorMapEntry3 = createContributorListEntry(
648 "Leader of Controller", "Controller Leader name", "Controller",
649 "Controller description ...", contributorListSchemaNode);
651 final MapEntryNode contributorMapEntry4 = createContributorListEntry(
652 "jdoe", "John Doe", "MD-SAL", "Yangtools description ...",
653 contributorListSchemaNode);
655 final MapEntryNode contributorMapEntry5 = createContributorListEntry(
656 "foo", "foo name", "Controller", "MD-SAL description ...",
657 contributorListSchemaNode);
659 final MapEntryNode contributorMapEntry6 = createContributorListEntry(
660 "bar", "bar name", "Yangtools", "Controller description ...",
661 contributorListSchemaNode);
663 final MapEntryNode contributorMapEntry7 = createContributorListEntry(
664 "baz", "baz name", "Unknown Project",
665 "Unknown Project description ...", contributorListSchemaNode);
667 final MapEntryNode contributorMapEntry8 = createContributorListEntry(
668 "pk", "pk name", "Unknown Project 2",
669 "Controller description ...", contributorListSchemaNode);
671 contributorMapBldr.addChild(contributorMapEntry1);
672 contributorMapBldr.addChild(contributorMapEntry2);
673 contributorMapBldr.addChild(contributorMapEntry3);
674 contributorMapBldr.addChild(contributorMapEntry4);
675 contributorMapBldr.addChild(contributorMapEntry5);
676 contributorMapBldr.addChild(contributorMapEntry6);
677 contributorMapBldr.addChild(contributorMapEntry7);
678 contributorMapBldr.addChild(contributorMapEntry8);
680 final MapNode contributorMap = contributorMapBldr.build();
682 return contributorMap;
686 private static MapEntryNode createContributorListEntry(
687 final String loginVal, final String contributorNameVal,
688 final String odlProjectNameVal, final String odlProjectDescVal,
689 final ListSchemaNode contributorListSchemaNode) {
691 final LeafNode<String> loginLeaf = ImmutableNodes.leafNode(login,
693 final LeafNode<String> contributorNameLeaf = ImmutableNodes.leafNode(
694 contributorName, contributorNameVal);
695 final LeafNode<String> odlProjectNameLeafRef = ImmutableNodes.leafNode(
696 odlProjectName, odlProjectNameVal);
697 final LeafNode<String> odlProjectDescLeafRef = ImmutableNodes.leafNode(
698 odlProjectDesc, odlProjectDescVal);
700 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> contributorMapEntryBldr = Builders
701 .mapEntryBuilder(contributorListSchemaNode);
703 contributorMapEntryBldr.addChild(loginLeaf);
704 contributorMapEntryBldr.addChild(contributorNameLeaf);
705 contributorMapEntryBldr.addChild(odlProjectNameLeafRef);
706 contributorMapEntryBldr.addChild(odlProjectDescLeafRef);
708 final MapEntryNode contributorMapEntry = contributorMapEntryBldr
711 return contributorMapEntry;
714 private static ContainerNode createOdlContainer(
715 final ContainerSchemaNode container) {
717 final ListSchemaNode projListSchemaNode = (ListSchemaNode) container
718 .getDataChildByName(project);
720 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> odlProjectContainerBldr = Builders
721 .containerBuilder(container);
723 final MapNode projectMap = createProjectList(projListSchemaNode);
724 odlProjectContainerBldr.addChild(projectMap);
726 final ContainerNode odlProjectContainer = odlProjectContainerBldr
729 return odlProjectContainer;
732 private static MapNode createProjectList(
733 final ListSchemaNode projListSchemaNode) {
735 final CollectionNodeBuilder<MapEntryNode, MapNode> projectMapBldr = Builders
736 .mapBuilder(projListSchemaNode);
738 final MapEntryNode projMapEntry1 = createProjectListEntry("Yangtools",
739 "Yangtools description ...", "Leader of Yangtools",
740 "Owner of Yangtools", projListSchemaNode);
741 final MapEntryNode projMapEntry2 = createProjectListEntry("MD-SAL",
742 "MD-SAL description ...", "Leader of MD-SAL",
743 "Owner of MD-SAL", projListSchemaNode);
744 final MapEntryNode projMapEntry3 = createProjectListEntry("Controller",
745 "Controller description ...", "Leader of Controller",
746 "Owner of Controller", projListSchemaNode);
748 projectMapBldr.addChild(projMapEntry1);
749 projectMapBldr.addChild(projMapEntry2);
750 projectMapBldr.addChild(projMapEntry3);
752 final MapNode projectMap = projectMapBldr.build();
757 private static MapEntryNode createProjectListEntry(final String nameVal,
758 final String descVal, final String leadVal, final String ownerVal,
759 final ListSchemaNode projListSchemaNode) {
761 final LeafNode<String> nameLeaf = ImmutableNodes
762 .leafNode(name, nameVal);
763 final LeafNode<String> descLeaf = ImmutableNodes
764 .leafNode(desc, descVal);
765 final LeafNode<String> leadLeafRef = ImmutableNodes.leafNode(lead,
767 final LeafNode<String> ownerLeafRef = ImmutableNodes.leafNode(owner,
770 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> projMapEntryBldr = Builders
771 .mapEntryBuilder(projListSchemaNode);
773 projMapEntryBldr.addChild(nameLeaf);
774 projMapEntryBldr.addChild(descLeaf);
775 projMapEntryBldr.addChild(leadLeafRef);
776 projMapEntryBldr.addChild(ownerLeafRef);
777 final MapEntryNode projMapEntry = projMapEntryBldr.build();
782 private static ContainerNode createBasicContributorContainer(
783 final ContainerSchemaNode contributorContSchemaNode) {
785 final ListSchemaNode contributorListSchemaNode = (ListSchemaNode) contributorContSchemaNode
786 .getDataChildByName(contributor);
788 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> contributorContainerBldr = Builders
789 .containerBuilder(contributorContSchemaNode);
791 final MapNode contributorMap = createBasicContributorList(contributorListSchemaNode);
792 contributorContainerBldr.addChild(contributorMap);
794 final ContainerNode contributorContainer = contributorContainerBldr
797 return contributorContainer;
801 private static MapNode createBasicContributorList(
802 final ListSchemaNode contributorListSchemaNode) {
804 final CollectionNodeBuilder<MapEntryNode, MapNode> contributorMapBldr = Builders
805 .mapBuilder(contributorListSchemaNode);
807 final MapEntryNode contributorMapEntry1 = createContributorListEntry(
808 "Leader of Yangtools", "Yangtools Leader name", "Yangtools",
809 "Yangtools description ...", contributorListSchemaNode);
810 final MapEntryNode contributorMapEntry2 = createContributorListEntry(
811 "Leader of MD-SAL", "MD-SAL Leader name", "MD-SAL",
812 "MD-SAL description ...", contributorListSchemaNode);
813 final MapEntryNode contributorMapEntry3 = createContributorListEntry(
814 "Leader of Controller", "Controller Leader name", "Controller",
815 "Controller description ...", contributorListSchemaNode);
817 contributorMapBldr.addChild(contributorMapEntry1);
818 contributorMapBldr.addChild(contributorMapEntry2);
819 contributorMapBldr.addChild(contributorMapEntry3);
821 final MapNode contributorMap = contributorMapBldr.build();
823 return contributorMap;