Do not create effective copy for unsupported statements
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / YT1532Test.java
1 /*
2  * Copyright (c) 2023 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.junit.jupiter.api.Assertions.assertEquals;
11
12 import java.util.Set;
13 import java.util.stream.Collectors;
14 import java.util.stream.Stream;
15 import org.junit.jupiter.params.ParameterizedTest;
16 import org.junit.jupiter.params.provider.Arguments;
17 import org.junit.jupiter.params.provider.MethodSource;
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.ModuleEffectiveStatement;
22
23 class YT1532Test extends AbstractYangTest {
24     private static final QName FOO = QName.create("urn:foo", "foo");
25     private static final QName BAR1 = QName.create("urn:foo", "bar1");
26     private static final QName BAR2 = QName.create("urn:foo", "bar2");
27     private static final QName BAZ = QName.create("urn:foo", "baz");
28
29     @ParameterizedTest(name = "Augmentation of grouping with {0}")
30     @MethodSource("generateArgs")
31     void assertFoo(final String testDesc, final String dirName, final Set<QName> expectedLeafs) {
32         final var foo = assertFooModule(dirName)
33             .findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow();
34         assertEquals(FOO, foo.argument());
35         assertEquals(expectedLeafs, findLeafs(foo));
36     }
37
38     private static Stream<Arguments> generateArgs() {
39         return Stream.of(
40             Arguments.of("description and no leaf with if-feature",
41                 "augment-with-description-no-leaf-with-if-feature",
42                 Set.of(BAR1, BAR2, BAZ)),
43             Arguments.of("no description and all leafs with if-feature",
44                 "augment-with-no-description-all-leafs-with-if-feature",
45                 Set.of(BAZ)),
46             Arguments.of("description and all leafs with if-feature",
47                 "augment-with-description-all-leafs-with-if-feature",
48                 Set.of(BAZ)),
49             Arguments.of("no description and one leaf with if-feature",
50                 "augment-with-no-description-one-leaf-with-if-feature",
51                 Set.of(BAR2, BAZ)));
52     }
53
54     private static ModuleEffectiveStatement assertFooModule(final String dirName) {
55         return assertEffectiveModelDir("/bugs/YT1532/" + dirName, Set.of())
56             .findModuleStatement(FOO).orElseThrow();
57     }
58
59     private static Set<Object> findLeafs(final ContainerEffectiveStatement foo) {
60         return foo.effectiveSubstatements().stream().filter(LeafEffectiveStatement.class::isInstance)
61             .map(LeafEffectiveStatement.class::cast)
62             .map(LeafEffectiveStatement::argument)
63             .collect(Collectors.toSet());
64     }
65 }