040b5725e2dd2b341e8cd76a64ca1b18a7df4973
[yangtools.git] / yang / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / YT1208Test.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.junit.Assert.assertNotNull;
11 import static org.junit.Assert.assertSame;
12
13 import java.net.URI;
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.common.QNameModule;
16 import org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
20 import org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement;
21
22 public class YT1208Test {
23     @Test
24     public void testLeafStatementReuse() throws Exception {
25         final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1208/leaf.yang")
26             .getModuleStatements()
27             .get(QNameModule.create(URI.create("foo")));
28         assertNotNull(module);
29
30         final NotificationEffectiveStatement notif = module
31             .findFirstEffectiveSubstatement(NotificationEffectiveStatement.class).orElseThrow();
32
33         final LeafEffectiveStatement grpBar = notif
34             .findFirstEffectiveSubstatement(GroupingEffectiveStatement.class).orElseThrow()
35             .findFirstEffectiveSubstatement(LeafEffectiveStatement.class).orElseThrow();
36         final LeafEffectiveStatement contBar = notif
37             .findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow()
38             .findFirstEffectiveSubstatement(LeafEffectiveStatement.class).orElseThrow();
39
40         assertSame(contBar, grpBar);
41     }
42 }