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.hamcrest.CoreMatchers.instanceOf;
11 import static org.hamcrest.MatcherAssert.assertThat;
13 import org.junit.Test;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.common.QNameModule;
16 import org.opendaylight.yangtools.yang.common.XMLNamespace;
17 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
20 import org.opendaylight.yangtools.yang.model.api.type.Uint32TypeDefinition;
22 public class Bug6771Test {
23 private static final QNameModule NS = QNameModule.create(XMLNamespace.of("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 ModuleEffectiveStatement module = TestUtils.parseYangSource("/bugs/bug6771/augment.yang")
32 .getModuleStatement(NS);
34 verifyLeafType(module, ROOT, CONT_B, LEAF_CONT_B);
35 verifyLeafType(module, ROOT, CONT_B, INNER_CONTAINER, LEAF_CONT_B);
39 public void choiceCaseTest() throws Exception {
40 final ModuleEffectiveStatement module = TestUtils.parseYangSource("/bugs/bug6771/choice-case.yang")
41 .getModuleStatement(NS);
43 final QName myChoice = QName.create(NS, "my-choice");
44 final QName caseOne = QName.create(NS, "one");
45 final QName caseTwo = QName.create(NS, "two");
46 final QName caseThree = QName.create(NS, "three");
47 final QName containerOne = QName.create(NS, "container-one");
48 final QName containerTwo = QName.create(NS, "container-two");
49 final QName containerThree = QName.create(NS, "container-three");
51 verifyLeafType(module, ROOT, myChoice, caseOne, containerOne, LEAF_CONT_B);
52 verifyLeafType(module, ROOT, myChoice, caseTwo, containerTwo, LEAF_CONT_B);
53 verifyLeafType(module, ROOT, myChoice, caseThree, containerThree, INNER_CONTAINER, LEAF_CONT_B);
57 public void groupingTest() throws Exception {
58 verifyLeafType(TestUtils.parseYangSource("/bugs/bug6771/grouping.yang").getModuleStatement(NS),
59 ROOT, CONT_B, LEAF_CONT_B);
62 private static void verifyLeafType(final ModuleEffectiveStatement module, final QName... qnames) {
63 final SchemaTreeEffectiveStatement<?> stmt = module.findSchemaTreeNode(qnames).orElse(null);
64 assertThat(stmt, instanceOf(LeafSchemaNode.class));
65 assertThat(((LeafSchemaNode) stmt).getType(), instanceOf(Uint32TypeDefinition.class));