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.model.util;
10 import static org.hamcrest.MatcherAssert.assertThat;
11 import static org.hamcrest.Matchers.isA;
13 import org.junit.Test;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
16 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
20 import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
21 import org.opendaylight.yangtools.yang.model.api.type.Int16TypeDefinition;
22 import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
23 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
25 public class YT588Test {
26 private static final String NS = "foo";
27 private static final String REV = "2016-03-01";
31 EffectiveModelContext context = YangParserTestUtils.parseYangResource("/yt588.yang");
33 QName root = QName.create(NS, REV, "root");
34 QName leafRef2 = QName.create(NS, REV, "leaf-ref-2");
35 QName conGrp = QName.create(NS, REV, "con-grp");
36 QName leafRef = QName.create(NS, REV, "leaf-ref");
38 SchemaNode findDataSchemaNode = context.findDataTreeChild(root, conGrp, leafRef).get();
39 SchemaNode findDataSchemaNode2 = context.findDataTreeChild(root, leafRef2).get();
40 assertThat(findDataSchemaNode, isA(LeafSchemaNode.class));
41 assertThat(findDataSchemaNode2, isA(LeafSchemaNode.class));
43 LeafSchemaNode leafRefNode = (LeafSchemaNode) findDataSchemaNode;
44 LeafSchemaNode leafRefNode2 = (LeafSchemaNode) findDataSchemaNode2;
46 assertThat(leafRefNode.getType(), isA(LeafrefTypeDefinition.class));
47 assertThat(leafRefNode2.getType(), isA(LeafrefTypeDefinition.class));
49 EffectiveStatement<?, ?> found = SchemaInferenceStack.ofDataTreePath(context, root, conGrp, leafRef)
50 .resolvePathExpression(((LeafrefTypeDefinition) leafRefNode.getType()).getPathStatement());
51 assertThat(((TypedDataSchemaNode)found).getType(), isA(BinaryTypeDefinition.class));
53 found = SchemaInferenceStack.ofDataTreePath(context, root, leafRef2)
54 .resolvePathExpression(((LeafrefTypeDefinition) leafRefNode2.getType()).getPathStatement());
55 assertThat(((TypedDataSchemaNode)found).getType(), isA(Int16TypeDefinition.class));