Bug 5101: Status deprecated must not be propagated via uses statement
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / test / Bug5101.java
1 /*
2  * Copyright (c) 2015 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 package org.opendaylight.yangtools.yang.stmt.test;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13
14 import java.io.FileNotFoundException;
15 import java.net.URISyntaxException;
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.SchemaContext;
20 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
22 import org.opendaylight.yangtools.yang.model.api.Status;
23 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
25 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
26
27 public class Bug5101 {
28     private static final String NS = "foo";
29     private static final String REV = "2016-01-29";
30
31     @Test
32     public void test() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException {
33         SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5101");
34         assertNotNull(context);
35
36         QName grp = QName.create(NS, REV, "my-grouping");
37         QName myContainer = QName.create(NS, REV, "my-container");
38         QName root = QName.create(NS, REV, "root");
39
40         SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
41                 SchemaPath.create(true, grp, myContainer));
42         assertTrue(findDataSchemaNode instanceof ContainerSchemaNode);
43         ContainerSchemaNode myContainerInGrouping = (ContainerSchemaNode) findDataSchemaNode;
44         assertEquals(Status.DEPRECATED, myContainerInGrouping.getStatus());
45
46         findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, root, myContainer));
47         assertTrue(findDataSchemaNode instanceof ContainerSchemaNode);
48         ContainerSchemaNode myContainerInRoot = (ContainerSchemaNode) findDataSchemaNode;
49         assertEquals(Status.DEPRECATED, myContainerInRoot.getStatus());
50
51         findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, myContainer));
52         assertTrue(findDataSchemaNode instanceof ContainerSchemaNode);
53         ContainerSchemaNode myContainerInModule = (ContainerSchemaNode) findDataSchemaNode;
54         assertEquals(Status.DEPRECATED, myContainerInModule.getStatus());
55
56         findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, root));
57         assertTrue(findDataSchemaNode instanceof ContainerSchemaNode);
58         ContainerSchemaNode rootContainer = (ContainerSchemaNode) findDataSchemaNode;
59         assertEquals(Status.CURRENT, rootContainer.getStatus());
60     }
61 }