2 * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.data.codec.binfmt;
10 import com.google.common.collect.ImmutableSet;
11 import org.opendaylight.yangtools.yang.common.Decimal64;
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.common.Uint64;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
18 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
19 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
20 import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder;
21 import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes;
23 public final class TestModel {
24 static final QName TEST_QNAME = QName.create(
25 "urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test",
26 "2014-03-13", "test");
27 static final QName AUG_NAME_QNAME = QName.create(
28 "urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:aug",
29 "2014-03-13", "name");
30 private static final QName AUG_CONT_QNAME = QName.create(
31 "urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:aug",
32 "2014-03-13", "cont");
33 static final QName DESC_QNAME = QName.create(TEST_QNAME, "desc");
34 static final QName SOME_BINARY_DATA_QNAME = QName.create(TEST_QNAME, "some-binary-data");
35 static final QName BINARY_LEAF_LIST_QNAME = QName.create(TEST_QNAME, "binary_leaf_list");
36 private static final QName SOME_REF_QNAME = QName.create(TEST_QNAME, "some-ref");
37 private static final QName MYIDENTITY_QNAME = QName.create(TEST_QNAME, "myidentity");
38 private static final QName SWITCH_FEATURES_QNAME = QName.create(TEST_QNAME, "switch-features");
40 private static final QName AUGMENTED_LIST_QNAME = QName.create(TEST_QNAME, "augmented-list");
41 static final QName AUGMENTED_LIST_ENTRY_QNAME = QName.create(TEST_QNAME, "augmented-list-entry");
43 static final QName OUTER_LIST_QNAME = QName.create(TEST_QNAME, "outer-list");
44 static final QName INNER_LIST_QNAME = QName.create(TEST_QNAME, "inner-list");
45 static final QName ID_QNAME = QName.create(TEST_QNAME, "id");
46 private static final QName NAME_QNAME = QName.create(TEST_QNAME, "name");
47 static final QName BOOLEAN_LEAF_QNAME = QName.create(TEST_QNAME, "boolean-leaf");
48 private static final QName SHORT_LEAF_QNAME = QName.create(TEST_QNAME, "short-leaf");
49 private static final QName BYTE_LEAF_QNAME = QName.create(TEST_QNAME, "byte-leaf");
50 private static final QName BIGINTEGER_LEAF_QNAME = QName.create(TEST_QNAME, "biginteger-leaf");
51 private static final QName BIGDECIMAL_LEAF_QNAME = QName.create(TEST_QNAME, "bigdecimal-leaf");
52 static final QName ORDERED_LIST_QNAME = QName.create(TEST_QNAME, "ordered-list");
53 static final QName ORDERED_LIST_ENTRY_QNAME = QName.create(TEST_QNAME, "ordered-list-leaf");
54 private static final QName UNKEYED_LIST_QNAME = QName.create(TEST_QNAME, "unkeyed-list");
55 private static final QName SHOE_QNAME = QName.create(TEST_QNAME, "shoe");
56 static final QName ANY_XML_QNAME = QName.create(TEST_QNAME, "any");
57 static final QName EMPTY_QNAME = QName.create(TEST_QNAME, "empty-leaf");
59 static final YangInstanceIdentifier TEST_PATH = YangInstanceIdentifier.of(TEST_QNAME);
60 private static final QName TWO_THREE_QNAME = QName.create(TEST_QNAME, "two");
61 private static final QName TWO_QNAME = QName.create(TEST_QNAME, "two");
63 private static final Integer ONE_ID = 1;
64 private static final Integer TWO_ID = 2;
65 private static final String TWO_ONE_NAME = "one";
66 private static final String TWO_TWO_NAME = "two";
67 private static final String DESC = "Hello there";
68 private static final Boolean ENABLED = true;
69 private static final Short SHORT_ID = 1;
70 private static final Byte BYTE_ID = 1;
71 // Family specific constants
72 private static final QName FAMILY_QNAME = QName.create(
73 "urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:notification-test", "2014-04-17", "family");
74 static final QName CHILD_NUMBER_QNAME = QName.create(FAMILY_QNAME, "child-number");
75 static final QName CHILD_NAME_QNAME = QName.create(FAMILY_QNAME, "child-name");
77 private static final MapEntryNode BAR_NODE = ImmutableNodes.newMapEntryBuilder()
78 .withNodeIdentifier(NodeIdentifierWithPredicates.of(OUTER_LIST_QNAME, ID_QNAME, TWO_ID))
79 .withChild(ImmutableNodes.leafNode(ID_QNAME, TWO_ID))
80 .withChild(ImmutableNodes.newSystemMapBuilder()
81 .withNodeIdentifier(new NodeIdentifier(INNER_LIST_QNAME))
82 .withChild(ImmutableNodes.newMapEntryBuilder()
83 .withNodeIdentifier(NodeIdentifierWithPredicates.of(INNER_LIST_QNAME, NAME_QNAME, TWO_ONE_NAME))
84 .withChild(ImmutableNodes.leafNode(NAME_QNAME, TWO_ONE_NAME))
86 .withChild(ImmutableNodes.newMapEntryBuilder()
87 .withNodeIdentifier(NodeIdentifierWithPredicates.of(INNER_LIST_QNAME, NAME_QNAME, TWO_TWO_NAME))
88 .withChild(ImmutableNodes.leafNode(NAME_QNAME, TWO_TWO_NAME))
94 throw new UnsupportedOperationException();
97 public static DataContainerNodeBuilder<NodeIdentifier, ContainerNode> createBaseTestContainerBuilder() {
98 // Create the document
99 return ImmutableNodes.newContainerBuilder()
100 .withNodeIdentifier(new NodeIdentifier(TEST_QNAME))
101 // Create a bits leaf
102 .withChild(ImmutableNodes.leafNode(QName.create(TEST_QNAME, "my-bits"), ImmutableSet.of("foo", "bar")))
103 .withChild(ImmutableNodes.leafNode(DESC_QNAME, DESC))
104 .withChild(ImmutableNodes.leafNode(BOOLEAN_LEAF_QNAME, ENABLED))
105 .withChild(ImmutableNodes.leafNode(SHORT_LEAF_QNAME, SHORT_ID))
106 .withChild(ImmutableNodes.leafNode(BYTE_LEAF_QNAME, BYTE_ID))
107 .withChild(ImmutableNodes.leafNode(TestModel.BIGINTEGER_LEAF_QNAME, Uint64.valueOf(100)))
108 .withChild(ImmutableNodes.leafNode(TestModel.BIGDECIMAL_LEAF_QNAME, Decimal64.valueOf("1.2")))
109 .withChild(ImmutableNodes.leafNode(SOME_REF_QNAME,
110 // Create YangInstanceIdentifier with all path arg types.
111 YangInstanceIdentifier.of(new NodeIdentifier(QName.create(TEST_QNAME, "qname")),
112 NodeIdentifierWithPredicates.of(QName.create(TEST_QNAME, "list-entry"),
113 QName.create(TEST_QNAME, "key"), 10),
114 new NodeWithValue<>(QName.create(TEST_QNAME, "leaf-list-entry"), "foo"))))
115 .withChild(ImmutableNodes.leafNode(MYIDENTITY_QNAME, DESC_QNAME))
116 .withChild(ImmutableNodes.newUnkeyedListBuilder()
117 .withNodeIdentifier(new NodeIdentifier(UNKEYED_LIST_QNAME))
118 // Create unkeyed list entry
119 .withChild(ImmutableNodes.newUnkeyedListEntryBuilder()
120 .withNodeIdentifier(new NodeIdentifier(UNKEYED_LIST_QNAME))
121 .withChild(ImmutableNodes.leafNode(NAME_QNAME, "unkeyed-entry-name"))
124 .withChild(ImmutableNodes.newChoiceBuilder()
125 .withNodeIdentifier(new NodeIdentifier(TWO_THREE_QNAME))
126 .withChild(ImmutableNodes.leafNode(TWO_QNAME, "two"))
128 .withChild(ImmutableNodes.newUserMapBuilder()
129 .withNodeIdentifier(new NodeIdentifier(ORDERED_LIST_QNAME))
130 .withChild(ImmutableNodes.newMapEntryBuilder()
132 NodeIdentifierWithPredicates.of(ORDERED_LIST_QNAME, ORDERED_LIST_ENTRY_QNAME, "1"))
133 .withChild(ImmutableNodes.leafNode(ORDERED_LIST_ENTRY_QNAME, "1"))
135 .withChild(ImmutableNodes.newMapEntryBuilder()
137 NodeIdentifierWithPredicates.of(ORDERED_LIST_QNAME, ORDERED_LIST_ENTRY_QNAME, "2"))
138 .withChild(ImmutableNodes.leafNode(ORDERED_LIST_ENTRY_QNAME, "2"))
141 // Create a list of shoes
142 .withChild(ImmutableNodes.newSystemLeafSetBuilder()
143 .withNodeIdentifier(new NodeIdentifier(SHOE_QNAME))
144 .withChild(ImmutableNodes.leafSetEntry(SHOE_QNAME, "nike"))
145 .withChild(ImmutableNodes.leafSetEntry(SHOE_QNAME, "puma"))
147 // Create a leaf list with numbers
148 .withChild(ImmutableNodes.newSystemLeafSetBuilder()
149 .withNodeIdentifier(new NodeIdentifier(QName.create(TEST_QNAME, "number")))
150 .withChild(ImmutableNodes.leafSetEntry(QName.create(TEST_QNAME, "number"), 5))
151 .withChild(ImmutableNodes.leafSetEntry(QName.create(TEST_QNAME, "number"), 15))
153 .withChild(ImmutableNodes.newContainerBuilder()
154 .withNodeIdentifier(new NodeIdentifier(SWITCH_FEATURES_QNAME))
155 // Test a leaf-list where each entry contains an identity
156 .withChild(ImmutableNodes.newSystemLeafSetBuilder()
157 .withNodeIdentifier(new NodeIdentifier(QName.create(TEST_QNAME, "capability")))
158 .withChild(ImmutableNodes.leafSetEntry(QName.create(TEST_QNAME, "capability"), DESC_QNAME))
161 .withChild(ImmutableNodes.newSystemMapBuilder()
162 .withNodeIdentifier(new NodeIdentifier(AUGMENTED_LIST_QNAME))
163 // Create augmentations
164 .withChild(createAugmentedListEntry(1, "First Test"))
166 .withChild(ImmutableNodes.newSystemMapBuilder()
167 .withNodeIdentifier(new NodeIdentifier(OUTER_LIST_QNAME))
168 .withChild(ImmutableNodes.newMapEntryBuilder()
169 .withNodeIdentifier(NodeIdentifierWithPredicates.of(OUTER_LIST_QNAME, ID_QNAME, ONE_ID))
170 .withChild(ImmutableNodes.leafNode(ID_QNAME, ONE_ID))
176 static ContainerNode createTestContainer() {
177 return createBaseTestContainerBuilder().build();
180 private static MapEntryNode createAugmentedListEntry(final int id, final String name) {
181 return ImmutableNodes.newMapEntryBuilder()
182 .withNodeIdentifier(NodeIdentifierWithPredicates.of(AUGMENTED_LIST_QNAME, ID_QNAME, id))
183 .withChild(ImmutableNodes.leafNode(ID_QNAME, id))
184 .withChild(ImmutableNodes.newContainerBuilder()
185 .withNodeIdentifier(new NodeIdentifier(AUG_CONT_QNAME))
186 .withChild(ImmutableNodes.leafNode(AUG_NAME_QNAME, name))