Migrate YANG inputs for yang-model-util
[yangtools.git] / model / yang-model-util / src / test / java / org / opendaylight / yangtools / yang / model / util / YT1292Test.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.assertInstanceOf;
12
13 import com.google.common.collect.Iterables;
14 import java.util.Optional;
15 import org.junit.jupiter.api.BeforeAll;
16 import org.junit.jupiter.api.BeforeEach;
17 import org.junit.jupiter.api.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.stmt.ActionEffectiveStatement;
20 import org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
22 import org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement;
23 import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement;
24 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
25
26 class YT1292Test {
27     private static final QName FOO = QName.create("foo", "foo");
28     private static final QName BAR = QName.create("foo", "bar");
29     private static final QName BAZ = QName.create("foo", "baz");
30
31     private static ModuleEffectiveStatement module;
32
33     private ContainerEffectiveStatement baz;
34
35     @BeforeAll
36     static void beforeClass() {
37         module = Iterables.getOnlyElement(YangParserTestUtils.parseYang("""
38             module foo {
39               namespace foo;
40               prefix foo;
41               yang-version 1.1;
42
43               rpc foo;
44
45               notification bar;
46
47               container baz {
48                 action foo;
49                 notification bar;
50               }
51             }""").getModuleStatements()
52                 .values());
53     }
54
55     @BeforeEach
56     void before() {
57         baz = assertInstanceOf(ContainerEffectiveStatement.class, module.findDataTreeNode(BAZ).orElseThrow());
58     }
59
60     @Test
61     void testRpc() {
62         assertEquals(Optional.empty(), module.findDataTreeNode(FOO));
63         assertInstanceOf(RpcEffectiveStatement.class, module.findSchemaTreeNode(FOO).orElseThrow());
64     }
65
66     @Test
67     void testNotification() {
68         assertEquals(Optional.empty(), module.findDataTreeNode(BAR));
69         assertInstanceOf(NotificationEffectiveStatement.class, module.findSchemaTreeNode(BAR).orElseThrow());
70
71         assertEquals(Optional.empty(), baz.findDataTreeNode(BAR));
72         assertInstanceOf(NotificationEffectiveStatement.class, baz.findSchemaTreeNode(BAR).orElseThrow());
73     }
74
75     @Test
76     void testAction() {
77         assertEquals(Optional.empty(), baz.findDataTreeNode(FOO));
78         assertInstanceOf(ActionEffectiveStatement.class, baz.findSchemaTreeNode(FOO).orElseThrow());
79     }
80 }