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.SchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
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 DataSchemaNode leaf = module.findDataTreeChild(
35 QName.create(qnm, "foo"), QName.create(qnm, "scheduler-node"), QName.create(qnm, "child-scheduler-nodes"),
36 QName.create(qnm, "name")).orElseThrow();
37 assertThat(leaf, instanceOf(LeafSchemaNode.class));
39 final TypeDefinition<?> type = ((LeafSchemaNode) leaf).getType();
40 assertThat(type, instanceOf(LeafrefTypeDefinition.class));
41 final PathExpression leafref = ((LeafrefTypeDefinition) type).getPathStatement();
43 final SchemaNode ref = SchemaContextUtil.findDataSchemaNodeForRelativeXPath(context, module, leaf, leafref);
44 assertThat(ref, instanceOf(LeafSchemaNode.class));
45 final LeafSchemaNode targetLeaf = (LeafSchemaNode) ref;
46 assertEquals(QName.create(qnm, "name"), targetLeaf.getQName());
47 assertThat(targetLeaf.getType(), instanceOf(StringTypeDefinition.class));