5492924a6e9a0a798e73047593d9156446cad306
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug7954Test.java
1 /*
2  * Copyright (c) 2017 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.assertTrue;
12 import static org.junit.Assert.fail;
13
14 import java.io.File;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
17 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
18
19 public class Bug7954Test {
20
21     @Test
22     public void testParsingTheSameModuleTwice() throws Exception {
23         final File yang = new File(getClass().getResource("/bugs/bug7954/foo.yang").toURI());
24
25         try {
26             StmtTestUtils.parseYangSources(yang, yang);
27             fail("An exception should have been thrown because of adding the same YANG module twice.");
28         } catch (final ReactorException ex) {
29             final Throwable cause = ex.getCause();
30             assertTrue(cause instanceof SourceException);
31             assertTrue(cause.getMessage().startsWith("Module namespace collision: foo-ns."));
32         }
33     }
34
35     @Test
36     public void testParsingTheSameSubmoduleTwice() throws Exception {
37         final File yang = new File(getClass().getResource("/bugs/bug7954/bar.yang").toURI());
38         final File childYang = new File(getClass().getResource("/bugs/bug7954/subbar.yang").toURI());
39
40         try {
41             StmtTestUtils.parseYangSources(yang, childYang, childYang);
42             fail("An exception should have been thrown because of adding the same YANG submodule twice.");
43         } catch (final ReactorException ex) {
44             final Throwable cause = ex.getCause();
45             assertTrue(cause instanceof SourceException);
46             assertTrue(cause.getMessage().startsWith("Submodule name collision: subbar."));
47         }
48     }
49 }