Deprecate yang.binding.InstanceIdentifier
[yangtools.git] / model / yang-model-util / src / test / java / org / opendaylight / yangtools / yang / model / util / YT1282Test.java
1 /*
2  * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.model.util;
9
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertFalse;
12 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
13
14 import org.junit.jupiter.api.BeforeAll;
15 import org.junit.jupiter.api.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
18 import org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.PathEffectiveStatement;
20 import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
21 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
22
23 class YT1282Test {
24     private static EffectiveModelContext context;
25
26     private final SchemaInferenceStack stack = SchemaInferenceStack.of(context);
27
28     @BeforeAll
29     static void beforeClass() {
30         context = YangParserTestUtils.parseYang("""
31             module foo {
32               prefix foo;
33               namespace foo;
34
35               typedef foo {
36                 type leafref {
37                   path /bar;
38                 }
39               }
40
41               leaf bar {
42                 type int64;
43               }
44             }""");
45     }
46
47     @Test
48     void testResolveTypedef() {
49         final TypeEffectiveStatement<?> type = stack.enterTypedef(QName.create("foo", "foo"))
50                 .findFirstEffectiveSubstatement(TypeEffectiveStatement.class).orElseThrow();
51         assertFalse(stack.inInstantiatedContext());
52         assertFalse(stack.inGrouping());
53
54         final var bar = assertInstanceOf(LeafEffectiveStatement.class,
55             stack.resolvePathExpression(
56                 type.findFirstEffectiveSubstatementArgument(PathEffectiveStatement.class).orElseThrow()));
57         assertEquals(QName.create("foo", "bar"), bar.argument());
58     }
59 }