2 * Copyright (c) 2019 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.ut;
10 import static org.hamcrest.Matchers.isA;
11 import static org.junit.Assert.assertSame;
12 import static org.junit.Assert.assertThat;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
18 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.Module;
21 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
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.util.SchemaContextUtil;
26 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
28 public class YT1050Test {
29 private static final QName SECONDARY = QName.create("yt1050", "secondary");
30 private static final QName TYPE = QName.create(SECONDARY, "type");
31 private static final QName GRP_USES = QName.create(SECONDARY, "grp-uses");
33 private SchemaContext context;
34 private LeafSchemaNode secondaryType;
35 private LeafSchemaNode primaryType;
36 private Module module;
39 public void before() {
40 context = YangParserTestUtils.parseYangResource("/yt1050.yang");
41 module = context.getModules().iterator().next();
43 final ListSchemaNode grpUses = (ListSchemaNode) module.findDataChildByName(GRP_USES).get();
44 primaryType = (LeafSchemaNode) grpUses.findDataChildByName(TYPE).get();
46 final GroupingDefinition grp = module.getGroupings().iterator().next();
47 secondaryType = (LeafSchemaNode) ((ListSchemaNode) grp.findDataChildByName(SECONDARY).get())
48 .findDataChildByName(TYPE).get();
52 public void testFindDataSchemaNodeForRelativeXPathWithDeref() {
53 final TypeDefinition<?> typeNodeType = secondaryType.getType();
54 assertThat(typeNodeType, isA(LeafrefTypeDefinition.class));
56 final SchemaNode found = SchemaContextUtil.findDataSchemaNodeForRelativeXPath(context, module, secondaryType,
57 ((LeafrefTypeDefinition) typeNodeType).getPathStatement());
58 assertSame(primaryType, found);