YANGTOOLS-706: Split out yang-parser-rfc7950
[yangtools.git] / yang / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug5481Test.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.assertFalse;
13 import static org.junit.Assert.assertNotNull;
14 import static org.junit.Assert.assertTrue;
15
16 import java.util.Optional;
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
27 public class Bug5481Test {
28     @Test
29     public void test() throws Exception {
30         SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5481");
31         assertNotNull(context);
32
33         ContainerSchemaNode topContainer = verifyTopContainer(context);
34         verifyExtendedLeaf(topContainer);
35     }
36
37     private static ContainerSchemaNode verifyTopContainer(final SchemaContext context) {
38         QName top = QName.create("http://example.com/module1", "2016-03-09", "top");
39         DataSchemaNode dataChildByName = context.getDataChildByName(top);
40         assertTrue(dataChildByName instanceof ContainerSchemaNode);
41
42         ContainerSchemaNode topContainer = (ContainerSchemaNode) dataChildByName;
43
44         assertFalse(topContainer.getWhenCondition().isPresent());
45         assertEquals(Status.CURRENT, topContainer.getStatus());
46         assertFalse(topContainer.getDescription().isPresent());
47         assertFalse(topContainer.getReference().isPresent());
48         return topContainer;
49     }
50
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);
55
56         LeafSchemaNode extendedLeaf = (LeafSchemaNode) dataChildByName2;
57         RevisionAwareXPath whenConditionExtendedLeaf = extendedLeaf.getWhenCondition().get();
58
59         assertEquals(new RevisionAwareXPathImpl("module1:top = 'extended'", false), whenConditionExtendedLeaf);
60         assertEquals(Status.DEPRECATED, extendedLeaf.getStatus());
61         assertEquals(Optional.of("text"), extendedLeaf.getDescription());
62         assertEquals(Optional.of("ref"), extendedLeaf.getReference());
63     }
64 }