768183cd217e7a64547255727f60e690cdc4bd44
[yangtools.git] / yang / 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
9 package org.opendaylight.yangtools.yang.stmt;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertFalse;
13 import static org.junit.Assert.assertNotNull;
14 import static org.junit.Assert.assertTrue;
15
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.common.Revision;
19 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.ElementCountConstraint;
21 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.Module;
24 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
25
26 public class Bug9244Test {
27
28     @Test
29     public void testDeviateReplaceOfImplicitSubstatements() throws Exception {
30         final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/bugs/bug9244/");
31         assertNotNull(schemaContext);
32
33         final Module barModule = schemaContext.findModule("bar", Revision.of("2017-10-13")).get();
34         final ContainerSchemaNode barCont = (ContainerSchemaNode) barModule.getDataChildByName(
35                 QName.create(barModule.getQNameModule(), "bar-cont"));
36         assertNotNull(barCont);
37         assertFalse(barCont.isConfiguration());
38
39         final LeafListSchemaNode barLeafList = (LeafListSchemaNode) barModule.getDataChildByName(
40                 QName.create(barModule.getQNameModule(), "bar-leaf-list"));
41         assertNotNull(barLeafList);
42         final ElementCountConstraint constraint = barLeafList.getElementCountConstraint().get();
43         assertEquals(5, constraint.getMinElements().intValue());
44         assertEquals(10, constraint.getMaxElements().intValue());
45
46         final LeafSchemaNode barLeaf = (LeafSchemaNode) barModule.getDataChildByName(
47                 QName.create(barModule.getQNameModule(), "bar-leaf"));
48         assertNotNull(barLeaf);
49         assertTrue(barLeaf.isMandatory());
50     }
51 }