deefa72185e253b2aad756d1c8ef56893a44eeea
[smo/teiv.git] /
1 /*
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
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  *  SPDX-License-Identifier: Apache-2.0
19  *  ============LICENSE_END=========================================================
20  */
21 package org.oran.smo.yangtools.parser.model.statements.yang.test;
22
23 import static org.junit.Assert.assertTrue;
24
25 import java.util.Arrays;
26
27 import org.junit.Test;
28
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;
32
33 public class IncludeTest extends YangTestCommon {
34
35     @Test
36     public void testIncludeWithoutRevisionSubmoduleNotInInput() {
37
38         parseRelativeImplementsYangModels(Arrays.asList(
39                 "include-test/include-test-module-correct-submodule-no-revision.yang"));
40
41         assertHasFindingOfType(ParserFindingType.P037_UNRESOLVABLE_INCLUDE.toString());
42
43         final YModule module = getModule("include-test-module");
44         assertTrue(module != null);
45
46         assertStatementHasFindingOfType(module.getIncludes().get(0), ParserFindingType.P037_UNRESOLVABLE_INCLUDE
47                 .toString());
48     }
49
50     @Test
51     public void testIncludeWithoutRevisionTwoSubmodulesInInput() {
52
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"));
56
57         assertHasFindingOfType(ParserFindingType.P038_AMBIGUOUS_INCLUDE.toString());
58
59         final YModule module = getModule("include-test-module");
60         assertTrue(module != null);
61
62         assertStatementHasFindingOfType(module.getIncludes().get(0), ParserFindingType.P038_AMBIGUOUS_INCLUDE.toString());
63     }
64
65     @Test
66     public void testIncludeIsModuleNotSubmodule() {
67
68         parseRelativeImplementsYangModels(Arrays.asList(
69                 "include-test/include-test-module-correct-submodule-no-revision.yang",
70                 "include-test/other-test-module.yang"));
71
72         assertHasFindingOfType(ParserFindingType.P045_NOT_A_SUBMODULE.toString());
73
74         final YModule module = getModule("include-test-module");
75         assertTrue(module != null);
76
77         assertStatementHasFindingOfType(module.getIncludes().get(0), ParserFindingType.P045_NOT_A_SUBMODULE.toString());
78     }
79
80     @Test
81     public void testIncludeYangVersionMismatch() {
82
83         parseRelativeImplementsYangModels(Arrays.asList(
84                 "include-test/include-test-module-correct-submodule-no-revision.yang",
85                 "include-test/test-submodule-1999-01-01.yang"));
86
87         assertHasFindingOfType(ParserFindingType.P041_DIFFERENT_YANG_VERSIONS_BETWEEN_MODULE_AND_SUBMODULES.toString());
88
89         final YModule module = getModule("include-test-module");
90         assertTrue(module != null);
91
92         assertStatementHasFindingOfType(module.getIncludes().get(0),
93                 ParserFindingType.P041_DIFFERENT_YANG_VERSIONS_BETWEEN_MODULE_AND_SUBMODULES.toString());
94     }
95
96     @Test
97     public void testIncludeSubmoduleBelongsToDifferentModule() {
98
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"));
102
103         assertHasFindingOfType(ParserFindingType.P047_SUBMODULE_OWNERSHIP_MISMATCH.toString());
104
105         final YModule module = getModule("include-test-module");
106         assertTrue(module != null);
107
108         assertStatementHasFindingOfType(module.getIncludes().get(0), ParserFindingType.P047_SUBMODULE_OWNERSHIP_MISMATCH
109                 .toString());
110     }
111
112 }