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.fail;
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() throws Exception {
23 StmtTestUtils.parseYangSource("/bugs/name-collision-within-case/foo.yang");
24 fail("Expected failure due to node name collision");
25 } catch (ReactorException e) {
26 final Throwable cause = e.getCause();
27 assertThat(cause, instanceOf(SourceException.class));
28 assertThat(cause.getMessage(), startsWith(
29 "Cannot add data tree child with name (foo?revision=2018-02-11)bar, a conflicting child already exists "
35 public void testChildNameCollisionOfAugmentChoice() throws Exception {
37 StmtTestUtils.parseYangSource("/bugs/name-collision-within-case/bar.yang");
38 fail("Expected failure due to node name collision");
39 } catch (ReactorException e) {
40 final Throwable cause = e.getCause();
41 assertThat(cause, instanceOf(SourceException.class));
42 assertThat(cause.getMessage(), startsWith(
43 "Cannot add data tree child with name (bar?revision=2018-02-11)bar, a conflicting child already exists "
49 public void testChildNameCollisionNormal() throws Exception {
51 StmtTestUtils.parseYangSource("/bugs/name-collision-within-case/baz.yang");
52 fail("Expected failure due to node name collision");
53 } catch (ReactorException e) {
54 final Throwable cause = e.getCause();
55 assertThat(cause, instanceOf(SourceException.class));
56 assertThat(cause.getMessage(), startsWith(
57 "Error in module 'baz': cannot add '(baz?revision=2018-02-28)bar'. Node name collision: "));