3061fb16bcd98c181584ef14990485dfa71b2ff7
[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.schema.test;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertNull;
26
27 import java.util.Arrays;
28 import java.util.Collections;
29 import java.util.List;
30
31 import org.junit.Test;
32
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;
37
38 public class RemoveProtocolAccessibleObjectsTest extends YangTestCommon {
39
40     private static final String TEST_DIR = "src/test/resources/model-schema/remove-protocol-accessible-objects/";
41
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";
45
46     @Test
47     public void test___ignore_true___base_other_implement() {
48
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();
52
53         context.setIgnoreImportedProtocolAccessibleObjects(true);
54         parseAbsoluteYangModels(absoluteImplementsFilePath, absoluteImportsFilePath);
55
56         assertNoFindings();
57
58         final YModule baseModule = getModule("base-module");
59         assertNotNull(baseModule);
60
61         final YContainer cont1 = getContainer(baseModule, "cont1");
62         assertNotNull(cont1);
63         assertEquals(BASE_NS, cont1.getEffectiveNamespace());
64         final YContainer cont2 = getContainer(baseModule, "cont2");
65         assertNotNull(cont2);
66         assertEquals(BASE_NS, cont2.getEffectiveNamespace());
67
68         final YModule otherModule = getModule("other-module");
69         assertNotNull(otherModule);
70
71         final YContainer cont5 = getContainer(otherModule, "cont5");
72         assertNotNull(cont5);
73         assertEquals(OTHER_NS, cont5.getEffectiveNamespace());
74         final YContainer cont6 = getContainer(otherModule, "cont6");
75         assertNotNull(cont6);
76         assertEquals(OTHER_NS, cont6.getEffectiveNamespace());
77     }
78
79     @Test
80     public void test___ignore_true___base_implements_other_imports() {
81
82         final List<String> absoluteImplementsFilePath = Arrays.asList(TEST_DIR + "base-module.yang");
83         final List<String> absoluteImportsFilePath = Arrays.asList(TEST_DIR + "other-module.yang");
84
85         context.setIgnoreImportedProtocolAccessibleObjects(true);
86         parseAbsoluteYangModels(absoluteImplementsFilePath, absoluteImportsFilePath);
87
88         assertNoFindings();
89
90         final YModule baseModule = getModule("base-module");
91         assertNotNull(baseModule);
92
93         final YContainer cont1 = getContainer(baseModule, "cont1");
94         assertNotNull(cont1);
95         final YContainer cont2 = getContainer(baseModule, "cont2");
96         assertNotNull(cont2);
97
98         final YModule otherModule = getModule("other-module");
99         assertNotNull(otherModule);
100
101         final YContainer cont5 = getContainer(otherModule, "cont5");            // Shouldn't exist
102         assertNull(cont5);
103         final YContainer cont6 = getContainer(otherModule, "cont6");            // Shouldn't exist
104         assertNull(cont6);
105     }
106
107     @Test
108     public void test___ignore_false___base_implements___other_imports() {
109
110         final List<String> absoluteImplementsFilePath = Arrays.asList(TEST_DIR + "base-module.yang");
111         final List<String> absoluteImportsFilePath = Arrays.asList(TEST_DIR + "other-module.yang");
112
113         context.setIgnoreImportedProtocolAccessibleObjects(false);
114         parseAbsoluteYangModels(absoluteImplementsFilePath, absoluteImportsFilePath);
115
116         assertNoFindings();
117
118         final YModule baseModule = getModule("base-module");
119         assertNotNull(baseModule);
120
121         final YContainer cont1 = getContainer(baseModule, "cont1");
122         assertNotNull(cont1);
123         final YContainer cont2 = getContainer(baseModule, "cont2");
124         assertNotNull(cont2);
125
126         final YModule otherModule = getModule("other-module");
127         assertNotNull(otherModule);
128
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);
133     }
134
135     @Test
136     public void test___ignore_true___base_other_augments_implement() {
137
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();
141
142         context.setIgnoreImportedProtocolAccessibleObjects(true);
143         parseAbsoluteYangModels(absoluteImplementsFilePath, absoluteImportsFilePath);
144
145         assertNoFindings();
146
147         final YModule baseModule = getModule("base-module");
148         assertNotNull(baseModule);
149
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());
159
160         final YContainer cont2 = getContainer(baseModule, "cont2");
161         assertNotNull(cont2);
162         assertEquals(BASE_NS, cont2.getEffectiveNamespace());
163
164         final YModule otherModule = getModule("other-module");
165         assertNotNull(otherModule);
166
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());
176
177         final YContainer cont6 = getContainer(otherModule, "cont6");
178         assertNotNull(cont6);
179         assertEquals(OTHER_NS, cont6.getEffectiveNamespace());
180     }
181
182     @Test
183     public void test___ignore_true___base_other_implement___augments_imports() {
184
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");
188
189         context.setIgnoreImportedProtocolAccessibleObjects(true);
190         parseAbsoluteYangModels(absoluteImplementsFilePath, absoluteImportsFilePath);
191
192         assertNoFindings();
193
194         final YModule baseModule = getModule("base-module");
195         assertNotNull(baseModule);
196
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");
204         assertNull(leaf12);
205
206         final YContainer cont2 = getContainer(baseModule, "cont2");
207         assertNotNull(cont2);
208         assertEquals(BASE_NS, cont2.getEffectiveNamespace());
209
210         final YModule otherModule = getModule("other-module");
211         assertNotNull(otherModule);
212
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");
220         assertNull(leaf52);
221
222         final YContainer cont6 = getContainer(otherModule, "cont6");
223         assertNotNull(cont6);
224         assertEquals(OTHER_NS, cont6.getEffectiveNamespace());
225     }
226
227     @Test
228     public void test___ignore_false___base_other_implement___augments_imports() {
229
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");
233
234         context.setIgnoreImportedProtocolAccessibleObjects(false);
235         parseAbsoluteYangModels(absoluteImplementsFilePath, absoluteImportsFilePath);
236
237         assertNoFindings();
238
239         final YModule baseModule = getModule("base-module");
240         assertNotNull(baseModule);
241
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());
251
252         final YContainer cont2 = getContainer(baseModule, "cont2");
253         assertNotNull(cont2);
254         assertEquals(BASE_NS, cont2.getEffectiveNamespace());
255
256         final YModule otherModule = getModule("other-module");
257         assertNotNull(otherModule);
258
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());
268
269         final YContainer cont6 = getContainer(otherModule, "cont6");
270         assertNotNull(cont6);
271         assertEquals(OTHER_NS, cont6.getEffectiveNamespace());
272     }
273 }