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 org.junit.Rule;
14 import org.junit.Test;
15 import org.junit.rules.ExpectedException;
16 import org.opendaylight.mdsal.binding.generator.spi.TypeProvider;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.Module;
22 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
23 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
24 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
26 public class Bug4621 {
29 public ExpectedException expectedEx = ExpectedException.none();
32 public void bug4621test() {
33 final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug-4621/foo.yang");
34 final Module moduleValid = schemaContext.findModules(URI.create("foo")).iterator().next();
35 final TypeProvider typeProvider = new RuntimeTypeProvider(schemaContext);
37 expectedEx.expect(IllegalArgumentException.class);
39 final QName listNode = QName.create(moduleValid.getQNameModule(), "neighbor");
40 final QName leafrefNode = QName.create(moduleValid.getQNameModule(), "neighbor2-id");
41 DataSchemaNode leafrefRel = ((ListSchemaNode) moduleValid.getDataChildByName(listNode))
42 .getDataChildByName(leafrefNode);
43 LeafSchemaNode leafRel = (LeafSchemaNode) leafrefRel;
44 TypeDefinition<?> leafTypeRel = leafRel.getType();
45 assertNotNull(typeProvider.javaTypeForSchemaDefinitionType(leafTypeRel, leafRel));