Adjust to yangtools-2.0.0 changes
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / md / cluster / datastore / model / TestModel.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.data.api.YangInstanceIdentifier;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
13 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
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.model.api.SchemaContext;
21 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
22
23 public final class TestModel {
24
25     public static final QName TEST_QNAME =
26             QName.create("urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test", "2014-03-13", "test");
27
28     public static final QName TEST2_QNAME =
29             QName.create("urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test", "2014-03-13", "test2");
30
31     public static final QName JUNK_QNAME =
32             QName.create("urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:junk", "2014-03-13", "junk");
33
34     public static final QName OUTER_LIST_QNAME = QName.create(TEST_QNAME, "outer-list");
35     public static final QName OUTER_CONTAINER_QNAME = QName.create(TEST_QNAME, "outer-container");
36     public static final QName INNER_LIST_QNAME = QName.create(TEST_QNAME, "inner-list");
37     public static final QName OUTER_CHOICE_QNAME = QName.create(TEST_QNAME, "outer-choice");
38     public static final QName ID_QNAME = QName.create(TEST_QNAME, "id");
39     public static final QName NAME_QNAME = QName.create(TEST_QNAME, "name");
40     public static final QName VALUE_QNAME = QName.create(TEST_QNAME, "value");
41     public static final QName DESC_QNAME = QName.create(TEST_QNAME, "desc");
42     private static final String DATASTORE_TEST_YANG = "/odl-datastore-test.yang";
43
44     public static final YangInstanceIdentifier TEST_PATH = YangInstanceIdentifier.of(TEST_QNAME);
45     public static final YangInstanceIdentifier TEST2_PATH = YangInstanceIdentifier.of(TEST2_QNAME);
46     public static final YangInstanceIdentifier JUNK_PATH = YangInstanceIdentifier.of(JUNK_QNAME);
47     public static final YangInstanceIdentifier OUTER_LIST_PATH = YangInstanceIdentifier.builder(TEST_PATH)
48             .node(OUTER_LIST_QNAME).build();
49     public static final YangInstanceIdentifier INNER_LIST_PATH = YangInstanceIdentifier.builder(TEST_PATH)
50             .node(OUTER_LIST_QNAME).node(INNER_LIST_QNAME).build();
51     public static final YangInstanceIdentifier OUTER_CONTAINER_PATH = TEST_PATH.node(OUTER_CONTAINER_QNAME);
52     public static final QName TWO_QNAME = QName.create(TEST_QNAME,"two");
53     public static final QName THREE_QNAME = QName.create(TEST_QNAME,"three");
54
55     private TestModel() {
56
57     }
58
59     public static SchemaContext createTestContext() {
60         return YangParserTestUtils.parseYangResource(DATASTORE_TEST_YANG);
61     }
62
63     public static DataContainerChild<?, ?> outerNode(final int... ids) {
64         CollectionNodeBuilder<MapEntryNode, MapNode> outer = ImmutableNodes.mapNodeBuilder(OUTER_LIST_QNAME);
65         for (int id: ids) {
66             outer.addChild(ImmutableNodes.mapEntry(OUTER_LIST_QNAME, ID_QNAME, id));
67         }
68
69         return outer.build();
70     }
71
72     public static DataContainerChild<?, ?> outerNode(final MapEntryNode... entries) {
73         CollectionNodeBuilder<MapEntryNode, MapNode> outer = ImmutableNodes.mapNodeBuilder(OUTER_LIST_QNAME);
74         for (MapEntryNode e: entries) {
75             outer.addChild(e);
76         }
77
78         return outer.build();
79     }
80
81     public static DataContainerChild<?, ?> innerNode(final String... names) {
82         CollectionNodeBuilder<MapEntryNode, MapNode> outer = ImmutableNodes.mapNodeBuilder(INNER_LIST_QNAME);
83         for (String name: names) {
84             outer.addChild(ImmutableNodes.mapEntry(INNER_LIST_QNAME, NAME_QNAME, name));
85         }
86
87         return outer.build();
88     }
89
90     public static MapEntryNode outerNodeEntry(final int id, final DataContainerChild<?, ?> inner) {
91         return ImmutableNodes.mapEntryBuilder(OUTER_LIST_QNAME, ID_QNAME, id).addChild(inner).build();
92     }
93
94     public static NormalizedNode<?, ?> testNodeWithOuter(final int... ids) {
95         return testNodeWithOuter(outerNode(ids));
96     }
97
98     public static NormalizedNode<?, ?> testNodeWithOuter(final DataContainerChild<?, ?> outer) {
99         return ImmutableContainerNodeBuilder.create().withNodeIdentifier(
100                 new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)).withChild(outer).build();
101     }
102
103     public static NodeIdentifierWithPredicates outerEntryKey(final int id) {
104         return new NodeIdentifierWithPredicates(OUTER_LIST_QNAME, ID_QNAME, id);
105     }
106
107     public static YangInstanceIdentifier outerEntryPath(final int id) {
108         return OUTER_LIST_PATH.node(outerEntryKey(id));
109     }
110
111     public static NodeIdentifierWithPredicates innerEntryKey(final String name) {
112         return new NodeIdentifierWithPredicates(INNER_LIST_QNAME, NAME_QNAME, name);
113     }
114
115     public static YangInstanceIdentifier innerEntryPath(final int id, final String name) {
116         return OUTER_LIST_PATH.node(outerEntryKey(id)).node(INNER_LIST_QNAME).node(innerEntryKey(name));
117     }
118 }

©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.