1 package org.opendaylight.yangtools.yang.data.impl.schema.test;
3 import static org.junit.Assert.assertNotNull;
4 import static org.junit.Assert.assertTrue;
5 import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntry;
6 import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntryBuilder;
7 import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapNodeBuilder;
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.NodeIdentifier;
13 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
14 import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeUtils;
15 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
17 import com.google.common.base.Optional;
21 * Schema structure of document is
46 public class NormalizedNodeUtilsTest {
48 private static final QName ROOT_QNAME = QName.create("urn:opendalight:controller:sal:dom:store:test", "2014-03-13",
50 private static final QName LIST_A_QNAME = QName.create(ROOT_QNAME, "list-a");
51 private static final QName LIST_B_QNAME = QName.create(ROOT_QNAME, "list-b");
52 private static final QName LEAF_A_QNAME = QName.create(ROOT_QNAME, "leaf-a");
53 private static final QName LEAF_B_QNAME = QName.create(ROOT_QNAME, "leaf-b");
54 private static final String FOO = "foo";
55 private static final String BAR = "bar";
56 private static final String ONE = "one";
57 private static final String TWO = "two";
59 private static final YangInstanceIdentifier LIST_A_FOO_PATH = YangInstanceIdentifier.builder()
62 .nodeWithKey(LIST_A_QNAME, LEAF_A_QNAME, FOO)
64 private static final YangInstanceIdentifier LIST_B_TWO_PATH = YangInstanceIdentifier.builder()
67 .nodeWithKey(LIST_A_QNAME, LEAF_A_QNAME, BAR)
69 .nodeWithKey(LIST_B_QNAME,LEAF_B_QNAME,TWO)
73 * Returns a test document
90 public NormalizedNode<?, ?> createDocumentOne() {
91 return ImmutableContainerNodeBuilder
93 .withNodeIdentifier(new NodeIdentifier(ROOT_QNAME))
95 mapNodeBuilder(LIST_A_QNAME)
96 .withChild(mapEntry(LIST_A_QNAME, LEAF_A_QNAME, FOO))
98 mapEntryBuilder(LIST_A_QNAME, LEAF_A_QNAME, BAR).withChild(
99 mapNodeBuilder(LIST_B_QNAME)
100 .withChild(mapEntry(LIST_B_QNAME, LEAF_B_QNAME, ONE))
101 .withChild(mapEntry(LIST_B_QNAME, LEAF_B_QNAME, TWO)).build())
102 .build()).build()).build();
107 public void findNodeTest() {
108 NormalizedNode<?, ?> tree = createDocumentOne();
111 Optional<NormalizedNode<?, ?>> listFooResult = NormalizedNodeUtils.findNode(tree, LIST_A_FOO_PATH);
112 assertTrue(listFooResult.isPresent());
114 Optional<NormalizedNode<?, ?>> listTwoResult = NormalizedNodeUtils.findNode(tree, LIST_B_TWO_PATH);
115 assertTrue(listTwoResult.isPresent());