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.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertNull;
14 import static org.junit.Assert.assertTrue;
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.RevisionAwareXPath;
22 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
23 import org.opendaylight.yangtools.yang.model.api.Status;
24 import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl;
26 public class Bug5481Test {
28 public void test() throws Exception {
29 SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5481");
30 assertNotNull(context);
32 ContainerSchemaNode topContainer = verifyTopContainer(context);
33 verifyExtendedLeaf(topContainer);
36 private static ContainerSchemaNode verifyTopContainer(final SchemaContext context) {
37 QName top = QName.create("http://example.com/module1", "2016-03-09", "top");
38 DataSchemaNode dataChildByName = context.getDataChildByName(top);
39 assertTrue(dataChildByName instanceof ContainerSchemaNode);
41 ContainerSchemaNode topContainer = (ContainerSchemaNode) dataChildByName;
42 RevisionAwareXPath whenConditionTopContainer = topContainer.getConstraints().getWhenCondition();
44 assertNull(whenConditionTopContainer);
45 assertEquals(Status.CURRENT, topContainer.getStatus());
46 assertNull(topContainer.getDescription());
47 assertNull(topContainer.getReference());
51 private static void verifyExtendedLeaf(final ContainerSchemaNode topContainer) {
52 DataSchemaNode dataChildByName2 = topContainer.getDataChildByName(QName.create("http://example.com/module2",
53 "2016-03-09", "extended-leaf"));
54 assertTrue(dataChildByName2 instanceof LeafSchemaNode);
56 LeafSchemaNode extendedLeaf = (LeafSchemaNode) dataChildByName2;
57 RevisionAwareXPath whenConditionExtendedLeaf = extendedLeaf.getConstraints().getWhenCondition();
59 assertEquals(new RevisionAwareXPathImpl("module1:top = 'extended'", false), whenConditionExtendedLeaf);
60 assertEquals(Status.DEPRECATED, extendedLeaf.getStatus());
61 assertEquals("text", extendedLeaf.getDescription());
62 assertEquals("ref", extendedLeaf.getReference());