f21fe3e769e3ffcac7014a470119030b8b5bdff8
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / YT838Test.java
1 /*
2  * Copyright (c) 2017 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 import static org.junit.Assert.assertTrue;
15
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;
19
20 public class YT838Test {
21     @Test
22     public void testGroupingShadowing() {
23         testGrouping("grouping.yang");
24     }
25
26     @Test
27     public void testGroupingPostShadowing() {
28         testGrouping("grouping-post.yang");
29     }
30
31     @Test
32     public void testTypedefShadowing() {
33         testTypedef("typedef.yang");
34     }
35
36     @Test
37     public void testTypedefPostShadowing() {
38         testTypedef("typedef-post.yang");
39     }
40
41     private static void testGrouping(final String model) {
42         final ReactorException ex = assertThrows(ReactorException.class,
43             () -> StmtTestUtils.parseYangSource("/bugs/YT838/" + model));
44
45         final Throwable cause = ex.getCause();
46         assertThat(cause, instanceOf(SourceException.class));
47         assertThat(cause.getMessage(),
48             startsWith("Duplicate name for grouping (grouping?revision=2017-12-20)foo [at "));
49     }
50
51     private static void testTypedef(final String model) {
52         final ReactorException ex = assertThrows(ReactorException.class,
53             () -> StmtTestUtils.parseYangSource("/bugs/YT838/" + model));
54         final Throwable cause = ex.getCause();
55         assertTrue(cause instanceof SourceException);
56         assertThat(cause, instanceOf(SourceException.class));
57         assertThat(cause.getMessage(), startsWith("Duplicate name for typedef (typedef?revision=2017-12-20)foo [at "));
58     }
59 }