1577884e76a22bb22d0a0a6fc03cbe3eadd7e5a2
[mdsal.git] / binding / mdsal-binding-generator-impl / src / test / java / org / opendaylight / mdsal / binding / yang / types / Bug4621.java
1 /*
2  * Copyright (c) 2015 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.mdsal.binding.yang.types;
9
10 import static org.junit.Assert.assertNotNull;
11
12 import java.io.File;
13 import java.net.URI;
14 import org.junit.Rule;
15 import org.junit.Test;
16 import org.junit.rules.ExpectedException;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.Module;
22 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
23 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
24 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
25
26 public class Bug4621 {
27
28     @Rule
29     public ExpectedException expectedEx = ExpectedException.none();
30
31     @Test
32     public void bug4621test() throws Exception {
33         final File file = new File(getClass().getResource("/bug-4621/foo.yang").toURI());
34
35         final SchemaContext schemaContext = YangParserTestUtils.parseYangFiles(file);
36         final Module moduleValid = schemaContext.findModuleByNamespace(new URI("foo")).iterator().next();
37         final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext);
38
39         expectedEx.expect(IllegalArgumentException.class);
40
41         final QName listNode = QName.create(moduleValid.getQNameModule(), "neighbor");
42         final QName leafrefNode = QName.create(moduleValid.getQNameModule(), "neighbor2-id");
43         final DataSchemaNode leafrefRel = ((ListSchemaNode) moduleValid.getDataChildByName(listNode))
44                 .getDataChildByName(leafrefNode);
45         final LeafSchemaNode leafRel = (LeafSchemaNode) leafrefRel;
46         final TypeDefinition<?> leafTypeRel = leafRel.getType();
47         assertNotNull(typeProvider.javaTypeForSchemaDefinitionType(leafTypeRel, leafRel));
48     }
49 }