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.mdsal.binding.yang.types;
10 import static org.junit.Assert.assertNotNull;
13 import java.io.FileNotFoundException;
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.mdsal.binding.yang.types.TypeProviderImpl;
20 import org.opendaylight.yangtools.yang.common.QName;
21 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
24 import org.opendaylight.yangtools.yang.model.api.Module;
25 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
26 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
27 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
28 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
30 public class Bug4621 {
33 public ExpectedException expectedEx = ExpectedException.none();
36 public void bug4621test() throws FileNotFoundException, ReactorException, URISyntaxException {
37 File file = new File(getClass().getResource("/bug-4621/foo.yang").toURI());
39 final SchemaContext schemaContext = YangParserTestUtils.parseYangSources(file);
40 final Module moduleValid = schemaContext.findModuleByNamespace(new URI("foo")).iterator().next();
41 final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext);
43 expectedEx.expect(IllegalArgumentException.class);
45 final QName listNode = QName.create(moduleValid.getQNameModule(), "neighbor");
46 final QName leafrefNode = QName.create(moduleValid.getQNameModule(), "neighbor2-id");
47 DataSchemaNode leafrefRel = ((ListSchemaNode) moduleValid.getDataChildByName(listNode))
48 .getDataChildByName(leafrefNode);
49 LeafSchemaNode leafRel = (LeafSchemaNode) leafrefRel;
50 TypeDefinition<?> leafTypeRel = leafRel.getType();
51 assertNotNull(typeProvider.javaTypeForSchemaDefinitionType(leafTypeRel, leafRel));