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;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertFalse;
14 import static org.junit.Assert.assertTrue;
16 import java.util.Optional;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
22 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.Status;
24 import org.opendaylight.yangtools.yang.xpath.api.YangXPathExpression.QualifiedBound;
26 public class Bug5481Test extends AbstractYangTest {
28 public void test() throws Exception {
29 final var context = assertEffectiveModelDir("/bugs/bug5481");
30 ContainerSchemaNode topContainer = verifyTopContainer(context);
31 verifyExtendedLeaf(topContainer);
34 private static ContainerSchemaNode verifyTopContainer(final EffectiveModelContext context) {
35 QName top = QName.create("http://example.com/module1", "2016-03-09", "top");
36 DataSchemaNode dataChildByName = context.getDataChildByName(top);
37 assertThat(dataChildByName, instanceOf(ContainerSchemaNode.class));
39 ContainerSchemaNode topContainer = (ContainerSchemaNode) dataChildByName;
41 assertFalse(topContainer.getWhenCondition().isPresent());
42 assertEquals(Status.CURRENT, topContainer.getStatus());
43 assertFalse(topContainer.getDescription().isPresent());
44 assertFalse(topContainer.getReference().isPresent());
48 private static void verifyExtendedLeaf(final ContainerSchemaNode topContainer) {
49 DataSchemaNode dataChildByName2 = topContainer.getDataChildByName(QName.create("http://example.com/module2",
50 "2016-03-09", "extended-leaf"));
51 assertTrue(dataChildByName2 instanceof LeafSchemaNode);
53 LeafSchemaNode extendedLeaf = (LeafSchemaNode) dataChildByName2;
54 assertEquals(Status.DEPRECATED, extendedLeaf.getStatus());
55 assertEquals(Optional.of("text"), extendedLeaf.getDescription());
56 assertEquals(Optional.of("ref"), extendedLeaf.getReference());
58 QualifiedBound whenConditionExtendedLeaf = extendedLeaf.getWhenCondition().orElseThrow();
59 assertEquals("module1:top = 'extended'", whenConditionExtendedLeaf.toString());