2 * Copyright (c) 2015 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
8 package org.opendaylight.yangtools.sal.binding.yang.types;
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;
28 public class Bug4621 {
31 public ExpectedException expectedEx = ExpectedException.none();
34 public void bug4621test() throws ReactorException, URISyntaxException {
35 final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
37 File file = new File(getClass().getResource("/bug-4621/foo.yang").toURI());
38 reactor.addSource(new YangStatementSourceImpl(file.getPath(), true));
40 final SchemaContext schemaContext = reactor.buildEffective();
41 final Module moduleValid = schemaContext.findModuleByNamespace(new URI("foo")).iterator().next();
42 final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext);
44 expectedEx.expect(IllegalArgumentException.class);
46 DataSchemaNode leafrefRel = ((ListSchemaNode) moduleValid.getDataChildByName("neighbor")).getDataChildByName
48 LeafSchemaNode leafRel = (LeafSchemaNode) leafrefRel;
49 TypeDefinition<?> leafTypeRel = leafRel.getType();
50 Type leafrefRelResolvedType = typeProvider.javaTypeForSchemaDefinitionType(leafTypeRel, leafRel);