Clean up TreeNode API
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug9244Test.java
1 /*
2  * Copyright (c) 2017 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.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.assertTrue;
13
14 import java.util.Optional;
15 import org.junit.jupiter.api.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.common.Revision;
18 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
21
22 class Bug9244Test extends AbstractYangTest {
23     @Test
24     void testDeviateReplaceOfImplicitSubstatements() {
25         final var schemaContext = assertEffectiveModelDir("/bugs/bug9244/");
26
27         final var barModule = schemaContext.findModule("bar", Revision.of("2017-10-13")).orElseThrow();
28         final var barCont = assertInstanceOf(ContainerSchemaNode.class,
29             barModule.getDataChildByName(QName.create(barModule.getQNameModule(), "bar-cont")));
30         assertEquals(Optional.of(Boolean.FALSE), barCont.effectiveConfig());
31
32         final var barLeafList = assertInstanceOf(LeafListSchemaNode.class,
33             barModule.getDataChildByName(QName.create(barModule.getQNameModule(), "bar-leaf-list")));
34         final var constraint = barLeafList.getElementCountConstraint().orElseThrow();
35         assertEquals(5, constraint.getMinElements());
36         assertEquals(10, constraint.getMaxElements());
37
38         final var barLeaf = assertInstanceOf(LeafSchemaNode.class,
39             barModule.getDataChildByName(QName.create(barModule.getQNameModule(), "bar-leaf")));
40         assertTrue(barLeaf.isMandatory());
41     }
42 }