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.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertFalse;
12 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
14 import java.util.Optional;
15 import org.junit.jupiter.api.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
20 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.Status;
22 import org.opendaylight.yangtools.yang.xpath.api.YangXPathExpression.QualifiedBound;
24 class Bug5481Test extends AbstractYangTest {
26 void test() throws Exception {
27 final var context = assertEffectiveModelDir("/bugs/bug5481");
28 ContainerSchemaNode topContainer = verifyTopContainer(context);
29 verifyExtendedLeaf(topContainer);
32 private static ContainerSchemaNode verifyTopContainer(final EffectiveModelContext context) {
33 QName top = QName.create("http://example.com/module1", "2016-03-09", "top");
34 DataSchemaNode dataChildByName = context.getDataChildByName(top);
35 ContainerSchemaNode topContainer = assertInstanceOf(ContainerSchemaNode.class, dataChildByName);
37 assertFalse(topContainer.getWhenCondition().isPresent());
38 assertEquals(Status.CURRENT, topContainer.getStatus());
39 assertFalse(topContainer.getDescription().isPresent());
40 assertFalse(topContainer.getReference().isPresent());
44 private static void verifyExtendedLeaf(final ContainerSchemaNode topContainer) {
45 DataSchemaNode dataChildByName2 = topContainer.getDataChildByName(QName.create("http://example.com/module2",
46 "2016-03-09", "extended-leaf"));
47 LeafSchemaNode extendedLeaf = assertInstanceOf(LeafSchemaNode.class, dataChildByName2);
49 assertEquals(Status.DEPRECATED, extendedLeaf.getStatus());
50 assertEquals(Optional.of("text"), extendedLeaf.getDescription());
51 assertEquals(Optional.of("ref"), extendedLeaf.getReference());
53 QualifiedBound whenConditionExtendedLeaf = extendedLeaf.getWhenCondition().orElseThrow();
54 assertEquals("module1:top = 'extended'", whenConditionExtendedLeaf.toString());