BUG-7954: identify source of the offending statement
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug7424Test.java
1 /*
2  * Copyright (c) 2017 Cisco Systems, Inc. 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.SomeModifiersUnresolvedException;
15
16 public class Bug7424Test {
17     @Test
18     public void testRpc() throws Exception {
19         try {
20             StmtTestUtils.parseYangSource("/bugs/bug7424/foo-rpc.yang");
21             fail("Test should fail due to invalid yang model.");
22         } catch (final SomeModifiersUnresolvedException e) {
23             assertTrue(e.getCause().getMessage().startsWith(
24                         "Error in module 'foo': cannot add '(foo?revision=1970-01-01)name'. "
25                         + "Node name collision: '(foo?revision=1970-01-01)name' already declared"));
26         }
27     }
28
29     @Test
30     public void testNotification() throws Exception {
31         try {
32             StmtTestUtils.parseYangSource("/bugs/bug7424/foo-notification.yang");
33             fail("Test should fail due to invalid yang model.");
34         } catch (final SomeModifiersUnresolvedException e) {
35             assertTrue(e.getCause().getMessage().startsWith(
36                         "Error in module 'foo': cannot add '(foo?revision=1970-01-01)name'. "
37                         + "Node name collision: '(foo?revision=1970-01-01)name' already declared"));
38         }
39     }
40
41     @Test
42     public void testData() throws Exception {
43         try {
44             StmtTestUtils.parseYangSource("/bugs/bug7424/foo-data.yang");
45             fail("Test should fail due to invalid yang model.");
46         } catch (final SomeModifiersUnresolvedException e) {
47             assertTrue(e.getCause().getMessage().startsWith(
48                         "Error in module 'foo': cannot add '(foo?revision=1970-01-01)name'. "
49                         + "Node name collision: '(foo?revision=1970-01-01)name' already declared"));
50         }
51     }
52
53     @Test
54     public void testRpcUses() throws Exception {
55         try {
56             StmtTestUtils.parseYangSource("/bugs/bug7424/foo-rpc-uses.yang");
57             fail("Test should fail due to invalid yang model.");
58         } catch (final SomeModifiersUnresolvedException e) {
59             assertTrue(e.getCause().getMessage().startsWith(
60                         "Error in module 'foo': cannot add '(foo?revision=1970-01-01)name'. "
61                         + "Node name collision: '(foo?revision=1970-01-01)name' already declared"));
62         }
63     }
64 }