Bug 6410: Fixed initialization of typedefs in rpc
[yangtools.git] / yang / yang-parser-impl / 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
9 package org.opendaylight.yangtools.yang.stmt;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
13 import static org.junit.Assert.fail;
14
15 import java.util.Set;
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;
24
25 public class Bug6410Test {
26
27     @Test
28     public void testTypedefsInRpc() throws ReactorException {
29         final SchemaContext schemaContext = StmtTestUtils.parseYangSources(
30                 new YangStatementSourceImpl("/bugs/bug6410/foo.yang", false));
31
32         final Set<Module> modules = schemaContext.getModules();
33         assertEquals(1, modules.size());
34         final Module module = modules.iterator().next();
35
36         final Set<RpcDefinition> rpcs = module.getRpcs();
37         assertEquals(1, rpcs.size());
38         final RpcDefinition rpc = rpcs.iterator().next();
39
40         final Set<TypeDefinition<?>> typeDefs = rpc.getTypeDefinitions();
41         assertEquals(2, typeDefs.size());
42     }
43
44     @Test
45     public void shouldFailOnDuplicateTypedefs() {
46         try {
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"));
53         }
54     }
55 }