Bug 5437: Issue accessing mounted device supporting OpenConfig BGP.
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / test / Bug5437.java
1 /*
2  * Copyright (c) 2015 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.test;
9
10 import static org.junit.Assert.assertNotNull;
11 import static org.junit.Assert.assertTrue;
12
13 import java.io.FileNotFoundException;
14 import java.net.URISyntaxException;
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.api.TypeDefinition;
22 import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
23 import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
24 import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
25 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
27 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
28
29 public class Bug5437 {
30     private static final String NS = "foo";
31     private static final String REV = "2016-03-01";
32
33     @Test
34     public void test() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException {
35         SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5437");
36         assertNotNull(context);
37
38         QName root = QName.create(NS, REV, "root");
39         QName leafRef2 = QName.create(NS, REV, "leaf-ref-2");
40         QName conGrp = QName.create(NS, REV, "con-grp");
41         QName leafRef = QName.create(NS, REV, "leaf-ref");
42
43         SchemaPath leafRefPath = SchemaPath.create(true, root, conGrp, leafRef);
44         SchemaPath leafRef2Path = SchemaPath.create(true, root, leafRef2);
45         SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, leafRefPath);
46         SchemaNode findDataSchemaNode2 = SchemaContextUtil.findDataSchemaNode(context, leafRef2Path);
47         assertTrue(findDataSchemaNode instanceof LeafSchemaNode);
48         assertTrue(findDataSchemaNode2 instanceof LeafSchemaNode);
49         LeafSchemaNode leafRefNode = (LeafSchemaNode) findDataSchemaNode;
50         LeafSchemaNode leafRefNode2 = (LeafSchemaNode) findDataSchemaNode2;
51
52         assertTrue(leafRefNode.getType() instanceof LeafrefTypeDefinition);
53         assertTrue(leafRefNode2.getType() instanceof LeafrefTypeDefinition);
54
55         TypeDefinition<?> baseTypeForLeafRef = SchemaContextUtil.getBaseTypeForLeafRef(
56                 (LeafrefTypeDefinition) leafRefNode.getType(), context, leafRefNode);
57         TypeDefinition<?> baseTypeForLeafRef2 = SchemaContextUtil.getBaseTypeForLeafRef(
58                 (LeafrefTypeDefinition) leafRefNode2.getType(), context, leafRefNode2);
59
60         assertTrue(baseTypeForLeafRef instanceof BinaryTypeDefinition);
61         assertTrue(baseTypeForLeafRef2 instanceof IntegerTypeDefinition);
62     }
63 }