Migrate users of deprecated QNameModule methods
[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.jupiter.api.Assertions.assertNotSame;
11 import static org.junit.jupiter.api.Assertions.assertSame;
12
13 import org.junit.jupiter.api.Test;
14 import org.opendaylight.yangtools.yang.common.QNameModule;
15 import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.WhenEffectiveStatement;
18
19 class YT1209Test extends AbstractYangTest {
20     @Test
21     void testWhenStatementReuse() {
22         final var module = assertEffectiveModel("/bugs/YT1209/when.yang").getModuleStatement(QNameModule.of("foo"));
23
24         final LeafEffectiveStatement grpFoo = module
25             .findFirstEffectiveSubstatement(GroupingEffectiveStatement.class).orElseThrow()
26             .findFirstEffectiveSubstatement(LeafEffectiveStatement.class).orElseThrow();
27         final LeafEffectiveStatement foo = module
28             .findFirstEffectiveSubstatement(LeafEffectiveStatement.class).orElseThrow();
29
30         // The statements should not be the same due SchemaPath being part of LeafSchemaNode
31         assertNotSame(foo, grpFoo);
32         // The statements are instantiated in the same module, hence they should have the same argument
33         assertSame(foo.argument(), grpFoo.argument());
34         // The statements' when substatement should be reused
35         assertSame(foo.findFirstEffectiveSubstatement(WhenEffectiveStatement.class).orElseThrow(),
36             grpFoo.findFirstEffectiveSubstatement(WhenEffectiveStatement.class).orElseThrow());
37     }
38 }