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.startsWith;
11 import static org.hamcrest.MatcherAssert.assertThat;
13 import org.junit.jupiter.api.Test;
14 import org.opendaylight.yangtools.yang.common.YangVersion;
15 import org.opendaylight.yangtools.yang.parser.spi.source.YangVersionLinkageException;
18 * Tests for {@code MUST NOT} statements around include/import interop of RFC6020 and RFC7950, as per
19 * <a href="https://www.rfc-editor.org/rfc/rfc7950#section-12">RFC7950 section 12</a>.
21 class YT1339Test extends AbstractYangTest {
24 // A YANG version 1.1 module MUST NOT include a YANG version 1 submodule,
25 assertFailedInclude("old-sub", YangVersion.VERSION_1, YangVersion.VERSION_1_1);
26 // ... and a YANG version 1 module MUST NOT include a YANG version 1.1 submodule
27 assertFailedInclude("new-sub", YangVersion.VERSION_1_1, YangVersion.VERSION_1);
31 void testImportNewByRev() {
32 // A YANG version 1 module or submodule MUST NOT import a YANG version 1.1 module by revision.
33 assertFailedImport("import-rev");
34 assertFailedImport("import-rev-sub");
38 void testImportOldByRev() {
39 // A YANG version 1.1 module or submodule MAY import a YANG version 1 module by revision.
40 assertEffectiveModelDir("/bugs/YT1339/import");
44 void testImportNoRev() {
45 // no language forbidding imports without revision
46 assertEffectiveModelDir("/bugs/YT1339/import-norev");
49 private static void assertFailedImport(final String subdir) {
50 assertThat(assertYangVersionLinkageException(subdir),
51 startsWith("Cannot import by revision version 1.1 module new [at "));
54 private static void assertFailedInclude(final String subdir, final YangVersion subVer, final YangVersion modVer) {
55 assertThat(assertYangVersionLinkageException(subdir),
56 startsWith("Cannot include a version " + subVer + " submodule in a version " + modVer + " module [at "));
59 private static String assertYangVersionLinkageException(final String subdir) {
60 return assertExceptionDir("/bugs/YT1339/" + subdir, YangVersionLinkageException.class).getMessage();