Bump mdsal/yangtools
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / md / cluster / datastore / model / PeopleModel.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.md.cluster.datastore.model;
9
10 import org.opendaylight.yangtools.yang.common.QName;
11 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
12 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
13 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
14 import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder;
16 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
17 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
18 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeBuilder;
19
20 public final class PeopleModel {
21     public static final QName BASE_QNAME = QName.create(
22             "urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test:people", "2014-03-13", "people");
23
24     public static final QName PEOPLE_QNAME = QName.create(BASE_QNAME, "people");
25     public static final QName PERSON_QNAME = QName.create(PEOPLE_QNAME, "person");
26     public static final QName PERSON_NAME_QNAME = QName.create(PERSON_QNAME, "name");
27     public static final QName PERSON_AGE_QNAME = QName.create(PERSON_QNAME, "age");
28
29     public static final YangInstanceIdentifier BASE_PATH = YangInstanceIdentifier.of(BASE_QNAME);
30     public static final YangInstanceIdentifier PERSON_LIST_PATH = BASE_PATH.node(PERSON_QNAME);
31
32     private PeopleModel() {
33
34     }
35
36     public static ContainerNode create() {
37
38         // Create a list builder
39         CollectionNodeBuilder<MapEntryNode, SystemMapNode> cars =
40             ImmutableMapNodeBuilder.create().withNodeIdentifier(
41                 new YangInstanceIdentifier.NodeIdentifier(
42                     PERSON_QNAME));
43
44         // Create an entry for the person jack
45         MapEntryNode jack =
46             ImmutableNodes.mapEntryBuilder(PERSON_QNAME, PERSON_NAME_QNAME, "jack")
47                 .withChild(ImmutableNodes.leafNode(PERSON_NAME_QNAME, "jack"))
48                 .withChild(ImmutableNodes.leafNode(PERSON_AGE_QNAME, 100L))
49                 .build();
50
51         // Create an entry for the person jill
52         MapEntryNode jill =
53             ImmutableNodes.mapEntryBuilder(PERSON_QNAME, PERSON_NAME_QNAME, "jill")
54                 .withChild(ImmutableNodes.leafNode(PERSON_NAME_QNAME, "jill"))
55                 .withChild(ImmutableNodes.leafNode(PERSON_AGE_QNAME, 200L))
56                 .build();
57
58         cars.withChild(jack);
59         cars.withChild(jill);
60
61         return ImmutableContainerNodeBuilder.create()
62             .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(BASE_QNAME))
63             .withChild(cars.build())
64             .build();
65
66     }
67
68     public static ContainerNode emptyContainer() {
69         return ImmutableContainerNodeBuilder.create()
70             .withNodeIdentifier(
71                 new YangInstanceIdentifier.NodeIdentifier(BASE_QNAME))
72             .build();
73     }
74
75     public static SystemMapNode newPersonMapNode() {
76         return ImmutableNodes.mapNodeBuilder(PERSON_QNAME).build();
77     }
78
79     public static MapEntryNode newPersonEntry(final String name) {
80         return ImmutableNodes.mapEntryBuilder(PERSON_QNAME, PERSON_NAME_QNAME, name)
81                 .withChild(ImmutableNodes.leafNode(PERSON_NAME_QNAME, name)).build();
82     }
83
84     public static YangInstanceIdentifier newPersonPath(final String name) {
85         return YangInstanceIdentifier.builder(PERSON_LIST_PATH)
86                 .nodeWithKey(PERSON_QNAME, PERSON_NAME_QNAME, name).build();
87     }
88 }