2 * Copyright (c) 2023 Verizon and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.stmt;
10 import static org.junit.jupiter.api.Assertions.assertEquals;
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;
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");
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));
38 private static Stream<Arguments> generateArgs() {
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",
46 Arguments.of("description and all leafs with if-feature",
47 "augment-with-description-all-leafs-with-if-feature",
49 Arguments.of("no description and one leaf with if-feature",
50 "augment-with-no-description-one-leaf-with-if-feature",
54 private static ModuleEffectiveStatement assertFooModule(final String dirName) {
55 return assertEffectiveModelDir("/bugs/YT1532/" + dirName, Set.of())
56 .findModuleStatement(FOO).orElseThrow();
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());