Bug 8126 - Some augments are not being processed
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug8126Test.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 package org.opendaylight.yangtools.yang.stmt;
9
10 import static org.junit.Assert.assertNotNull;
11 import static org.junit.Assert.assertNull;
12 import static org.junit.Assert.assertTrue;
13
14 import com.google.common.collect.ImmutableList;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
19 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
21 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
22
23 public class Bug8126Test {
24     private static final String FOO_NS = "foo";
25     private static final String BAR_NS = "bar";
26     private static final String REV = "1970-01-01";
27
28     @Test
29     public void test() throws Exception {
30         final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug8126");
31         assertNotNull(context);
32         assertTrue(findNode(context, ImmutableList.of(foo("root"), bar("my-container"), bar("my-choice"), bar("one"),
33                 bar("one"), bar("mandatory-leaf"))) instanceof LeafSchemaNode);
34         assertTrue(findNode(context, ImmutableList.of(foo("root"), bar("my-list"), bar("two"), bar("mandatory-leaf-2"))) instanceof LeafSchemaNode);
35
36         assertNull(findNode(context, ImmutableList.of(foo("root"), bar("mandatory-list"))));
37         assertNull(findNode(context, ImmutableList.of(foo("root"), bar("mandatory-container"), bar("mandatory-choice"))));
38         assertNull(findNode(context,
39                 ImmutableList.of(foo("root"), bar("mandatory-container-2"), bar("one"), bar("mandatory-leaf-3"))));
40     }
41
42     private static SchemaNode findNode(final SchemaContext context, final Iterable<QName> qNames) {
43         return SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(qNames, true));
44     }
45
46     private static QName foo(final String localName) {
47         return QName.create(FOO_NS, REV, localName);
48     }
49
50     private static QName bar(final String localName) {
51         return QName.create(BAR_NS, REV, localName);
52     }
53 }