9fa1ef1b87fb8295a16c9254f7eb8616ad49fc47
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / NameCollisionWithinCaseTest.java
1 /*
2  * Copyright (c) 2018 Pantheon Technologies, s.r.o. 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.assertThrows;
14
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 NameCollisionWithinCaseTest {
20     @Test
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 "));
28     }
29
30     @Test
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 "));
38     }
39
40     @Test
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: "));
48     }
49 }