BUG-4688: Rework SchemaContext module lookups
[yangtools.git] / yang / yang-parser-impl / 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.model.api.ContainerSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.Module;
22 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
23
24 public class Bug9244Test {
25
26     @Test
27     public void testDeviateReplaceOfImplicitSubstatements() throws Exception {
28         final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/bugs/bug9244/");
29         assertNotNull(schemaContext);
30
31         final Module barModule = schemaContext.findModule("bar", QName.parseRevision("2017-10-13")).get();
32         final ContainerSchemaNode barCont = (ContainerSchemaNode) barModule.getDataChildByName(
33                 QName.create(barModule.getQNameModule(), "bar-cont"));
34         assertNotNull(barCont);
35         assertFalse(barCont.isConfiguration());
36
37         final LeafListSchemaNode barLeafList = (LeafListSchemaNode) barModule.getDataChildByName(
38                 QName.create(barModule.getQNameModule(), "bar-leaf-list"));
39         assertNotNull(barLeafList);
40         assertEquals(5, barLeafList.getConstraints().getMinElements().intValue());
41         assertEquals(10, barLeafList.getConstraints().getMaxElements().intValue());
42
43         final LeafSchemaNode barLeaf = (LeafSchemaNode) barModule.getDataChildByName(
44                 QName.create(barModule.getQNameModule(), "bar-leaf"));
45         assertNotNull(barLeaf);
46         assertTrue(barLeaf.getConstraints().isMandatory());
47     }
48 }