2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2024 Ericsson
4 * Modifications Copyright (C) 2024 OpenInfra Foundation Europe
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
21 package org.oran.smo.yangtools.parser.model.statements.yang.test;
23 import static org.junit.Assert.assertTrue;
25 import java.util.Arrays;
27 import org.junit.Test;
29 import org.oran.smo.yangtools.parser.findings.ParserFindingType;
30 import org.oran.smo.yangtools.parser.model.statements.yang.YModule;
31 import org.oran.smo.yangtools.parser.testutils.YangTestCommon;
33 public class ImportTest extends YangTestCommon {
35 private static final String TEST_DIR = "src/test/resources/model-statements-yang/import-test/";
38 public void testTwoImportsWithoutRevision() {
40 parseAbsoluteImplementsYangModels(Arrays.asList(TEST_DIR + "import-twice-no-revisions-test-module.yang",
43 assertHasFindingOfType(ParserFindingType.P036_MODULE_IMPORTED_MULTIPLE_TIMES.toString());
45 final YModule module = getModule("import-twice-no-revisions-test-module");
46 assertTrue(module != null);
48 assertStatementHasFindingOfType(module.getImports().get(1), ParserFindingType.P036_MODULE_IMPORTED_MULTIPLE_TIMES
53 public void testFirstImportNoRevision() {
55 parseAbsoluteImplementsYangModels(Arrays.asList(TEST_DIR + "import-twice-first-no-revision-test-module.yang",
58 assertHasFindingOfType(ParserFindingType.P036_MODULE_IMPORTED_MULTIPLE_TIMES.toString());
60 final YModule module = getModule("import-twice-first-no-revision-test-module");
61 assertTrue(module != null);
63 assertStatementHasFindingOfType(module.getImports().get(1), ParserFindingType.P036_MODULE_IMPORTED_MULTIPLE_TIMES
68 public void testSecondImportNoRevision() {
70 parseAbsoluteImplementsYangModels(Arrays.asList(TEST_DIR + "import-twice-second-no-revision-test-module.yang",
73 assertHasFindingOfType(ParserFindingType.P036_MODULE_IMPORTED_MULTIPLE_TIMES.toString());
75 final YModule module = getModule("import-twice-second-no-revision-test-module");
76 assertTrue(module != null);
78 assertStatementHasFindingOfType(module.getImports().get(1), ParserFindingType.P036_MODULE_IMPORTED_MULTIPLE_TIMES
83 public void testBothHaveSameRevision() {
85 parseAbsoluteImplementsYangModels(Arrays.asList(TEST_DIR + "import-twice-same-revisions-test-module.yang",
88 assertHasFindingOfType(ParserFindingType.P036_MODULE_IMPORTED_MULTIPLE_TIMES.toString());
90 final YModule module = getModule("import-twice-same-revisions-test-module");
91 assertTrue(module != null);
93 assertStatementHasFindingOfType(module.getImports().get(1), ParserFindingType.P036_MODULE_IMPORTED_MULTIPLE_TIMES
98 public void testImportsItself() {
100 parseAbsoluteImplementsYangModels(Arrays.asList(TEST_DIR + "import-itself-test-module.yang"));
102 assertHasFindingOfType(ParserFindingType.P034_UNRESOLVABLE_IMPORT.toString());
104 final YModule module = getModule("import-itself-test-module");
105 assertTrue(module != null);
107 assertStatementHasFindingOfType(module.getImports().get(0), ParserFindingType.P034_UNRESOLVABLE_IMPORT.toString());
111 public void testUnresolvableNoRevisionImportNotInInput() {
113 parseAbsoluteImplementsYangModels(Arrays.asList(TEST_DIR + "unresolvable-import-no-revision-test-module.yang"));
115 assertHasFindingOfType(ParserFindingType.P034_UNRESOLVABLE_IMPORT.toString());
117 final YModule module = getModule("unresolvable-import-no-revision-test-module");
118 assertTrue(module != null);
120 assertStatementHasFindingOfType(module.getImports().get(0), ParserFindingType.P034_UNRESOLVABLE_IMPORT.toString());
124 public void testAmbiguousNoRevisionImport() {
126 parseAbsoluteImplementsYangModels(Arrays.asList(TEST_DIR + "unresolvable-import-ambiguous-test-module.yang",
127 ORIG_MODULES_PATH + "ietf-yang-types-2010-09-24.yang",
128 ORIG_MODULES_PATH + "ietf-yang-types-2019-11-04.yang"));
130 assertHasFindingOfType(ParserFindingType.P035_AMBIGUOUS_IMPORT.toString());
132 final YModule module = getModule("unresolvable-import-ambiguous-test-module");
133 assertTrue(module != null);
135 assertStatementHasFindingOfType(module.getImports().get(0), ParserFindingType.P035_AMBIGUOUS_IMPORT.toString());
139 public void testUnresolvableWithRevisionImportNotInInput() {
141 parseAbsoluteImplementsYangModels(Arrays.asList(TEST_DIR + "unresolvable-import-with-revision-test-module.yang"));
143 assertHasFindingOfType(ParserFindingType.P034_UNRESOLVABLE_IMPORT.toString());
145 final YModule module = getModule("unresolvable-import-with-revision-test-module");
146 assertTrue(module != null);
148 assertStatementHasFindingOfType(module.getImports().get(0), ParserFindingType.P034_UNRESOLVABLE_IMPORT.toString());
152 public void testUnresolvableWithWrongRevisionImport() {
154 parseAbsoluteImplementsYangModels(Arrays.asList(TEST_DIR + "unresolvable-import-wrong-revision-test-module.yang",
155 ORIG_MODULES_PATH + "ietf-yang-types-2010-09-24.yang"));
157 assertHasFindingOfType(ParserFindingType.P034_UNRESOLVABLE_IMPORT.toString());
159 final YModule module = getModule("unresolvable-import-wrong-revision-test-module");
160 assertTrue(module != null);
162 assertStatementHasFindingOfType(module.getImports().get(0), ParserFindingType.P034_UNRESOLVABLE_IMPORT.toString());