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 java.io.FileNotFoundException;
17 import java.net.URISyntaxException;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
24 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
25 import org.opendaylight.yangtools.yang.model.api.Status;
26 import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl;
27 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
28 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
30 public class Bug5481 {
32 public void test() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException {
33 SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5481");
34 assertNotNull(context);
36 ContainerSchemaNode topContainer = verifyTopContainer(context);
37 verifyExtendedLeaf(topContainer);
40 private ContainerSchemaNode verifyTopContainer(SchemaContext context) {
41 QName top = QName.create("http://example.com/module1", "2016-03-09", "top");
42 DataSchemaNode dataChildByName = context.getDataChildByName(top);
43 assertTrue(dataChildByName instanceof ContainerSchemaNode);
45 ContainerSchemaNode topContainer = (ContainerSchemaNode) dataChildByName;
46 RevisionAwareXPath whenConditionTopContainer = topContainer.getConstraints().getWhenCondition();
48 assertNull(whenConditionTopContainer);
49 assertEquals(Status.CURRENT, topContainer.getStatus());
50 assertNull(topContainer.getDescription());
51 assertNull(topContainer.getReference());
55 private void verifyExtendedLeaf(ContainerSchemaNode topContainer) {
56 DataSchemaNode dataChildByName2 = topContainer.getDataChildByName(QName.create("http://example.com/module2",
57 "2016-03-09", "extended-leaf"));
58 assertTrue(dataChildByName2 instanceof LeafSchemaNode);
60 LeafSchemaNode extendedLeaf = (LeafSchemaNode) dataChildByName2;
61 RevisionAwareXPath whenConditionExtendedLeaf = extendedLeaf.getConstraints().getWhenCondition();
63 assertEquals(new RevisionAwareXPathImpl("module1:top = 'extended'", false), whenConditionExtendedLeaf);
64 assertEquals(Status.DEPRECATED, extendedLeaf.getStatus());
65 assertEquals("text", extendedLeaf.getDescription());
66 assertEquals("ref", extendedLeaf.getReference());