Update StmtTestUtils
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug6771Test.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.Assert.assertNotNull;
11 import static org.junit.Assert.assertTrue;
12
13 import org.junit.Test;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
16 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
17 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
19 import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
20 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
21
22 public class Bug6771Test {
23     private static final String NS = "http://www.example.com/typedef-bug";
24     private static final String REV = "1970-01-01";
25     private static final QName ROOT = QName.create(NS, REV, "root");
26     private static final QName CONT_B = QName.create(NS, REV, "container-b");
27     private static final QName LEAF_CONT_B = QName.create(NS, REV, "leaf-container-b");
28     private static final QName INNER_CONTAINER = QName.create(NS, REV, "inner-container");
29
30     @Test
31     public void augmentTest() throws Exception {
32         final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6771/augment");
33         assertNotNull(context);
34
35         verifyLeafType(SchemaContextUtil
36                 .findDataSchemaNode(context, SchemaPath.create(true, ROOT, CONT_B, LEAF_CONT_B)));
37         verifyLeafType(SchemaContextUtil.findDataSchemaNode(context,
38                 SchemaPath.create(true, ROOT, CONT_B, INNER_CONTAINER, LEAF_CONT_B)));
39     }
40
41     @Test
42     public void choiceCaseTest() throws Exception {
43         final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6771/choice-case");
44         assertNotNull(context);
45
46         final QName myChoice = QName.create(NS, REV, "my-choice");
47         final QName caseOne = QName.create(NS, REV, "one");
48         final QName caseTwo = QName.create(NS, REV, "two");
49         final QName caseThree = QName.create(NS, REV, "three");
50         final QName containerOne = QName.create(NS, REV, "container-one");
51         final QName containerTwo = QName.create(NS, REV, "container-two");
52         final QName containerThree = QName.create(NS, REV, "container-three");
53
54         verifyLeafType(SchemaContextUtil.findDataSchemaNode(context,
55                 SchemaPath.create(true, ROOT, myChoice, caseOne, containerOne, LEAF_CONT_B)));
56         verifyLeafType(SchemaContextUtil.findDataSchemaNode(context,
57                 SchemaPath.create(true, ROOT, myChoice, caseTwo, containerTwo, LEAF_CONT_B)));
58         verifyLeafType(SchemaContextUtil.findDataSchemaNode(context,
59                 SchemaPath.create(true, ROOT, myChoice, caseThree, containerThree, INNER_CONTAINER, LEAF_CONT_B)));
60     }
61
62     @Test
63     public void groupingTest() throws Exception {
64         final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6771/grouping");
65         assertNotNull(context);
66         verifyLeafType(SchemaContextUtil
67                 .findDataSchemaNode(context, SchemaPath.create(true, ROOT, CONT_B, LEAF_CONT_B)));
68     }
69
70     private static void verifyLeafType(final SchemaNode schemaNode) {
71         assertTrue(schemaNode instanceof LeafSchemaNode);
72         assertTrue(((LeafSchemaNode) schemaNode).getType() instanceof UnsignedIntegerTypeDefinition);
73     }
74 }