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.MatcherAssert.assertThat;
11 import static org.hamcrest.Matchers.isA;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertTrue;
15 import com.google.common.collect.ImmutableList;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
21 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.Module;
23 import org.opendaylight.yangtools.yang.model.api.PathExpression;
24 import org.opendaylight.yangtools.yang.model.api.PathExpression.LocationPathSteps;
25 import org.opendaylight.yangtools.yang.model.api.PathExpression.Steps;
26 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
27 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
28 import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
29 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
30 import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath;
31 import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.ResolvedQNameStep;
32 import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.Step;
34 public class YT1060Test {
35 private static final QName CONT = QName.create("parent", "cont");
36 private static final QName LEAF1 = QName.create(CONT, "leaf1");
38 private EffectiveModelContext context;
39 private PathExpression path;
42 public void before() {
43 context = YangParserTestUtils.parseYangResourceDirectory("/yt1060");
45 final Module module = context.findModule(CONT.getModule()).get();
46 final ContainerSchemaNode cont = (ContainerSchemaNode) module.findDataChildByName(CONT).get();
47 final LeafSchemaNode leaf1 = (LeafSchemaNode) cont.findDataChildByName(LEAF1).get();
48 path = ((LeafrefTypeDefinition) leaf1.getType()).getPathStatement();
50 // Quick checks before we get to the point
51 final Steps pathSteps = path.getSteps();
52 assertThat(pathSteps, isA(LocationPathSteps.class));
53 final YangLocationPath locationPath = ((LocationPathSteps) pathSteps).getLocationPath();
54 assertTrue(locationPath.isAbsolute());
55 final ImmutableList<Step> steps = locationPath.getSteps();
56 assertEquals(2, steps.size());
57 steps.forEach(step -> assertThat(step, isA(ResolvedQNameStep.class)));
61 public void testFindDataSchemaNode() {
62 final SchemaNode found = SchemaContextUtil.findDataTreeSchemaNode(context, CONT.getModule(), path);
63 assertThat(found, isA(LeafSchemaNode.class));
64 assertEquals(SchemaPath.create(true, QName.create("imported", "root"), QName.create("imported", "leaf1")),