2 * Copyright (c) 2016 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
9 package org.opendaylight.yangtools.yang.data.impl.schema;
11 import static org.junit.jupiter.api.Assertions.assertNotNull;
12 import static org.junit.jupiter.api.Assertions.assertTrue;
13 import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntry;
14 import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntryBuilder;
15 import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapNodeBuilder;
17 import org.junit.jupiter.api.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
22 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
23 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
26 * Schema structure of document is:
48 class NormalizedNodeUtilsTest {
49 private static final QName ROOT_QNAME = QName.create("urn:opendaylight:controller:sal:dom:store:test", "2014-03-13",
51 private static final QName LIST_A_QNAME = QName.create(ROOT_QNAME, "list-a");
52 private static final QName LIST_B_QNAME = QName.create(ROOT_QNAME, "list-b");
53 private static final QName LEAF_A_QNAME = QName.create(ROOT_QNAME, "leaf-a");
54 private static final QName LEAF_B_QNAME = QName.create(ROOT_QNAME, "leaf-b");
55 private static final String FOO = "foo";
56 private static final String BAR = "bar";
57 private static final String ONE = "one";
58 private static final String TWO = "two";
60 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()
66 .nodeWithKey(LIST_A_QNAME, LEAF_A_QNAME, BAR)
68 .nodeWithKey(LIST_B_QNAME,LEAF_B_QNAME,TWO)
72 * Returns a test document.
87 * @return A test document
89 private static NormalizedNode createDocumentOne() {
90 return ImmutableContainerNodeBuilder.create()
91 .withNodeIdentifier(new NodeIdentifier(ROOT_QNAME))
92 .withChild(mapNodeBuilder(LIST_A_QNAME)
93 .withChild(mapEntry(LIST_A_QNAME, LEAF_A_QNAME, FOO))
94 .withChild(mapEntryBuilder(LIST_A_QNAME, LEAF_A_QNAME, BAR)
95 .withChild(mapNodeBuilder(LIST_B_QNAME)
96 .withChild(mapEntry(LIST_B_QNAME, LEAF_B_QNAME, ONE))
97 .withChild(mapEntry(LIST_B_QNAME, LEAF_B_QNAME, TWO))
105 void findNodeTest() {
106 final var tree = createDocumentOne();
109 final var listFooResult = NormalizedNodes.findNode(tree, LIST_A_FOO_PATH);
110 assertTrue(listFooResult.isPresent());
112 final var listTwoResult = NormalizedNodes.findNode(tree, LIST_B_TWO_PATH);
113 assertTrue(listTwoResult.isPresent());