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