34294e62e733d23a301a92a3eb5511e5463b9181
[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
9 package org.opendaylight.yangtools.yang.stmt;
10
11 import static org.hamcrest.CoreMatchers.instanceOf;
12 import static org.hamcrest.MatcherAssert.assertThat;
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertFalse;
15 import static org.junit.Assert.assertTrue;
16
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.common.QNameModule;
20 import org.opendaylight.yangtools.yang.common.XMLNamespace;
21 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
24 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
25 import org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement;
26 import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
27 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
28
29 public class Bug7038Test {
30     @Test
31     public void unknownNodeTest() throws Exception {
32         final ModuleStatement bar = StmtTestUtils.parseYangSources("/bugs/bug7038")
33             .getModuleStatement(QNameModule.create(XMLNamespace.of("bar"))).getDeclared();
34         final UnrecognizedStatement decimal64 = bar.findFirstDeclaredSubstatement(UnrecognizedStatement.class)
35             .orElseThrow();
36         assertEquals("decimal64", decimal64.argument());
37         assertEquals(QName.create("foo", "decimal64"), decimal64.statementDefinition().getStatementName());
38     }
39
40     @Test
41     public void testYang11() throws Exception {
42         final ContainerSchemaNode root = (ContainerSchemaNode) StmtTestUtils.parseYangSources("/bugs/bug7038/yang11")
43             .getDataChildByName(QName.create("foo", "root"));
44         final TypeDefinition<?> typedef = ((LeafSchemaNode) root.getDataChildByName(QName.create("foo", "my-leafref")))
45             .getType();
46         assertThat(typedef, instanceOf(LeafrefTypeDefinition.class));
47         assertFalse(((LeafrefTypeDefinition) typedef).requireInstance());
48     }
49
50     @Test
51     public void testYang10() throws Exception {
52         try {
53             StmtTestUtils.parseYangSources("/bugs/bug7038/yang10");
54         } catch (final SomeModifiersUnresolvedException e) {
55             assertTrue(e.getCause().getMessage().startsWith("REQUIRE_INSTANCE is not valid for TYPE"));
56         }
57     }
58 }