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 QName ROOT = QName.create(NS, "root");
25 private static final QName CONT_B = QName.create(NS, "container-b");
26 private static final QName LEAF_CONT_B = QName.create(NS, "leaf-container-b");
27 private static final QName INNER_CONTAINER = QName.create(NS, "inner-container");
30 public void augmentTest() throws Exception {
31 final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6771/augment");
32 assertNotNull(context);
34 verifyLeafType(SchemaContextUtil
35 .findDataSchemaNode(context, SchemaPath.create(true, ROOT, CONT_B, LEAF_CONT_B)));
36 verifyLeafType(SchemaContextUtil.findDataSchemaNode(context,
37 SchemaPath.create(true, ROOT, CONT_B, INNER_CONTAINER, LEAF_CONT_B)));
41 public void choiceCaseTest() throws Exception {
42 final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6771/choice-case");
43 assertNotNull(context);
45 final QName myChoice = QName.create(NS, "my-choice");
46 final QName caseOne = QName.create(NS, "one");
47 final QName caseTwo = QName.create(NS, "two");
48 final QName caseThree = QName.create(NS, "three");
49 final QName containerOne = QName.create(NS, "container-one");
50 final QName containerTwo = QName.create(NS, "container-two");
51 final QName containerThree = QName.create(NS, "container-three");
53 verifyLeafType(SchemaContextUtil.findDataSchemaNode(context,
54 SchemaPath.create(true, ROOT, myChoice, caseOne, containerOne, LEAF_CONT_B)));
55 verifyLeafType(SchemaContextUtil.findDataSchemaNode(context,
56 SchemaPath.create(true, ROOT, myChoice, caseTwo, containerTwo, LEAF_CONT_B)));
57 verifyLeafType(SchemaContextUtil.findDataSchemaNode(context,
58 SchemaPath.create(true, ROOT, myChoice, caseThree, containerThree, INNER_CONTAINER, LEAF_CONT_B)));
62 public void groupingTest() throws Exception {
63 final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6771/grouping");
64 assertNotNull(context);
65 verifyLeafType(SchemaContextUtil
66 .findDataSchemaNode(context, SchemaPath.create(true, ROOT, CONT_B, LEAF_CONT_B)));
69 private static void verifyLeafType(final SchemaNode schemaNode) {
70 assertTrue(schemaNode instanceof LeafSchemaNode);
71 assertTrue(((LeafSchemaNode) schemaNode).getType() instanceof UnsignedIntegerTypeDefinition);