Remove getSemanticVersion()
[yangtools.git] / model / yang-model-util / src / test / java / org / opendaylight / yangtools / yang / model / util / YT1283Test.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.hamcrest.CoreMatchers.instanceOf;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.Assert.assertEquals;
13
14 import org.junit.BeforeClass;
15 import org.junit.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.meta.EffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.CaseEffectiveStatement;
20 import org.opendaylight.yangtools.yang.model.api.stmt.ChoiceEffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement;
22 import org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement;
23 import org.opendaylight.yangtools.yang.model.api.stmt.PathEffectiveStatement;
24 import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
25 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
26
27 public class YT1283Test {
28     private static final QName FOO = QName.create("foo", "foo");
29     private static final QName BAR = QName.create("foo", "bar");
30
31     private static EffectiveModelContext context;
32
33     private final SchemaInferenceStack stack = SchemaInferenceStack.of(context);
34
35     @BeforeClass
36     public static void beforeClass() {
37         context = YangParserTestUtils.parseYangResource("/yt1283.yang");
38     }
39
40     @Test
41     public void testResolveUnderCaseViaDataTree() {
42         assertThat(stack.enterDataTree(FOO), instanceOf(ContainerEffectiveStatement.class));
43         assertResolve(stack.enterDataTree(FOO));
44     }
45
46     @Test
47     public void testResolveUnderCaseViaSchemaTree() {
48         assertThat(stack.enterSchemaTree(FOO), instanceOf(ContainerEffectiveStatement.class));
49         assertThat(stack.enterSchemaTree(FOO), instanceOf(ChoiceEffectiveStatement.class));
50         assertThat(stack.enterSchemaTree(FOO), instanceOf(CaseEffectiveStatement.class));
51         assertResolve(stack.enterSchemaTree(FOO));
52     }
53
54     private void assertResolve(final EffectiveStatement<?, ?> foo) {
55         assertThat(foo, instanceOf(LeafEffectiveStatement.class));
56
57         final TypeEffectiveStatement<?> type = foo.findFirstEffectiveSubstatement(TypeEffectiveStatement.class)
58             .orElseThrow();
59         final EffectiveStatement<?, ?> bar = stack.resolvePathExpression(
60             type.findFirstEffectiveSubstatementArgument(PathEffectiveStatement.class).orElseThrow());
61         assertThat(bar, instanceOf(LeafEffectiveStatement.class));
62         assertEquals(BAR, bar.argument());
63     }
64 }