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;
13 import com.google.common.collect.Iterables;
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.stmt.InputEffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.OutputEffectiveStatement;
20 import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
22 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
23 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
25 public class YT1291Test {
26 private static final QName FOO = QName.create("foo", "foo");
27 private static final QName INPUT = QName.create("foo", "input");
28 private static final QName OUTPUT = QName.create("foo", "output");
30 private static EffectiveModelContext context;
33 public static void beforeClass() {
34 context = YangParserTestUtils.parseYangResource("/yt1291.yang");
38 public void testRpcIndexing() {
39 final SchemaTreeEffectiveStatement<?> foo = Iterables.getOnlyElement(context.getModuleStatements().values())
40 .findSchemaTreeNode(FOO).orElseThrow();
41 assertThat(foo, instanceOf(RpcEffectiveStatement.class));
42 final RpcEffectiveStatement rpc = (RpcEffectiveStatement) foo;
44 assertThat(rpc.findDataTreeNode(INPUT).orElseThrow(), instanceOf(InputEffectiveStatement.class));
45 assertThat(rpc.findDataTreeNode(OUTPUT).orElseThrow(), instanceOf(OutputEffectiveStatement.class));
49 public void testEnterDataTree() {
50 final SchemaInferenceStack stack = SchemaInferenceStack.of(context, Absolute.of(FOO));
51 assertThat(stack.enterDataTree(INPUT), instanceOf(InputEffectiveStatement.class));
53 assertThat(stack.enterDataTree(OUTPUT), instanceOf(OutputEffectiveStatement.class));