6e87a45343dbffc84a4c5a22a10a1715ce1efa7c
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug5101Test.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 package org.opendaylight.yangtools.yang.stmt;
9
10 import static org.hamcrest.CoreMatchers.instanceOf;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertFalse;
14
15 import java.util.Iterator;
16 import java.util.stream.Collectors;
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.Status;
21 import org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement;
22 import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement;
23 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
24
25 public class Bug5101Test {
26     @Test
27     public void test() throws Exception {
28         final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/bug5101.yang")
29             .getModuleStatement(QName.create("foo", "2016-01-29", "foo"));
30
31         final ContainerEffectiveStatement myContainerInGrouping = module
32             .findFirstEffectiveSubstatement(GroupingEffectiveStatement.class).orElseThrow()
33             .findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElse(null);
34         assertThat(myContainerInGrouping, instanceOf(ContainerSchemaNode.class));
35         assertEquals(Status.DEPRECATED, ((ContainerSchemaNode) myContainerInGrouping).getStatus());
36
37         // This relies on schema definition order
38         final Iterator<ContainerEffectiveStatement> containers =
39             module.streamEffectiveSubstatements(ContainerEffectiveStatement.class)
40             .collect(Collectors.toList()).iterator();
41
42         final ContainerEffectiveStatement root = containers.next();
43         assertThat(root, instanceOf(ContainerSchemaNode.class));
44         assertEquals(Status.CURRENT, ((ContainerSchemaNode) root).getStatus());
45
46         final ContainerEffectiveStatement rootMyContainer = root
47             .streamEffectiveSubstatements(ContainerEffectiveStatement.class)
48             .findAny().orElse(null);
49         assertThat(rootMyContainer, instanceOf(ContainerSchemaNode.class));
50         assertEquals(Status.DEPRECATED, ((ContainerSchemaNode) rootMyContainer).getStatus());
51
52         final ContainerEffectiveStatement myContainer = containers.next();
53         assertFalse(containers.hasNext());
54         assertThat(myContainer, instanceOf(ContainerSchemaNode.class));
55         assertEquals(Status.DEPRECATED, ((ContainerSchemaNode) myContainer).getStatus());
56
57     }
58 }