2 * Copyright (c) 2021 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;
10 import static org.hamcrest.CoreMatchers.instanceOf;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.Assert.assertEquals;
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;
27 public class YT1283Test {
28 private static final QName FOO = QName.create("foo", "foo");
29 private static final QName BAR = QName.create("foo", "bar");
31 private static EffectiveModelContext context;
33 private final SchemaInferenceStack stack = SchemaInferenceStack.of(context);
36 public static void beforeClass() {
37 context = YangParserTestUtils.parseYangResource("/yt1283.yang");
41 public void testResolveUnderCaseViaDataTree() {
42 assertThat(stack.enterDataTree(FOO), instanceOf(ContainerEffectiveStatement.class));
43 assertResolve(stack.enterDataTree(FOO));
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));
54 private void assertResolve(final EffectiveStatement<?, ?> foo) {
55 assertThat(foo, instanceOf(LeafEffectiveStatement.class));
57 final TypeEffectiveStatement<?> type = foo.findFirstEffectiveSubstatement(TypeEffectiveStatement.class)
59 final EffectiveStatement<?, ?> bar = stack.resolvePathExpression(
60 type.findFirstEffectiveSubstatementArgument(PathEffectiveStatement.class).orElseThrow());
61 assertThat(bar, instanceOf(LeafEffectiveStatement.class));
62 assertEquals(BAR, bar.argument());