Deprecate simple DataTreeFactory.create()
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / YT1465Test.java
1 /*
2  * Copyright (c) 2022 PANTHEON.tech s.r.o. 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 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
12
13 import java.util.Set;
14 import org.junit.jupiter.api.Test;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
17 import org.opendaylight.yangtools.yang.model.api.stmt.CaseEffectiveStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.ChoiceEffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement;
20
21 class YT1465Test extends AbstractYangTest {
22     @Test
23     void supportedLeafInChoiceAugment() throws Exception {
24         final var baz = assertBaz(StmtTestUtils.parseYangSource("/bugs/YT1465/foo.yang", null));
25         final var schemas = baz.schemaTreeNodes();
26         assertEquals(2, schemas.size());
27         final var it = schemas.iterator();
28
29         final var first = assertInstanceOf(CaseEffectiveStatement.class, it.next());
30         assertEquals(QName.create("foo", "one"), first.argument());
31
32         final var second = assertInstanceOf(CaseEffectiveStatement.class, it.next());
33         assertEquals(QName.create("foo", "two"), second.argument());
34     }
35
36     @Test
37     void unsupportedLeafInChoiceAugment() throws Exception {
38         final var baz = assertBaz(StmtTestUtils.parseYangSource("/bugs/YT1465/foo.yang", Set.of()));
39         final var schemas = baz.schemaTreeNodes();
40         assertEquals(1, schemas.size());
41         final var first = assertInstanceOf(CaseEffectiveStatement.class, schemas.iterator().next());
42         assertEquals(QName.create("foo", "one"), first.argument());
43     }
44
45     private static ChoiceEffectiveStatement assertBaz(final EffectiveModelContext ctx) {
46         final var foo = ctx.findModuleStatements("foo").iterator().next()
47             .findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow();
48         assertEquals(QName.create("foo", "foo"), foo.argument());
49
50         final var bar = foo.findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow();
51         assertEquals(QName.create("foo", "bar"), bar.argument());
52
53         final var baz = bar.findFirstEffectiveSubstatement(ChoiceEffectiveStatement.class).orElseThrow();
54         assertEquals(QName.create("foo", "baz"), baz.argument());
55         return baz;
56     }
57 }