468e2da3101513e33c1c0e29c51976df2d56a970
[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
9 package org.opendaylight.controller.md.cluster.datastore.model;
10
11 import java.math.BigInteger;
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
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.impl.schema.ImmutableNodes;
18 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
19 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
20 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeBuilder;
21
22 public class CarsModel {
23     public static final QName BASE_QNAME = QName.create("urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test:cars", "2014-03-13",
24         "cars");
25
26     public static final QName CARS_QNAME = QName.create(BASE_QNAME, "cars");
27     public static final QName CAR_QNAME = QName.create(CARS_QNAME, "car");
28     public static final QName CAR_NAME_QNAME = QName.create(CAR_QNAME, "name");
29     public static final QName CAR_PRICE_QNAME = QName.create(CAR_QNAME, "price");
30
31     public static final YangInstanceIdentifier BASE_PATH = YangInstanceIdentifier.of(BASE_QNAME);
32     public static final YangInstanceIdentifier CAR_LIST_PATH = BASE_PATH.node(CAR_QNAME);
33
34     public static NormalizedNode<?, ?> create(){
35
36         // Create a list builder
37         CollectionNodeBuilder<MapEntryNode, MapNode> cars =
38             ImmutableMapNodeBuilder.create().withNodeIdentifier(
39                 new YangInstanceIdentifier.NodeIdentifier(
40                     CAR_QNAME));
41
42         // Create an entry for the car altima
43         MapEntryNode altima =
44             ImmutableNodes.mapEntryBuilder(CAR_QNAME, CAR_NAME_QNAME, "altima")
45                 .withChild(ImmutableNodes.leafNode(CAR_NAME_QNAME, "altima"))
46                 .withChild(ImmutableNodes.leafNode(CAR_PRICE_QNAME, new BigInteger("1000")))
47                 .build();
48
49         // Create an entry for the car accord
50         MapEntryNode honda =
51             ImmutableNodes.mapEntryBuilder(CAR_QNAME, CAR_NAME_QNAME, "accord")
52                 .withChild(ImmutableNodes.leafNode(CAR_NAME_QNAME, "accord"))
53                 .withChild(ImmutableNodes.leafNode(CAR_PRICE_QNAME, new BigInteger("2000")))
54                 .build();
55
56         cars.withChild(altima);
57         cars.withChild(honda);
58
59         return ImmutableContainerNodeBuilder.create()
60             .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(BASE_QNAME))
61             .withChild(cars.build())
62             .build();
63
64     }
65
66     public static NormalizedNode<?, ?> emptyContainer(){
67         return ImmutableContainerNodeBuilder.create()
68             .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(BASE_QNAME))
69             .build();
70     }
71
72     public static NormalizedNode<?, ?> newCarMapNode() {
73         return ImmutableNodes.mapNodeBuilder(CAR_QNAME).build();
74     }
75
76     public static MapEntryNode newCarEntry(String name, BigInteger price) {
77         return ImmutableNodes.mapEntryBuilder(CAR_QNAME, CAR_NAME_QNAME, name)
78                 .withChild(ImmutableNodes.leafNode(CAR_NAME_QNAME, name))
79                 .withChild(ImmutableNodes.leafNode(CAR_PRICE_QNAME, price)).build();
80     }
81
82     public static YangInstanceIdentifier newCarPath(String name) {
83         return YangInstanceIdentifier.builder(CAR_LIST_PATH).nodeWithKey(CAR_QNAME, CAR_NAME_QNAME, name).build();
84     }
85 }