Adjust test suite parser update to conform with API changes
[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 import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
15
16 import java.util.Set;
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;
24
25 public class Bug6410Test {
26
27     @Test
28     public void testTypedefsInRpc() throws ReactorException {
29         final SchemaContext schemaContext = StmtTestUtils.parseYangSources(sourceForResource("/bugs/bug6410/foo.yang"));
30
31         final Set<Module> modules = schemaContext.getModules();
32         assertEquals(1, modules.size());
33         final Module module = modules.iterator().next();
34
35         final Set<RpcDefinition> rpcs = module.getRpcs();
36         assertEquals(1, rpcs.size());
37         final RpcDefinition rpc = rpcs.iterator().next();
38
39         final Set<TypeDefinition<?>> typeDefs = rpc.getTypeDefinitions();
40         assertEquals(2, typeDefs.size());
41     }
42
43     @Test
44     public void shouldFailOnDuplicateTypedefs() {
45         try {
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"));
52         }
53     }
54 }