2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.data.impl.leafref.context;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
13 import java.util.HashMap;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.junit.AfterClass;
17 import org.junit.BeforeClass;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.common.QNameModule;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
23 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
25 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
26 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
27 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
28 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
29 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
30 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
31 import org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode;
32 import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
33 import org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder;
34 import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder;
35 import org.opendaylight.yangtools.yang.data.api.schema.builder.ListNodeBuilder;
36 import org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeBuilder;
37 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
38 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
39 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
40 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
41 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
42 import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContext;
43 import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefDataValidationFailedException;
44 import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefValidation;
45 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
46 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
47 import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
48 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
49 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
50 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
51 import org.opendaylight.yangtools.yang.model.api.Module;
52 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
53 import org.slf4j.Logger;
54 import org.slf4j.LoggerFactory;
56 public class DataTreeCandidateValidatorTest {
58 private static EffectiveModelContext context;
59 private static Module valModule;
60 private static QNameModule valModuleQname;
61 private static LeafRefContext rootLeafRefContext;
62 public static DataTree inMemoryDataTree;
64 private static QName odl;
65 private static QName project;
66 private static QName name;
67 private static QName desc;
68 private static QName lead;
69 private static QName owner;
70 private static QName odlContributor;
71 private static QName contributor;
72 private static QName odlProjectName;
73 private static QName odlProjectDesc;
74 private static QName login;
75 private static QName contributorName;
76 private static QName l1;
77 private static QName l2;
78 private static QName con1;
79 private static QName ch1;
80 private static QName ch2;
81 private static QName leafrefInChoice;
82 private static QName listInChoice;
84 private static QName leafrefInChoiceToChoice;
85 private static QName con3;
86 private static QName list3InChoice;
87 private static QName l3;
88 private static QName choiceInCon3;
90 private static QName listInChoiceKey;
91 private static QName k;
93 private static QName leafrefLeafList;
95 private static final Logger LOG = LoggerFactory.getLogger(DataTreeCandidateValidatorTest.class);
96 private static final String NEW_LINE = System.getProperty("line.separator");
99 public static void init() throws DataValidationFailedException {
100 context = YangParserTestUtils.parseYangResourceDirectory("/leafref-validation");
102 for (final Module module : context.getModules()) {
103 if (module.getName().equals("leafref-validation")) {
108 valModuleQname = valModule.getQNameModule();
109 rootLeafRefContext = LeafRefContext.create(context);
111 odl = QName.create(valModuleQname, "odl-project");
112 project = QName.create(valModuleQname, "project");
113 name = QName.create(valModuleQname, "name");
114 desc = QName.create(valModuleQname, "desc");
115 lead = QName.create(valModuleQname, "project-lead");
116 owner = QName.create(valModuleQname, "project-owner");
118 odlContributor = QName.create(valModuleQname, "odl-contributor");
119 contributor = QName.create(valModuleQname, "contributor");
120 odlProjectName = QName.create(valModuleQname, "odl-project-name");
121 login = QName.create(valModuleQname, "login");
122 contributorName = QName.create(valModuleQname, "contributor-name");
124 con1 = QName.create(valModuleQname, "con1");
125 l1 = QName.create(valModuleQname, "l1");
126 l2 = QName.create(valModuleQname, "l2");
127 odlProjectDesc = QName.create(valModuleQname, "odl-project-desc");
129 ch1 = QName.create(valModuleQname, "ch1");
130 ch2 = QName.create(valModuleQname, "ch2");
131 leafrefInChoice = QName.create(valModuleQname, "leafref-in-choice");
132 listInChoice = QName.create(valModuleQname, "list-in-choice");
134 leafrefInChoiceToChoice = QName.create(valModuleQname,
135 "leafref-in-choice-to-choice");
136 con3 = QName.create(valModuleQname, "con3");
137 list3InChoice = QName.create(valModuleQname, "list3-in-choice");
138 l3 = QName.create(valModuleQname, "l3");
139 choiceInCon3 = QName.create(valModuleQname, "choice-in-con3");
141 listInChoiceKey = QName.create(valModuleQname, "list-in-choice-key");
142 k = QName.create(valModuleQname, "k");
144 leafrefLeafList = QName.create(valModuleQname, "leafref-leaf-list");
146 inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, context);
148 final DataTreeModification initialDataTreeModification = inMemoryDataTree
149 .takeSnapshot().newModification();
151 final ContainerSchemaNode odlProjContSchemaNode = (ContainerSchemaNode) valModule.findDataChildByName(odl)
154 final ContainerNode odlProjectContainer = createOdlContainer(odlProjContSchemaNode);
156 final YangInstanceIdentifier path = YangInstanceIdentifier.of(odl);
157 initialDataTreeModification.write(path, odlProjectContainer);
158 initialDataTreeModification.ready();
160 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
161 .prepare(initialDataTreeModification);
162 inMemoryDataTree.commit(writeContributorsCandidate);
166 public static void cleanup() {
167 inMemoryDataTree = null;
168 rootLeafRefContext = null;
174 public void dataTreeCanditateValidationTest() throws DataValidationFailedException {
188 private static void writeContributors() throws DataValidationFailedException {
190 final ContainerSchemaNode contributorContSchemaNode = (ContainerSchemaNode) valModule
191 .findDataChildByName(odlContributor).get();
193 final ContainerNode contributorContainer = createBasicContributorContainer(contributorContSchemaNode);
195 final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
197 final DataTreeModification writeModification = inMemoryDataTree
198 .takeSnapshot().newModification();
199 writeModification.write(contributorPath, contributorContainer);
200 writeModification.ready();
202 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
203 .prepare(writeModification);
205 LOG.debug("*************************");
206 LOG.debug("Before write of contributors: ");
207 LOG.debug("*************************");
208 LOG.debug(inMemoryDataTree.toString());
210 boolean exception = false;
212 LeafRefValidation.validate(writeContributorsCandidate,
214 } catch (final LeafRefDataValidationFailedException e) {
215 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
216 assertEquals(3, e.getValidationsErrorsCount());
220 inMemoryDataTree.commit(writeContributorsCandidate);
222 LOG.debug("*************************");
223 LOG.debug("After write of contributors: ");
224 LOG.debug("*************************");
225 LOG.debug(inMemoryDataTree.toString());
227 assertTrue(exception);
231 private static void writeIntoMapEntry() throws DataValidationFailedException {
233 final Map<QName, Object> keys = new HashMap<>();
234 keys.put(name, "New Project");
235 final NodeIdentifierWithPredicates mapEntryPath = NodeIdentifierWithPredicates.of(project, keys);
237 final YangInstanceIdentifier leaderPath = YangInstanceIdentifier
238 .of(odl).node(project).node(mapEntryPath).node(lead);
240 final LeafNode<String> leader = ImmutableNodes.leafNode(lead,
243 final DataTreeModification writeModification = inMemoryDataTree
244 .takeSnapshot().newModification();
245 writeModification.write(leaderPath, leader);
246 writeModification.ready();
248 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
249 .prepare(writeModification);
251 LOG.debug("*************************");
252 LOG.debug("Before write into map entry (update of leader name): ");
253 LOG.debug("*************************");
254 LOG.debug(inMemoryDataTree.toString());
256 boolean exception = false;
258 LeafRefValidation.validate(writeContributorsCandidate,
260 } catch (final LeafRefDataValidationFailedException e) {
261 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
262 assertEquals(1, e.getValidationsErrorsCount());
266 inMemoryDataTree.commit(writeContributorsCandidate);
268 LOG.debug("*************************");
269 LOG.debug("After write into map entry (update of leader name): ");
270 LOG.debug("*************************");
271 LOG.debug(inMemoryDataTree.toString());
273 assertTrue(exception);
277 private static void writeMapEntry() throws DataValidationFailedException {
279 final Map<QName, Object> keys = new HashMap<>();
280 keys.put(name, "New Project");
281 final NodeIdentifierWithPredicates mapEntryPath = NodeIdentifierWithPredicates.of(project, keys);
283 final YangInstanceIdentifier newOdlProjectMapEntryPath = YangInstanceIdentifier
284 .of(odl).node(project).node(mapEntryPath);
286 final ContainerSchemaNode odlProjContSchemaNode = (ContainerSchemaNode) valModule.findDataChildByName(odl)
288 final ListSchemaNode projListSchemaNode = (ListSchemaNode) odlProjContSchemaNode.findDataChildByName(project)
290 final MapEntryNode newProjectMapEntry = createProjectListEntry(
291 "New Project", "New Project description ...",
292 "Leader of New Project", "Owner of New Project",
295 final DataTreeModification writeModification = inMemoryDataTree
296 .takeSnapshot().newModification();
297 writeModification.write(newOdlProjectMapEntryPath, newProjectMapEntry);
298 writeModification.ready();
300 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
301 .prepare(writeModification);
303 LOG.debug("*************************");
304 LOG.debug("Before map entry write: ");
305 LOG.debug("*************************");
306 LOG.debug(inMemoryDataTree.toString());
308 boolean exception = false;
310 LeafRefValidation.validate(writeContributorsCandidate,
312 } catch (final LeafRefDataValidationFailedException e) {
313 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
314 assertEquals(2, e.getValidationsErrorsCount());
318 inMemoryDataTree.commit(writeContributorsCandidate);
320 LOG.debug("*************************");
321 LOG.debug("After map entry write: ");
322 LOG.debug("*************************");
323 LOG.debug(inMemoryDataTree.toString());
325 assertTrue(exception);
329 private static void write() throws DataValidationFailedException {
331 final ContainerSchemaNode contributorContSchemaNode = (ContainerSchemaNode) valModule
332 .findDataChildByName(odlContributor).get();
334 final ContainerNode contributorContainer = createContributorContainer(contributorContSchemaNode);
336 final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
338 final DataTreeModification writeModification = inMemoryDataTree
339 .takeSnapshot().newModification();
340 writeModification.write(contributorPath, contributorContainer);
342 writeModification.write(YangInstanceIdentifier.of(l1),
343 ImmutableNodes.leafNode(l1, "Leafref l1 under the root"));
345 .write(YangInstanceIdentifier.of(l2), ImmutableNodes.leafNode(
346 l2, "Leafref target l2 under the root"));
348 writeModification.ready();
349 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
350 .prepare(writeModification);
352 LOG.debug("*************************");
353 LOG.debug("Before write: ");
354 LOG.debug("*************************");
355 LOG.debug(inMemoryDataTree.toString());
357 boolean exception = false;
359 LeafRefValidation.validate(writeContributorsCandidate,
361 } catch (final LeafRefDataValidationFailedException e) {
362 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
363 assertEquals(12, e.getValidationsErrorsCount());
367 inMemoryDataTree.commit(writeContributorsCandidate);
369 LOG.debug("*************************");
370 LOG.debug("After write: ");
371 LOG.debug("*************************");
372 LOG.debug(inMemoryDataTree.toString());
374 assertTrue(exception);
377 private static void write2() throws DataValidationFailedException {
379 final ContainerSchemaNode odlCon = (ContainerSchemaNode) valModule.findDataChildByName(odl).get();
380 final ContainerSchemaNode con1Con = (ContainerSchemaNode) odlCon.findDataChildByName(con1).get();
381 final LeafNode<String> l1Leaf = ImmutableNodes.leafNode(l1, "l1 value");
382 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> containerBuilder = Builders
383 .containerBuilder(con1Con);
384 containerBuilder.addChild(l1Leaf);
385 final ContainerNode con1Node = containerBuilder.build();
387 final YangInstanceIdentifier con1Path = YangInstanceIdentifier.of(odl)
389 final DataTreeModification writeModification = inMemoryDataTree
390 .takeSnapshot().newModification();
391 writeModification.write(con1Path, con1Node);
393 final ChoiceNode choiceNode = createChoiceNode();
394 final YangInstanceIdentifier choicePath = YangInstanceIdentifier
396 writeModification.write(choicePath, choiceNode);
398 final ContainerNode con3Node = createCon3Node();
399 final YangInstanceIdentifier con3Path = YangInstanceIdentifier.of(odl)
401 writeModification.write(con3Path, con3Node);
403 final LeafSetNode<?> leafListNode = createLeafRefLeafListNode();
404 final YangInstanceIdentifier leafListPath = YangInstanceIdentifier.of(
405 odl).node(leafrefLeafList);
406 writeModification.write(leafListPath, leafListNode);
407 writeModification.ready();
409 final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
410 .prepare(writeModification);
412 LOG.debug("*************************");
413 LOG.debug("Before write2: ");
414 LOG.debug("*************************");
415 LOG.debug(inMemoryDataTree.toString());
417 boolean exception = false;
419 LeafRefValidation.validate(writeContributorsCandidate,
421 } catch (final LeafRefDataValidationFailedException e) {
422 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
423 assertEquals(6, e.getValidationsErrorsCount());
427 assertTrue(exception);
429 inMemoryDataTree.commit(writeContributorsCandidate);
431 LOG.debug("*************************");
432 LOG.debug("After write2: ");
433 LOG.debug("*************************");
434 LOG.debug(inMemoryDataTree.toString());
438 private static @NonNull LeafSetNode<Object> createLeafRefLeafListNode() {
439 return Builders.leafSetBuilder()
440 .withNodeIdentifier(new NodeIdentifier(leafrefLeafList))
441 .addChild(createLeafSetEntry(leafrefLeafList, "k1"))
442 .addChild(createLeafSetEntry(leafrefLeafList, "k2"))
443 .addChild(createLeafSetEntry(leafrefLeafList, "k3"))
447 private static ContainerNode createCon3Node() {
449 final CollectionNodeBuilder<MapEntryNode, SystemMapNode> mapBuilder = Builders.mapBuilder();
450 mapBuilder.withNodeIdentifier(new NodeIdentifier(list3InChoice));
452 mapBuilder.addChild(createList3Entry("k1", "val1", "valA", "valX"));
453 mapBuilder.addChild(createList3Entry("k2", "val2", "valB", "valY"));
455 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choiceBuilder = Builders
457 choiceBuilder.withNodeIdentifier(new NodeIdentifier(choiceInCon3));
459 choiceBuilder.addChild(mapBuilder.build());
461 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> containerBuilder = Builders
463 containerBuilder.withNodeIdentifier(new NodeIdentifier(con3));
465 containerBuilder.addChild(choiceBuilder.build());
467 return containerBuilder.build();
470 private static MapEntryNode createList3Entry(final String keyVal,
471 final String l3Val1, final String l3Val2, final String l3Val3) {
472 final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder = Builders
474 mapEntryBuilder.withNodeIdentifier(NodeIdentifierWithPredicates.of(list3InChoice, k, keyVal));
476 final ListNodeBuilder<Object, SystemLeafSetNode<Object>> leafSetBuilder = Builders.leafSetBuilder();
477 leafSetBuilder.withNodeIdentifier(new NodeIdentifier(l3));
479 leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val1));
480 leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val2));
481 leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val3));
483 mapEntryBuilder.addChild(ImmutableNodes.leafNode(k, keyVal));
484 mapEntryBuilder.addChild(leafSetBuilder.build());
486 return mapEntryBuilder.build();
489 private static LeafSetEntryNode<Object> createLeafSetEntry(
490 final QName qname, final String val) {
491 final NormalizedNodeBuilder<NodeWithValue, Object, LeafSetEntryNode<Object>> leafSetEntryBuilder = Builders
492 .leafSetEntryBuilder();
493 leafSetEntryBuilder.withNodeIdentifier(new NodeWithValue<>(qname, val));
494 leafSetEntryBuilder.withValue(val);
495 return leafSetEntryBuilder.build();
498 private static ChoiceNode createChoiceNode() {
500 final CollectionNodeBuilder<MapEntryNode, SystemMapNode> listInChoiceBuilder = Builders.mapBuilder();
501 listInChoiceBuilder.withNodeIdentifier(new NodeIdentifier(listInChoice));
503 listInChoiceBuilder.addChild(createListInChoiceEntry("key1", "leafref-in-choice value", "val1"));
504 listInChoiceBuilder.addChild(createListInChoiceEntry("key2", "l1 value", "val2"));
505 listInChoiceBuilder.addChild(createListInChoiceEntry("key3", "l1 value", "val3"));
507 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choice2Builder = Builders.choiceBuilder();
508 choice2Builder.withNodeIdentifier(new NodeIdentifier(ch2));
510 choice2Builder.addChild(listInChoiceBuilder.build());
512 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choiceBuilder = Builders.choiceBuilder();
513 choiceBuilder.withNodeIdentifier(new NodeIdentifier(ch1));
514 choiceBuilder.addChild(choice2Builder.build());
516 return choiceBuilder.build();
519 private static MapEntryNode createListInChoiceEntry(final String keyVal,
520 final String leafrefInChoiceVal,
521 final String leafrefInChoiceToChoiceVal) {
523 final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder = Builders
526 mapEntryBuilder.withNodeIdentifier(NodeIdentifierWithPredicates.of(
527 listInChoice, listInChoiceKey, keyVal));
529 mapEntryBuilder.addChild(ImmutableNodes.leafNode(listInChoiceKey,
531 mapEntryBuilder.addChild(ImmutableNodes.leafNode(leafrefInChoice,
532 leafrefInChoiceVal));
533 mapEntryBuilder.addChild(ImmutableNodes.leafNode(
534 leafrefInChoiceToChoice, leafrefInChoiceToChoiceVal));
536 return mapEntryBuilder.build();
539 private static void delete() throws DataValidationFailedException {
541 final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
543 final DataTreeModification delete = inMemoryDataTree.takeSnapshot()
545 delete.delete(contributorPath);
548 final DataTreeCandidate deleteContributorsCanditate = inMemoryDataTree.prepare(delete);
550 LOG.debug("*************************");
551 LOG.debug("Before delete: ");
552 LOG.debug("*************************");
553 LOG.debug(inMemoryDataTree.toString());
555 boolean exception = false;
557 LeafRefValidation.validate(deleteContributorsCanditate,
559 } catch (final LeafRefDataValidationFailedException e) {
560 LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
561 assertEquals(6, e.getValidationsErrorsCount());
565 assertTrue(exception);
567 inMemoryDataTree.commit(deleteContributorsCanditate);
569 LOG.debug("*************************");
570 LOG.debug("After delete: ");
571 LOG.debug("*************************");
572 LOG.debug(inMemoryDataTree.toString());
576 private static ContainerNode createContributorContainer(
577 final ContainerSchemaNode contributorContSchemaNode) {
579 final ListSchemaNode contributorListSchemaNode =
580 (ListSchemaNode) contributorContSchemaNode.findDataChildByName(contributor).get();
582 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> contributorContainerBldr =
583 Builders.containerBuilder(contributorContSchemaNode);
585 final SystemMapNode contributorMap = createContributorList(contributorListSchemaNode);
586 contributorContainerBldr.addChild(contributorMap);
588 final ContainerNode contributorContainer = contributorContainerBldr.build();
590 return contributorContainer;
594 private static SystemMapNode createContributorList(
595 final ListSchemaNode contributorListSchemaNode) {
597 final CollectionNodeBuilder<MapEntryNode, SystemMapNode> contributorMapBldr =
598 Builders.mapBuilder(contributorListSchemaNode);
600 final MapEntryNode contributorMapEntry1 = createContributorListEntry(
601 "Leader of Yangtools", "Yangtools Leader name", "Yangtools",
602 "Yangtools description ...", contributorListSchemaNode);
603 final MapEntryNode contributorMapEntry2 = createContributorListEntry(
604 "Leader of MD-SAL", "MD-SAL Leader name", "MD-SAL",
605 "MD-SAL description ...", contributorListSchemaNode);
606 final MapEntryNode contributorMapEntry3 = createContributorListEntry(
607 "Leader of Controller", "Controller Leader name", "Controller",
608 "Controller description ...", contributorListSchemaNode);
610 final MapEntryNode contributorMapEntry4 = createContributorListEntry(
611 "jdoe", "John Doe", "MD-SAL", "Yangtools description ...",
612 contributorListSchemaNode);
614 final MapEntryNode contributorMapEntry5 = createContributorListEntry(
615 "foo", "foo name", "Controller", "MD-SAL description ...",
616 contributorListSchemaNode);
618 final MapEntryNode contributorMapEntry6 = createContributorListEntry(
619 "bar", "bar name", "Yangtools", "Controller description ...",
620 contributorListSchemaNode);
622 final MapEntryNode contributorMapEntry7 = createContributorListEntry(
623 "baz", "baz name", "Unknown Project",
624 "Unknown Project description ...", contributorListSchemaNode);
626 final MapEntryNode contributorMapEntry8 = createContributorListEntry(
627 "pk", "pk name", "Unknown Project 2",
628 "Controller description ...", contributorListSchemaNode);
630 contributorMapBldr.addChild(contributorMapEntry1);
631 contributorMapBldr.addChild(contributorMapEntry2);
632 contributorMapBldr.addChild(contributorMapEntry3);
633 contributorMapBldr.addChild(contributorMapEntry4);
634 contributorMapBldr.addChild(contributorMapEntry5);
635 contributorMapBldr.addChild(contributorMapEntry6);
636 contributorMapBldr.addChild(contributorMapEntry7);
637 contributorMapBldr.addChild(contributorMapEntry8);
639 return contributorMapBldr.build();
642 private static MapEntryNode createContributorListEntry(
643 final String loginVal, final String contributorNameVal,
644 final String odlProjectNameVal, final String odlProjectDescVal,
645 final ListSchemaNode contributorListSchemaNode) {
647 final LeafNode<String> loginLeaf = ImmutableNodes.leafNode(login, loginVal);
648 final LeafNode<String> contributorNameLeaf = ImmutableNodes.leafNode(contributorName, contributorNameVal);
649 final LeafNode<String> odlProjectNameLeafRef = ImmutableNodes.leafNode(odlProjectName, odlProjectNameVal);
650 final LeafNode<String> odlProjectDescLeafRef = ImmutableNodes.leafNode(odlProjectDesc, odlProjectDescVal);
652 return Builders.mapEntryBuilder(contributorListSchemaNode)
654 .addChild(contributorNameLeaf)
655 .addChild(odlProjectNameLeafRef)
656 .addChild(odlProjectDescLeafRef)
660 private static ContainerNode createOdlContainer(
661 final ContainerSchemaNode container) {
663 final ListSchemaNode projListSchemaNode = (ListSchemaNode) container.findDataChildByName(project).get();
665 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> odlProjectContainerBldr = Builders
666 .containerBuilder(container);
668 final SystemMapNode projectMap = createProjectList(projListSchemaNode);
669 odlProjectContainerBldr.addChild(projectMap);
671 final ContainerNode odlProjectContainer = odlProjectContainerBldr
674 return odlProjectContainer;
677 private static SystemMapNode createProjectList(
678 final ListSchemaNode projListSchemaNode) {
680 final CollectionNodeBuilder<MapEntryNode, SystemMapNode> projectMapBldr = Builders
681 .mapBuilder(projListSchemaNode);
683 final MapEntryNode projMapEntry1 = createProjectListEntry("Yangtools",
684 "Yangtools description ...", "Leader of Yangtools",
685 "Owner of Yangtools", projListSchemaNode);
686 final MapEntryNode projMapEntry2 = createProjectListEntry("MD-SAL",
687 "MD-SAL description ...", "Leader of MD-SAL",
688 "Owner of MD-SAL", projListSchemaNode);
689 final MapEntryNode projMapEntry3 = createProjectListEntry("Controller",
690 "Controller description ...", "Leader of Controller",
691 "Owner of Controller", projListSchemaNode);
693 projectMapBldr.addChild(projMapEntry1);
694 projectMapBldr.addChild(projMapEntry2);
695 projectMapBldr.addChild(projMapEntry3);
697 return projectMapBldr.build();
700 private static MapEntryNode createProjectListEntry(final String nameVal,
701 final String descVal, final String leadVal, final String ownerVal,
702 final ListSchemaNode projListSchemaNode) {
704 final LeafNode<String> nameLeaf = ImmutableNodes
705 .leafNode(name, nameVal);
706 final LeafNode<String> descLeaf = ImmutableNodes
707 .leafNode(desc, descVal);
708 final LeafNode<String> leadLeafRef = ImmutableNodes.leafNode(lead,
710 final LeafNode<String> ownerLeafRef = ImmutableNodes.leafNode(owner,
713 final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> projMapEntryBldr = Builders
714 .mapEntryBuilder(projListSchemaNode);
716 projMapEntryBldr.addChild(nameLeaf);
717 projMapEntryBldr.addChild(descLeaf);
718 projMapEntryBldr.addChild(leadLeafRef);
719 projMapEntryBldr.addChild(ownerLeafRef);
720 final MapEntryNode projMapEntry = projMapEntryBldr.build();
725 private static ContainerNode createBasicContributorContainer(
726 final ContainerSchemaNode contributorContSchemaNode) {
728 final ListSchemaNode contributorListSchemaNode = (ListSchemaNode) contributorContSchemaNode
729 .findDataChildByName(contributor).get();
731 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> contributorContainerBldr = Builders
732 .containerBuilder(contributorContSchemaNode);
734 final SystemMapNode contributorMap = createBasicContributorList(contributorListSchemaNode);
735 contributorContainerBldr.addChild(contributorMap);
737 final ContainerNode contributorContainer = contributorContainerBldr
740 return contributorContainer;
744 private static SystemMapNode createBasicContributorList(
745 final ListSchemaNode contributorListSchemaNode) {
747 final CollectionNodeBuilder<MapEntryNode, SystemMapNode> contributorMapBldr =
748 Builders.mapBuilder(contributorListSchemaNode);
750 final MapEntryNode contributorMapEntry1 = createContributorListEntry(
751 "Leader of Yangtools", "Yangtools Leader name", "Yangtools",
752 "Yangtools description ...", contributorListSchemaNode);
753 final MapEntryNode contributorMapEntry2 = createContributorListEntry(
754 "Leader of MD-SAL", "MD-SAL Leader name", "MD-SAL",
755 "MD-SAL description ...", contributorListSchemaNode);
756 final MapEntryNode contributorMapEntry3 = createContributorListEntry(
757 "Leader of Controller", "Controller Leader name", "Controller",
758 "Controller description ...", contributorListSchemaNode);
760 contributorMapBldr.addChild(contributorMapEntry1);
761 contributorMapBldr.addChild(contributorMapEntry2);
762 contributorMapBldr.addChild(contributorMapEntry3);
764 return contributorMapBldr.build();