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.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
15 import java.util.Optional;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
22 import org.opendaylight.yangtools.yang.model.api.Status;
23 import org.opendaylight.yangtools.yang.xpath.api.YangXPathExpression.QualifiedBound;
25 public class Bug5481Test {
27 public void test() throws Exception {
28 SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5481");
29 assertNotNull(context);
31 ContainerSchemaNode topContainer = verifyTopContainer(context);
32 verifyExtendedLeaf(topContainer);
35 private static ContainerSchemaNode verifyTopContainer(final SchemaContext context) {
36 QName top = QName.create("http://example.com/module1", "2016-03-09", "top");
37 DataSchemaNode dataChildByName = context.getDataChildByName(top);
38 assertTrue(dataChildByName instanceof ContainerSchemaNode);
40 ContainerSchemaNode topContainer = (ContainerSchemaNode) dataChildByName;
42 assertFalse(topContainer.getWhenCondition().isPresent());
43 assertEquals(Status.CURRENT, topContainer.getStatus());
44 assertFalse(topContainer.getDescription().isPresent());
45 assertFalse(topContainer.getReference().isPresent());
49 private static void verifyExtendedLeaf(final ContainerSchemaNode topContainer) {
50 DataSchemaNode dataChildByName2 = topContainer.getDataChildByName(QName.create("http://example.com/module2",
51 "2016-03-09", "extended-leaf"));
52 assertTrue(dataChildByName2 instanceof LeafSchemaNode);
54 LeafSchemaNode extendedLeaf = (LeafSchemaNode) dataChildByName2;
55 assertEquals(Status.DEPRECATED, extendedLeaf.getStatus());
56 assertEquals(Optional.of("text"), extendedLeaf.getDescription());
57 assertEquals(Optional.of("ref"), extendedLeaf.getReference());
59 QualifiedBound whenConditionExtendedLeaf = extendedLeaf.getWhenCondition().orElseThrow();
60 assertEquals("module1:top = 'extended'", whenConditionExtendedLeaf.toString());