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.test;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertNull;
13 import static org.junit.Assert.assertTrue;
15 import java.io.FileNotFoundException;
16 import java.net.URISyntaxException;
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.LeafSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
23 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
24 import org.opendaylight.yangtools.yang.model.api.Status;
25 import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
27 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
29 public class Bug5481 {
31 public void test() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException {
32 SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5481");
33 assertNotNull(context);
35 ContainerSchemaNode topContainer = verifyTopContainer(context);
36 verifyExtendedLeaf(topContainer);
39 private ContainerSchemaNode verifyTopContainer(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;
45 RevisionAwareXPath whenConditionTopContainer = topContainer.getConstraints().getWhenCondition();
47 assertNull(whenConditionTopContainer);
48 assertEquals(Status.CURRENT, topContainer.getStatus());
49 assertNull(topContainer.getDescription());
50 assertNull(topContainer.getReference());
54 private void verifyExtendedLeaf(ContainerSchemaNode topContainer) {
55 DataSchemaNode dataChildByName2 = topContainer.getDataChildByName(QName.create("http://example.com/module2",
56 "2016-03-09", "extended-leaf"));
57 assertTrue(dataChildByName2 instanceof LeafSchemaNode);
59 LeafSchemaNode extendedLeaf = (LeafSchemaNode) dataChildByName2;
60 RevisionAwareXPath whenConditionExtendedLeaf = extendedLeaf.getConstraints().getWhenCondition();
62 assertEquals(new RevisionAwareXPathImpl("module1:top = 'extended'", false), whenConditionExtendedLeaf);
63 assertEquals(Status.DEPRECATED, extendedLeaf.getStatus());
64 assertEquals("text", extendedLeaf.getDescription());
65 assertEquals("ref", extendedLeaf.getReference());