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;
26 import java.util.Collections;
28 import org.junit.Test;
30 import org.oran.smo.yangtools.parser.findings.ParserFindingType;
31 import org.oran.smo.yangtools.parser.model.ConformanceType;
32 import org.oran.smo.yangtools.parser.model.statements.yang.CY;
33 import org.oran.smo.yangtools.parser.model.statements.yang.YContainer;
34 import org.oran.smo.yangtools.parser.model.statements.yang.YModule;
35 import org.oran.smo.yangtools.parser.testutils.YangTestCommon;
37 public class ConformanceTypeTest extends YangTestCommon {
40 public void test2ModulesImports() {
42 context.setFailFast(false);
43 context.setIgnoreImportedProtocolAccessibleObjects(false);
45 parseRelativeYangModels(Collections.<String> emptyList(), Arrays.asList("conformance-type-test/module1.yang",
46 "conformance-type-test/module2.yang"));
48 assertHasFindingOfType(ParserFindingType.P005_NO_IMPLEMENTS.toString());
50 final YModule module1 = getModule("module1");
51 final YModule module2 = getModule("module2");
53 assertTrue(module1 != null);
54 assertTrue(module2 != null);
56 final YContainer container1 = getContainer(module1, "cont1");
57 final YContainer container2 = getContainer(module2, "cont2");
59 assertTrue(container1.getEffectiveConformanceType() == ConformanceType.IMPORT);
60 assertTrue(container2.getEffectiveConformanceType() == ConformanceType.IMPORT);
62 final YContainer contGroup2InModule1 = getContainer(module1, "contgroup2");
63 final YContainer contGroup2InModule2 = getContainer(module2, "contgroup2");
65 assertTrue(contGroup2InModule1.getEffectiveConformanceType() == ConformanceType.IMPORT);
66 assertTrue(contGroup2InModule2.getEffectiveConformanceType() == ConformanceType.IMPORT);
70 public void test2ModulesImplements() {
72 parseRelativeImplementsYangModels(Arrays.asList("conformance-type-test/module1.yang",
73 "conformance-type-test/module2.yang"));
75 assertHasNotFindingOfType(ParserFindingType.P005_NO_IMPLEMENTS.toString());
77 final YModule module1 = getModule("module1");
78 final YModule module2 = getModule("module2");
80 assertTrue(module1 != null);
81 assertTrue(module2 != null);
83 final YContainer container1 = getContainer(module1, "cont1");
84 final YContainer container2 = getContainer(module2, "cont2");
86 assertTrue(container1.getEffectiveConformanceType() == ConformanceType.IMPLEMENT);
87 assertTrue(container2.getEffectiveConformanceType() == ConformanceType.IMPLEMENT);
89 final YContainer contGroup2InModule1 = getContainer(module1, "contgroup2");
90 final YContainer contGroup2InModule2 = getContainer(module2, "contgroup2");
92 assertTrue(contGroup2InModule1.getEffectiveConformanceType() == ConformanceType.IMPLEMENT);
93 assertTrue(contGroup2InModule2.getEffectiveConformanceType() == ConformanceType.IMPLEMENT);
97 public void test2ModulesOneImplementsOneImports() {
99 context.setIgnoreImportedProtocolAccessibleObjects(false);
100 parseRelativeYangModels(Arrays.asList("conformance-type-test/module1.yang"), Arrays.asList(
101 "conformance-type-test/module2.yang"));
103 final YModule module1 = getModule("module1");
104 final YModule module2 = getModule("module2");
106 assertTrue(module1 != null);
107 assertTrue(module2 != null);
109 final YContainer container1 = getContainer(module1, "cont1");
110 final YContainer container2 = getContainer(module2, "cont2");
112 assertTrue(container1.getEffectiveConformanceType() == ConformanceType.IMPLEMENT);
113 assertTrue(container2.getEffectiveConformanceType() == ConformanceType.IMPORT);
115 final YContainer contGroup2InModule1 = getContainer(module1, "contgroup2");
116 final YContainer contGroup2InModule2 = getContainer(module2, "contgroup2");
118 assertTrue(contGroup2InModule1.getEffectiveConformanceType() == ConformanceType.IMPLEMENT);
119 assertTrue(contGroup2InModule2.getEffectiveConformanceType() == ConformanceType.IMPORT);
123 * Tests for "ignoreImportedProtocolAccessibleObjects"
127 public void test2ModulesImplementsIgnoreImportedProtocolAccessibleObjects() {
129 context.setIgnoreImportedProtocolAccessibleObjects(true);
131 parseRelativeImplementsYangModels(Arrays.asList("conformance-type-test/module1.yang",
132 "conformance-type-test/module2.yang"));
137 final YModule module1 = getModule("module1");
138 final YModule module2 = getModule("module2");
140 assertTrue(module1 != null);
141 assertTrue(module2 != null);
143 final YContainer container1 = getContainer(module1, "cont1");
144 final YContainer container2 = getContainer(module2, "cont2");
145 assertTrue(container1.getEffectiveConformanceType() == ConformanceType.IMPLEMENT);
146 assertTrue(container2.getEffectiveConformanceType() == ConformanceType.IMPLEMENT);
148 final YContainer contGroup2InModule1 = getContainer(module1, "contgroup2");
149 final YContainer contGroup2InModule2 = getContainer(module2, "contgroup2");
150 assertTrue(contGroup2InModule1.getEffectiveConformanceType() == ConformanceType.IMPLEMENT);
151 assertTrue(contGroup2InModule2.getEffectiveConformanceType() == ConformanceType.IMPLEMENT);
153 assertTrue(getChild(module2, CY.RPC, "rpc1") != null);
154 assertTrue(getChild(module2, CY.LIST, "list1") != null);
156 assertTrue(getChild(module2, CY.FEATURE, "feature1") != null);
157 assertTrue(getChild(module2, "this:ext", "ext1") != null);
161 public void test2ModulesOneImplementsOneImportsIgnoreImportedProtocolAccessibleObjects() {
163 context.setIgnoreImportedProtocolAccessibleObjects(true);
165 parseRelativeYangModels(Arrays.asList("conformance-type-test/module1.yang"), Arrays.asList(
166 "conformance-type-test/module2.yang"));
168 final YModule module1 = getModule("module1");
169 final YModule module2 = getModule("module2");
171 assertTrue(module1 != null);
172 assertTrue(module2 != null);
174 final YContainer container1 = getContainer(module1, "cont1");
175 final YContainer container2 = getContainer(module2, "cont2");
177 assertTrue(container1.getEffectiveConformanceType() == ConformanceType.IMPLEMENT);
178 assertTrue(container2 == null);
180 final YContainer contGroup2InModule1 = getContainer(module1, "contgroup2");
181 final YContainer contGroup2InModule2 = getContainer(module2, "contgroup2");
183 assertTrue(contGroup2InModule1.getEffectiveConformanceType() == ConformanceType.IMPLEMENT);
184 assertTrue(contGroup2InModule2 == null);
186 assertTrue(getChild(module2, CY.RPC, "rpc1") == null);
187 assertTrue(getChild(module2, CY.LIST, "list1") == null);
189 assertTrue(getChild(module2, CY.FEATURE, "feature1") != null);
190 assertTrue(getChild(module2, "this:ext", "ext1") != null);
193 // - - - - test crossing conformance type for module / submodule
196 public void test2ModuleAndSubmoduleSameConformance() {
198 parseRelativeYangModels(Arrays.asList("conformance-type-test/including-module.yang",
199 "conformance-type-test/submodule.yang"), Collections.emptyList());
201 final YModule module = getModule("including-module");
202 assertTrue(module != null);
208 public void test2ModuleAndSubmoduleDifferentConformance() {
210 parseRelativeYangModels(Arrays.asList("conformance-type-test/including-module.yang"), Arrays.asList(
211 "conformance-type-test/submodule.yang"));
213 final YModule module = getModule("including-module");
214 assertTrue(module != null);
216 assertHasFindingOfType(ParserFindingType.P006_IMPLEMENT_IMPORT_MISMATCH.toString());