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 java.util.Arrays;
24 import java.util.Collections;
25 import java.util.List;
27 import org.junit.Test;
29 import org.oran.smo.yangtools.parser.findings.ParserFindingType;
30 import org.oran.smo.yangtools.parser.model.statements.yang.CY;
31 import org.oran.smo.yangtools.parser.model.statements.yang.YModule;
32 import org.oran.smo.yangtools.parser.model.yangdom.YangDomElement;
33 import org.oran.smo.yangtools.parser.testutils.YangTestCommon;
35 public class RemoveFindingsOnUnusedSchemaNodesTest extends YangTestCommon {
38 public void test___simple___do_not_suppress_findings() {
40 final List<String> absoluteImplementsFilePath = Arrays.asList(
41 "src/test/resources/model-schema/remove-findings-on-unused-schema-nodes/simple/simple-module.yang");
42 final List<String> absoluteImportsFilePath = Collections.<String> emptyList();
44 context.setSuppressFindingsOnUnusedSchemaNodes(false);
46 parseAbsoluteYangModels(absoluteImplementsFilePath, absoluteImportsFilePath);
49 * We expect a number of findings
51 final YModule yModule = getModule("simple-module");
53 // ----- The typedef -----
55 final YangDomElement typedef01 = getDomChild(yModule.getDomElement(), CY.TYPEDEF, "typedef01");
56 assertDomElementHasFindingOfType(typedef01, ParserFindingType.P114_TYPEDEF_NOT_USED.toString());
58 final YangDomElement typeUnderTypedef01 = getDomChild(typedef01, CY.TYPE);
59 assertDomElementHasFindingOfType(typeUnderTypedef01, ParserFindingType.P113_UNRESOLVABLE_DERIVED_TYPE.toString());
61 // ----- The grouping -----
63 final YangDomElement grouping01 = getDomChild(yModule.getDomElement(), CY.GROUPING, "grouping01");
64 assertDomElementHasFindingOfType(grouping01, ParserFindingType.P132_GROUPING_NOT_USED.toString());
66 final YangDomElement statementUnderGrouping01 = getDomChild(grouping01, "unknown-statement");
67 assertDomElementHasFindingOfType(statementUnderGrouping01, ParserFindingType.P015_INVALID_SYNTAX_IN_DOCUMENT
70 // ----- The leaf02 -----
72 final YangDomElement cont1 = getDomChild(yModule.getDomElement(), CY.CONTAINER, "cont1");
73 final YangDomElement leaf02 = getDomChild(cont1, CY.LEAF, "leaf02");
74 final YangDomElement typeUnderLeaf02 = getDomChild(leaf02, CY.TYPE);
75 assertDomElementHasFindingOfType(typeUnderLeaf02, ParserFindingType.P113_UNRESOLVABLE_DERIVED_TYPE.toString());
77 // ----- The leaf03 -----
79 final YangDomElement leaf03 = getDomChild(cont1, CY.LEAF, "leaf03");
80 final YangDomElement typeUnderLeaf03 = getDomChild(leaf03, CY.TYPE);
81 assertDomElementHasFindingOfType(typeUnderLeaf03, ParserFindingType.P113_UNRESOLVABLE_DERIVED_TYPE.toString());
83 // ----- The deviation -----
85 final YangDomElement deviation = getDomChild(yModule.getDomElement(), CY.DEVIATION);
86 assertDomElementHasFindingOfType(deviation, ParserFindingType.P162_DEVIATION_TARGET_NODE_IN_SAME_MODULE.toString());
90 public void test___simple___suppress_findings() {
92 final List<String> absoluteImplementsFilePath = Arrays.asList(
93 "src/test/resources/model-schema/remove-findings-on-unused-schema-nodes/simple/simple-module.yang");
94 final List<String> absoluteImportsFilePath = Collections.<String> emptyList();
96 context.setSuppressFindingsOnUnusedSchemaNodes(true);
98 parseAbsoluteYangModels(absoluteImplementsFilePath, absoluteImportsFilePath);
101 * We expect a number of findings
103 final YModule yModule = getModule("simple-module");
105 // ----- The typedef -----
107 final YangDomElement typedef01 = getDomChild(yModule.getDomElement(), CY.TYPEDEF, "typedef01");
108 assertDomElementHasFindingOfType(typedef01, ParserFindingType.P114_TYPEDEF_NOT_USED.toString());
110 final YangDomElement typeUnderTypedef01 = getDomChild(typedef01, CY.TYPE);
111 assertDomElementHasNoFindings(typeUnderTypedef01);
113 // ----- The grouping -----
115 final YangDomElement grouping01 = getDomChild(yModule.getDomElement(), CY.GROUPING, "grouping01");
116 assertDomElementHasFindingOfType(grouping01, ParserFindingType.P132_GROUPING_NOT_USED.toString());
118 final YangDomElement statementUnderGrouping01 = getDomChild(grouping01, "unknown-statement");
119 assertDomElementHasNoFindings(statementUnderGrouping01);
121 // ----- The leaf02 -----
123 final YangDomElement cont1 = getDomChild(yModule.getDomElement(), CY.CONTAINER, "cont1");
124 final YangDomElement leaf02 = getDomChild(cont1, CY.LEAF, "leaf02");
125 final YangDomElement typeUnderLeaf02 = getDomChild(leaf02, CY.TYPE);
126 assertDomElementHasNoFindings(typeUnderLeaf02);
128 // ----- The leaf03 -----
130 final YangDomElement leaf03 = getDomChild(cont1, CY.LEAF, "leaf03");
131 final YangDomElement typeUnderLeaf03 = getDomChild(leaf03, CY.TYPE);
132 assertDomElementHasFindingOfType(typeUnderLeaf03, ParserFindingType.P113_UNRESOLVABLE_DERIVED_TYPE.toString());
134 // ----- The deviation -----
136 final YangDomElement deviation = getDomChild(yModule.getDomElement(), CY.DEVIATION);
137 assertDomElementHasFindingOfType(deviation, ParserFindingType.P162_DEVIATION_TARGET_NODE_IN_SAME_MODULE.toString());