2 * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.stmt;
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;
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;
20 public class Bug7954Test {
22 public void testParsingTheSameModuleTwice() throws Exception {
23 final File yang = new File(getClass().getResource("/bugs/bug7954/foo.yang").toURI());
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."));
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());
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."));