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
8 package org.opendaylight.yangtools.yang.stmt;
10 import static org.junit.Assert.assertNotNull;
11 import static org.junit.Assert.assertTrue;
13 import org.junit.Test;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
16 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
17 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
19 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
20 import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
21 import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
22 import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
23 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
25 public class Bug5437Test {
26 private static final String NS = "foo";
27 private static final String REV = "2016-03-01";
30 public void test() throws Exception {
31 SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5437");
32 assertNotNull(context);
34 QName root = QName.create(NS, REV, "root");
35 QName leafRef2 = QName.create(NS, REV, "leaf-ref-2");
36 QName conGrp = QName.create(NS, REV, "con-grp");
37 QName leafRef = QName.create(NS, REV, "leaf-ref");
39 SchemaPath leafRefPath = SchemaPath.create(true, root, conGrp, leafRef);
40 SchemaPath leafRef2Path = SchemaPath.create(true, root, leafRef2);
41 SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, leafRefPath);
42 SchemaNode findDataSchemaNode2 = SchemaContextUtil.findDataSchemaNode(context, leafRef2Path);
43 assertTrue(findDataSchemaNode instanceof LeafSchemaNode);
44 assertTrue(findDataSchemaNode2 instanceof LeafSchemaNode);
45 LeafSchemaNode leafRefNode = (LeafSchemaNode) findDataSchemaNode;
46 LeafSchemaNode leafRefNode2 = (LeafSchemaNode) findDataSchemaNode2;
48 assertTrue(leafRefNode.getType() instanceof LeafrefTypeDefinition);
49 assertTrue(leafRefNode2.getType() instanceof LeafrefTypeDefinition);
51 TypeDefinition<?> baseTypeForLeafRef = SchemaContextUtil.getBaseTypeForLeafRef(
52 (LeafrefTypeDefinition) leafRefNode.getType(), context, leafRefNode);
53 TypeDefinition<?> baseTypeForLeafRef2 = SchemaContextUtil.getBaseTypeForLeafRef(
54 (LeafrefTypeDefinition) leafRefNode2.getType(), context, leafRefNode2);
56 assertTrue(baseTypeForLeafRef instanceof BinaryTypeDefinition);
57 assertTrue(baseTypeForLeafRef2 instanceof IntegerTypeDefinition);