Bug 4564: Implement datastore restore from backup file
[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.ContainerNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
17 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
18 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
19 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
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 class CarsModel {
24     public static final QName BASE_QNAME = QName.create("urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test:cars", "2014-03-13",
25         "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     public static NormalizedNode<?, ?> create(){
36
37         // Create a list builder
38         CollectionNodeBuilder<MapEntryNode, MapNode> cars =
39             ImmutableMapNodeBuilder.create().withNodeIdentifier(
40                 new YangInstanceIdentifier.NodeIdentifier(
41                     CAR_QNAME));
42
43         // Create an entry for the car altima
44         MapEntryNode altima =
45             ImmutableNodes.mapEntryBuilder(CAR_QNAME, CAR_NAME_QNAME, "altima")
46                 .withChild(ImmutableNodes.leafNode(CAR_NAME_QNAME, "altima"))
47                 .withChild(ImmutableNodes.leafNode(CAR_PRICE_QNAME, new BigInteger("1000")))
48                 .build();
49
50         // Create an entry for the car accord
51         MapEntryNode honda =
52             ImmutableNodes.mapEntryBuilder(CAR_QNAME, CAR_NAME_QNAME, "accord")
53                 .withChild(ImmutableNodes.leafNode(CAR_NAME_QNAME, "accord"))
54                 .withChild(ImmutableNodes.leafNode(CAR_PRICE_QNAME, new BigInteger("2000")))
55                 .build();
56
57         cars.withChild(altima);
58         cars.withChild(honda);
59
60         return ImmutableContainerNodeBuilder.create()
61             .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(BASE_QNAME))
62             .withChild(cars.build())
63             .build();
64
65     }
66
67     public static NormalizedNode<?, ?> createEmptyCarsList(){
68         return newCarsNode(newCarsMapNode());
69     }
70
71     public static ContainerNode newCarsNode(MapNode carsList) {
72         return ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(
73                 BASE_QNAME)).withChild(carsList).build();
74     }
75
76     public static MapNode newCarsMapNode(MapEntryNode... carEntries) {
77         CollectionNodeBuilder<MapEntryNode, MapNode> builder = ImmutableMapNodeBuilder.create().
78                 withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CAR_QNAME));
79         for(MapEntryNode e: carEntries) {
80             builder.withChild(e);
81         }
82
83         return builder.build();
84     }
85
86     public static NormalizedNode<?, ?> emptyContainer(){
87         return ImmutableContainerNodeBuilder.create()
88             .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(BASE_QNAME))
89             .build();
90     }
91
92     public static NormalizedNode<?, ?> newCarMapNode() {
93         return ImmutableNodes.mapNodeBuilder(CAR_QNAME).build();
94     }
95
96     public static MapEntryNode newCarEntry(String name, BigInteger price) {
97         return ImmutableNodes.mapEntryBuilder(CAR_QNAME, CAR_NAME_QNAME, name)
98                 .withChild(ImmutableNodes.leafNode(CAR_NAME_QNAME, name))
99                 .withChild(ImmutableNodes.leafNode(CAR_PRICE_QNAME, price)).build();
100     }
101
102     public static YangInstanceIdentifier newCarPath(String name) {
103         return YangInstanceIdentifier.builder(CAR_LIST_PATH).nodeWithKey(CAR_QNAME, CAR_NAME_QNAME, name).build();
104     }
105 }