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;
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;
23 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
25 public class Bug6410Test {
28 public void testTypedefsInRpc() throws ReactorException {
29 final SchemaContext schemaContext = StmtTestUtils.parseYangSources(
30 new YangStatementSourceImpl("/bugs/bug6410/foo.yang", false));
32 final Set<Module> modules = schemaContext.getModules();
33 assertEquals(1, modules.size());
34 final Module module = modules.iterator().next();
36 final Set<RpcDefinition> rpcs = module.getRpcs();
37 assertEquals(1, rpcs.size());
38 final RpcDefinition rpc = rpcs.iterator().next();
40 final Set<TypeDefinition<?>> typeDefs = rpc.getTypeDefinitions();
41 assertEquals(2, typeDefs.size());
45 public void shouldFailOnDuplicateTypedefs() {
47 final SchemaContext schemaContext = StmtTestUtils.parseYangSources(
48 new YangStatementSourceImpl("/bugs/bug6410/bar.yang", false));
49 fail("A ReactorException should have been thrown.");
50 } catch (ReactorException ex) {
51 assertTrue(ex.getCause() instanceof SourceException);
52 assertTrue(ex.getCause().getMessage().contains("Node name collision"));