Revert "Move SchemaNodeIdentifier to yang-common"
[yangtools.git] / model / yang-model-util / src / test / java / org / opendaylight / yangtools / yang / model / util / YT1291Test.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
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;
24
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");
29
30     private static EffectiveModelContext context;
31
32     @BeforeClass
33     public static void beforeClass() {
34         context = YangParserTestUtils.parseYangResource("/yt1291.yang");
35     }
36
37     @Test
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;
43
44         assertThat(rpc.findDataTreeNode(INPUT).orElseThrow(), instanceOf(InputEffectiveStatement.class));
45         assertThat(rpc.findDataTreeNode(OUTPUT).orElseThrow(), instanceOf(OutputEffectiveStatement.class));
46     }
47
48     @Test
49     public void testEnterDataTree() {
50         final SchemaInferenceStack stack = SchemaInferenceStack.of(context, Absolute.of(FOO));
51         assertThat(stack.enterDataTree(INPUT), instanceOf(InputEffectiveStatement.class));
52         stack.exit();
53         assertThat(stack.enterDataTree(OUTPUT), instanceOf(OutputEffectiveStatement.class));
54     }
55 }