Check rc:yang-data template name duplications
[yangtools.git] / parser / rfc8040-parser-support / src / test / java / org / opendaylight / yangtools / rfc8040 / parser / YT1482Test.java
1 /*
2  * Copyright (c) 2022 PANTHEON.tech, 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.rfc8040.parser;
9
10 import static org.hamcrest.CoreMatchers.startsWith;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
13 import static org.junit.jupiter.api.Assertions.assertThrows;
14
15 import org.junit.jupiter.api.Test;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
17 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
18
19 class YT1482Test extends AbstractYangDataTest {
20     @Test
21     void duplicateNamesAreRejected() throws Exception {
22         final var action = REACTOR.newBuild().addSources(IETF_RESTCONF_MODULE, sourceForResource("/yt1482.yang"));
23
24         final var ex = assertThrows(SomeModifiersUnresolvedException.class, action::buildEffective);
25         final var cause = assertInstanceOf(SourceException.class, ex.getCause());
26         assertThat(cause.getMessage(), startsWith("""
27             Error in module 'yt1482': cannot add 'YangDataName[module=QNameModule{ns=yt1482}, name=some]'. Node name \
28             collision: 'YangDataName[module=QNameModule{ns=yt1482}, name=some]' already declared at """));
29     }
30 }