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.hamcrest.Matchers.isA;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertThat;
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
18 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
20 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
21 import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
22 import org.opendaylight.yangtools.yang.model.api.type.Int16TypeDefinition;
23 import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
24 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
26 public class Bug5437Test {
27 private static final String NS = "foo";
28 private static final String REV = "2016-03-01";
31 public void test() throws Exception {
32 SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5437");
33 assertNotNull(context);
35 QName root = QName.create(NS, REV, "root");
36 QName leafRef2 = QName.create(NS, REV, "leaf-ref-2");
37 QName conGrp = QName.create(NS, REV, "con-grp");
38 QName leafRef = QName.create(NS, REV, "leaf-ref");
40 SchemaPath leafRefPath = SchemaPath.create(true, root, conGrp, leafRef);
41 SchemaPath leafRef2Path = SchemaPath.create(true, root, leafRef2);
42 SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, leafRefPath);
43 SchemaNode findDataSchemaNode2 = SchemaContextUtil.findDataSchemaNode(context, leafRef2Path);
44 assertThat(findDataSchemaNode, isA(LeafSchemaNode.class));
45 assertThat(findDataSchemaNode2, isA(LeafSchemaNode.class));
47 LeafSchemaNode leafRefNode = (LeafSchemaNode) findDataSchemaNode;
48 LeafSchemaNode leafRefNode2 = (LeafSchemaNode) findDataSchemaNode2;
50 assertThat(leafRefNode.getType(), isA(LeafrefTypeDefinition.class));
51 assertThat(leafRefNode2.getType(), isA(LeafrefTypeDefinition.class));
53 TypeDefinition<?> baseTypeForLeafRef = SchemaContextUtil.getBaseTypeForLeafRef(
54 (LeafrefTypeDefinition) leafRefNode.getType(), context, leafRefNode);
55 TypeDefinition<?> baseTypeForLeafRef2 = SchemaContextUtil.getBaseTypeForLeafRef(
56 (LeafrefTypeDefinition) leafRefNode2.getType(), context, leafRefNode2);
58 assertThat(baseTypeForLeafRef, isA(BinaryTypeDefinition.class));
59 assertThat(baseTypeForLeafRef2, isA(Int16TypeDefinition.class));