2 * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.yangtools.yang.stmt;
11 import static org.hamcrest.CoreMatchers.instanceOf;
12 import static org.hamcrest.CoreMatchers.startsWith;
13 import static org.hamcrest.MatcherAssert.assertThat;
14 import static org.junit.Assert.assertEquals;
15 import static org.junit.Assert.assertFalse;
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;
28 public class Bug7038Test extends AbstractYangTest {
30 public void unknownNodeTest() {
31 final ModuleStatement bar = assertEffectiveModelDir("/bugs/bug7038")
32 .getModuleStatement(QNameModule.create(XMLNamespace.of("bar"))).getDeclared();
33 final UnrecognizedStatement decimal64 = bar.findFirstDeclaredSubstatement(UnrecognizedStatement.class)
35 assertEquals("decimal64", decimal64.argument());
36 assertEquals(QName.create("foo", "decimal64"), decimal64.statementDefinition().getStatementName());
40 public void testYang11() throws Exception {
41 final ContainerSchemaNode root = (ContainerSchemaNode) assertEffectiveModelDir("/bugs/bug7038/yang11")
42 .getDataChildByName(QName.create("foo", "root"));
43 final TypeDefinition<?> typedef = ((LeafSchemaNode) root.getDataChildByName(QName.create("foo", "my-leafref")))
45 assertThat(typedef, instanceOf(LeafrefTypeDefinition.class));
46 assertFalse(((LeafrefTypeDefinition) typedef).requireInstance());
50 public void testYang10() throws Exception {
51 assertInvalidSubstatementExceptionDir("/bugs/bug7038/yang10",
52 startsWith("REQUIRE_INSTANCE is not valid for TYPE"));