Deprecate simple DataTreeFactory.create()
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug7038Test.java
1 /*
2  * Copyright (c) 2017 Cisco Systems, Inc. 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.startsWith;
11 import static org.junit.jupiter.api.Assertions.assertEquals;
12 import static org.junit.jupiter.api.Assertions.assertFalse;
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.common.QNameModule;
18 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement;
21 import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
22
23 class Bug7038Test extends AbstractYangTest {
24     @Test
25     void unknownNodeTest() {
26         final var bar = assertEffectiveModelDir("/bugs/bug7038").getModuleStatement(QNameModule.of("bar"))
27             .getDeclared();
28         final var decimal64 = bar.findFirstDeclaredSubstatement(UnrecognizedStatement.class).orElseThrow();
29         assertEquals("decimal64", decimal64.argument());
30         assertEquals(QName.create("foo", "decimal64"), decimal64.statementDefinition().getStatementName());
31     }
32
33     @Test
34     void testYang11() {
35         final var root = (ContainerSchemaNode) assertEffectiveModelDir("/bugs/bug7038/yang11")
36             .getDataChildByName(QName.create("foo", "root"));
37         final var typedef = ((LeafSchemaNode) root.getDataChildByName(QName.create("foo", "my-leafref")))
38             .getType();
39         assertFalse(assertInstanceOf(LeafrefTypeDefinition.class, typedef).requireInstance());
40     }
41
42     @Test
43     void testYang10() {
44         assertInvalidSubstatementExceptionDir("/bugs/bug7038/yang10",
45             startsWith("REQUIRE_INSTANCE is not valid for TYPE"));
46     }
47 }