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;
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;
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;
25 public class Bug5101Test {
27 public void test() throws Exception {
28 final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/bug5101.yang")
29 .getModuleStatement(QName.create("foo", "2016-01-29", "foo"));
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());
37 // This relies on schema definition order
38 final Iterator<ContainerEffectiveStatement> containers =
39 module.streamEffectiveSubstatements(ContainerEffectiveStatement.class)
40 .collect(Collectors.toList()).iterator();
42 final ContainerEffectiveStatement root = containers.next();
43 assertThat(root, instanceOf(ContainerSchemaNode.class));
44 assertEquals(Status.CURRENT, ((ContainerSchemaNode) root).getStatus());
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());
52 final ContainerEffectiveStatement myContainer = containers.next();
53 assertFalse(containers.hasNext());
54 assertThat(myContainer, instanceOf(ContainerSchemaNode.class));
55 assertEquals(Status.DEPRECATED, ((ContainerSchemaNode) myContainer).getStatus());