8d27314b75f6504f41c64d51bd92d7a560811ebd
[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.test;
22
23 import static org.junit.Assert.assertTrue;
24
25 import java.util.Arrays;
26 import java.util.HashSet;
27 import java.util.Set;
28
29 import org.junit.Test;
30
31 import org.oran.smo.yangtools.parser.findings.ParserFindingType;
32 import org.oran.smo.yangtools.parser.model.statements.yang.YCase;
33 import org.oran.smo.yangtools.parser.model.statements.yang.YChoice;
34 import org.oran.smo.yangtools.parser.model.statements.yang.YContainer;
35 import org.oran.smo.yangtools.parser.model.statements.yang.YLeaf;
36 import org.oran.smo.yangtools.parser.model.statements.yang.YModule;
37 import org.oran.smo.yangtools.parser.model.util.YangFeature;
38 import org.oran.smo.yangtools.parser.testutils.YangTestCommon;
39
40 public class UnsatisfiedIfFeatureRemoveTest extends YangTestCommon {
41
42     private static final String MODULE1 = "src/test/resources/basics/unsatisfied-if-feature-remove-test/module1.yang";
43     private static final String MODULE2 = "src/test/resources/basics/unsatisfied-if-feature-remove-test/module2.yang";
44     private static final String SUBMODULE3 = "src/test/resources/basics/unsatisfied-if-feature-remove-test/submodule3.yang";
45
46     @Test
47     public void test_module1_no_removal_no_supported_features() {
48
49         severityCalculator.suppressFinding(ParserFindingType.P103_ILLEGAL_IF_FEATURE_SYNTAX.toString());
50         severityCalculator.suppressFinding(ParserFindingType.P132_GROUPING_NOT_USED.toString());
51         severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
52         severityCalculator.suppressFinding(ParserFindingType.P143_ENUM_WITHOUT_VALUE.toString());
53
54         parseAbsoluteImplementsYangModels(Arrays.asList(MODULE1, MODULE2, SUBMODULE3));
55
56         assertNoFindings();
57
58         final YModule module = getModule("module1");
59
60         final YContainer cont1 = getContainer(module, "cont1");
61         assertTrue(cont1 != null);
62
63         final YLeaf leaf11 = getLeaf(cont1, "leaf11");
64         assertTrue(leaf11 != null);
65
66         final YLeaf leaf12 = getLeaf(cont1, "leaf12");
67         assertTrue(leaf12 != null);
68
69         final YLeaf leaf13 = getLeaf(cont1, "leaf13");
70         assertTrue(leaf13 != null);
71
72         final YLeaf leaf14 = getLeaf(cont1, "leaf14");
73         assertTrue(leaf14 != null);
74     }
75
76     @Test
77     public void test_module1_no_removal_with_supported_features() {
78
79         final Set<YangFeature> supportedFeatures = new HashSet<>();
80         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature11"));
81         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature12"));
82         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature13"));
83         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature14"));
84
85         context.setSupportedFeatures(supportedFeatures);
86
87         severityCalculator.suppressFinding(ParserFindingType.P103_ILLEGAL_IF_FEATURE_SYNTAX.toString());
88         severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
89         severityCalculator.suppressFinding(ParserFindingType.P143_ENUM_WITHOUT_VALUE.toString());
90
91         parseAbsoluteImplementsYangModels(Arrays.asList(MODULE1, MODULE2, SUBMODULE3));
92
93         assertNoFindings();
94
95         final YModule module = getModule("module1");
96
97         final YContainer cont1 = getContainer(module, "cont1");
98         assertTrue(cont1 != null);
99
100         final YLeaf leaf11 = getLeaf(cont1, "leaf11");
101         assertTrue(leaf11 != null);
102
103         final YLeaf leaf12 = getLeaf(cont1, "leaf12");
104         assertTrue(leaf12 != null);
105
106         final YLeaf leaf13 = getLeaf(cont1, "leaf13");
107         assertTrue(leaf13 != null);
108
109         final YLeaf leaf14 = getLeaf(cont1, "leaf14");
110         assertTrue(leaf14 != null);
111     }
112
113     @Test
114     public void test_module1_with_removal_no_supported_features() {
115
116         final Set<YangFeature> supportedFeatures = new HashSet<>();
117         context.setSupportedFeatures(supportedFeatures);
118         context.setRemoveSchemaNodesNotSatisfyingIfFeature(true);
119
120         severityCalculator.suppressFinding(ParserFindingType.P103_ILLEGAL_IF_FEATURE_SYNTAX.toString());
121         severityCalculator.suppressFinding(ParserFindingType.P132_GROUPING_NOT_USED.toString());
122         severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
123         parseAbsoluteImplementsYangModels(Arrays.asList(MODULE1, MODULE2, SUBMODULE3));
124
125         assertNoFindings();
126
127         final YModule module = getModule("module1");
128
129         final YContainer cont1 = getContainer(module, "cont1");
130         assertTrue(cont1 != null);
131
132         assertTrue(getLeaf(cont1, "leaf11") == null);
133         assertTrue(getLeaf(cont1, "leaf12") == null);
134         assertTrue(getLeaf(cont1, "leaf13") == null);
135         assertTrue(getLeaf(cont1, "leaf14") == null);
136
137         final YContainer cont2 = getContainer(module, "cont2");
138         assertTrue(cont2 != null);
139         final YChoice choice21 = getChoice(cont2, "choice21");
140         assertTrue(choice21 != null);
141
142         assertTrue(getCase(choice21, "case211") == null);
143         assertTrue(getCase(choice21, "case212") == null);
144         assertTrue(getCase(choice21, "case213") == null);
145         assertTrue(getCase(choice21, "case214") == null);
146         assertTrue(getCase(choice21, "leaf215") == null);
147
148         final YContainer cont3 = getContainer(module, "cont3");
149         assertTrue(cont3 != null);
150
151         assertTrue(getLeaf(cont3, "leaf51") == null);
152         assertTrue(getLeaf(cont3, "leaf52") == null);
153         assertTrue(getLeaf(cont3, "leaf53") == null);
154     }
155
156     @Test
157     public void test_module1_with_removal_with_supported_features() {
158
159         final Set<YangFeature> supportedFeatures = new HashSet<>();
160         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature11"));
161         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature12"));
162         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature13"));
163         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature14"));
164
165         context.setSupportedFeatures(supportedFeatures);
166         context.setRemoveSchemaNodesNotSatisfyingIfFeature(true);
167
168         severityCalculator.suppressFinding(ParserFindingType.P103_ILLEGAL_IF_FEATURE_SYNTAX.toString());
169         severityCalculator.suppressFinding(ParserFindingType.P132_GROUPING_NOT_USED.toString());
170         severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
171         parseAbsoluteImplementsYangModels(Arrays.asList(MODULE1, MODULE2, SUBMODULE3));
172
173         assertNoFindings();
174
175         final YModule module = getModule("module1");
176
177         final YContainer cont1 = getContainer(module, "cont1");
178         assertTrue(cont1 != null);
179
180         final YLeaf leaf11 = getLeaf(cont1, "leaf11");
181         assertTrue(leaf11 != null);
182
183         final YLeaf leaf12 = getLeaf(cont1, "leaf12");
184         assertTrue(leaf12 != null);
185
186         final YLeaf leaf13 = getLeaf(cont1, "leaf13");
187         assertTrue(leaf13 != null);
188
189         final YLeaf leaf14 = getLeaf(cont1, "leaf14");
190         assertTrue(leaf14 != null);
191     }
192
193     @Test
194     public void test_module1_with_removal_with_feature11_only() {
195
196         final Set<YangFeature> supportedFeatures = new HashSet<>();
197         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature11"));
198
199         context.setSupportedFeatures(supportedFeatures);
200         context.setRemoveSchemaNodesNotSatisfyingIfFeature(true);
201
202         severityCalculator.suppressFinding(ParserFindingType.P103_ILLEGAL_IF_FEATURE_SYNTAX.toString());
203         severityCalculator.suppressFinding(ParserFindingType.P132_GROUPING_NOT_USED.toString());
204         severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
205         parseAbsoluteImplementsYangModels(Arrays.asList(MODULE1, MODULE2, SUBMODULE3));
206
207         assertNoFindings();
208
209         final YModule module = getModule("module1");
210
211         final YContainer cont1 = getContainer(module, "cont1");
212         assertTrue(cont1 != null);
213
214         final YLeaf leaf11 = getLeaf(cont1, "leaf11");
215         assertTrue(leaf11 != null);
216
217         final YLeaf leaf12 = getLeaf(cont1, "leaf12");
218         assertTrue(leaf12 == null);
219
220         final YLeaf leaf13 = getLeaf(cont1, "leaf13");
221         assertTrue(leaf13 != null);
222
223         final YLeaf leaf14 = getLeaf(cont1, "leaf14");
224         assertTrue(leaf14 == null);
225     }
226
227     @Test
228     public void test_module1_with_removal_with_feature11_and_feature12() {
229
230         final Set<YangFeature> supportedFeatures = new HashSet<>();
231         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature11"));
232         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature12"));
233
234         context.setSupportedFeatures(supportedFeatures);
235         context.setRemoveSchemaNodesNotSatisfyingIfFeature(true);
236
237         severityCalculator.suppressFinding(ParserFindingType.P103_ILLEGAL_IF_FEATURE_SYNTAX.toString());
238         severityCalculator.suppressFinding(ParserFindingType.P132_GROUPING_NOT_USED.toString());
239         severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
240         parseAbsoluteImplementsYangModels(Arrays.asList(MODULE1, MODULE2, SUBMODULE3));
241
242         assertNoFindings();
243
244         final YModule module = getModule("module1");
245
246         final YContainer cont1 = getContainer(module, "cont1");
247         assertTrue(cont1 != null);
248
249         final YLeaf leaf11 = getLeaf(cont1, "leaf11");
250         assertTrue(leaf11 != null);
251
252         final YLeaf leaf12 = getLeaf(cont1, "leaf12");
253         assertTrue(leaf12 != null);
254
255         final YLeaf leaf13 = getLeaf(cont1, "leaf13");
256         assertTrue(leaf13 != null);
257
258         final YLeaf leaf14 = getLeaf(cont1, "leaf14");
259         assertTrue(leaf14 == null);
260     }
261
262     @Test
263     public void test_module1_with_removal_with_feature12_and_feature13() {
264
265         final Set<YangFeature> supportedFeatures = new HashSet<>();
266         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature12"));
267         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature13"));
268
269         context.setSupportedFeatures(supportedFeatures);
270         context.setRemoveSchemaNodesNotSatisfyingIfFeature(true);
271
272         severityCalculator.suppressFinding(ParserFindingType.P103_ILLEGAL_IF_FEATURE_SYNTAX.toString());
273         severityCalculator.suppressFinding(ParserFindingType.P132_GROUPING_NOT_USED.toString());
274         severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
275         parseAbsoluteImplementsYangModels(Arrays.asList(MODULE1, MODULE2, SUBMODULE3));
276
277         assertNoFindings();
278
279         final YModule module = getModule("module1");
280
281         final YContainer cont1 = getContainer(module, "cont1");
282         assertTrue(cont1 != null);
283
284         final YLeaf leaf11 = getLeaf(cont1, "leaf11");
285         assertTrue(leaf11 == null);
286
287         final YLeaf leaf12 = getLeaf(cont1, "leaf12");
288         assertTrue(leaf12 != null);
289
290         final YLeaf leaf13 = getLeaf(cont1, "leaf13");
291         assertTrue(leaf13 != null);
292
293         final YLeaf leaf14 = getLeaf(cont1, "leaf14");
294         assertTrue(leaf14 == null);
295     }
296
297     @Test
298     public void test_module1_with_removal_with_feature13_and_feature14() {
299
300         final Set<YangFeature> supportedFeatures = new HashSet<>();
301         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature13"));
302         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature14"));
303
304         context.setSupportedFeatures(supportedFeatures);
305         context.setRemoveSchemaNodesNotSatisfyingIfFeature(true);
306
307         severityCalculator.suppressFinding(ParserFindingType.P103_ILLEGAL_IF_FEATURE_SYNTAX.toString());
308         severityCalculator.suppressFinding(ParserFindingType.P132_GROUPING_NOT_USED.toString());
309         severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
310         parseAbsoluteImplementsYangModels(Arrays.asList(MODULE1, MODULE2, SUBMODULE3));
311
312         final YModule module = getModule("module1");
313
314         /*
315          * Should have resulted in a finding - feature 14 depends on 11 and 12, and these are not set.
316          */
317
318         assertStatementHasFindingOfType(getFeature(module, "feature14"), ParserFindingType.P086_FEATURE_CANNOT_BE_SUPPORTED
319                 .toString());
320     }
321
322     @Test
323     public void test_module1_with_removal_with_feature16() {
324
325         final Set<YangFeature> supportedFeatures = new HashSet<>();
326         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature16"));
327
328         context.setSupportedFeatures(supportedFeatures);
329         context.setRemoveSchemaNodesNotSatisfyingIfFeature(true);
330
331         severityCalculator.suppressFinding(ParserFindingType.P103_ILLEGAL_IF_FEATURE_SYNTAX.toString());
332         severityCalculator.suppressFinding(ParserFindingType.P132_GROUPING_NOT_USED.toString());
333         severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
334         parseAbsoluteImplementsYangModels(Arrays.asList(MODULE1, MODULE2, SUBMODULE3));
335
336         assertNoFindings();
337
338         final YModule module = getModule("module1");
339
340         final YContainer cont2 = getContainer(module, "cont2");
341         assertTrue(cont2 != null);
342
343         final YChoice choice21 = getChoice(cont2, "choice21");
344         assertTrue(choice21 != null);
345
346         assertTrue(choice21.getCases().size() == 1);
347
348         final YCase case211 = getCase(choice21, "case211");
349         assertTrue(case211 != null);
350         assertTrue(getLeaf(case211, "leaf211") != null);
351     }
352
353     @Test
354     public void test_module1_with_removal_with_feature18_and_feature19() {
355
356         final Set<YangFeature> supportedFeatures = new HashSet<>();
357         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature18"));
358         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature19"));
359
360         context.setSupportedFeatures(supportedFeatures);
361         context.setRemoveSchemaNodesNotSatisfyingIfFeature(true);
362
363         severityCalculator.suppressFinding(ParserFindingType.P103_ILLEGAL_IF_FEATURE_SYNTAX.toString());
364         severityCalculator.suppressFinding(ParserFindingType.P132_GROUPING_NOT_USED.toString());
365         severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
366         parseAbsoluteImplementsYangModels(Arrays.asList(MODULE1, MODULE2, SUBMODULE3));
367
368         assertNoFindings();
369
370         final YModule module = getModule("module1");
371
372         final YContainer cont2 = getContainer(module, "cont2");
373         assertTrue(cont2 != null);
374
375         final YChoice choice21 = getChoice(cont2, "choice21");
376         assertTrue(choice21 != null);
377
378         assertTrue(choice21.getCases().size() == 3);
379
380         final YCase case213 = getCase(choice21, "case213");
381         assertTrue(case213 != null);
382         assertTrue(getLeaf(case213, "leaf213") != null);
383
384         final YCase case214 = getCase(choice21, "case214");
385         assertTrue(case214 != null);
386         assertTrue(getLeaf(case214, "leaf214") != null);
387
388         final YCase case215 = getCase(choice21, "leaf215");
389         assertTrue(case215 != null);
390         assertTrue(getLeaf(case215, "leaf215") != null);
391     }
392
393     @Test
394     public void test_module1_with_removal_with_feature21() {
395
396         final Set<YangFeature> supportedFeatures = new HashSet<>();
397         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature21"));
398
399         context.setSupportedFeatures(supportedFeatures);
400         context.setRemoveSchemaNodesNotSatisfyingIfFeature(true);
401
402         severityCalculator.suppressFinding(ParserFindingType.P103_ILLEGAL_IF_FEATURE_SYNTAX.toString());
403         severityCalculator.suppressFinding(ParserFindingType.P132_GROUPING_NOT_USED.toString());
404         severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
405         parseAbsoluteImplementsYangModels(Arrays.asList(MODULE1, MODULE2, SUBMODULE3));
406
407         assertNoFindings();
408
409         final YModule module = getModule("module1");
410
411         final YContainer cont3 = getContainer(module, "cont3");
412         assertTrue(cont3 != null);
413
414         assertTrue(getLeaf(cont3, "leaf51") == null);
415         assertTrue(getLeaf(cont3, "leaf52") == null);
416         assertTrue(getLeaf(cont3, "leaf53") == null);
417     }
418
419     @Test
420     public void test_module1_with_removal_with_feature23() {
421
422         final Set<YangFeature> supportedFeatures = new HashSet<>();
423         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature23"));
424
425         context.setSupportedFeatures(supportedFeatures);
426         context.setRemoveSchemaNodesNotSatisfyingIfFeature(true);
427
428         severityCalculator.suppressFinding(ParserFindingType.P103_ILLEGAL_IF_FEATURE_SYNTAX.toString());
429         severityCalculator.suppressFinding(ParserFindingType.P132_GROUPING_NOT_USED.toString());
430         severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
431         severityCalculator.suppressFinding(ParserFindingType.P143_ENUM_WITHOUT_VALUE.toString());
432
433         parseAbsoluteImplementsYangModels(Arrays.asList(MODULE1, MODULE2, SUBMODULE3));
434
435         assertNoFindings();
436
437         final YModule module = getModule("module1");
438
439         final YContainer cont3 = getContainer(module, "cont3");
440         assertTrue(cont3 != null);
441
442         assertTrue(getLeaf(cont3, "leaf51") != null);
443         assertTrue(getLeaf(cont3, "leaf52") == null);
444         assertTrue(getLeaf(cont3, "leaf53") != null);
445
446         assertTrue(getLeaf(cont3, "leaf53").getType().getEnums().size() == 2);
447     }
448
449     @Test
450     public void test_module1_with_removal_with_feature21_and_feature23() {
451
452         final Set<YangFeature> supportedFeatures = new HashSet<>();
453         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature21"));
454         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature23"));
455
456         context.setSupportedFeatures(supportedFeatures);
457         context.setRemoveSchemaNodesNotSatisfyingIfFeature(true);
458
459         severityCalculator.suppressFinding(ParserFindingType.P103_ILLEGAL_IF_FEATURE_SYNTAX.toString());
460         severityCalculator.suppressFinding(ParserFindingType.P132_GROUPING_NOT_USED.toString());
461         severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
462         severityCalculator.suppressFinding(ParserFindingType.P143_ENUM_WITHOUT_VALUE.toString());
463
464         parseAbsoluteImplementsYangModels(Arrays.asList(MODULE1, MODULE2, SUBMODULE3));
465
466         assertNoFindings();
467
468         final YModule module = getModule("module1");
469
470         final YContainer cont3 = getContainer(module, "cont3");
471         assertTrue(cont3 != null);
472
473         assertTrue(getLeaf(cont3, "leaf51") != null);
474         assertTrue(getLeaf(cont3, "leaf52") != null);
475         assertTrue(getLeaf(cont3, "leaf53") != null);
476
477         assertTrue(getLeaf(cont3, "leaf53").getType().getEnums().size() == 2);
478     }
479
480     @Test
481     public void test_module1_with_removal_with_feature22_and_feature23() {
482
483         final Set<YangFeature> supportedFeatures = new HashSet<>();
484         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature22"));
485         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature23"));
486
487         context.setSupportedFeatures(supportedFeatures);
488         context.setRemoveSchemaNodesNotSatisfyingIfFeature(true);
489
490         severityCalculator.suppressFinding(ParserFindingType.P103_ILLEGAL_IF_FEATURE_SYNTAX.toString());
491         severityCalculator.suppressFinding(ParserFindingType.P132_GROUPING_NOT_USED.toString());
492         severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
493         severityCalculator.suppressFinding(ParserFindingType.P143_ENUM_WITHOUT_VALUE.toString());
494
495         parseAbsoluteImplementsYangModels(Arrays.asList(MODULE1, MODULE2, SUBMODULE3));
496
497         assertNoFindings();
498
499         final YModule module = getModule("module1");
500
501         final YContainer cont3 = getContainer(module, "cont3");
502         assertTrue(cont3 != null);
503
504         assertTrue(getLeaf(cont3, "leaf51") != null);
505         assertTrue(getLeaf(cont3, "leaf52") == null);
506         assertTrue(getLeaf(cont3, "leaf53") != null);
507
508         assertTrue(getLeaf(cont3, "leaf53").getType().getEnums().size() == 3);
509     }
510
511     @Test
512     public void test_module1_with_removal_with_feature31() {
513
514         final Set<YangFeature> supportedFeatures = new HashSet<>();
515         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature31"));
516
517         context.setSupportedFeatures(supportedFeatures);
518         context.setRemoveSchemaNodesNotSatisfyingIfFeature(true);
519
520         severityCalculator.suppressFinding(ParserFindingType.P103_ILLEGAL_IF_FEATURE_SYNTAX.toString());
521         severityCalculator.suppressFinding(ParserFindingType.P132_GROUPING_NOT_USED.toString());
522         severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
523         parseAbsoluteImplementsYangModels(Arrays.asList(MODULE1, MODULE2, SUBMODULE3));
524
525         assertNoFindings();
526
527         final YModule module = getModule("module1");
528
529         final YContainer cont4 = getContainer(module, "cont4");
530         assertTrue(cont4 != null);
531
532         assertTrue(getLeaf(cont4, "leaf91") != null);
533         assertTrue(getLeaf(cont4, "leaf92") == null);
534         assertTrue(getLeaf(cont4, "leaf93") == null);
535         assertTrue(getLeaf(cont4, "leaf94") == null);
536     }
537
538     @Test
539     public void test_module1_with_removal_with_feature31_and_module2_feature11() {
540
541         final Set<YangFeature> supportedFeatures = new HashSet<>();
542         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature31"));
543         supportedFeatures.add(new YangFeature("urn:test:module2", "module2", "feature11"));     // !!!!! module2 !!!!!
544
545         context.setSupportedFeatures(supportedFeatures);
546         context.setRemoveSchemaNodesNotSatisfyingIfFeature(true);
547
548         severityCalculator.suppressFinding(ParserFindingType.P103_ILLEGAL_IF_FEATURE_SYNTAX.toString());
549         severityCalculator.suppressFinding(ParserFindingType.P132_GROUPING_NOT_USED.toString());
550         severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
551         parseAbsoluteImplementsYangModels(Arrays.asList(MODULE1, MODULE2, SUBMODULE3));
552
553         assertNoFindings();
554
555         final YModule module = getModule("module1");
556
557         final YContainer cont4 = getContainer(module, "cont4");
558         assertTrue(cont4 != null);
559
560         assertTrue(getLeaf(cont4, "leaf91") != null);
561         assertTrue(getLeaf(cont4, "leaf92") != null);
562         assertTrue(getLeaf(cont4, "leaf93") != null);
563         assertTrue(getLeaf(cont4, "leaf94") == null);
564     }
565
566     @Test
567     public void test_module1_with_removal_with_feature31_and_feature11_of_both_modules() {
568
569         final Set<YangFeature> supportedFeatures = new HashSet<>();
570         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature31"));
571         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature11"));
572         supportedFeatures.add(new YangFeature("urn:test:module2", "module2", "feature11"));     // !!!!! module2 !!!!!
573
574         context.setSupportedFeatures(supportedFeatures);
575         context.setRemoveSchemaNodesNotSatisfyingIfFeature(true);
576
577         severityCalculator.suppressFinding(ParserFindingType.P103_ILLEGAL_IF_FEATURE_SYNTAX.toString());
578         severityCalculator.suppressFinding(ParserFindingType.P132_GROUPING_NOT_USED.toString());
579         severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
580         parseAbsoluteImplementsYangModels(Arrays.asList(MODULE1, MODULE2, SUBMODULE3));
581
582         assertNoFindings();
583
584         final YModule module = getModule("module1");
585
586         final YContainer cont4 = getContainer(module, "cont4");
587         assertTrue(cont4 != null);
588
589         assertTrue(getLeaf(cont4, "leaf91") != null);
590         assertTrue(getLeaf(cont4, "leaf92") != null);
591         assertTrue(getLeaf(cont4, "leaf93") != null);
592         assertTrue(getLeaf(cont4, "leaf94") != null);
593     }
594
595     @Test
596     public void test_module1_with_removal_with_feature51() {
597
598         final Set<YangFeature> supportedFeatures = new HashSet<>();
599         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature51"));
600
601         context.setSupportedFeatures(supportedFeatures);
602         context.setRemoveSchemaNodesNotSatisfyingIfFeature(true);
603
604         severityCalculator.suppressFinding(ParserFindingType.P103_ILLEGAL_IF_FEATURE_SYNTAX.toString());
605         severityCalculator.suppressFinding(ParserFindingType.P132_GROUPING_NOT_USED.toString());
606         severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
607         parseAbsoluteImplementsYangModels(Arrays.asList(MODULE1, MODULE2, SUBMODULE3));
608
609         assertNoFindings();
610
611         final YModule module = getModule("module1");
612
613         final YContainer cont5 = getContainer(module, "cont5");
614         assertTrue(cont5 != null);
615
616         assertTrue(getLeaf(cont5, "leaf51") != null);
617         assertTrue(getLeaf(cont5, "leaf52") == null);
618         assertTrue(getLeaf(cont5, "leaf53") == null);
619     }
620
621     @Test
622     public void test_module1_with_removal_with_feature52_and_feature58() {
623
624         final Set<YangFeature> supportedFeatures = new HashSet<>();
625         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature52"));
626         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature58"));
627
628         context.setSupportedFeatures(supportedFeatures);
629         context.setRemoveSchemaNodesNotSatisfyingIfFeature(true);
630
631         severityCalculator.suppressFinding(ParserFindingType.P103_ILLEGAL_IF_FEATURE_SYNTAX.toString());
632         severityCalculator.suppressFinding(ParserFindingType.P132_GROUPING_NOT_USED.toString());
633         severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
634         parseAbsoluteImplementsYangModels(Arrays.asList(MODULE1, MODULE2, SUBMODULE3));
635
636         assertNoFindings();
637
638         final YModule module = getModule("module1");
639
640         final YContainer cont5 = getContainer(module, "cont5");
641         assertTrue(cont5 != null);
642
643         assertTrue(getLeaf(cont5, "leaf51") == null);
644         assertTrue(getLeaf(cont5, "leaf52") != null);
645         assertTrue(getLeaf(cont5, "leaf53") != null);
646     }
647
648     @Test
649     public void test_module1_with_removal_with_feature52() {
650
651         final Set<YangFeature> supportedFeatures = new HashSet<>();
652         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature52"));
653
654         context.setSupportedFeatures(supportedFeatures);
655         context.setRemoveSchemaNodesNotSatisfyingIfFeature(true);
656
657         severityCalculator.suppressFinding(ParserFindingType.P103_ILLEGAL_IF_FEATURE_SYNTAX.toString());
658         severityCalculator.suppressFinding(ParserFindingType.P132_GROUPING_NOT_USED.toString());
659         severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
660         parseAbsoluteImplementsYangModels(Arrays.asList(MODULE1, MODULE2, SUBMODULE3));
661
662         final YModule module = getModule("module1");
663
664         assertStatementHasFindingOfType(getFeature(module, "feature52"), ParserFindingType.P086_FEATURE_CANNOT_BE_SUPPORTED
665                 .toString());
666     }
667
668     @Test
669     public void test_module1_no_remove_thus_leaf61_does_exists() {
670
671         context.setRemoveSchemaNodesNotSatisfyingIfFeature(false);              // !!!!!! FALSE !!!!!!
672
673         severityCalculator.suppressFinding(ParserFindingType.P103_ILLEGAL_IF_FEATURE_SYNTAX.toString());
674         severityCalculator.suppressFinding(ParserFindingType.P132_GROUPING_NOT_USED.toString());
675         severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
676         parseAbsoluteImplementsYangModels(Arrays.asList(MODULE1, MODULE2, SUBMODULE3));
677
678         final YModule module = getModule("module1");
679
680         final YContainer cont6 = getContainer(module, "cont6");
681         assertTrue(cont6 != null);
682         assertTrue(getLeaf(cont6, "leaf61") != null);
683     }
684
685     @Test
686     public void test_module1_remove_thus_leaf61_not_exists() {
687
688         final Set<YangFeature> supportedFeatures = new HashSet<>();
689         context.setSupportedFeatures(supportedFeatures);
690         context.setRemoveSchemaNodesNotSatisfyingIfFeature(true);
691
692         severityCalculator.suppressFinding(ParserFindingType.P103_ILLEGAL_IF_FEATURE_SYNTAX.toString());
693         severityCalculator.suppressFinding(ParserFindingType.P132_GROUPING_NOT_USED.toString());
694         severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
695         parseAbsoluteImplementsYangModels(Arrays.asList(MODULE1, MODULE2, SUBMODULE3));
696
697         final YModule module = getModule("module1");
698
699         final YContainer cont6 = getContainer(module, "cont6");
700         assertTrue(cont6 != null);
701         assertTrue(getLeaf(cont6, "leaf61") == null);
702     }
703
704     @Test
705     public void test_module1_with_removal_with_feature71() {
706
707         final Set<YangFeature> supportedFeatures = new HashSet<>();
708         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature71"));
709
710         context.setSupportedFeatures(supportedFeatures);
711         context.setRemoveSchemaNodesNotSatisfyingIfFeature(true);
712
713         severityCalculator.suppressFinding(ParserFindingType.P103_ILLEGAL_IF_FEATURE_SYNTAX.toString());
714         severityCalculator.suppressFinding(ParserFindingType.P132_GROUPING_NOT_USED.toString());
715         severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
716         parseAbsoluteImplementsYangModels(Arrays.asList(MODULE1, MODULE2, SUBMODULE3));
717
718         assertNoFindings();
719
720         final YModule module = getModule("module1");
721
722         final YContainer cont7 = getContainer(module, "cont7");
723         assertTrue(cont7 != null);
724
725         assertTrue(getLeaf(cont7, "leaf71") != null);
726         assertTrue(getLeaf(cont7, "leaf72") == null);
727         assertTrue(getLeaf(cont7, "leaf73") == null);
728         assertTrue(getLeaf(cont7, "leaf74") == null);
729     }
730
731     @Test
732     public void test_module1_with_removal_with_feature71_and_feature72() {
733
734         final Set<YangFeature> supportedFeatures = new HashSet<>();
735         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature71"));
736         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature72"));
737
738         context.setSupportedFeatures(supportedFeatures);
739         context.setRemoveSchemaNodesNotSatisfyingIfFeature(true);
740
741         severityCalculator.suppressFinding(ParserFindingType.P103_ILLEGAL_IF_FEATURE_SYNTAX.toString());
742         severityCalculator.suppressFinding(ParserFindingType.P132_GROUPING_NOT_USED.toString());
743         severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
744         parseAbsoluteImplementsYangModels(Arrays.asList(MODULE1, MODULE2, SUBMODULE3));
745
746         assertNoFindings();
747
748         final YModule module = getModule("module1");
749
750         final YContainer cont7 = getContainer(module, "cont7");
751         assertTrue(cont7 != null);
752
753         assertTrue(getLeaf(cont7, "leaf71") == null);
754         assertTrue(getLeaf(cont7, "leaf72") == null);
755         assertTrue(getLeaf(cont7, "leaf73") == null);
756         assertTrue(getLeaf(cont7, "leaf74") == null);
757     }
758
759     @Test
760     public void test_module1_with_removal_with_feature71_and_feature72_and_feature73() {
761
762         final Set<YangFeature> supportedFeatures = new HashSet<>();
763         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature71"));
764         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature72"));
765         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature73"));
766
767         context.setSupportedFeatures(supportedFeatures);
768         context.setRemoveSchemaNodesNotSatisfyingIfFeature(true);
769
770         severityCalculator.suppressFinding(ParserFindingType.P103_ILLEGAL_IF_FEATURE_SYNTAX.toString());
771         severityCalculator.suppressFinding(ParserFindingType.P132_GROUPING_NOT_USED.toString());
772         severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
773         parseAbsoluteImplementsYangModels(Arrays.asList(MODULE1, MODULE2, SUBMODULE3));
774
775         assertNoFindings();
776
777         final YModule module = getModule("module1");
778
779         final YContainer cont7 = getContainer(module, "cont7");
780         assertTrue(cont7 != null);
781
782         assertTrue(getLeaf(cont7, "leaf71") == null);
783         assertTrue(getLeaf(cont7, "leaf72") != null);
784         assertTrue(getLeaf(cont7, "leaf73") == null);
785         assertTrue(getLeaf(cont7, "leaf74") == null);
786     }
787
788     @Test
789     public void test_module1_with_removal_with_feature71_and_feature72_and_feature73_and_feature74() {
790
791         final Set<YangFeature> supportedFeatures = new HashSet<>();
792         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature71"));
793         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature72"));
794         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature73"));
795         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature74"));
796
797         context.setSupportedFeatures(supportedFeatures);
798         context.setRemoveSchemaNodesNotSatisfyingIfFeature(true);
799
800         severityCalculator.suppressFinding(ParserFindingType.P103_ILLEGAL_IF_FEATURE_SYNTAX.toString());
801         severityCalculator.suppressFinding(ParserFindingType.P132_GROUPING_NOT_USED.toString());
802         severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
803         parseAbsoluteImplementsYangModels(Arrays.asList(MODULE1, MODULE2, SUBMODULE3));
804
805         assertNoFindings();
806
807         final YModule module = getModule("module1");
808
809         final YContainer cont7 = getContainer(module, "cont7");
810         assertTrue(cont7 != null);
811
812         assertTrue(getLeaf(cont7, "leaf71") == null);
813         assertTrue(getLeaf(cont7, "leaf72") != null);
814         assertTrue(getLeaf(cont7, "leaf73") != null);
815         assertTrue(getLeaf(cont7, "leaf74") == null);
816     }
817
818     @Test
819     public void test_module1_with_removal_with_feature71_and_feature73_and_feature75() {
820
821         final Set<YangFeature> supportedFeatures = new HashSet<>();
822         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature71"));
823         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature73"));
824         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature75"));
825
826         context.setSupportedFeatures(supportedFeatures);
827         context.setRemoveSchemaNodesNotSatisfyingIfFeature(true);
828
829         severityCalculator.suppressFinding(ParserFindingType.P103_ILLEGAL_IF_FEATURE_SYNTAX.toString());
830         severityCalculator.suppressFinding(ParserFindingType.P132_GROUPING_NOT_USED.toString());
831         severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
832         parseAbsoluteImplementsYangModels(Arrays.asList(MODULE1, MODULE2, SUBMODULE3));
833
834         assertNoFindings();
835
836         final YModule module = getModule("module1");
837
838         final YContainer cont7 = getContainer(module, "cont7");
839         assertTrue(cont7 != null);
840
841         assertTrue(getLeaf(cont7, "leaf71") != null);
842         assertTrue(getLeaf(cont7, "leaf72") == null);
843         assertTrue(getLeaf(cont7, "leaf73") != null);
844         assertTrue(getLeaf(cont7, "leaf74") == null);
845     }
846
847     @Test
848     public void test_module1_with_removal_with_feature74() {
849
850         final Set<YangFeature> supportedFeatures = new HashSet<>();
851         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature74"));
852
853         context.setSupportedFeatures(supportedFeatures);
854         context.setRemoveSchemaNodesNotSatisfyingIfFeature(true);
855
856         severityCalculator.suppressFinding(ParserFindingType.P103_ILLEGAL_IF_FEATURE_SYNTAX.toString());
857         severityCalculator.suppressFinding(ParserFindingType.P132_GROUPING_NOT_USED.toString());
858         severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
859         parseAbsoluteImplementsYangModels(Arrays.asList(MODULE1, MODULE2, SUBMODULE3));
860
861         assertNoFindings();
862
863         final YModule module = getModule("module1");
864
865         final YContainer cont7 = getContainer(module, "cont7");
866         assertTrue(cont7 != null);
867
868         assertTrue(getLeaf(cont7, "leaf71") == null);
869         assertTrue(getLeaf(cont7, "leaf72") == null);
870         assertTrue(getLeaf(cont7, "leaf73") == null);
871         assertTrue(getLeaf(cont7, "leaf74") != null);
872     }
873
874     @Test
875     public void test_module1_with_removal_with_feature74_and_feature76() {
876
877         final Set<YangFeature> supportedFeatures = new HashSet<>();
878         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature74"));
879         supportedFeatures.add(new YangFeature("urn:test:module1", "module1", "feature76"));
880
881         context.setSupportedFeatures(supportedFeatures);
882         context.setRemoveSchemaNodesNotSatisfyingIfFeature(true);
883
884         severityCalculator.suppressFinding(ParserFindingType.P103_ILLEGAL_IF_FEATURE_SYNTAX.toString());
885         severityCalculator.suppressFinding(ParserFindingType.P132_GROUPING_NOT_USED.toString());
886         severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
887         parseAbsoluteImplementsYangModels(Arrays.asList(MODULE1, MODULE2, SUBMODULE3));
888
889         assertNoFindings();
890
891         final YModule module = getModule("module1");
892
893         final YContainer cont7 = getContainer(module, "cont7");
894         assertTrue(cont7 != null);
895
896         assertTrue(getLeaf(cont7, "leaf71") == null);
897         assertTrue(getLeaf(cont7, "leaf72") == null);
898         assertTrue(getLeaf(cont7, "leaf73") == null);
899         assertTrue(getLeaf(cont7, "leaf74") == null);
900     }
901
902 }