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.schema.test;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertNull;
27 import java.util.Arrays;
28 import java.util.Collections;
29 import java.util.List;
31 import org.junit.Test;
33 import org.oran.smo.yangtools.parser.model.statements.yang.YContainer;
34 import org.oran.smo.yangtools.parser.model.statements.yang.YLeaf;
35 import org.oran.smo.yangtools.parser.model.statements.yang.YModule;
36 import org.oran.smo.yangtools.parser.testutils.YangTestCommon;
38 public class RemoveProtocolAccessibleObjectsTest extends YangTestCommon {
40 private static final String TEST_DIR = "src/test/resources/model-schema/remove-protocol-accessible-objects/";
42 private static final String BASE_NS = "test:base-module";
43 private static final String OTHER_NS = "test:other-module";
44 private static final String AUGMENTING_NS = "test:augmenting-module";
47 public void test___ignore_true___base_other_implement() {
49 final List<String> absoluteImplementsFilePath = Arrays.asList(TEST_DIR + "base-module.yang",
50 TEST_DIR + "other-module.yang");
51 final List<String> absoluteImportsFilePath = Collections.emptyList();
53 context.setIgnoreImportedProtocolAccessibleObjects(true);
54 parseAbsoluteYangModels(absoluteImplementsFilePath, absoluteImportsFilePath);
58 final YModule baseModule = getModule("base-module");
59 assertNotNull(baseModule);
61 final YContainer cont1 = getContainer(baseModule, "cont1");
63 assertEquals(BASE_NS, cont1.getEffectiveNamespace());
64 final YContainer cont2 = getContainer(baseModule, "cont2");
66 assertEquals(BASE_NS, cont2.getEffectiveNamespace());
68 final YModule otherModule = getModule("other-module");
69 assertNotNull(otherModule);
71 final YContainer cont5 = getContainer(otherModule, "cont5");
73 assertEquals(OTHER_NS, cont5.getEffectiveNamespace());
74 final YContainer cont6 = getContainer(otherModule, "cont6");
76 assertEquals(OTHER_NS, cont6.getEffectiveNamespace());
80 public void test___ignore_true___base_implements_other_imports() {
82 final List<String> absoluteImplementsFilePath = Arrays.asList(TEST_DIR + "base-module.yang");
83 final List<String> absoluteImportsFilePath = Arrays.asList(TEST_DIR + "other-module.yang");
85 context.setIgnoreImportedProtocolAccessibleObjects(true);
86 parseAbsoluteYangModels(absoluteImplementsFilePath, absoluteImportsFilePath);
90 final YModule baseModule = getModule("base-module");
91 assertNotNull(baseModule);
93 final YContainer cont1 = getContainer(baseModule, "cont1");
95 final YContainer cont2 = getContainer(baseModule, "cont2");
98 final YModule otherModule = getModule("other-module");
99 assertNotNull(otherModule);
101 final YContainer cont5 = getContainer(otherModule, "cont5"); // Shouldn't exist
103 final YContainer cont6 = getContainer(otherModule, "cont6"); // Shouldn't exist
108 public void test___ignore_false___base_implements___other_imports() {
110 final List<String> absoluteImplementsFilePath = Arrays.asList(TEST_DIR + "base-module.yang");
111 final List<String> absoluteImportsFilePath = Arrays.asList(TEST_DIR + "other-module.yang");
113 context.setIgnoreImportedProtocolAccessibleObjects(false);
114 parseAbsoluteYangModels(absoluteImplementsFilePath, absoluteImportsFilePath);
118 final YModule baseModule = getModule("base-module");
119 assertNotNull(baseModule);
121 final YContainer cont1 = getContainer(baseModule, "cont1");
122 assertNotNull(cont1);
123 final YContainer cont2 = getContainer(baseModule, "cont2");
124 assertNotNull(cont2);
126 final YModule otherModule = getModule("other-module");
127 assertNotNull(otherModule);
129 final YContainer cont5 = getContainer(otherModule, "cont5"); // Should exist as flag = false
130 assertNotNull(cont5);
131 final YContainer cont6 = getContainer(otherModule, "cont6"); // Should exist as flag = false
132 assertNotNull(cont6);
136 public void test___ignore_true___base_other_augments_implement() {
138 final List<String> absoluteImplementsFilePath = Arrays.asList(TEST_DIR + "base-module.yang",
139 TEST_DIR + "other-module.yang", TEST_DIR + "augmenting-module.yang");
140 final List<String> absoluteImportsFilePath = Collections.emptyList();
142 context.setIgnoreImportedProtocolAccessibleObjects(true);
143 parseAbsoluteYangModels(absoluteImplementsFilePath, absoluteImportsFilePath);
147 final YModule baseModule = getModule("base-module");
148 assertNotNull(baseModule);
150 final YContainer cont1 = getContainer(baseModule, "cont1");
151 assertNotNull(cont1);
152 assertEquals(BASE_NS, cont1.getEffectiveNamespace());
153 final YLeaf leaf11 = getLeaf(cont1, "leaf11");
154 assertNotNull(leaf11);
155 assertEquals(BASE_NS, leaf11.getEffectiveNamespace());
156 final YLeaf leaf12 = getLeaf(cont1, "leaf12");
157 assertNotNull(leaf12);
158 assertEquals(AUGMENTING_NS, leaf12.getEffectiveNamespace());
160 final YContainer cont2 = getContainer(baseModule, "cont2");
161 assertNotNull(cont2);
162 assertEquals(BASE_NS, cont2.getEffectiveNamespace());
164 final YModule otherModule = getModule("other-module");
165 assertNotNull(otherModule);
167 final YContainer cont5 = getContainer(otherModule, "cont5");
168 assertNotNull(cont5);
169 assertEquals(OTHER_NS, cont5.getEffectiveNamespace());
170 final YLeaf leaf51 = getLeaf(cont5, "leaf51");
171 assertNotNull(leaf51);
172 assertEquals(OTHER_NS, leaf51.getEffectiveNamespace());
173 final YLeaf leaf52 = getLeaf(cont5, "leaf52");
174 assertNotNull(leaf52);
175 assertEquals(AUGMENTING_NS, leaf52.getEffectiveNamespace());
177 final YContainer cont6 = getContainer(otherModule, "cont6");
178 assertNotNull(cont6);
179 assertEquals(OTHER_NS, cont6.getEffectiveNamespace());
183 public void test___ignore_true___base_other_implement___augments_imports() {
185 final List<String> absoluteImplementsFilePath = Arrays.asList(TEST_DIR + "base-module.yang",
186 TEST_DIR + "other-module.yang");
187 final List<String> absoluteImportsFilePath = Arrays.asList(TEST_DIR + "augmenting-module.yang");
189 context.setIgnoreImportedProtocolAccessibleObjects(true);
190 parseAbsoluteYangModels(absoluteImplementsFilePath, absoluteImportsFilePath);
194 final YModule baseModule = getModule("base-module");
195 assertNotNull(baseModule);
197 final YContainer cont1 = getContainer(baseModule, "cont1");
198 assertNotNull(cont1);
199 assertEquals(BASE_NS, cont1.getEffectiveNamespace());
200 final YLeaf leaf11 = getLeaf(cont1, "leaf11");
201 assertNotNull(leaf11);
202 assertEquals(BASE_NS, leaf11.getEffectiveNamespace());
203 final YLeaf leaf12 = getLeaf(cont1, "leaf12");
206 final YContainer cont2 = getContainer(baseModule, "cont2");
207 assertNotNull(cont2);
208 assertEquals(BASE_NS, cont2.getEffectiveNamespace());
210 final YModule otherModule = getModule("other-module");
211 assertNotNull(otherModule);
213 final YContainer cont5 = getContainer(otherModule, "cont5");
214 assertNotNull(cont5);
215 assertEquals(OTHER_NS, cont5.getEffectiveNamespace());
216 final YLeaf leaf51 = getLeaf(cont5, "leaf51");
217 assertNotNull(leaf51);
218 assertEquals(OTHER_NS, leaf51.getEffectiveNamespace());
219 final YLeaf leaf52 = getLeaf(cont5, "leaf52");
222 final YContainer cont6 = getContainer(otherModule, "cont6");
223 assertNotNull(cont6);
224 assertEquals(OTHER_NS, cont6.getEffectiveNamespace());
228 public void test___ignore_false___base_other_implement___augments_imports() {
230 final List<String> absoluteImplementsFilePath = Arrays.asList(TEST_DIR + "base-module.yang",
231 TEST_DIR + "other-module.yang");
232 final List<String> absoluteImportsFilePath = Arrays.asList(TEST_DIR + "augmenting-module.yang");
234 context.setIgnoreImportedProtocolAccessibleObjects(false);
235 parseAbsoluteYangModels(absoluteImplementsFilePath, absoluteImportsFilePath);
239 final YModule baseModule = getModule("base-module");
240 assertNotNull(baseModule);
242 final YContainer cont1 = getContainer(baseModule, "cont1");
243 assertNotNull(cont1);
244 assertEquals(BASE_NS, cont1.getEffectiveNamespace());
245 final YLeaf leaf11 = getLeaf(cont1, "leaf11");
246 assertNotNull(leaf11);
247 assertEquals(BASE_NS, leaf11.getEffectiveNamespace());
248 final YLeaf leaf12 = getLeaf(cont1, "leaf12");
249 assertNotNull(leaf12);
250 assertEquals(AUGMENTING_NS, leaf12.getEffectiveNamespace());
252 final YContainer cont2 = getContainer(baseModule, "cont2");
253 assertNotNull(cont2);
254 assertEquals(BASE_NS, cont2.getEffectiveNamespace());
256 final YModule otherModule = getModule("other-module");
257 assertNotNull(otherModule);
259 final YContainer cont5 = getContainer(otherModule, "cont5");
260 assertNotNull(cont5);
261 assertEquals(OTHER_NS, cont5.getEffectiveNamespace());
262 final YLeaf leaf51 = getLeaf(cont5, "leaf51");
263 assertNotNull(leaf51);
264 assertEquals(OTHER_NS, leaf51.getEffectiveNamespace());
265 final YLeaf leaf52 = getLeaf(cont5, "leaf52");
266 assertNotNull(leaf52);
267 assertEquals(AUGMENTING_NS, leaf52.getEffectiveNamespace());
269 final YContainer cont6 = getContainer(otherModule, "cont6");
270 assertNotNull(cont6);
271 assertEquals(OTHER_NS, cont6.getEffectiveNamespace());