2 * Copyright (c) 2018 Pantheon Technologies, s.r.o. 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.assertThrows;
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;
19 public class NameCollisionWithinCaseTest {
21 public void testChildNameCollisionOfAugmentCase() {
22 final ReactorException ex = assertThrows(ReactorException.class,
23 () -> StmtTestUtils.parseYangSource("/bugs/name-collision-within-case/foo.yang"));
24 final Throwable cause = ex.getCause();
25 assertThat(cause, instanceOf(SourceException.class));
26 assertThat(cause.getMessage(), startsWith("Cannot add data tree child with name (foo?revision=2018-02-11)bar, "
27 + "a conflicting child already exists [at "));
31 public void testChildNameCollisionOfAugmentChoice() {
32 final ReactorException ex = assertThrows(ReactorException.class,
33 () -> StmtTestUtils.parseYangSource("/bugs/name-collision-within-case/bar.yang"));
34 final Throwable cause = ex.getCause();
35 assertThat(cause, instanceOf(SourceException.class));
36 assertThat(cause.getMessage(), startsWith("Cannot add data tree child with name (bar?revision=2018-02-11)bar, "
37 + "a conflicting child already exists [at "));
41 public void testChildNameCollisionNormal() throws Exception {
42 final ReactorException ex = assertThrows(ReactorException.class,
43 () -> StmtTestUtils.parseYangSource("/bugs/name-collision-within-case/baz.yang"));
44 final Throwable cause = ex.getCause();
45 assertThat(cause, instanceOf(SourceException.class));
46 assertThat(cause.getMessage(), startsWith(
47 "Error in module 'baz': cannot add '(baz?revision=2018-02-28)bar'. Node name collision: "));