464896674d29c7f1dc7da1dc4fba88445e3e0ba7
[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.parseYangResource("/yt1282.yang");
31     }
32
33     @Test
34     void testResolveTypedef() {
35         final TypeEffectiveStatement<?> type = stack.enterTypedef(QName.create("foo", "foo"))
36                 .findFirstEffectiveSubstatement(TypeEffectiveStatement.class).orElseThrow();
37         assertFalse(stack.inInstantiatedContext());
38         assertFalse(stack.inGrouping());
39
40         final var bar = assertInstanceOf(LeafEffectiveStatement.class,
41             stack.resolvePathExpression(
42                 type.findFirstEffectiveSubstatementArgument(PathEffectiveStatement.class).orElseThrow()));
43         assertEquals(QName.create("foo", "bar"), bar.argument());
44     }
45 }