2 * Copyright (c) 2016 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.yang.stmt;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
12 import static org.junit.Assert.fail;
13 import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
15 import java.util.Collection;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.model.api.Module;
18 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
19 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
20 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
22 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
24 public class Bug6410Test {
27 public void testTypedefsInRpc() throws ReactorException {
28 final SchemaContext schemaContext = StmtTestUtils.parseYangSources(sourceForResource("/bugs/bug6410/foo.yang"));
30 final Collection<? extends Module> modules = schemaContext.getModules();
31 assertEquals(1, modules.size());
32 final Module module = modules.iterator().next();
34 final Collection<? extends RpcDefinition> rpcs = module.getRpcs();
35 assertEquals(1, rpcs.size());
36 final RpcDefinition rpc = rpcs.iterator().next();
38 final Collection<? extends TypeDefinition<?>> typeDefs = rpc.getTypeDefinitions();
39 assertEquals(2, typeDefs.size());
43 public void shouldFailOnDuplicateTypedefs() {
45 StmtTestUtils.parseYangSources(sourceForResource("/bugs/bug6410/bar.yang"));
46 fail("A ReactorException should have been thrown.");
47 } catch (ReactorException ex) {
48 final Throwable cause = ex.getCause();
49 assertTrue(cause instanceof SourceException);
50 assertTrue(cause.getMessage().contains("Duplicate name for typedef"));