Remove getSemanticVersion()
[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.hamcrest.CoreMatchers.instanceOf;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.Assert.assertEquals;
13
14 import com.google.common.collect.Iterables;
15 import java.util.Optional;
16 import org.junit.Before;
17 import org.junit.BeforeClass;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.model.api.stmt.ActionEffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement;
22 import org.opendaylight.yangtools.yang.model.api.stmt.DataTreeEffectiveStatement;
23 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
24 import org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement;
25 import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement;
26 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
27 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
28
29 public class YT1292Test {
30     private static final QName FOO = QName.create("foo", "foo");
31     private static final QName BAR = QName.create("foo", "bar");
32     private static final QName BAZ = QName.create("foo", "baz");
33
34     private static ModuleEffectiveStatement module;
35
36     private ContainerEffectiveStatement baz;
37
38     @BeforeClass
39     public static void beforeClass() {
40         module = Iterables.getOnlyElement(YangParserTestUtils.parseYangResource("/yt1292.yang").getModuleStatements()
41             .values());
42     }
43
44     @Before
45     public void before() {
46         final DataTreeEffectiveStatement<?> tmp = module.findDataTreeNode(BAZ).orElseThrow();
47         assertThat(tmp, instanceOf(ContainerEffectiveStatement.class));
48         baz = (ContainerEffectiveStatement) tmp;
49     }
50
51     @Test
52     public void testRpc() {
53         assertEquals(Optional.empty(), module.findDataTreeNode(FOO));
54         final SchemaTreeEffectiveStatement<?> foo = module.findSchemaTreeNode(FOO).orElseThrow();
55         assertThat(foo, instanceOf(RpcEffectiveStatement.class));
56     }
57
58     @Test
59     public void testNotification() {
60         assertEquals(Optional.empty(), module.findDataTreeNode(BAR));
61         SchemaTreeEffectiveStatement<?> bar = module.findSchemaTreeNode(BAR).orElseThrow();
62         assertThat(bar, instanceOf(NotificationEffectiveStatement.class));
63
64         assertEquals(Optional.empty(), baz.findDataTreeNode(BAR));
65         bar = baz.findSchemaTreeNode(BAR).orElseThrow();
66         assertThat(bar, instanceOf(NotificationEffectiveStatement.class));
67     }
68
69     @Test
70     public void testAction() {
71         assertEquals(Optional.empty(), baz.findDataTreeNode(FOO));
72         final SchemaTreeEffectiveStatement<?> foo = baz.findSchemaTreeNode(FOO).orElseThrow();
73         assertThat(foo, instanceOf(ActionEffectiveStatement.class));
74     }
75 }