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.jupiter.api.Assertions.assertInstanceOf;
12 import org.junit.jupiter.api.Test;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.common.QNameModule;
15 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
16 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
17 import org.opendaylight.yangtools.yang.model.api.type.Uint32TypeDefinition;
19 class Bug6771Test extends AbstractYangTest {
20 private static final QNameModule NS = QNameModule.of("http://www.example.com/typedef-bug");
21 private static final QName ROOT = QName.create(NS, "root");
22 private static final QName CONT_B = QName.create(NS, "container-b");
23 private static final QName LEAF_CONT_B = QName.create(NS, "leaf-container-b");
24 private static final QName INNER_CONTAINER = QName.create(NS, "inner-container");
28 final var module = assertEffectiveModel("/bugs/bug6771/augment.yang").getModuleStatement(NS);
30 verifyLeafType(module, ROOT, CONT_B, LEAF_CONT_B);
31 verifyLeafType(module, ROOT, CONT_B, INNER_CONTAINER, LEAF_CONT_B);
35 void choiceCaseTest() {
36 final var module = assertEffectiveModel("/bugs/bug6771/choice-case.yang").getModuleStatement(NS);
38 final QName myChoice = QName.create(NS, "my-choice");
39 final QName caseOne = QName.create(NS, "one");
40 final QName caseTwo = QName.create(NS, "two");
41 final QName caseThree = QName.create(NS, "three");
42 final QName containerOne = QName.create(NS, "container-one");
43 final QName containerTwo = QName.create(NS, "container-two");
44 final QName containerThree = QName.create(NS, "container-three");
46 verifyLeafType(module, ROOT, myChoice, caseOne, containerOne, LEAF_CONT_B);
47 verifyLeafType(module, ROOT, myChoice, caseTwo, containerTwo, LEAF_CONT_B);
48 verifyLeafType(module, ROOT, myChoice, caseThree, containerThree, INNER_CONTAINER, LEAF_CONT_B);
53 verifyLeafType(assertEffectiveModel("/bugs/bug6771/grouping.yang").getModuleStatement(NS),
54 ROOT, CONT_B, LEAF_CONT_B);
57 private static void verifyLeafType(final ModuleEffectiveStatement module, final QName... qnames) {
58 assertInstanceOf(Uint32TypeDefinition.class,
59 assertInstanceOf(LeafSchemaNode.class, module.findSchemaTreeNode(qnames).orElseThrow()).getType());