Address FIXME for QueuedNotificationManager
[yangtools.git] / yang / yang-data-impl / src / test / java / org / opendaylight / yangtools / yang / data / impl / schema / NormalizedNodeUtilsTest.java
1 /*
2  * Copyright (c) 2016 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
9 package org.opendaylight.yangtools.yang.data.impl.schema;
10
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.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;
16 import com.google.common.base.Optional;
17 import org.junit.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;
24
25 /**
26  *
27  * Schema structure of document is
28  *
29  * <pre>
30  * container root { 
31  *      list list-a {
32  *              key leaf-a;
33  *              leaf leaf-a;
34  *              choice choice-a {
35  *                      case one {
36  *                              leaf one;
37  *                      }
38  *                      case two-three {
39  *                              leaf two;
40  *                              leaf three;
41  *                      }
42  *              }
43  *              list list-b {
44  *                      key leaf-b;
45  *                      leaf leaf-b;
46  *              }
47  *      }
48  * }
49  * </pre>
50  *
51  */
52 public class NormalizedNodeUtilsTest {
53
54     private static final QName ROOT_QNAME = QName.create("urn:opendaylight:controller:sal:dom:store:test", "2014-03-13",
55             "root");
56     private static final QName LIST_A_QNAME = QName.create(ROOT_QNAME, "list-a");
57     private static final QName LIST_B_QNAME = QName.create(ROOT_QNAME, "list-b");
58     private static final QName LEAF_A_QNAME = QName.create(ROOT_QNAME, "leaf-a");
59     private static final QName LEAF_B_QNAME = QName.create(ROOT_QNAME, "leaf-b");
60     private static final String FOO = "foo";
61     private static final String BAR = "bar";
62     private static final String ONE = "one";
63     private static final String TWO = "two";
64
65     private static final YangInstanceIdentifier LIST_A_FOO_PATH = YangInstanceIdentifier.builder()
66                 .node(LIST_A_QNAME)
67                 .nodeWithKey(LIST_A_QNAME, LEAF_A_QNAME, FOO)
68                 .build();
69     private static final YangInstanceIdentifier LIST_B_TWO_PATH = YangInstanceIdentifier.builder()
70                 .node(LIST_A_QNAME)
71                 .nodeWithKey(LIST_A_QNAME, LEAF_A_QNAME, BAR)
72                 .node(LIST_B_QNAME)
73                 .nodeWithKey(LIST_B_QNAME,LEAF_B_QNAME,TWO)
74                 .build();
75
76     /**
77      * Returns a test document
78      *
79      * <pre>
80      * root
81      *     list-a
82      *          leaf-a "foo"
83      *     list-a
84      *          leaf-a "bar"
85      *          list-b
86      *                  leaf-b "one"
87      *          list-b
88      *                  leaf-b "two"
89      *
90      * </pre>
91      *
92      * @return
93      */
94     public NormalizedNode<?, ?> createDocumentOne() {
95         return ImmutableContainerNodeBuilder
96                 .create()
97                 .withNodeIdentifier(new NodeIdentifier(ROOT_QNAME))
98                 .withChild(
99                         mapNodeBuilder(LIST_A_QNAME)
100                                 .withChild(mapEntry(LIST_A_QNAME, LEAF_A_QNAME, FOO))
101                                 .withChild(
102                                         mapEntryBuilder(LIST_A_QNAME, LEAF_A_QNAME, BAR).withChild(
103                                                 mapNodeBuilder(LIST_B_QNAME)
104                                                         .withChild(mapEntry(LIST_B_QNAME, LEAF_B_QNAME, ONE))
105                                                         .withChild(mapEntry(LIST_B_QNAME, LEAF_B_QNAME, TWO)).build())
106                                                 .build()).build()).build();
107
108     }
109
110     @Test
111     public void findNodeTest() {
112         NormalizedNode<?, ?> tree = createDocumentOne();
113         assertNotNull(tree);
114
115         Optional<NormalizedNode<?, ?>> listFooResult = NormalizedNodes.findNode(tree, LIST_A_FOO_PATH);
116         assertTrue(listFooResult.isPresent());
117
118         Optional<NormalizedNode<?, ?>> listTwoResult = NormalizedNodes.findNode(tree, LIST_B_TWO_PATH);
119         assertTrue(listTwoResult.isPresent());
120     }
121
122 }