Improve segmented journal actor metrics
[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.YangInstanceIdentifier.NodeIdentifier;
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.api.schema.SystemMapNode;
19 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
20 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
21
22 public final class CarsModel {
23     public static final QName BASE_QNAME = QName.create(
24             "urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test:cars", "2014-03-13", "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     private CarsModel() {
35         // Hidden on purpose
36     }
37
38     public static ContainerNode create() {
39         return Builders.containerBuilder()
40             .withNodeIdentifier(new NodeIdentifier(BASE_QNAME))
41             .withChild(Builders.mapBuilder()
42                 .withNodeIdentifier(new NodeIdentifier(CAR_QNAME))
43                 // Create an entry for the car altima
44                 .withChild(ImmutableNodes.mapEntryBuilder(CAR_QNAME, CAR_NAME_QNAME, "altima")
45                     .withChild(ImmutableNodes.leafNode(CAR_NAME_QNAME, "altima"))
46                     .withChild(ImmutableNodes.leafNode(CAR_PRICE_QNAME, Uint64.valueOf(1000)))
47                     .build())
48                 // Create an entry for the car accord
49                 .withChild(ImmutableNodes.mapEntryBuilder(CAR_QNAME, CAR_NAME_QNAME, "accord")
50                     .withChild(ImmutableNodes.leafNode(CAR_NAME_QNAME, "accord"))
51                     .withChild(ImmutableNodes.leafNode(CAR_PRICE_QNAME, Uint64.valueOf("2000")))
52                     .build())
53                 .build())
54             .build();
55     }
56
57     public static NormalizedNode createEmptyCarsList() {
58         return newCarsNode(newCarsMapNode());
59     }
60
61     public static ContainerNode newCarsNode(final MapNode carsList) {
62         return Builders.containerBuilder()
63             .withNodeIdentifier(new NodeIdentifier(BASE_QNAME))
64             .withChild(carsList)
65             .build();
66     }
67
68     public static MapNode newCarsMapNode(final MapEntryNode... carEntries) {
69         var builder = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(CAR_QNAME));
70         for (MapEntryNode e : carEntries) {
71             builder.withChild(e);
72         }
73
74         return builder.build();
75     }
76
77     public static ContainerNode emptyContainer() {
78         return Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(BASE_QNAME)).build();
79     }
80
81     public static SystemMapNode newCarMapNode() {
82         return ImmutableNodes.mapNodeBuilder(CAR_QNAME).build();
83     }
84
85     public static MapEntryNode newCarEntry(final String name, final Uint64 price) {
86         return ImmutableNodes.mapEntryBuilder(CAR_QNAME, CAR_NAME_QNAME, name)
87                 .withChild(ImmutableNodes.leafNode(CAR_NAME_QNAME, name))
88                 .withChild(ImmutableNodes.leafNode(CAR_PRICE_QNAME, price)).build();
89     }
90
91     public static YangInstanceIdentifier newCarPath(final String name) {
92         return YangInstanceIdentifier.builder(CAR_LIST_PATH).nodeWithKey(CAR_QNAME, CAR_NAME_QNAME, name).build();
93     }
94 }