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;
27 import org.junit.Test;
29 import org.oran.smo.yangtools.parser.findings.ParserFindingType;
30 import org.oran.smo.yangtools.parser.model.statements.threegpp.C3GPP;
31 import org.oran.smo.yangtools.parser.model.statements.threegpp.Y3gppInitialValue;
32 import org.oran.smo.yangtools.parser.model.statements.yang.YContainer;
33 import org.oran.smo.yangtools.parser.model.statements.yang.YDeviate.DeviateType;
34 import org.oran.smo.yangtools.parser.testutils.YangTestCommon;
35 import org.oran.smo.yangtools.parser.model.statements.yang.YDeviation;
36 import org.oran.smo.yangtools.parser.model.statements.yang.YModule;
38 public class DeviationTest extends YangTestCommon {
41 public void testDeviateAdd() {
43 parseImplementsYangModels(Arrays.asList("deviation-test/deviation-host-test-module.yang",
44 "deviation-test/deviate-add-test-module.yang"), Arrays.asList(THREEGPP_YANG_EXT_PATH));
46 final YModule hostModule = getModule("deviation-host-test-module");
47 final YModule deviateAddModule = getModule("deviate-add-test-module");
49 // ------------------------- All of these are just fine -------------------------------
51 assertTrue(getContainer(hostModule, "cont1") != null);
52 assertSubTreeNoFindings(getContainer(hostModule, "cont1"));
54 assertTrue(getLeafUnderContainer(hostModule, "cont1", "leaf11") != null);
55 assertTrue(getLeafUnderContainer(hostModule, "cont1", "leaf11").getType().getDataType().equals("string"));
56 assertTrue(getLeafUnderContainer(hostModule, "cont1", "leaf11").getDefault() != null);
57 assertTrue(getLeafUnderContainer(hostModule, "cont1", "leaf11").getDefault().getValue().equals("Hello World!"));
58 assertTrue(getLeafUnderContainer(hostModule, "cont1", "leaf11").getMusts().size() == 1);
59 assertTrue(getLeafUnderContainer(hostModule, "cont1", "leaf11").getMusts().get(0).getXpathExpression().equals(
61 assertTrue(getLeafUnderContainer(hostModule, "cont1", "leaf11").getUnits() != null);
62 assertTrue(getLeafUnderContainer(hostModule, "cont1", "leaf11").getUnits().getValue().equals("seconds"));
63 assertTrue(getLeafUnderContainer(hostModule, "cont1", "leaf11").getChild(
64 C3GPP.THREEGPP_COMMON_YANG_EXTENSIONS__INITIAL_VALUE) != null);
65 assertTrue(((Y3gppInitialValue) getLeafUnderContainer(hostModule, "cont1", "leaf11").getChild(
66 C3GPP.THREEGPP_COMMON_YANG_EXTENSIONS__INITIAL_VALUE)).getInitialValue().equals("Hello World"));
68 assertTrue(getList(hostModule, "list11") != null);
69 assertSubTreeNoFindings(getList(hostModule, "list11"));
71 assertTrue(getList(hostModule, "list11").getUniques().size() == 1);
72 assertTrue(getList(hostModule, "list11").getUniques().get(0).getValue().equals("leaf111 leaf112"));
74 assertTrue(getLeafListUnderList(hostModule, "list11", "leaflist113") != null);
75 assertTrue(getLeafListUnderList(hostModule, "list11", "leaflist113").getDefaults().size() == 3);
76 assertTrue(getLeafListUnderList(hostModule, "list11", "leaflist113").getDefaults().get(0).getValue().equals("10"));
77 assertTrue(getLeafListUnderList(hostModule, "list11", "leaflist113").getDefaults().get(1).getValue().equals("13"));
78 assertTrue(getLeafListUnderList(hostModule, "list11", "leaflist113").getDefaults().get(2).getValue().equals("18"));
79 assertTrue(getLeafListUnderList(hostModule, "list11", "leaflist113").getMusts().size() == 2);
80 assertTrue(getLeafListUnderList(hostModule, "list11", "leaflist113").getMusts().get(0).getXpathExpression().equals(
82 assertTrue(getLeafListUnderList(hostModule, "list11", "leaflist113").getMusts().get(1).getXpathExpression().equals(
85 assertSubTreeNoFindings(getChild(deviateAddModule, "deviation", "/host:cont1/host:leaf11"));
86 assertSubTreeNoFindings(getChild(deviateAddModule, "deviation", "/host:list11"));
87 assertSubTreeNoFindings(getChild(deviateAddModule, "deviation", "/host:list11/host:leaflist113"));
89 // ------------------------- Trying to add things that already exist -------------------------------
91 assertTrue(getLeafUnderContainer(hostModule, "cont2", "leaf21") != null);
92 assertTrue(getLeafUnderContainer(hostModule, "cont2", "leaf21").getType().getDataType().equals("int16"));
93 assertTrue(getLeafUnderContainer(hostModule, "cont2", "leaf21").getConfig().getValue().equals("false"));
94 assertTrue(getLeafUnderContainer(hostModule, "cont2", "leaf21").getMandatory().isMandatoryTrue());
95 assertTrue(getLeafUnderContainer(hostModule, "cont2", "leaf21").getUnits().getValue().equals("minutes"));
97 final YDeviation deviationCont2Leaf21 = (YDeviation) getChild(deviateAddModule, "deviation",
98 "/host:cont2/host:leaf21");
99 assertTrue(deviationCont2Leaf21 != null);
100 assertTrue(deviationCont2Leaf21.getDeviates().size() == 1);
101 assertTrue(deviationCont2Leaf21.getDeviates().get(0).getDeviateType() == DeviateType.ADD);
103 assertTrue(deviationCont2Leaf21.getDeviates().get(0).getType().getDataType().equals("string"));
104 assertStatementHasFindingOfType(deviationCont2Leaf21.getDeviates().get(0).getType(),
105 ParserFindingType.P161_INVALID_DEVIATE_OPERATION.toString());
106 assertStatementHasFindingOfType(deviationCont2Leaf21.getDeviates().get(0).getConfig(),
107 ParserFindingType.P161_INVALID_DEVIATE_OPERATION.toString());
108 assertStatementHasFindingOfType(deviationCont2Leaf21.getDeviates().get(0).getMandatory(),
109 ParserFindingType.P161_INVALID_DEVIATE_OPERATION.toString());
110 assertStatementHasFindingOfType(deviationCont2Leaf21.getDeviates().get(0).getUnits(),
111 ParserFindingType.P161_INVALID_DEVIATE_OPERATION.toString());
113 final YDeviation deviationList21 = (YDeviation) getChild(deviateAddModule, "deviation", "/host:list21");
114 assertTrue(deviationList21 != null);
115 assertTrue(deviationList21.getDeviates().size() == 1);
116 assertTrue(deviationList21.getDeviates().get(0).getDeviateType() == DeviateType.ADD);
118 assertTrue(deviationList21.getDeviates().get(0).getMinElements().getMinValue() == 67);
119 assertStatementHasFindingOfType(deviationList21.getDeviates().get(0).getMinElements(),
120 ParserFindingType.P161_INVALID_DEVIATE_OPERATION.toString());
121 assertTrue(deviationList21.getDeviates().get(0).getMaxElements().getMaxValue() == 82);
122 assertStatementHasFindingOfType(deviationList21.getDeviates().get(0).getMaxElements(),
123 ParserFindingType.P161_INVALID_DEVIATE_OPERATION.toString());
125 // ------------------------- Various other findings -------------------------------
127 final YDeviation deviationUnknownElement = (YDeviation) getChild(deviateAddModule, "deviation",
128 "/host:unknownelement");
129 assertTrue(deviationUnknownElement != null);
130 assertStatementHasFindingOfType(deviationUnknownElement, ParserFindingType.P054_UNRESOLVABLE_PATH.toString());
132 final YDeviation deviationCont4 = (YDeviation) getChild(deviateAddModule, "deviation", "/host:cont4");
133 assertTrue(deviationCont4 != null);
134 assertStatementHasFindingOfType(deviationCont4.getDeviates().get(0),
135 ParserFindingType.P019_MISSING_REQUIRED_CHILD_STATEMENT.toString());
137 final YDeviation deviationCont3 = (YDeviation) getChild(deviateAddModule, "deviation", "/host:cont3");
138 assertTrue(deviationCont3 != null);
139 assertStatementHasFindingOfType(deviationCont3.getDeviates().get(0).getMinElements(),
140 ParserFindingType.P018_ILLEGAL_CHILD_STATEMENT.toString());
141 assertStatementHasFindingOfType(deviationCont3.getDeviates().get(0).getMaxElements(),
142 ParserFindingType.P018_ILLEGAL_CHILD_STATEMENT.toString());
144 final YDeviation deviationList11Leaf112 = (YDeviation) getChild(deviateAddModule, "deviation",
145 "/host:list11/host:leaf112");
146 assertTrue(deviationList11Leaf112 != null);
147 assertStatementHasFindingOfType(deviationList11Leaf112.getDeviates().get(0).getDefaults().get(0),
148 ParserFindingType.P166_DEVIATE_RESULTS_IN_CHILD_CARDINALITY_VIOLATION.toString());
152 public void testDeviateReplace() {
154 parseImplementsYangModels(Arrays.asList("deviation-test/deviation-host-test-module.yang",
155 "deviation-test/deviate-replace-test-module.yang"), Arrays.asList(THREEGPP_YANG_EXT_PATH));
157 final YModule hostModule = getModule("deviation-host-test-module");
158 final YModule deviateReplaceModule = getModule("deviate-replace-test-module");
160 // ------------------------- All of these are just fine -------------------------------
162 assertTrue(getLeafUnderContainer(hostModule, "cont2", "leaf21") != null);
163 assertTrue(getLeafUnderContainer(hostModule, "cont2", "leaf21").getType().getDataType().equals("int16"));
164 assertTrue(getLeafUnderContainer(hostModule, "cont2", "leaf21").getConfig().getValue().equals("true"));
165 assertTrue(getLeafUnderContainer(hostModule, "cont2", "leaf21").getMandatory().isMandatoryFalse());
166 assertTrue(getLeafUnderContainer(hostModule, "cont2", "leaf21").getUnits().getValue().equals("days"));
167 assertSubTreeNoFindings(getContainer(hostModule, "cont2"));
169 assertTrue(getLeafListUnderList(hostModule, "list11", "leaflist113") != null);
170 assertTrue(getLeafListUnderList(hostModule, "list11", "leaflist113").getType().getDataType().equals("int16"));
171 assertTrue(getLeafListUnderList(hostModule, "list11", "leaflist113").getDefaults().size() == 2);
172 assertTrue(getLeafListUnderList(hostModule, "list11", "leaflist113").getDefaults().get(0).getValue().equals(
174 assertTrue(getLeafListUnderList(hostModule, "list11", "leaflist113").getDefaults().get(1).getValue().equals(
176 assertTrue(getLeafListUnderList(hostModule, "list11", "leaflist113").getMusts().size() == 1);
177 assertTrue(getLeafListUnderList(hostModule, "list11", "leaflist113").getMusts().get(0).getXpathExpression().equals(
179 assertTrue(((Y3gppInitialValue) getLeafListUnderList(hostModule, "list11", "leaflist113").getChild(
180 C3GPP.THREEGPP_COMMON_YANG_EXTENSIONS__INITIAL_VALUE)).getValue().equals("70"));
181 assertSubTreeNoFindings(getLeafListUnderList(hostModule, "list11", "leaflist113"));
183 assertTrue(getList(hostModule, "list21") != null);
184 assertTrue(getList(hostModule, "list21").getMinElements().getMinValue() == 2);
185 assertTrue(getList(hostModule, "list21").getMaxElements().getMaxValue() == 36);
186 assertSubTreeNoFindings(getList(hostModule, "list21"));
188 assertTrue(getLeafUnderContainer(hostModule, "cont5", "leaf51") != null);
189 assertTrue(getLeafUnderContainer(hostModule, "cont5", "leaf51").getType().getDataType().equals("string"));
190 assertTrue(getLeafUnderContainer(hostModule, "cont5", "leaf51").getType().getLength() != null);
191 assertTrue(getLeafUnderContainer(hostModule, "cont5", "leaf51").getType().getLength().getBoundaries().size() == 1);
192 assertTrue(getLeafUnderContainer(hostModule, "cont5", "leaf51").getType().getLength().getBoundaries().get(
194 assertTrue(getLeafUnderContainer(hostModule, "cont5", "leaf51").getType().getLength().getBoundaries().get(
196 assertSubTreeNoFindings(getLeafUnderContainer(hostModule, "cont5", "leaf51"));
198 assertSubTreeNoFindings(getChild(deviateReplaceModule, "deviation", "/host:cont2/host:leaf21"));
199 assertSubTreeNoFindings(getChild(deviateReplaceModule, "deviation", "/host:list11/host:leaflist113"));
200 assertSubTreeNoFindings(getChild(deviateReplaceModule, "deviation", "/host:list21"));
201 assertSubTreeNoFindings(getChild(deviateReplaceModule, "deviation", "/host:cont5/host:leaf51"));
203 // ------------------------------- Trying to replace things that don't exist -----------------------
205 final YDeviation deviationCont1Leaf11 = (YDeviation) getChild(deviateReplaceModule, "deviation",
206 "/host:cont1/host:leaf11");
207 assertTrue(deviationCont1Leaf11 != null);
208 assertTrue(deviationCont1Leaf11.getDeviates().size() == 1);
209 assertTrue(deviationCont1Leaf11.getDeviates().get(0).getDeviateType() == DeviateType.REPLACE);
210 assertStatementHasFindingOfType(deviationCont1Leaf11.getDeviates().get(0).getUnits(),
211 ParserFindingType.P161_INVALID_DEVIATE_OPERATION.toString());
213 // ---------------- Various other findings ---------------------
215 final YDeviation deviationCont4 = (YDeviation) getChild(deviateReplaceModule, "deviation", "/host:cont4");
216 assertTrue(deviationCont4 != null);
217 assertStatementHasFindingOfType(deviationCont4.getDeviates().get(0),
218 ParserFindingType.P019_MISSING_REQUIRED_CHILD_STATEMENT.toString());
220 final YDeviation deviationList11Leaf112 = (YDeviation) getChild(deviateReplaceModule, "deviation",
221 "/host:list11/host:leaf112");
222 assertTrue(deviationList11Leaf112 != null);
223 assertStatementHasFindingOfType(deviationList11Leaf112.getDeviates().get(0).getType(),
224 ParserFindingType.P057_DATA_TYPE_CHANGED.toString());
226 final YDeviation deviationList22 = (YDeviation) getChild(deviateReplaceModule, "deviation", "/host:list22");
227 assertTrue(deviationList22 != null);
228 assertStatementHasFindingOfType(deviationList22.getDeviates().get(0).getMinElements(),
229 ParserFindingType.P056_CONSTRAINT_NARROWED.toString());
230 assertStatementHasFindingOfType(deviationList22.getDeviates().get(0).getMaxElements(),
231 ParserFindingType.P056_CONSTRAINT_NARROWED.toString());
233 final YDeviation deviationList11Leaf114 = (YDeviation) getChild(deviateReplaceModule, "deviation",
234 "/host:list11/host:leaf114");
235 assertTrue(deviationList11Leaf114 != null);
236 assertStatementHasFindingOfType(deviationList11Leaf114.getDeviates().get(0).getDefaults().get(0),
237 ParserFindingType.P166_DEVIATE_RESULTS_IN_CHILD_CARDINALITY_VIOLATION.toString());
241 public void testDeviateDelete() {
243 parseImplementsYangModels(Arrays.asList("deviation-test/deviation-host-test-module.yang",
244 "deviation-test/deviate-delete-test-module.yang"), Arrays.asList(THREEGPP_YANG_EXT_PATH));
246 final YModule hostModule = getModule("deviation-host-test-module");
247 final YModule deviateDeleteModule = getModule("deviate-delete-test-module");
249 // ------------------------- All of these are just fine -------------------------------
251 assertTrue(getLeafUnderContainer(hostModule, "cont2", "leaf21") != null);
252 assertTrue(getLeafUnderContainer(hostModule, "cont2", "leaf21").getType().getDataType().equals("int16"));
253 assertTrue(getLeafUnderContainer(hostModule, "cont2", "leaf21").getConfig() != null);
254 assertTrue(getLeafUnderContainer(hostModule, "cont2", "leaf21").getMandatory() != null);
255 assertTrue(getLeafUnderContainer(hostModule, "cont2", "leaf21").getUnits() == null);
256 assertSubTreeNoFindings(getLeafUnderContainer(hostModule, "cont2", "leaf21"));
258 assertTrue(getLeafListUnderList(hostModule, "list11", "leaflist113") != null);
259 assertTrue(getLeafListUnderList(hostModule, "list11", "leaflist113").getType().getDataType().equals("int16"));
260 assertTrue(getLeafListUnderList(hostModule, "list11", "leaflist113").getDefaults().size() == 2);
261 assertTrue(getLeafListUnderList(hostModule, "list11", "leaflist113").getDefaults().get(0).getValue().equals("10"));
262 assertTrue(getLeafListUnderList(hostModule, "list11", "leaflist113").getDefaults().get(1).getValue().equals("13"));
263 assertTrue(getLeafListUnderList(hostModule, "list11", "leaflist113").getMusts().size() == 1);
264 assertTrue(getLeafListUnderList(hostModule, "list11", "leaflist113").getMusts().get(0).getXpathExpression().equals(
266 assertTrue(getLeafListUnderList(hostModule, "list11", "leaflist113").getChild(
267 C3GPP.THREEGPP_COMMON_YANG_EXTENSIONS__INITIAL_VALUE) == null);
268 assertSubTreeNoFindings(getLeafListUnderList(hostModule, "list11", "leaflist113"));
270 assertSubTreeNoFindings(getChild(deviateDeleteModule, "deviation", "/host:cont2/host:leaf21"));
271 assertSubTreeNoFindings(getChild(deviateDeleteModule, "deviation", "/host:list11/host:leaflist113"));
273 // ---------------- These deviations try to delete things that don't exist in the host model ---------------------
275 final YDeviation deviationCont1Leaf11 = (YDeviation) getChild(deviateDeleteModule, "deviation",
276 "/host:cont1/host:leaf11");
277 assertTrue(deviationCont1Leaf11 != null);
278 assertTrue(deviationCont1Leaf11.getDeviates().size() == 1);
279 assertTrue(deviationCont1Leaf11.getDeviates().get(0).getDeviateType() == DeviateType.DELETE);
280 assertStatementHasFindingOfType(deviationCont1Leaf11.getDeviates().get(0).getConfig(),
281 ParserFindingType.P161_INVALID_DEVIATE_OPERATION.toString());
283 final YDeviation deviationList11 = (YDeviation) getChild(deviateDeleteModule, "deviation", "/host:list11");
284 assertTrue(deviationList11 != null);
285 assertStatementHasFindingOfType(deviationList11.getDeviates().get(0).getMinElements(),
286 ParserFindingType.P161_INVALID_DEVIATE_OPERATION.toString());
287 assertStatementHasFindingOfType(deviationList11.getDeviates().get(0).getMaxElements(),
288 ParserFindingType.P161_INVALID_DEVIATE_OPERATION.toString());
290 // ---------------- Various other findings ---------------------
292 final YDeviation deviationCont4 = (YDeviation) getChild(deviateDeleteModule, "deviation", "/host:cont4");
293 assertTrue(deviationCont4 != null);
294 assertStatementHasFindingOfType(deviationCont4.getDeviates().get(0),
295 ParserFindingType.P019_MISSING_REQUIRED_CHILD_STATEMENT.toString());
297 final YDeviation deviationList11Leaf112 = (YDeviation) getChild(deviateDeleteModule, "deviation",
298 "/host:list11/host:leaf112");
299 assertTrue(deviationList11Leaf112 != null);
300 assertStatementHasFindingOfType(deviationList11Leaf112.getDeviates().get(0).getType(),
301 ParserFindingType.P166_DEVIATE_RESULTS_IN_CHILD_CARDINALITY_VIOLATION.toString());
305 public void testDeviateNotSupported() {
307 parseImplementsYangModels(Arrays.asList("deviation-test/deviation-host-test-module.yang",
308 "deviation-test/deviate-not-supported-test-module.yang"), Arrays.asList(THREEGPP_YANG_EXT_PATH));
310 final YModule hostModule = getModule("deviation-host-test-module");
311 final YModule deviateNotSupportedModule = getModule("deviate-not-supported-test-module");
313 // ------------------------- All of these are just fine -------------------------------
315 assertTrue(getContainer(hostModule, "cont2") != null);
316 assertTrue(getLeafUnderContainer(hostModule, "cont2", "leaf21") == null);
317 assertTrue(getList(hostModule, "list21") == null);
318 assertTrue(getList(hostModule, "cont1") == null);
320 assertSubTreeNoFindings(getChild(deviateNotSupportedModule, "deviation", "/host:cont2/host:leaf21"));
321 assertSubTreeNoFindings(getChild(deviateNotSupportedModule, "deviation", "/host:list21"));
322 assertSubTreeNoFindings(getChild(deviateNotSupportedModule, "deviation", "/host:cont1"));
324 // ---------------- These deviations try to not-support things that don't exist in the host model ---------------------
326 final YDeviation deviationUnknownElement = (YDeviation) getChild(deviateNotSupportedModule, "deviation",
327 "/host:unknownElement");
328 assertTrue(deviationUnknownElement != null);
329 assertTrue(deviationUnknownElement.getDeviates().size() == 1);
330 assertTrue(deviationUnknownElement.getDeviates().get(0).getDeviateType() == DeviateType.NOT_SUPPORTED);
331 assertStatementHasFindingOfType(deviationUnknownElement, ParserFindingType.P054_UNRESOLVABLE_PATH.toString());
333 final YDeviation deviationCont3UnknownElement = (YDeviation) getChild(deviateNotSupportedModule, "deviation",
334 "/host:cont3/host:unknownElement");
335 assertTrue(deviationCont3UnknownElement != null);
336 assertStatementHasFindingOfType(deviationCont3UnknownElement, ParserFindingType.P054_UNRESOLVABLE_PATH.toString());
338 // ---------------- Various other findings ---------------------
340 final YDeviation deviationCont4 = (YDeviation) getChild(deviateNotSupportedModule, "deviation", "/host:cont4");
341 assertTrue(deviationCont4 != null);
342 assertStatementHasFindingOfType(deviationCont4.getDeviates().get(0).getType(),
343 ParserFindingType.P018_ILLEGAL_CHILD_STATEMENT.toString());
347 public void testDeviateOthers() {
349 severityCalculator.suppressFinding(ParserFindingType.P152_AUGMENT_TARGET_NODE_IN_SAME_MODULE.toString());
351 parseImplementsYangModels(Arrays.asList("deviation-test/deviate-other-tests-module.yang"), Arrays.asList(
352 THREEGPP_YANG_EXT_PATH));
354 final YModule module = getModule("deviate-other-tests-module");
355 assertTrue(module != null);
357 // ---------------- Deviate something augmented ---------------------
359 assertTrue(getContainer(module, "cont01") != null);
360 assertSubTreeNoFindings(getContainer(module, "cont01"));
362 assertTrue(getLeafUnderContainer(module, "cont01", "leaf11") != null);
363 assertTrue(getLeafUnderContainer(module, "cont01", "leaf11").getType().getDataType().equals("string"));
364 assertTrue(getLeafUnderContainer(module, "cont01", "leaf11").getMandatory() != null);
365 assertTrue(getLeafUnderContainer(module, "cont01", "leaf11").getMandatory().isMandatoryTrue());
366 assertTrue(getLeafUnderContainer(module, "cont01", "leaf11").getConfig() != null);
367 assertTrue(getLeafUnderContainer(module, "cont01", "leaf11").getConfig().getValue().equals("false"));
368 assertTrue(getLeafListUnderContainer(module, "cont01", "leaflist12") != null);
369 assertTrue(getLeafListUnderContainer(module, "cont01", "leaflist12").getType().getDataType().equals("int16"));
370 assertTrue(getLeafListUnderContainer(module, "cont01", "leaflist12").getMinElements() != null);
371 assertTrue(getLeafListUnderContainer(module, "cont01", "leaflist12").getMinElements().getMinValue() == 20);
372 assertTrue(getLeafListUnderContainer(module, "cont01", "leaflist12").getMaxElements() != null);
373 assertTrue(getLeafListUnderContainer(module, "cont01", "leaflist12").getMaxElements().getMaxValue() == 25);
375 assertStatementHasSingleFindingOfType(getChild(module, "deviation", "/this:cont01/this:leaf11"),
376 ParserFindingType.P162_DEVIATION_TARGET_NODE_IN_SAME_MODULE.toString());
377 assertStatementHasSingleFindingOfType(getChild(module, "deviation", "/this:cont01/this:leaflist12"),
378 ParserFindingType.P162_DEVIATION_TARGET_NODE_IN_SAME_MODULE.toString());
380 // ---------------- Deviate-replace something that was deviate-added ---------------------
382 assertTrue(getContainer(module, "cont02") != null);
383 assertSubTreeNoFindings(getContainer(module, "cont02"));
385 assertTrue(getContainer(module, "cont02").getConfig() != null);
386 assertTrue(getContainer(module, "cont02").getConfig().getValue().equals("true"));
388 assertStatementHasFindingOfType(getChild(module, "deviation", "/this:cont02"),
389 ParserFindingType.P162_DEVIATION_TARGET_NODE_IN_SAME_MODULE.toString());
390 assertStatementHasFindingOfType(((YDeviation) getChild(module, "deviation", "/this:cont02")).getDeviates().get(1)
391 .getConfig(), ParserFindingType.P164_DEVIATE_REPLACE_OF_DEVIATE_ADDED_STATEMENT.toString());
393 // ---------------- Deviate-add something that was deviate-added ---------------------
395 assertTrue(getContainer(module, "cont03") != null);
396 assertSubTreeNoFindings(getContainer(module, "cont03"));
398 assertTrue(getContainer(module, "cont03").getConfig() != null);
399 assertTrue(getContainer(module, "cont03").getConfig().getValue().equals("false"));
401 assertStatementHasFindingOfType(getChild(module, "deviation", "/this:cont03"),
402 ParserFindingType.P162_DEVIATION_TARGET_NODE_IN_SAME_MODULE.toString());
403 assertStatementHasFindingOfType(((YDeviation) getChild(module, "deviation", "/this:cont03")).getDeviates().get(1)
404 .getConfig(), ParserFindingType.P161_INVALID_DEVIATE_OPERATION.toString());
406 // ---------------- Deviate-replace something that was deviate-replaced ---------------------
408 assertTrue(getContainer(module, "cont04") != null);
409 assertSubTreeNoFindings(getContainer(module, "cont04"));
411 assertTrue(getContainer(module, "cont04").getConfig() != null);
412 assertTrue(getContainer(module, "cont04").getConfig().getValue().equals("true"));
414 assertStatementHasFindingOfType(((YDeviation) getChild(module, "deviation", "/this:cont04")).getDeviates().get(1)
415 .getConfig(), ParserFindingType.P163_AMBIGUOUS_DEVIATE_REPLACE_OF_SAME_STATEMENT.toString());
417 // ---------------- Deviate-delete something that was deviate-replaced ---------------------
419 assertTrue(getContainer(module, "cont05") != null);
420 assertSubTreeNoFindings(getContainer(module, "cont05"));
422 assertTrue(getContainer(module, "cont05").getConfig() == null);
424 assertStatementHasFindingOfType(((YDeviation) getChild(module, "deviation", "/this:cont05")).getDeviates().get(1)
425 .getConfig(), ParserFindingType.P165_DEVIATE_DELETE_OF_DEVIATED_STATEMENT.toString());
427 // ---------------- Deviate-delete something that was deviate-added ---------------------
429 assertTrue(getContainer(module, "cont06") != null);
430 assertSubTreeNoFindings(getContainer(module, "cont06"));
432 assertTrue(getContainer(module, "cont06").getConfig() == null);
434 assertStatementHasFindingOfType(((YDeviation) getChild(module, "deviation", "/this:cont06")).getDeviates().get(1)
435 .getConfig(), ParserFindingType.P165_DEVIATE_DELETE_OF_DEVIATED_STATEMENT.toString());
437 // ---------------- Some error scenarios ---------------------
439 assertStatementHasFindingOfType(((YDeviation) getChild(module, "deviation", "/this:cont07")).getDeviates().get(0),
440 ParserFindingType.P015_INVALID_SYNTAX_IN_DOCUMENT.toString());
442 assertStatementHasFindingOfType(((YDeviation) getChild(module, "deviation", "/this:cont08")).getDeviates().get(0),
443 ParserFindingType.P015_INVALID_SYNTAX_IN_DOCUMENT.toString());
445 assertStatementHasFindingOfType(getChild(module, "deviation", "//this:cont08"),
446 ParserFindingType.P054_UNRESOLVABLE_PATH.toString());
448 assertStatementHasNotFindingOfType(getChild(module, "deviation", "/this:cont09/"),
449 ParserFindingType.P054_UNRESOLVABLE_PATH.toString());
451 assertStatementHasFindingOfType(getChild(module, "deviation", "/"), ParserFindingType.P054_UNRESOLVABLE_PATH
454 assertStatementHasFindingOfType(getChild(module, "deviation", ""), ParserFindingType.P015_INVALID_SYNTAX_IN_DOCUMENT
457 assertStatementHasFindingOfType(getChild(module, "deviation", null),
458 ParserFindingType.P015_INVALID_SYNTAX_IN_DOCUMENT.toString());
460 assertStatementHasNotFindingOfType(getChild(module, "deviation", " /this:cont10 "),
461 ParserFindingType.P054_UNRESOLVABLE_PATH.toString());
465 public void testDeviateNotSupportedMultiLevel() {
467 severityCalculator.suppressFinding(ParserFindingType.P162_DEVIATION_TARGET_NODE_IN_SAME_MODULE.toString());
469 parseImplementsYangModels(Arrays.asList("deviation-test/deviate-not-supported-multi-level-test-module.yang"), Arrays
470 .asList(THREEGPP_YANG_EXT_PATH));
472 final YModule module = getModule("deviate-not-supported-multi-level-test-module");
473 assertTrue(module != null);
477 final YContainer cont1 = getContainer(module, "cont1");
478 assertTrue(cont1 != null);
480 final YContainer cont2 = getContainer(cont1, "cont2");
481 assertTrue(cont2 == null);