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;
10 import static org.junit.Assert.assertNotNull;
14 import java.net.URISyntaxException;
15 import org.junit.Rule;
16 import org.junit.Test;
17 import org.junit.rules.ExpectedException;
18 import org.opendaylight.yangtools.sal.binding.model.api.Type;
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.parser.stmt.reactor.CrossSourceStatementReactor;
28 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
29 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
31 public class Bug4621 {
34 public ExpectedException expectedEx = ExpectedException.none();
37 public void bug4621test() throws ReactorException, URISyntaxException {
38 final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
40 File file = new File(getClass().getResource("/bug-4621/foo.yang").toURI());
41 reactor.addSource(new YangStatementSourceImpl(file.getPath(), true));
43 final SchemaContext schemaContext = reactor.buildEffective();
44 final Module moduleValid = schemaContext.findModuleByNamespace(new URI("foo")).iterator().next();
45 final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext);
47 expectedEx.expect(IllegalArgumentException.class);
49 final QName listNode = QName.create(moduleValid.getQNameModule(), "neighbor");
50 final QName leafrefNode = QName.create(moduleValid.getQNameModule(), "neighbor2-id");
51 DataSchemaNode leafrefRel = ((ListSchemaNode) moduleValid.getDataChildByName(listNode))
52 .getDataChildByName(leafrefNode);
53 LeafSchemaNode leafRel = (LeafSchemaNode) leafrefRel;
54 TypeDefinition<?> leafTypeRel = leafRel.getType();
55 Type leafrefRelResolvedType = typeProvider.javaTypeForSchemaDefinitionType(leafTypeRel, leafRel);
56 assertNotNull(leafrefRelResolvedType);