1789757ff90d054647b52bbfcea93b00d8a7d4a2
[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 java.io.File;
11 import java.net.URI;
12 import java.net.URISyntaxException;
13 import org.junit.Rule;
14 import org.junit.Test;
15 import org.junit.rules.ExpectedException;
16 import org.opendaylight.yangtools.sal.binding.model.api.Type;
17 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.Module;
21 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
22 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
24 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
25 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
26 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
27
28 public class Bug4621 {
29
30     @Rule
31     public ExpectedException expectedEx = ExpectedException.none();
32
33     @Test
34     public void bug4621test() throws ReactorException, URISyntaxException {
35         final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
36                 .newBuild();
37         File file = new File(getClass().getResource("/bug-4621/foo.yang").toURI());
38         reactor.addSource(new YangStatementSourceImpl(file.getPath(), true));
39
40         final SchemaContext schemaContext = reactor.buildEffective();
41         final Module moduleValid = schemaContext.findModuleByNamespace(new URI("foo")).iterator().next();
42         final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext);
43
44         expectedEx.expect(IllegalArgumentException.class);
45
46         DataSchemaNode leafrefRel = ((ListSchemaNode) moduleValid.getDataChildByName("neighbor")).getDataChildByName
47                 ("neighbor2-id");
48         LeafSchemaNode leafRel = (LeafSchemaNode) leafrefRel;
49         TypeDefinition<?> leafTypeRel = leafRel.getType();
50         Type leafrefRelResolvedType = typeProvider.javaTypeForSchemaDefinitionType(leafTypeRel, leafRel);
51     }
52 }