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 IncludeTest extends YangTestCommon {
36 public void testIncludeWithoutRevisionSubmoduleNotInInput() {
38 parseRelativeImplementsYangModels(Arrays.asList(
39 "include-test/include-test-module-correct-submodule-no-revision.yang"));
41 assertHasFindingOfType(ParserFindingType.P037_UNRESOLVABLE_INCLUDE.toString());
43 final YModule module = getModule("include-test-module");
44 assertTrue(module != null);
46 assertStatementHasFindingOfType(module.getIncludes().get(0), ParserFindingType.P037_UNRESOLVABLE_INCLUDE
51 public void testIncludeWithoutRevisionTwoSubmodulesInInput() {
53 parseRelativeImplementsYangModels(Arrays.asList(
54 "include-test/include-test-module-correct-submodule-no-revision.yang",
55 "include-test/test-submodule-1999-01-01.yang", "include-test/test-submodule-2020-10-02.yang"));
57 assertHasFindingOfType(ParserFindingType.P038_AMBIGUOUS_INCLUDE.toString());
59 final YModule module = getModule("include-test-module");
60 assertTrue(module != null);
62 assertStatementHasFindingOfType(module.getIncludes().get(0), ParserFindingType.P038_AMBIGUOUS_INCLUDE.toString());
66 public void testIncludeIsModuleNotSubmodule() {
68 parseRelativeImplementsYangModels(Arrays.asList(
69 "include-test/include-test-module-correct-submodule-no-revision.yang",
70 "include-test/other-test-module.yang"));
72 assertHasFindingOfType(ParserFindingType.P045_NOT_A_SUBMODULE.toString());
74 final YModule module = getModule("include-test-module");
75 assertTrue(module != null);
77 assertStatementHasFindingOfType(module.getIncludes().get(0), ParserFindingType.P045_NOT_A_SUBMODULE.toString());
81 public void testIncludeYangVersionMismatch() {
83 parseRelativeImplementsYangModels(Arrays.asList(
84 "include-test/include-test-module-correct-submodule-no-revision.yang",
85 "include-test/test-submodule-1999-01-01.yang"));
87 assertHasFindingOfType(ParserFindingType.P041_DIFFERENT_YANG_VERSIONS_BETWEEN_MODULE_AND_SUBMODULES.toString());
89 final YModule module = getModule("include-test-module");
90 assertTrue(module != null);
92 assertStatementHasFindingOfType(module.getIncludes().get(0),
93 ParserFindingType.P041_DIFFERENT_YANG_VERSIONS_BETWEEN_MODULE_AND_SUBMODULES.toString());
97 public void testIncludeSubmoduleBelongsToDifferentModule() {
99 parseRelativeImplementsYangModels(Arrays.asList(
100 "include-test/include-test-module-correct-submodule-no-revision.yang",
101 "include-test/test-submodule-belongs-to-other-module.yang"));
103 assertHasFindingOfType(ParserFindingType.P047_SUBMODULE_OWNERSHIP_MISMATCH.toString());
105 final YModule module = getModule("include-test-module");
106 assertTrue(module != null);
108 assertStatementHasFindingOfType(module.getIncludes().get(0), ParserFindingType.P047_SUBMODULE_OWNERSHIP_MISMATCH