Merge branch 'master' of ../controller
[yangtools.git] / yang / 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.junit.Assert.assertTrue;
11 import static org.junit.Assert.fail;
12
13 import org.junit.Test;
14 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
15 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
16
17 public class NameCollisionWithinCaseTest {
18     @Test
19     public void testChildNameCollisionOfAugmentCase() throws Exception {
20         try {
21             StmtTestUtils.parseYangSource("/bugs/name-collision-within-case/foo.yang");
22             fail("Expected failure due to node name collision");
23         } catch (ReactorException e) {
24             final Throwable cause = e.getCause();
25             assertTrue(cause instanceof SourceException);
26             assertTrue(cause.getMessage().startsWith(
27                 "Cannot add data tree child with name (foo?revision=2018-02-11)bar, a conflicting child already exists "
28                         + "[at "));
29         }
30     }
31
32     @Test
33     public void testChildNameCollisionOfAugmentChoice() throws Exception {
34         try {
35             StmtTestUtils.parseYangSource("/bugs/name-collision-within-case/bar.yang");
36             fail("Expected failure due to node name collision");
37         } catch (ReactorException e) {
38             final Throwable cause = e.getCause();
39             assertTrue(cause instanceof SourceException);
40             assertTrue(cause.getMessage().startsWith(
41                 "Cannot add data tree child with name (bar?revision=2018-02-11)bar, a conflicting child already exists "
42                         + "[at "));
43         }
44     }
45
46     @Test
47     public void testChildNameCollisionNormal() throws Exception {
48         try {
49             StmtTestUtils.parseYangSource("/bugs/name-collision-within-case/baz.yang");
50             fail("Expected failure due to node name collision");
51         } catch (ReactorException e) {
52             final Throwable cause = e.getCause();
53             assertTrue(cause instanceof SourceException);
54             assertTrue(cause.getMessage().startsWith(
55                 "Error in module 'baz': cannot add '(baz?revision=2018-02-28)bar'. Node name collision: "));
56         }
57     }
58 }