Deprecate simple DataTreeFactory.create()
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug6771Test.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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.stmt;
9
10 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
11
12 import org.junit.jupiter.api.Test;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.common.QNameModule;
15 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
16 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
17 import org.opendaylight.yangtools.yang.model.api.type.Uint32TypeDefinition;
18
19 class Bug6771Test extends AbstractYangTest {
20     private static final QNameModule NS = QNameModule.of("http://www.example.com/typedef-bug");
21     private static final QName ROOT = QName.create(NS, "root");
22     private static final QName CONT_B = QName.create(NS, "container-b");
23     private static final QName LEAF_CONT_B = QName.create(NS, "leaf-container-b");
24     private static final QName INNER_CONTAINER = QName.create(NS, "inner-container");
25
26     @Test
27     void augmentTest() {
28         final var module = assertEffectiveModel("/bugs/bug6771/augment.yang").getModuleStatement(NS);
29
30         verifyLeafType(module, ROOT, CONT_B, LEAF_CONT_B);
31         verifyLeafType(module, ROOT, CONT_B, INNER_CONTAINER, LEAF_CONT_B);
32     }
33
34     @Test
35     void choiceCaseTest() {
36         final var module = assertEffectiveModel("/bugs/bug6771/choice-case.yang").getModuleStatement(NS);
37
38         final QName myChoice = QName.create(NS, "my-choice");
39         final QName caseOne = QName.create(NS, "one");
40         final QName caseTwo = QName.create(NS, "two");
41         final QName caseThree = QName.create(NS, "three");
42         final QName containerOne = QName.create(NS, "container-one");
43         final QName containerTwo = QName.create(NS, "container-two");
44         final QName containerThree = QName.create(NS, "container-three");
45
46         verifyLeafType(module, ROOT, myChoice, caseOne, containerOne, LEAF_CONT_B);
47         verifyLeafType(module, ROOT, myChoice, caseTwo, containerTwo, LEAF_CONT_B);
48         verifyLeafType(module, ROOT, myChoice, caseThree, containerThree, INNER_CONTAINER, LEAF_CONT_B);
49     }
50
51     @Test
52     void groupingTest() {
53         verifyLeafType(assertEffectiveModel("/bugs/bug6771/grouping.yang").getModuleStatement(NS),
54             ROOT, CONT_B, LEAF_CONT_B);
55     }
56
57     private static void verifyLeafType(final ModuleEffectiveStatement module, final QName... qnames) {
58         assertInstanceOf(Uint32TypeDefinition.class,
59             assertInstanceOf(LeafSchemaNode.class, module.findSchemaTreeNode(qnames).orElseThrow()).getType());
60     }
61 }