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
9 package org.opendaylight.yangtools.yang.stmt;
11 import static org.hamcrest.Matchers.instanceOf;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertFalse;
14 import static org.junit.Assert.assertNotNull;
15 import static org.junit.Assert.assertThat;
16 import static org.junit.Assert.assertTrue;
18 import java.util.Optional;
19 import org.junit.Test;
20 import org.opendaylight.yangtools.yang.common.QName;
21 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
24 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
25 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath.WithExpression;
26 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
27 import org.opendaylight.yangtools.yang.model.api.Status;
29 public class Bug5481Test {
31 public void test() throws Exception {
32 SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5481");
33 assertNotNull(context);
35 ContainerSchemaNode topContainer = verifyTopContainer(context);
36 verifyExtendedLeaf(topContainer);
39 private static ContainerSchemaNode verifyTopContainer(final SchemaContext context) {
40 QName top = QName.create("http://example.com/module1", "2016-03-09", "top");
41 DataSchemaNode dataChildByName = context.getDataChildByName(top);
42 assertTrue(dataChildByName instanceof ContainerSchemaNode);
44 ContainerSchemaNode topContainer = (ContainerSchemaNode) dataChildByName;
46 assertFalse(topContainer.getWhenCondition().isPresent());
47 assertEquals(Status.CURRENT, topContainer.getStatus());
48 assertFalse(topContainer.getDescription().isPresent());
49 assertFalse(topContainer.getReference().isPresent());
53 private static void verifyExtendedLeaf(final ContainerSchemaNode topContainer) {
54 DataSchemaNode dataChildByName2 = topContainer.getDataChildByName(QName.create("http://example.com/module2",
55 "2016-03-09", "extended-leaf"));
56 assertTrue(dataChildByName2 instanceof LeafSchemaNode);
58 LeafSchemaNode extendedLeaf = (LeafSchemaNode) dataChildByName2;
59 assertEquals(Status.DEPRECATED, extendedLeaf.getStatus());
60 assertEquals(Optional.of("text"), extendedLeaf.getDescription());
61 assertEquals(Optional.of("ref"), extendedLeaf.getReference());
63 RevisionAwareXPath whenConditionExtendedLeaf = extendedLeaf.getWhenCondition().get();
64 assertFalse(whenConditionExtendedLeaf.isAbsolute());
65 assertThat(whenConditionExtendedLeaf, instanceOf(WithExpression.class));
66 assertEquals("module1:top = 'extended'", whenConditionExtendedLeaf.getOriginalString());