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
9 package org.opendaylight.yangtools.yang.stmt;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
13 import static org.junit.Assert.fail;
14 import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.model.api.Module;
19 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
23 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
25 public class Bug6410Test {
28 public void testTypedefsInRpc() throws ReactorException {
29 final SchemaContext schemaContext = StmtTestUtils.parseYangSources(sourceForResource("/bugs/bug6410/foo.yang"));
31 final Set<Module> modules = schemaContext.getModules();
32 assertEquals(1, modules.size());
33 final Module module = modules.iterator().next();
35 final Set<RpcDefinition> rpcs = module.getRpcs();
36 assertEquals(1, rpcs.size());
37 final RpcDefinition rpc = rpcs.iterator().next();
39 final Set<TypeDefinition<?>> typeDefs = rpc.getTypeDefinitions();
40 assertEquals(2, typeDefs.size());
44 public void shouldFailOnDuplicateTypedefs() {
46 StmtTestUtils.parseYangSources(sourceForResource("/bugs/bug6410/bar.yang"));
47 fail("A ReactorException should have been thrown.");
48 } catch (ReactorException ex) {
49 final Throwable cause = ex.getCause();
50 assertTrue(cause instanceof SourceException);
51 assertTrue(cause.getMessage().contains("Duplicate name for typedef"));