2 * Copyright (c) 2015 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.test;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
14 import java.io.IOException;
15 import java.net.URISyntaxException;
16 import java.util.HashMap;
19 import org.apache.log4j.BasicConfigurator;
20 import org.junit.BeforeClass;
21 import org.junit.Test;
22 import org.opendaylight.yangtools.yang.common.QName;
23 import org.opendaylight.yangtools.yang.common.QNameModule;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
25 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
26 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
27 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
28 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
29 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
30 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
31 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
32 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
33 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
34 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
35 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
36 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
37 import org.opendaylight.yangtools.yang.data.api.schema.tree.TipProducingDataTree;
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.leafref.LeafRefYangSyntaxErrorException;
42 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
43 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
44 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
45 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
46 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
47 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
48 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeAttrBuilder;
49 import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
50 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
51 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
52 import org.opendaylight.yangtools.yang.model.api.Module;
53 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
54 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
55 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
56 import org.slf4j.Logger;
57 import org.slf4j.LoggerFactory;
59 public class DataTreeCandidateValidatorTest {
61 private static SchemaContext context;
62 private static Module valModule;
63 private static QNameModule valModuleQname;
64 private static LeafRefContext rootLeafRefContext;
65 public static TipProducingDataTree inMemoryDataTree;
67 private static QName odl;
68 private static QName project;
69 private static QName name;
70 private static QName desc;
71 private static QName lead;
72 private static QName owner;
73 private static QName odlContributor;
74 private static QName contributor;
75 private static QName odlProjectName;
76 private static QName odlProjectDesc;
77 private static QName login;
78 private static QName contributorName;
79 private static QName l1;
80 private static QName l2;
81 private static QName con1;
82 private static QName ch1;
83 private static QName ch2;
84 private static QName leafrefInChoice;
85 private static QName listInChoice;
87 private static QName leafrefInChoiceToChoice;
88 private static QName con3;
89 private static QName list3InChoice;
90 private static QName l3;
91 private static QName choiceInCon3;
93 private static QName listInChoiceKey;
94 private static QName k;
96 private static QName leafrefLeafList;
98 private static final Logger LOG = LoggerFactory.getLogger("");
99 private static final String NEW_LINE = System.getProperty("line.separator");
102 BasicConfigurator.configure();
106 public static void init() throws URISyntaxException, IOException,
107 YangSyntaxErrorException, LeafRefYangSyntaxErrorException {
110 initLeafRefContext();
118 private static void initSchemaContext() throws URISyntaxException,
119 IOException, YangSyntaxErrorException {
120 final File resourceFile = new File(DataTreeCandidateValidatorTest.class
121 .getResource("/leafref-validation/leafref-validation.yang")
123 final File resourceDir = resourceFile.getParentFile();
125 final YangParserImpl parser = YangParserImpl.getInstance();
126 context = parser.parseFile(resourceFile, resourceDir);
128 final Set<Module> modules = context.getModules();
129 for (final Module module : modules) {
130 if (module.getName().equals("leafref-validation")) {
135 valModuleQname = valModule.getQNameModule();
138 private static void initLeafRefContext() throws IOException,
139 LeafRefYangSyntaxErrorException {
140 rootLeafRefContext = LeafRefContext.create(context);
143 private static void initQnames() {
144 odl = QName.create(valModuleQname, "odl-project");
145 project = QName.create(valModuleQname, "project");
146 name = QName.create(valModuleQname, "name");
147 desc = QName.create(valModuleQname, "desc");
148 lead = QName.create(valModuleQname, "project-lead");
149 owner = QName.create(valModuleQname, "project-owner");
151 odlContributor = QName.create(valModuleQname, "odl-contributor");
152 contributor = QName.create(valModuleQname, "contributor");
153 odlProjectName = QName.create(valModuleQname, "odl-project-name");
154 login = QName.create(valModuleQname, "login");
155 contributorName = QName.create(valModuleQname, "contributor-name");
157 con1 = QName.create(valModuleQname, "con1");
158 l1 = QName.create(valModuleQname, "l1");
159 l2 = QName.create(valModuleQname, "l2");
160 odlProjectDesc = QName.create(valModuleQname, "odl-project-desc");
162 ch1 = QName.create(valModuleQname, "ch1");
163 ch2 = QName.create(valModuleQname, "ch2");
164 leafrefInChoice = QName.create(valModuleQname, "leafref-in-choice");
165 listInChoice = QName.create(valModuleQname, "list-in-choice");
167 leafrefInChoiceToChoice = QName.create(valModuleQname,
168 "leafref-in-choice-to-choice");
169 con3 = QName.create(valModuleQname, "con3");
170 list3InChoice = QName.create(valModuleQname, "list3-in-choice");
171 l3 = QName.create(valModuleQname, "l3");
172 choiceInCon3 = QName.create(valModuleQname, "choice-in-con3");
174 listInChoiceKey = QName.create(valModuleQname, "list-in-choice-key");
175 k = QName.create(valModuleQname, "k");
177 leafrefLeafList = QName.create(valModuleQname, "leafref-leaf-list");
181 private static void initDataTree() {
182 inMemoryDataTree = InMemoryDataTreeFactory.getInstance().create();
183 inMemoryDataTree.setSchemaContext(context);
185 final DataTreeModification initialDataTreeModification = inMemoryDataTree
186 .takeSnapshot().newModification();
188 final ContainerSchemaNode odlProjContSchemaNode = (ContainerSchemaNode) valModule
189 .getDataChildByName(odl);
191 final ContainerNode odlProjectContainer = createOdlContainer(odlProjContSchemaNode);
193 final YangInstanceIdentifier path = YangInstanceIdentifier.of(odl);
194 initialDataTreeModification.write(path, odlProjectContainer);
196 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
197 .prepare(initialDataTreeModification);
198 inMemoryDataTree.commit(writeContributorsCandidate);
203 public void dataTreeCanditateValidationTest() {
217 private void writeContributors() {
219 final ContainerSchemaNode contributorContSchemaNode = (ContainerSchemaNode) valModule
220 .getDataChildByName(odlContributor);
222 final ContainerNode contributorContainer = createBasicContributorContainer(contributorContSchemaNode);
224 final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
226 final DataTreeModification writeModification = inMemoryDataTree
227 .takeSnapshot().newModification();
228 writeModification.write(contributorPath, contributorContainer);
230 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
231 .prepare(writeModification);
233 LOG.debug("*************************");
234 LOG.debug("Before write of contributors: ");
235 LOG.debug("*************************");
236 LOG.debug(inMemoryDataTree.toString());
238 boolean exception = false;
240 LeafRefValidatation.validate(writeContributorsCandidate, rootLeafRefContext);
241 } catch (final LeafRefDataValidationFailedException e) {
242 LOG.debug("All validation errors:" + NEW_LINE + e.getMessage());
243 assertEquals(3, e.getValidationsErrorsCount());
247 inMemoryDataTree.commit(writeContributorsCandidate);
249 LOG.debug("*************************");
250 LOG.debug("After write of contributors: ");
251 LOG.debug("*************************");
252 LOG.debug(inMemoryDataTree.toString());
254 assertTrue(exception);
258 private void writeIntoMapEntry() {
260 final Map<QName, Object> keys = new HashMap<QName, Object>();
261 keys.put(name, "New Project");
262 final NodeIdentifierWithPredicates mapEntryPath = new NodeIdentifierWithPredicates(
265 final YangInstanceIdentifier leaderPath = YangInstanceIdentifier.of(odl)
266 .node(project).node(mapEntryPath).node(lead);
268 final LeafNode<String> leader = ImmutableNodes.leafNode(lead,
271 final DataTreeModification writeModification = inMemoryDataTree
272 .takeSnapshot().newModification();
273 writeModification.write(leaderPath, leader);
275 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
276 .prepare(writeModification);
278 LOG.debug("*************************");
279 LOG.debug("Before write into map entry (update of leader name): ");
280 LOG.debug("*************************");
281 LOG.debug(inMemoryDataTree.toString());
283 boolean exception = false;
285 LeafRefValidatation.validate(writeContributorsCandidate, rootLeafRefContext);
286 } catch (final LeafRefDataValidationFailedException e) {
287 LOG.debug("All validation errors:" + NEW_LINE + e.getMessage());
288 assertEquals(1, e.getValidationsErrorsCount());
292 inMemoryDataTree.commit(writeContributorsCandidate);
294 LOG.debug("*************************");
295 LOG.debug("After write into map entry (update of leader name): ");
296 LOG.debug("*************************");
297 LOG.debug(inMemoryDataTree.toString());
299 assertTrue(exception);
303 private void writeMapEntry() {
305 final Map<QName, Object> keys = new HashMap<QName, Object>();
306 keys.put(name, "New Project");
307 final NodeIdentifierWithPredicates mapEntryPath = new NodeIdentifierWithPredicates(
310 final YangInstanceIdentifier newOdlProjectMapEntryPath = YangInstanceIdentifier
311 .of(odl).node(project).node(mapEntryPath);
313 final ContainerSchemaNode odlProjContSchemaNode = (ContainerSchemaNode) valModule
314 .getDataChildByName(odl);
315 final ListSchemaNode projListSchemaNode = (ListSchemaNode) odlProjContSchemaNode
316 .getDataChildByName(project);
317 final MapEntryNode newProjectMapEntry = createProjectListEntry("New Project",
318 "New Project description ...", "Leader of New Project",
319 "Owner of New Project", projListSchemaNode);
321 final DataTreeModification writeModification = inMemoryDataTree
322 .takeSnapshot().newModification();
323 writeModification.write(newOdlProjectMapEntryPath, newProjectMapEntry);
325 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
326 .prepare(writeModification);
328 LOG.debug("*************************");
329 LOG.debug("Before map entry write: ");
330 LOG.debug("*************************");
331 LOG.debug(inMemoryDataTree.toString());
333 boolean exception = false;
335 LeafRefValidatation.validate(writeContributorsCandidate, rootLeafRefContext);
336 } catch (final LeafRefDataValidationFailedException e) {
337 LOG.debug("All validation errors:" + NEW_LINE + e.getMessage());
338 assertEquals(2, e.getValidationsErrorsCount());
342 inMemoryDataTree.commit(writeContributorsCandidate);
344 LOG.debug("*************************");
345 LOG.debug("After map entry write: ");
346 LOG.debug("*************************");
347 LOG.debug(inMemoryDataTree.toString());
349 assertTrue(exception);
353 private void write() {
355 final ContainerSchemaNode contributorContSchemaNode = (ContainerSchemaNode) valModule
356 .getDataChildByName(odlContributor);
358 final ContainerNode contributorContainer = createContributorContainer(contributorContSchemaNode);
360 final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
362 final DataTreeModification writeModification = inMemoryDataTree
363 .takeSnapshot().newModification();
364 writeModification.write(contributorPath, contributorContainer);
366 writeModification.write(YangInstanceIdentifier.of(l1),
367 ImmutableNodes.leafNode(l1, "Leafref l1 under the root"));
369 .write(YangInstanceIdentifier.of(l2), ImmutableNodes.leafNode(
370 l2, "Leafref target l2 under the root"));
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, rootLeafRefContext);
383 } catch (final LeafRefDataValidationFailedException e) {
384 LOG.debug("All validation errors:" + NEW_LINE + e.getMessage());
385 assertEquals(12, e.getValidationsErrorsCount());
389 inMemoryDataTree.commit(writeContributorsCandidate);
391 LOG.debug("*************************");
392 LOG.debug("After write: ");
393 LOG.debug("*************************");
394 LOG.debug(inMemoryDataTree.toString());
396 assertTrue(exception);
399 private void write2() {
401 final ContainerSchemaNode odlCon = (ContainerSchemaNode) valModule
402 .getDataChildByName(odl);
403 final ContainerSchemaNode con1Con = (ContainerSchemaNode) odlCon
404 .getDataChildByName(con1);
405 final LeafNode<String> l1Leaf = ImmutableNodes.leafNode(l1, "l1 value");
406 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> containerBuilder = Builders
407 .containerBuilder(con1Con);
408 containerBuilder.addChild(l1Leaf);
409 final ContainerNode con1Node = containerBuilder.build();
411 final YangInstanceIdentifier con1Path = YangInstanceIdentifier.of(odl).node(
413 final DataTreeModification writeModification = inMemoryDataTree
414 .takeSnapshot().newModification();
415 writeModification.write(con1Path, con1Node);
417 final ChoiceNode choiceNode = createChoiceNode();
418 final YangInstanceIdentifier choicePath = YangInstanceIdentifier.of(odl)
420 writeModification.write(choicePath, choiceNode);
422 final ContainerNode con3Node = createCon3Node();
423 final YangInstanceIdentifier con3Path = YangInstanceIdentifier.of(odl).node(
425 writeModification.write(con3Path, con3Node);
427 final LeafSetNode leafListNode = createLeafRefLeafListNode();
428 final YangInstanceIdentifier leafListPath = YangInstanceIdentifier.of(odl)
429 .node(leafrefLeafList);
430 writeModification.write(leafListPath, leafListNode);
432 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
433 .prepare(writeModification);
435 LOG.debug("*************************");
436 LOG.debug("Before write2: ");
437 LOG.debug("*************************");
438 LOG.debug(inMemoryDataTree.toString());
440 boolean exception = false;
442 LeafRefValidatation.validate(writeContributorsCandidate, rootLeafRefContext);
443 } catch (final LeafRefDataValidationFailedException e) {
444 LOG.debug("All validation errors:" + NEW_LINE + e.getMessage());
445 assertEquals(6, e.getValidationsErrorsCount());
449 assertTrue(exception);
451 inMemoryDataTree.commit(writeContributorsCandidate);
453 LOG.debug("*************************");
454 LOG.debug("After write2: ");
455 LOG.debug("*************************");
456 LOG.debug(inMemoryDataTree.toString());
460 private LeafSetNode createLeafRefLeafListNode() {
462 final ListNodeBuilder<Object, LeafSetEntryNode<Object>> leafSetBuilder = Builders
464 leafSetBuilder.withNodeIdentifier(new NodeIdentifier(leafrefLeafList));
466 leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k1"));
467 leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k2"));
468 leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k3"));
470 return leafSetBuilder.build();
473 private ContainerNode createCon3Node() {
475 final CollectionNodeBuilder<MapEntryNode, MapNode> mapBuilder = Builders
477 mapBuilder.withNodeIdentifier(new NodeIdentifier(list3InChoice));
479 mapBuilder.addChild(createList3Entry("k1", "val1", "valA", "valX"));
480 mapBuilder.addChild(createList3Entry("k2", "val2", "valB", "valY"));
482 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choiceBuilder = Builders
484 choiceBuilder.withNodeIdentifier(new NodeIdentifier(choiceInCon3));
486 choiceBuilder.addChild(mapBuilder.build());
488 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> containerBuilder = Builders
490 containerBuilder.withNodeIdentifier(new NodeIdentifier(con3));
492 containerBuilder.addChild(choiceBuilder.build());
494 return containerBuilder.build();
497 private MapEntryNode createList3Entry(final String kVal, final String l3Val1,
498 final String l3Val2, final String l3Val3) {
499 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder = Builders
501 mapEntryBuilder.withNodeIdentifier(new NodeIdentifierWithPredicates(
502 list3InChoice, k, kVal));
504 final ListNodeBuilder<Object, LeafSetEntryNode<Object>> leafSetBuilder = Builders
506 leafSetBuilder.withNodeIdentifier(new NodeIdentifier(l3));
508 leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val1));
509 leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val2));
510 leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val3));
512 mapEntryBuilder.addChild(ImmutableNodes.leafNode(k, kVal));
513 mapEntryBuilder.addChild(leafSetBuilder.build());
515 return mapEntryBuilder.build();
518 private LeafSetEntryNode<Object> createLeafSetEntry(final QName qname, final String val) {
519 final NormalizedNodeAttrBuilder<NodeWithValue, Object, LeafSetEntryNode<Object>> leafSetEntryBuilder = Builders
520 .leafSetEntryBuilder();
521 leafSetEntryBuilder.withNodeIdentifier(new NodeWithValue(qname, val));
522 leafSetEntryBuilder.withValue(val);
523 return leafSetEntryBuilder.build();
526 private ChoiceNode createChoiceNode() {
528 final CollectionNodeBuilder<MapEntryNode, MapNode> listInChoiceBuilder = Builders
531 .withNodeIdentifier(new NodeIdentifier(listInChoice));
533 listInChoiceBuilder.addChild(createListInChoiceEntry("key1",
534 "leafref-in-choice value", "val1"));
535 listInChoiceBuilder.addChild(createListInChoiceEntry("key2",
536 "l1 value", "val2"));
537 listInChoiceBuilder.addChild(createListInChoiceEntry("key3",
538 "l1 value", "val3"));
540 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choice2Builder = Builders
542 choice2Builder.withNodeIdentifier(new NodeIdentifier(ch2));
544 choice2Builder.addChild(listInChoiceBuilder.build());
546 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choiceBuilder = Builders
548 choiceBuilder.withNodeIdentifier(new NodeIdentifier(ch1));
549 choiceBuilder.addChild(choice2Builder.build());
551 return choiceBuilder.build();
554 private MapEntryNode createListInChoiceEntry(final String keyVal,
555 final String leafrefInChoiceVal, final String leafrefInChoiceToChoiceVal) {
557 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder = Builders
560 mapEntryBuilder.withNodeIdentifier(new NodeIdentifierWithPredicates(
561 listInChoice, listInChoiceKey, keyVal));
563 mapEntryBuilder.addChild(ImmutableNodes.leafNode(listInChoiceKey,
565 mapEntryBuilder.addChild(ImmutableNodes.leafNode(leafrefInChoice,
566 leafrefInChoiceVal));
567 mapEntryBuilder.addChild(ImmutableNodes.leafNode(
568 leafrefInChoiceToChoice, leafrefInChoiceToChoiceVal));
570 return mapEntryBuilder.build();
573 private void delete() {
575 final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
577 final DataTreeModification delete = inMemoryDataTree.takeSnapshot()
579 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, rootLeafRefContext);
592 } catch (final LeafRefDataValidationFailedException e) {
593 LOG.debug("All validation errors:" + NEW_LINE + e.getMessage());
594 assertEquals(6, e.getValidationsErrorsCount());
598 assertTrue(exception);
600 inMemoryDataTree.commit(deleteContributorsCanditate);
602 LOG.debug("*************************");
603 LOG.debug("After delete: ");
604 LOG.debug("*************************");
605 LOG.debug(inMemoryDataTree.toString());
609 private ContainerNode createContributorContainer(
610 final ContainerSchemaNode contributorContSchemaNode) {
612 final ListSchemaNode contributorListSchemaNode = (ListSchemaNode) contributorContSchemaNode
613 .getDataChildByName(contributor);
615 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> contributorContainerBldr = Builders
616 .containerBuilder(contributorContSchemaNode);
618 final MapNode contributorMap = createContributorList(contributorListSchemaNode);
619 contributorContainerBldr.addChild(contributorMap);
621 final ContainerNode contributorContainer = contributorContainerBldr.build();
623 return contributorContainer;
627 private MapNode createContributorList(
628 final ListSchemaNode contributorListSchemaNode) {
630 final CollectionNodeBuilder<MapEntryNode, MapNode> contributorMapBldr = Builders
631 .mapBuilder(contributorListSchemaNode);
633 final MapEntryNode contributorMapEntry1 = createContributorListEntry(
634 "Leader of Yangtools", "Yangtools Leader name", "Yangtools",
635 "Yangtools description ...", contributorListSchemaNode);
636 final MapEntryNode contributorMapEntry2 = createContributorListEntry(
637 "Leader of MD-SAL", "MD-SAL Leader name", "MD-SAL",
638 "MD-SAL description ...", contributorListSchemaNode);
639 final MapEntryNode contributorMapEntry3 = createContributorListEntry(
640 "Leader of Controller", "Controller Leader name", "Controller",
641 "Controller description ...", contributorListSchemaNode);
643 final MapEntryNode contributorMapEntry4 = createContributorListEntry("jdoe",
644 "John Doe", "MD-SAL", "Yangtools description ...",
645 contributorListSchemaNode);
647 final MapEntryNode contributorMapEntry5 = createContributorListEntry("foo",
648 "foo name", "Controller", "MD-SAL description ...",
649 contributorListSchemaNode);
651 final MapEntryNode contributorMapEntry6 = createContributorListEntry("bar",
652 "bar name", "Yangtools", "Controller description ...",
653 contributorListSchemaNode);
655 final MapEntryNode contributorMapEntry7 = createContributorListEntry("baz",
656 "baz name", "Unknown Project",
657 "Unknown Project description ...", contributorListSchemaNode);
659 final MapEntryNode contributorMapEntry8 = createContributorListEntry("pk",
660 "pk name", "Unknown Project 2", "Controller description ...",
661 contributorListSchemaNode);
663 contributorMapBldr.addChild(contributorMapEntry1);
664 contributorMapBldr.addChild(contributorMapEntry2);
665 contributorMapBldr.addChild(contributorMapEntry3);
666 contributorMapBldr.addChild(contributorMapEntry4);
667 contributorMapBldr.addChild(contributorMapEntry5);
668 contributorMapBldr.addChild(contributorMapEntry6);
669 contributorMapBldr.addChild(contributorMapEntry7);
670 contributorMapBldr.addChild(contributorMapEntry8);
672 final MapNode contributorMap = contributorMapBldr.build();
674 return contributorMap;
678 private MapEntryNode createContributorListEntry(final String loginVal,
679 final String contributorNameVal, final String odlProjectNameVal,
680 final String odlProjectDescVal, final ListSchemaNode contributorListSchemaNode) {
682 final LeafNode<String> loginLeaf = ImmutableNodes.leafNode(login, loginVal);
683 final LeafNode<String> contributorNameLeaf = ImmutableNodes.leafNode(
684 contributorName, contributorNameVal);
685 final LeafNode<String> odlProjectNameLeafRef = ImmutableNodes.leafNode(
686 odlProjectName, odlProjectNameVal);
687 final LeafNode<String> odlProjectDescLeafRef = ImmutableNodes.leafNode(
688 odlProjectDesc, odlProjectDescVal);
690 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> contributorMapEntryBldr = Builders
691 .mapEntryBuilder(contributorListSchemaNode);
693 contributorMapEntryBldr.addChild(loginLeaf);
694 contributorMapEntryBldr.addChild(contributorNameLeaf);
695 contributorMapEntryBldr.addChild(odlProjectNameLeafRef);
696 contributorMapEntryBldr.addChild(odlProjectDescLeafRef);
698 final MapEntryNode contributorMapEntry = contributorMapEntryBldr.build();
700 return contributorMapEntry;
703 private static ContainerNode createOdlContainer(
704 final ContainerSchemaNode container) {
706 final ListSchemaNode projListSchemaNode = (ListSchemaNode) container
707 .getDataChildByName(project);
709 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> odlProjectContainerBldr = Builders
710 .containerBuilder(container);
712 final MapNode projectMap = createProjectList(projListSchemaNode);
713 odlProjectContainerBldr.addChild(projectMap);
715 final ContainerNode odlProjectContainer = odlProjectContainerBldr.build();
717 return odlProjectContainer;
720 private static MapNode createProjectList(final ListSchemaNode projListSchemaNode) {
722 final CollectionNodeBuilder<MapEntryNode, MapNode> projectMapBldr = Builders
723 .mapBuilder(projListSchemaNode);
725 final MapEntryNode projMapEntry1 = createProjectListEntry("Yangtools",
726 "Yangtools description ...", "Leader of Yangtools",
727 "Owner of Yangtools", projListSchemaNode);
728 final MapEntryNode projMapEntry2 = createProjectListEntry("MD-SAL",
729 "MD-SAL description ...", "Leader of MD-SAL",
730 "Owner of MD-SAL", projListSchemaNode);
731 final MapEntryNode projMapEntry3 = createProjectListEntry("Controller",
732 "Controller description ...", "Leader of Controller",
733 "Owner of Controller", projListSchemaNode);
735 projectMapBldr.addChild(projMapEntry1);
736 projectMapBldr.addChild(projMapEntry2);
737 projectMapBldr.addChild(projMapEntry3);
739 final MapNode projectMap = projectMapBldr.build();
744 private static MapEntryNode createProjectListEntry(final String nameVal,
745 final String descVal, final String leadVal, final String ownerVal,
746 final ListSchemaNode projListSchemaNode) {
748 final LeafNode<String> nameLeaf = ImmutableNodes.leafNode(name, nameVal);
749 final LeafNode<String> descLeaf = ImmutableNodes.leafNode(desc, descVal);
750 final LeafNode<String> leadLeafRef = ImmutableNodes.leafNode(lead, leadVal);
751 final LeafNode<String> ownerLeafRef = ImmutableNodes
752 .leafNode(owner, ownerVal);
754 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> projMapEntryBldr = Builders
755 .mapEntryBuilder(projListSchemaNode);
757 projMapEntryBldr.addChild(nameLeaf);
758 projMapEntryBldr.addChild(descLeaf);
759 projMapEntryBldr.addChild(leadLeafRef);
760 projMapEntryBldr.addChild(ownerLeafRef);
761 final MapEntryNode projMapEntry = projMapEntryBldr.build();
766 private ContainerNode createBasicContributorContainer(
767 final ContainerSchemaNode contributorContSchemaNode) {
769 final ListSchemaNode contributorListSchemaNode = (ListSchemaNode) contributorContSchemaNode
770 .getDataChildByName(contributor);
772 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> contributorContainerBldr = Builders
773 .containerBuilder(contributorContSchemaNode);
775 final MapNode contributorMap = createBasicContributorList(contributorListSchemaNode);
776 contributorContainerBldr.addChild(contributorMap);
778 final ContainerNode contributorContainer = contributorContainerBldr.build();
780 return contributorContainer;
784 private MapNode createBasicContributorList(
785 final ListSchemaNode contributorListSchemaNode) {
787 final CollectionNodeBuilder<MapEntryNode, MapNode> contributorMapBldr = Builders
788 .mapBuilder(contributorListSchemaNode);
790 final MapEntryNode contributorMapEntry1 = createContributorListEntry(
791 "Leader of Yangtools", "Yangtools Leader name", "Yangtools",
792 "Yangtools description ...", contributorListSchemaNode);
793 final MapEntryNode contributorMapEntry2 = createContributorListEntry(
794 "Leader of MD-SAL", "MD-SAL Leader name", "MD-SAL",
795 "MD-SAL description ...", contributorListSchemaNode);
796 final MapEntryNode contributorMapEntry3 = createContributorListEntry(
797 "Leader of Controller", "Controller Leader name", "Controller",
798 "Controller description ...", contributorListSchemaNode);
800 contributorMapBldr.addChild(contributorMapEntry1);
801 contributorMapBldr.addChild(contributorMapEntry2);
802 contributorMapBldr.addChild(contributorMapEntry3);
804 final MapNode contributorMap = contributorMapBldr.build();
806 return contributorMap;