c22c2d53218d986a5fd663ac41a355d95e42ea5a
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / YT1209Test.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.assertNotSame;
11 import static org.junit.Assert.assertSame;
12
13 import org.junit.Test;
14 import org.opendaylight.yangtools.yang.common.QNameModule;
15 import org.opendaylight.yangtools.yang.common.XMLNamespace;
16 import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.WhenEffectiveStatement;
20
21 public class YT1209Test {
22     @Test
23     public void testWhenStatementReuse() throws Exception {
24         final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1209/when.yang")
25             .getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
26
27         final LeafEffectiveStatement grpFoo = module
28             .findFirstEffectiveSubstatement(GroupingEffectiveStatement.class).orElseThrow()
29             .findFirstEffectiveSubstatement(LeafEffectiveStatement.class).orElseThrow();
30         final LeafEffectiveStatement foo = module
31             .findFirstEffectiveSubstatement(LeafEffectiveStatement.class).orElseThrow();
32
33         // The statements should not be the same due SchemaPath being part of LeafSchemaNode
34         assertNotSame(foo, grpFoo);
35         // The statements are instantiated in the same module, hence they should have the same argument
36         assertSame(foo.argument(), grpFoo.argument());
37         // The statements' when substatement should be reused
38         assertSame(foo.findFirstEffectiveSubstatement(WhenEffectiveStatement.class).orElseThrow(),
39             grpFoo.findFirstEffectiveSubstatement(WhenEffectiveStatement.class).orElseThrow());
40     }
41 }