Migrate users of deprecated QNameModule methods
[yangtools.git] / data / yang-data-util / src / test / java / org / opendaylight / yangtools / yang / data / util / DataSchemaContextTreeTest.java
1 /*
2  * Copyright (c) 2018 Pantheon Technologies, 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.data.util;
9
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertTrue;
12
13 import java.util.Optional;
14 import org.junit.jupiter.api.AfterAll;
15 import org.junit.jupiter.api.BeforeAll;
16 import org.junit.jupiter.api.Test;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.common.QNameModule;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
21
22 class DataSchemaContextTreeTest {
23     private static final QNameModule MODULE = QNameModule.of("dataschemacontext");
24     private static final QName FOO = QName.create(MODULE, "foo");
25     private static final QName BAR = QName.create(MODULE, "bar");
26     private static final QName BAZ = QName.create(MODULE, "baz");
27     private static DataSchemaContextTree CONTEXT;
28
29     @BeforeAll
30     static void init() {
31         CONTEXT = DataSchemaContextTree.from(YangParserTestUtils.parseYang("""
32             module dataschemacontext {
33               namespace "dataschemacontext";
34               prefix dsc;
35
36               container foo {
37                 choice bar {
38                   leaf baz {
39                     type string;
40                   }
41                 }
42               }
43             }"""));
44     }
45
46     @AfterAll
47     static void cleanup() {
48         CONTEXT = null;
49     }
50
51     @Test
52     void testCorrectInput() {
53         assertTrue(CONTEXT.findChild(YangInstanceIdentifier.of(FOO)).isPresent());
54         assertTrue(CONTEXT.findChild(YangInstanceIdentifier.of(FOO, BAR)).isPresent());
55         assertTrue(CONTEXT.findChild(YangInstanceIdentifier.of(FOO, BAR, BAZ)).isPresent());
56     }
57
58     @Test
59     void testSimpleBad() {
60         assertEquals(Optional.empty(), CONTEXT.findChild(YangInstanceIdentifier.of(BAR)));
61     }
62
63     @Test
64     void testNestedBad() {
65         assertEquals(Optional.empty(), CONTEXT.findChild(YangInstanceIdentifier.of(BAR, BAZ)));
66     }
67 }