2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.CoreMatchers.instanceOf;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.Assert.assertEquals;
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.common.QNameModule;
17 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
19 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.Module;
21 import org.opendaylight.yangtools.yang.model.api.PathExpression;
22 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
23 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
24 import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
25 import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
26 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
28 public class YT1100Test {
30 public void testChoiceCaseRelativeLeafref() {
31 final EffectiveModelContext context = YangParserTestUtils.parseYangResource("/yt1100.yang");
32 final Module module = context.findModule("yt1100").orElseThrow();
33 final QNameModule qnm = module.getQNameModule();
34 final QName foo = QName.create(qnm, "foo");
35 final QName schedulerNode = QName.create(qnm, "scheduler-node");
36 final QName childSchedulerNodes = QName.create(qnm, "child-scheduler-nodes");
37 final QName name = QName.create(qnm, "name");
38 final DataSchemaNode leaf = module.findDataTreeChild(foo, schedulerNode, childSchedulerNodes, name)
40 assertThat(leaf, instanceOf(LeafSchemaNode.class));
42 final TypeDefinition<?> type = ((LeafSchemaNode) leaf).getType();
43 assertThat(type, instanceOf(LeafrefTypeDefinition.class));
44 final PathExpression leafref = ((LeafrefTypeDefinition) type).getPathStatement();
46 final EffectiveStatement<?, ?> resolvedLeafRef = SchemaInferenceStack.ofDataTreePath(
47 context, foo, schedulerNode,childSchedulerNodes, name).resolvePathExpression(leafref);
48 assertThat(resolvedLeafRef, instanceOf(LeafSchemaNode.class));
49 final LeafSchemaNode targetLeaf = (LeafSchemaNode) resolvedLeafRef;
50 assertEquals(QName.create(qnm, "name"), targetLeaf.getQName());
51 assertThat(targetLeaf.getType(), instanceOf(StringTypeDefinition.class));