Remove ImportResolutionMode.SEMVER_LATEST
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / YT1339Test.java
1 /*
2  * Copyright (c) 2021 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.yang.stmt;
9
10 import static org.hamcrest.CoreMatchers.startsWith;
11 import static org.hamcrest.MatcherAssert.assertThat;
12
13 import org.junit.Test;
14 import org.opendaylight.yangtools.yang.common.YangVersion;
15 import org.opendaylight.yangtools.yang.parser.spi.source.YangVersionLinkageException;
16
17 /**
18  * Tests for {@code MUST NOT} statements around include/import interop of RFC6020 and RFC7950, as per
19  * <a href="https://datatracker.ietf.org/doc/html/rfc7950#section-12">RFC7950 section 12</a>.
20  */
21 public class YT1339Test extends AbstractYangTest {
22     @Test
23     public void testInclude() {
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);
28     }
29
30     @Test
31     public 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");
35     }
36
37     @Test
38     public 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");
41     }
42
43     @Test
44     public void testImportNoRev() {
45         // no language forbidding imports without revision
46         assertEffectiveModelDir("/bugs/YT1339/import-norev");
47     }
48
49     private static void assertFailedImport(final String subdir) {
50         assertThat(assertYangVersionLinkageException(subdir),
51             startsWith("Cannot import by revision version 1.1 module new [at "));
52     }
53
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 "));
57     }
58
59     private static String assertYangVersionLinkageException(final String subdir) {
60         return assertExceptionDir("/bugs/YT1339/" + subdir, YangVersionLinkageException.class).getMessage();
61     }
62 }