Deprecate simple DataTreeFactory.create()
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / YT1410Test.java
1 /*
2  * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.CoreMatchers.startsWith;
12 import static org.hamcrest.MatcherAssert.assertThat;
13 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
14
15 import org.junit.jupiter.api.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.stmt.CaseEffectiveStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.ChoiceEffectiveStatement;
19
20 class YT1410Test extends AbstractYangTest {
21     @Test
22     void testRFC6020() {
23         assertInvalidSubstatementException(
24             startsWith("CHOICE is not valid for CHOICE. Error in module foo (QNameModule{ns=foo}) [at "),
25             "/bugs/YT1410/foo.yang");
26     }
27
28     @Test
29     void testRFC7950() {
30         final var module = assertEffectiveModel("/bugs/YT1410/bar.yang").getModuleStatement(QName.create("bar", "bar"));
31         final var one = module.findSchemaTreeNode(QName.create("bar", "one")).orElseThrow();
32         assertInstanceOf(ChoiceEffectiveStatement.class, one);
33         final var two = ((ChoiceEffectiveStatement) one).findSchemaTreeNode(QName.create("bar", "two")).orElseThrow();
34         assertInstanceOf(CaseEffectiveStatement.class, two);
35         assertThat(((CaseEffectiveStatement) two).findSchemaTreeNode(QName.create("bar", "two")).orElseThrow(),
36             instanceOf(ChoiceEffectiveStatement.class));
37     }
38 }