Populate xpath/ hierarchy
[yangtools.git] / parser / yang-parser-rfc7950 / 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 package org.opendaylight.yangtools.yang.stmt;
9
10 import static org.hamcrest.CoreMatchers.instanceOf;
11 import static org.hamcrest.CoreMatchers.startsWith;
12 import static org.hamcrest.MatcherAssert.assertThat;
13 import static org.junit.Assert.fail;
14
15 import java.io.File;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
18 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
19
20 public class Bug7954Test {
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             assertThat(cause, instanceOf(SourceException.class));
31             assertThat(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             assertThat(cause, instanceOf(SourceException.class));
46             assertThat(cause.getMessage(), startsWith("Submodule name collision: subbar."));
47         }
48     }
49 }