Remove unneeded throws
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug6410Test.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.stmt;
9
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;
14
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;
23
24 public class Bug6410Test {
25
26     @Test
27     public void testTypedefsInRpc() throws ReactorException {
28         final SchemaContext schemaContext = StmtTestUtils.parseYangSources(sourceForResource("/bugs/bug6410/foo.yang"));
29
30         final Collection<? extends Module> modules = schemaContext.getModules();
31         assertEquals(1, modules.size());
32         final Module module = modules.iterator().next();
33
34         final Collection<? extends RpcDefinition> rpcs = module.getRpcs();
35         assertEquals(1, rpcs.size());
36         final RpcDefinition rpc = rpcs.iterator().next();
37
38         final Collection<? extends TypeDefinition<?>> typeDefs = rpc.getTypeDefinitions();
39         assertEquals(2, typeDefs.size());
40     }
41
42     @Test
43     public void shouldFailOnDuplicateTypedefs() {
44         try {
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"));
51         }
52     }
53 }