Expose URLYangTextSource
[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.common.XMLNamespace;
19 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement;
22 import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
23
24 class Bug7038Test extends AbstractYangTest {
25     @Test
26     void unknownNodeTest() {
27         final var bar = assertEffectiveModelDir("/bugs/bug7038")
28             .getModuleStatement(QNameModule.create(XMLNamespace.of("bar"))).getDeclared();
29         final var decimal64 = bar.findFirstDeclaredSubstatement(UnrecognizedStatement.class).orElseThrow();
30         assertEquals("decimal64", decimal64.argument());
31         assertEquals(QName.create("foo", "decimal64"), decimal64.statementDefinition().getStatementName());
32     }
33
34     @Test
35     void testYang11() {
36         final var root = (ContainerSchemaNode) assertEffectiveModelDir("/bugs/bug7038/yang11")
37             .getDataChildByName(QName.create("foo", "root"));
38         final var typedef = ((LeafSchemaNode) root.getDataChildByName(QName.create("foo", "my-leafref")))
39             .getType();
40         assertFalse(assertInstanceOf(LeafrefTypeDefinition.class, typedef).requireInstance());
41     }
42
43     @Test
44     void testYang10() {
45         assertInvalidSubstatementExceptionDir("/bugs/bug7038/yang10",
46             startsWith("REQUIRE_INSTANCE is not valid for TYPE"));
47     }
48 }