9149dfbcc20499a6b7103c532be75ed726e43a64
[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
27     @Test
28     public void test() throws Exception {
29         final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug8126");
30         assertNotNull(context);
31         assertTrue(findNode(context, ImmutableList.of(foo("root"), bar("my-container"), bar("my-choice"), bar("one"),
32                 bar("one"), bar("mandatory-leaf"))) instanceof LeafSchemaNode);
33         assertTrue(findNode(context, ImmutableList.of(foo("root"), bar("my-list"), bar("two"), bar("mandatory-leaf-2")))
34             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"),
38             bar("mandatory-choice"))));
39         assertNull(findNode(context,
40                 ImmutableList.of(foo("root"), bar("mandatory-container-2"), bar("one"), bar("mandatory-leaf-3"))));
41     }
42
43     private static SchemaNode findNode(final SchemaContext context, final Iterable<QName> qNames) {
44         return SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(qNames, true));
45     }
46
47     private static QName foo(final String localName) {
48         return QName.create(FOO_NS, localName);
49     }
50
51     private static QName bar(final String localName) {
52         return QName.create(BAR_NS, localName);
53     }
54 }