2 * Copyright (c) 2021 PANTHEON.tech, 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.assertThrows;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.common.YangVersion;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
18 import org.opendaylight.yangtools.yang.parser.spi.source.YangVersionLinkageException;
21 * Tests for {@code MUST NOT} statements around include/import interop of RFC6020 and RFC7950, as per
22 * <a href="https://datatracker.ietf.org/doc/html/rfc7950#section-12">RFC7950 section 12</a>.
24 public class YT1339Test {
26 public void testInclude() {
27 // A YANG version 1.1 module MUST NOT include a YANG version 1 submodule,
28 assertFailedInclude("old-sub", YangVersion.VERSION_1, YangVersion.VERSION_1_1);
29 // ... and a YANG version 1 module MUST NOT include a YANG version 1.1 submodule
30 assertFailedInclude("new-sub", YangVersion.VERSION_1_1, YangVersion.VERSION_1);
34 public void testImportNewByRev() throws Exception {
35 // A YANG version 1 module or submodule MUST NOT import a YANG version 1.1 module by revision.
36 assertFailedImport("import-rev");
37 assertFailedImport("import-rev-sub");
41 public void testImportOldByRev() throws Exception {
42 // A YANG version 1.1 module or submodule MAY import a YANG version 1 module by revision.
47 public void testImportNoRev() throws Exception {
48 // no language forbidding imports without revision
49 compile("import-norev");
52 private static void assertFailedImport(final String subdir) {
53 assertThat(assertYangVersionLinkageException(subdir),
54 startsWith("Cannot import by revision version 1.1 module new [at "));
57 private static void assertFailedInclude(final String subdir, final YangVersion subVer, final YangVersion modVer) {
58 assertThat(assertYangVersionLinkageException(subdir),
59 startsWith("Cannot include a version " + subVer + " submodule in a version " + modVer + " module [at "));
62 private static String assertYangVersionLinkageException(final String subdir) {
63 final var cause = assertThrows(ReactorException.class, () -> compile(subdir)).getCause();
64 assertThat(cause, instanceOf(YangVersionLinkageException.class));
65 return cause.getMessage();
68 private static void compile(final String subdir) throws Exception {
69 StmtTestUtils.parseYangSources("/bugs/YT1339/" + subdir);