Do not suppress 'uses' node effects
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / YT1471Test.java
1 /*
2  * Copyright (c) 2022 Verizon 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.hamcrest.Matchers.contains;
13 import static org.junit.Assert.assertEquals;
14
15 import java.util.List;
16 import java.util.Set;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement;
20 import org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.api.stmt.UsesEffectiveStatement;
22
23 public class YT1471Test extends AbstractYangTest {
24     private static final QName FOO = QName.create("urn:foo", "foo");
25     private static final QName BAR = QName.create("urn:foo", "bar");
26     private static final QName BAZ = QName.create("urn:foo", "baz");
27     private static final QName BAZ_LEAF = QName.create("urn:foo", "baz-leaf");
28
29     @Test
30     public void testAugmentSingleGroupingWithFeatureSupported() {
31         assertSupportedFoo("single");
32     }
33
34     @Test
35     public void testAugmentSingleGroupingWithFeatureNotSupported() {
36         assertEquals(List.of(), assertFoo("single", Set.of()).effectiveSubstatements());
37     }
38
39     @Test
40     public void testAugmentNestedGroupingWithFeatureSupported() {
41         assertSupportedFoo("nested");
42     }
43
44     @Test
45     public void testAugmentNestedGroupingWithFeatureNotSupported() {
46         assertThat(assertFoo("nested", Set.of()).effectiveSubstatements(),
47             contains(instanceOf(UsesEffectiveStatement.class)));
48     }
49
50     private static ContainerEffectiveStatement assertFoo(final String dirName, final Set<QName> supportedFeatures) {
51         final var foo = assertEffectiveModelDir("/bugs/YT1471/" + dirName, supportedFeatures)
52             .findModuleStatement(FOO).orElseThrow()
53             .findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow();
54         assertEquals(FOO, foo.argument());
55         return foo;
56     }
57
58     private static void assertSupportedFoo(final String dirName) {
59         final var bar = assertFoo(dirName, null)
60             .findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow();
61         assertEquals(BAR, bar.argument());
62
63         final var baz = bar.findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow();
64         assertEquals(BAZ, baz.argument());
65
66         final var bazLeaf = baz.findFirstEffectiveSubstatement(LeafEffectiveStatement.class).orElseThrow();
67         assertEquals(BAZ_LEAF, bazLeaf.argument());
68     }
69 }