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

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.