2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.stmt;
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;
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;
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");
33 void effectiveBuildTest() throws ReactorException {
34 var result = RFC7950Reactors.defaultReactor().newBuild().addSources(SIMPLE_MODULE)
37 assertNotNull(result);
39 Module simpleModule = result.findModules("simple-module").iterator().next();
40 assertNotNull(simpleModule);
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");
50 ContainerSchemaNode rootCon = (ContainerSchemaNode) simpleModule.getDataChildByName(q1);
51 assertNotNull(rootCon);
53 ContainerSchemaNode subCon = (ContainerSchemaNode) rootCon.getDataChildByName(q2);
54 assertNotNull(subCon);
56 ContainerSchemaNode subSubCon = (ContainerSchemaNode) subCon.getDataChildByName(q3);
57 assertNotNull(subSubCon);
59 ContainerSchemaNode rootCon2 = (ContainerSchemaNode) simpleModule.getDataChildByName(q4);
60 assertNotNull(rootCon2);
62 ContainerSchemaNode subCon2 = (ContainerSchemaNode) rootCon2.getDataChildByName(q5);
63 assertNotNull(subCon2);
65 ContainerSchemaNode subSubCon2 = (ContainerSchemaNode) subCon2.getDataChildByName(q6);
66 assertNotNull(subSubCon2);
68 GroupingDefinition grp = simpleModule.getGroupings().iterator().next();
70 assertEquals(q7, grp.getQName());
72 ContainerSchemaNode grpSubCon2 = (ContainerSchemaNode) grp.getDataChildByName(q5);
73 assertNotNull(grpSubCon2);
75 ContainerSchemaNode grpSubSubCon2 = (ContainerSchemaNode) grpSubCon2.getDataChildByName(q6);
76 assertNotNull(grpSubSubCon2);
78 assertEquals(q3, subSubCon.getQName());
79 assertEquals(q6, subSubCon2.getQName());
80 assertEquals(q6, grpSubSubCon2.getQName());
84 void extensionsTest() throws ReactorException {
85 var result = RFC7950Reactors.defaultReactor().newBuild().addSource(YANG_EXT).buildEffective();
86 assertNotNull(result);
88 var groupings = result.getGroupings();
89 assertEquals(1, groupings.size());
91 var grp = groupings.iterator().next();
93 var childNodes = grp.getChildNodes();
94 assertEquals(1, childNodes.size());
96 LeafSchemaNode leaf = assertInstanceOf(LeafSchemaNode.class, childNodes.iterator().next());
98 assertNotNull(leaf.getType());
102 void mockTest() throws Exception {
103 var result = RFC7950Reactors.defaultReactor().newBuild().addSource(YANG_EXT).buildEffective();
104 assertNotNull(result);