Bump odlparent/yangtools/mdsal
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / md / cluster / datastore / model / CarsModel.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.common.Uint64;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
13 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
14 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
17 import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
18 import org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder;
19 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
20 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
21 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeBuilder;
22
23 public final class CarsModel {
24     public static final QName BASE_QNAME = QName.create(
25             "urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test:cars", "2014-03-13", "cars");
26
27     public static final QName CARS_QNAME = QName.create(BASE_QNAME, "cars");
28     public static final QName CAR_QNAME = QName.create(CARS_QNAME, "car");
29     public static final QName CAR_NAME_QNAME = QName.create(CAR_QNAME, "name");
30     public static final QName CAR_PRICE_QNAME = QName.create(CAR_QNAME, "price");
31
32     public static final YangInstanceIdentifier BASE_PATH = YangInstanceIdentifier.of(BASE_QNAME);
33     public static final YangInstanceIdentifier CAR_LIST_PATH = BASE_PATH.node(CAR_QNAME);
34
35     private CarsModel() {
36
37     }
38
39     public static ContainerNode create() {
40
41         // Create a list builder
42         CollectionNodeBuilder<MapEntryNode, SystemMapNode> cars =
43             ImmutableMapNodeBuilder.create().withNodeIdentifier(
44                 new YangInstanceIdentifier.NodeIdentifier(CAR_QNAME));
45
46         // Create an entry for the car altima
47         MapEntryNode altima =
48             ImmutableNodes.mapEntryBuilder(CAR_QNAME, CAR_NAME_QNAME, "altima")
49                 .withChild(ImmutableNodes.leafNode(CAR_NAME_QNAME, "altima"))
50                 .withChild(ImmutableNodes.leafNode(CAR_PRICE_QNAME, Uint64.valueOf(1000)))
51                 .build();
52
53         // Create an entry for the car accord
54         MapEntryNode honda =
55             ImmutableNodes.mapEntryBuilder(CAR_QNAME, CAR_NAME_QNAME, "accord")
56                 .withChild(ImmutableNodes.leafNode(CAR_NAME_QNAME, "accord"))
57                 .withChild(ImmutableNodes.leafNode(CAR_PRICE_QNAME, Uint64.valueOf("2000")))
58                 .build();
59
60         cars.withChild(altima);
61         cars.withChild(honda);
62
63         return ImmutableContainerNodeBuilder.create()
64             .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(BASE_QNAME))
65             .withChild(cars.build())
66             .build();
67
68     }
69
70     public static NormalizedNode createEmptyCarsList() {
71         return newCarsNode(newCarsMapNode());
72     }
73
74     public static ContainerNode newCarsNode(final MapNode carsList) {
75         return ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(
76                 BASE_QNAME)).withChild(carsList).build();
77     }
78
79     public static MapNode newCarsMapNode(final MapEntryNode... carEntries) {
80         CollectionNodeBuilder<MapEntryNode, SystemMapNode> builder = ImmutableMapNodeBuilder.create()
81                 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CAR_QNAME));
82         for (MapEntryNode e : carEntries) {
83             builder.withChild(e);
84         }
85
86         return builder.build();
87     }
88
89     public static ContainerNode emptyContainer() {
90         return ImmutableContainerNodeBuilder.create()
91             .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(BASE_QNAME))
92             .build();
93     }
94
95     public static SystemMapNode newCarMapNode() {
96         return ImmutableNodes.mapNodeBuilder(CAR_QNAME).build();
97     }
98
99     public static MapEntryNode newCarEntry(final String name, final Uint64 price) {
100         return ImmutableNodes.mapEntryBuilder(CAR_QNAME, CAR_NAME_QNAME, name)
101                 .withChild(ImmutableNodes.leafNode(CAR_NAME_QNAME, name))
102                 .withChild(ImmutableNodes.leafNode(CAR_PRICE_QNAME, price)).build();
103     }
104
105     public static YangInstanceIdentifier newCarPath(final String name) {
106         return YangInstanceIdentifier.builder(CAR_LIST_PATH).nodeWithKey(CAR_QNAME, CAR_NAME_QNAME, name).build();
107     }
108 }