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