Deprecate simple DataTreeFactory.create()
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / YT1485Test.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.hamcrest.MatcherAssert.assertThat;
11 import static org.hamcrest.Matchers.hasItem;
12 import static org.hamcrest.Matchers.instanceOf;
13 import static org.hamcrest.Matchers.not;
14 import static org.junit.jupiter.api.Assertions.assertEquals;
15
16 import java.util.List;
17 import java.util.Set;
18 import org.junit.jupiter.api.Test;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement;
22
23 class YT1485Test extends AbstractYangTest {
24     private static final QName FOO = QName.create("urn:foo", "foo");
25
26     @Test
27     void testLeafFooFeatureSupported() {
28         assertEquals(List.of(), assertFoo("leaf", null).effectiveSubstatements());
29     }
30
31     @Test
32     void testLeafFooFeatureNotSupported() {
33         assertEquals(List.of(), assertFoo("leaf", Set.of()).effectiveSubstatements());
34     }
35
36     @Test
37     void testAugmentFooFeatureSupported() {
38         assertThat(assertFoo("augment", null).effectiveSubstatements(),
39             not(hasItem(instanceOf(LeafEffectiveStatement.class))));
40     }
41
42     @Test
43     void testAugmentFooFeatureNotSupported() {
44         assertEquals(List.of(), assertFoo("augment", Set.of()).effectiveSubstatements());
45     }
46
47     private static ContainerEffectiveStatement assertFoo(final String dirName,
48             final Set<QName> supportedFeatures) {
49         final var foo = assertEffectiveModelDir("/bugs/YT1485/" + dirName, supportedFeatures)
50             .findModuleStatement(FOO).orElseThrow()
51             .findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow();
52         assertEquals(FOO, foo.argument());
53         return foo;
54     }
55 }