71f6a89ffaa9b51e5cefeb6da76eb874675bb8a1
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug5481.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.yangtools.yang.stmt;
10
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;
15
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;
29
30 public class Bug5481 {
31     @Test
32     public void test() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException {
33         SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5481");
34         assertNotNull(context);
35
36         ContainerSchemaNode topContainer = verifyTopContainer(context);
37         verifyExtendedLeaf(topContainer);
38     }
39
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);
44
45         ContainerSchemaNode topContainer = (ContainerSchemaNode) dataChildByName;
46         RevisionAwareXPath whenConditionTopContainer = topContainer.getConstraints().getWhenCondition();
47
48         assertNull(whenConditionTopContainer);
49         assertEquals(Status.CURRENT, topContainer.getStatus());
50         assertNull(topContainer.getDescription());
51         assertNull(topContainer.getReference());
52         return topContainer;
53     }
54
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);
59
60         LeafSchemaNode extendedLeaf = (LeafSchemaNode) dataChildByName2;
61         RevisionAwareXPath whenConditionExtendedLeaf = extendedLeaf.getConstraints().getWhenCondition();
62
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());
67     }
68 }