Migrate users of deprecated QNameModule methods
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / EffectiveBuildTest.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.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
12 import static org.junit.jupiter.api.Assertions.assertNotNull;
13 import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
14
15 import org.junit.jupiter.api.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.common.QNameModule;
18 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
20 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.Module;
22 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
24 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
25
26 class EffectiveBuildTest {
27     private static final StatementStreamSource SIMPLE_MODULE = sourceForResource(
28         "/stmt-test/effective-build/simple-module.yang");
29     private static final QNameModule SIMPLE_MODULE_QNAME = QNameModule.of("simple.yang");
30     private static final StatementStreamSource YANG_EXT = sourceForResource("/stmt-test/extensions/yang-ext.yang");
31
32     @Test
33     void effectiveBuildTest() throws ReactorException {
34         var result = RFC7950Reactors.defaultReactor().newBuild().addSources(SIMPLE_MODULE)
35             .buildEffective();
36
37         assertNotNull(result);
38
39         Module simpleModule = result.findModules("simple-module").iterator().next();
40         assertNotNull(simpleModule);
41
42         final QName q1 = QName.create(SIMPLE_MODULE_QNAME, "root-container");
43         final QName q2 = QName.create(SIMPLE_MODULE_QNAME, "sub-container");
44         final QName q3 = QName.create(SIMPLE_MODULE_QNAME, "sub-sub-container");
45         final QName q4 = QName.create(SIMPLE_MODULE_QNAME, "root-container2");
46         final QName q5 = QName.create(SIMPLE_MODULE_QNAME, "sub-container2");
47         final QName q6 = QName.create(SIMPLE_MODULE_QNAME, "sub-sub-container2");
48         final QName q7 = QName.create(SIMPLE_MODULE_QNAME, "grp");
49
50         ContainerSchemaNode rootCon = (ContainerSchemaNode) simpleModule.getDataChildByName(q1);
51         assertNotNull(rootCon);
52
53         ContainerSchemaNode subCon = (ContainerSchemaNode) rootCon.getDataChildByName(q2);
54         assertNotNull(subCon);
55
56         ContainerSchemaNode subSubCon = (ContainerSchemaNode) subCon.getDataChildByName(q3);
57         assertNotNull(subSubCon);
58
59         ContainerSchemaNode rootCon2 = (ContainerSchemaNode) simpleModule.getDataChildByName(q4);
60         assertNotNull(rootCon2);
61
62         ContainerSchemaNode subCon2 = (ContainerSchemaNode) rootCon2.getDataChildByName(q5);
63         assertNotNull(subCon2);
64
65         ContainerSchemaNode subSubCon2 = (ContainerSchemaNode) subCon2.getDataChildByName(q6);
66         assertNotNull(subSubCon2);
67
68         GroupingDefinition grp = simpleModule.getGroupings().iterator().next();
69         assertNotNull(grp);
70         assertEquals(q7, grp.getQName());
71
72         ContainerSchemaNode grpSubCon2 = (ContainerSchemaNode) grp.getDataChildByName(q5);
73         assertNotNull(grpSubCon2);
74
75         ContainerSchemaNode grpSubSubCon2 = (ContainerSchemaNode) grpSubCon2.getDataChildByName(q6);
76         assertNotNull(grpSubSubCon2);
77
78         assertEquals(q3, subSubCon.getQName());
79         assertEquals(q6, subSubCon2.getQName());
80         assertEquals(q6, grpSubSubCon2.getQName());
81     }
82
83     @Test
84     void extensionsTest() throws ReactorException {
85         var result = RFC7950Reactors.defaultReactor().newBuild().addSource(YANG_EXT).buildEffective();
86         assertNotNull(result);
87
88         var groupings = result.getGroupings();
89         assertEquals(1, groupings.size());
90
91         var grp = groupings.iterator().next();
92
93         var childNodes = grp.getChildNodes();
94         assertEquals(1, childNodes.size());
95
96         LeafSchemaNode leaf = assertInstanceOf(LeafSchemaNode.class, childNodes.iterator().next());
97
98         assertNotNull(leaf.getType());
99     }
100
101     @Test
102     void mockTest() throws Exception {
103         var result = RFC7950Reactors.defaultReactor().newBuild().addSource(YANG_EXT).buildEffective();
104         assertNotNull(result);
105     }
106 }