Merge branch 'master' of ../controller
[yangtools.git] / yang / 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.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 YT838Test {
18     @Test
19     public void testGroupingShadowing() throws Exception {
20         testGrouping("grouping.yang");
21     }
22
23     @Test
24     public void testGroupingPostShadowing() throws Exception {
25         testGrouping("grouping-post.yang");
26     }
27
28     @Test
29     public void testTypedefShadowing() throws Exception {
30         testTypedef("typedef.yang");
31     }
32
33     @Test
34     public void testTypedefPostShadowing() throws Exception {
35         testTypedef("typedef-post.yang");
36     }
37
38     private static void testGrouping(final String model) throws Exception {
39         try {
40             StmtTestUtils.parseYangSource("/bugs/YT838/" + model);
41             fail("Expected failure due to grouping identifier shadowing");
42         } catch (ReactorException e) {
43             final Throwable cause = e.getCause();
44             assertTrue(cause instanceof SourceException);
45             assertTrue(cause.getMessage().startsWith(
46                 "Duplicate name for grouping (grouping?revision=2017-12-20)foo [at "));
47         }
48     }
49
50     private static void testTypedef(final String model) throws Exception {
51         try {
52             StmtTestUtils.parseYangSource("/bugs/YT838/" + model);
53             fail("Expected failure due to type identifier shadowing");
54         } catch (ReactorException e) {
55             final Throwable cause = e.getCause();
56             assertTrue(cause instanceof SourceException);
57             assertTrue(cause.getMessage().startsWith(
58                 "Duplicate name for typedef (typedef?revision=2017-12-20)foo [at "));
59         }
60     }
61 }