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.Assert.assertNotNull;
11 import static org.junit.Assert.assertTrue;
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;
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");
31 public void augmentTest() throws Exception {
32 final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6771/augment");
33 assertNotNull(context);
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)));
42 public void choiceCaseTest() throws Exception {
43 final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6771/choice-case");
44 assertNotNull(context);
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");
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)));
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)));
70 private static void verifyLeafType(final SchemaNode schemaNode) {
71 assertTrue(schemaNode instanceof LeafSchemaNode);
72 assertTrue(((LeafSchemaNode) schemaNode).getType() instanceof UnsignedIntegerTypeDefinition);