a9672a8c0beacc1c3713d95ac6ddcd6112c493b1
[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.statements.yang.test;
22
23 import static org.junit.Assert.assertTrue;
24
25 import java.util.Arrays;
26
27 import org.junit.Test;
28
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;
37
38 public class DeviationTest extends YangTestCommon {
39
40     @Test
41     public void testDeviateAdd() {
42
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));
45
46         final YModule hostModule = getModule("deviation-host-test-module");
47         final YModule deviateAddModule = getModule("deviate-add-test-module");
48
49         // ------------------------- All of these are just fine -------------------------------
50
51         assertTrue(getContainer(hostModule, "cont1") != null);
52         assertSubTreeNoFindings(getContainer(hostModule, "cont1"));
53
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(
60                 "strlen(.) > 5"));
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"));
67
68         assertTrue(getList(hostModule, "list11") != null);
69         assertSubTreeNoFindings(getList(hostModule, "list11"));
70
71         assertTrue(getList(hostModule, "list11").getUniques().size() == 1);
72         assertTrue(getList(hostModule, "list11").getUniques().get(0).getValue().equals("leaf111 leaf112"));
73
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(
81                 ". > 4"));
82         assertTrue(getLeafListUnderList(hostModule, "list11", "leaflist113").getMusts().get(1).getXpathExpression().equals(
83                 ". < 98"));
84
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"));
88
89         // ------------------------- Trying to add things that already exist -------------------------------
90
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"));
96
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);
102
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());
112
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);
117
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());
124
125         // ------------------------- Various other findings -------------------------------
126
127         final YDeviation deviationUnknownElement = (YDeviation) getChild(deviateAddModule, "deviation",
128                 "/host:unknownelement");
129         assertTrue(deviationUnknownElement != null);
130         assertStatementHasFindingOfType(deviationUnknownElement, ParserFindingType.P054_UNRESOLVABLE_PATH.toString());
131
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());
136
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());
143
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());
149     }
150
151     @Test
152     public void testDeviateReplace() {
153
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));
156
157         final YModule hostModule = getModule("deviation-host-test-module");
158         final YModule deviateReplaceModule = getModule("deviate-replace-test-module");
159
160         // ------------------------- All of these are just fine -------------------------------
161
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"));
168
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(
173                 "1234"));
174         assertTrue(getLeafListUnderList(hostModule, "list11", "leaflist113").getDefaults().get(1).getValue().equals(
175                 "7890"));
176         assertTrue(getLeafListUnderList(hostModule, "list11", "leaflist113").getMusts().size() == 1);
177         assertTrue(getLeafListUnderList(hostModule, "list11", "leaflist113").getMusts().get(0).getXpathExpression().equals(
178                 ". > 4"));
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"));
182
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"));
187
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(
193                 0).lower == 10);
194         assertTrue(getLeafUnderContainer(hostModule, "cont5", "leaf51").getType().getLength().getBoundaries().get(
195                 0).upper == 40);
196         assertSubTreeNoFindings(getLeafUnderContainer(hostModule, "cont5", "leaf51"));
197
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"));
202
203         // ------------------------------- Trying to replace things that don't exist -----------------------
204
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());
212
213         // ---------------- Various other findings ---------------------
214
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());
219
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());
225
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());
232
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());
238     }
239
240     @Test
241     public void testDeviateDelete() {
242
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));
245
246         final YModule hostModule = getModule("deviation-host-test-module");
247         final YModule deviateDeleteModule = getModule("deviate-delete-test-module");
248
249         // ------------------------- All of these are just fine -------------------------------
250
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"));
257
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(
265                 ". > 4"));
266         assertTrue(getLeafListUnderList(hostModule, "list11", "leaflist113").getChild(
267                 C3GPP.THREEGPP_COMMON_YANG_EXTENSIONS__INITIAL_VALUE) == null);
268         assertSubTreeNoFindings(getLeafListUnderList(hostModule, "list11", "leaflist113"));
269
270         assertSubTreeNoFindings(getChild(deviateDeleteModule, "deviation", "/host:cont2/host:leaf21"));
271         assertSubTreeNoFindings(getChild(deviateDeleteModule, "deviation", "/host:list11/host:leaflist113"));
272
273         // ---------------- These deviations try to delete things that don't exist in the host model ---------------------
274
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());
282
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());
289
290         // ---------------- Various other findings ---------------------
291
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());
296
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());
302     }
303
304     @Test
305     public void testDeviateNotSupported() {
306
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));
309
310         final YModule hostModule = getModule("deviation-host-test-module");
311         final YModule deviateNotSupportedModule = getModule("deviate-not-supported-test-module");
312
313         // ------------------------- All of these are just fine -------------------------------
314
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);
319
320         assertSubTreeNoFindings(getChild(deviateNotSupportedModule, "deviation", "/host:cont2/host:leaf21"));
321         assertSubTreeNoFindings(getChild(deviateNotSupportedModule, "deviation", "/host:list21"));
322         assertSubTreeNoFindings(getChild(deviateNotSupportedModule, "deviation", "/host:cont1"));
323
324         // ---------------- These deviations try to not-support things that don't exist in the host model ---------------------
325
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());
332
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());
337
338         // ---------------- Various other findings ---------------------
339
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());
344     }
345
346     @Test
347     public void testDeviateOthers() {
348
349         severityCalculator.suppressFinding(ParserFindingType.P152_AUGMENT_TARGET_NODE_IN_SAME_MODULE.toString());
350
351         parseImplementsYangModels(Arrays.asList("deviation-test/deviate-other-tests-module.yang"), Arrays.asList(
352                 THREEGPP_YANG_EXT_PATH));
353
354         final YModule module = getModule("deviate-other-tests-module");
355         assertTrue(module != null);
356
357         // ---------------- Deviate something augmented ---------------------
358
359         assertTrue(getContainer(module, "cont01") != null);
360         assertSubTreeNoFindings(getContainer(module, "cont01"));
361
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);
374
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());
379
380         // ---------------- Deviate-replace something that was deviate-added ---------------------
381
382         assertTrue(getContainer(module, "cont02") != null);
383         assertSubTreeNoFindings(getContainer(module, "cont02"));
384
385         assertTrue(getContainer(module, "cont02").getConfig() != null);
386         assertTrue(getContainer(module, "cont02").getConfig().getValue().equals("true"));
387
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());
392
393         // ---------------- Deviate-add something that was deviate-added ---------------------
394
395         assertTrue(getContainer(module, "cont03") != null);
396         assertSubTreeNoFindings(getContainer(module, "cont03"));
397
398         assertTrue(getContainer(module, "cont03").getConfig() != null);
399         assertTrue(getContainer(module, "cont03").getConfig().getValue().equals("false"));
400
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());
405
406         // ---------------- Deviate-replace something that was deviate-replaced ---------------------
407
408         assertTrue(getContainer(module, "cont04") != null);
409         assertSubTreeNoFindings(getContainer(module, "cont04"));
410
411         assertTrue(getContainer(module, "cont04").getConfig() != null);
412         assertTrue(getContainer(module, "cont04").getConfig().getValue().equals("true"));
413
414         assertStatementHasFindingOfType(((YDeviation) getChild(module, "deviation", "/this:cont04")).getDeviates().get(1)
415                 .getConfig(), ParserFindingType.P163_AMBIGUOUS_DEVIATE_REPLACE_OF_SAME_STATEMENT.toString());
416
417         // ---------------- Deviate-delete something that was deviate-replaced ---------------------
418
419         assertTrue(getContainer(module, "cont05") != null);
420         assertSubTreeNoFindings(getContainer(module, "cont05"));
421
422         assertTrue(getContainer(module, "cont05").getConfig() == null);
423
424         assertStatementHasFindingOfType(((YDeviation) getChild(module, "deviation", "/this:cont05")).getDeviates().get(1)
425                 .getConfig(), ParserFindingType.P165_DEVIATE_DELETE_OF_DEVIATED_STATEMENT.toString());
426
427         // ---------------- Deviate-delete something that was deviate-added ---------------------
428
429         assertTrue(getContainer(module, "cont06") != null);
430         assertSubTreeNoFindings(getContainer(module, "cont06"));
431
432         assertTrue(getContainer(module, "cont06").getConfig() == null);
433
434         assertStatementHasFindingOfType(((YDeviation) getChild(module, "deviation", "/this:cont06")).getDeviates().get(1)
435                 .getConfig(), ParserFindingType.P165_DEVIATE_DELETE_OF_DEVIATED_STATEMENT.toString());
436
437         // ---------------- Some error scenarios ---------------------
438
439         assertStatementHasFindingOfType(((YDeviation) getChild(module, "deviation", "/this:cont07")).getDeviates().get(0),
440                 ParserFindingType.P015_INVALID_SYNTAX_IN_DOCUMENT.toString());
441
442         assertStatementHasFindingOfType(((YDeviation) getChild(module, "deviation", "/this:cont08")).getDeviates().get(0),
443                 ParserFindingType.P015_INVALID_SYNTAX_IN_DOCUMENT.toString());
444
445         assertStatementHasFindingOfType(getChild(module, "deviation", "//this:cont08"),
446                 ParserFindingType.P054_UNRESOLVABLE_PATH.toString());
447
448         assertStatementHasNotFindingOfType(getChild(module, "deviation", "/this:cont09/"),
449                 ParserFindingType.P054_UNRESOLVABLE_PATH.toString());
450
451         assertStatementHasFindingOfType(getChild(module, "deviation", "/"), ParserFindingType.P054_UNRESOLVABLE_PATH
452                 .toString());
453
454         assertStatementHasFindingOfType(getChild(module, "deviation", ""), ParserFindingType.P015_INVALID_SYNTAX_IN_DOCUMENT
455                 .toString());
456
457         assertStatementHasFindingOfType(getChild(module, "deviation", null),
458                 ParserFindingType.P015_INVALID_SYNTAX_IN_DOCUMENT.toString());
459
460         assertStatementHasNotFindingOfType(getChild(module, "deviation", "  /this:cont10  "),
461                 ParserFindingType.P054_UNRESOLVABLE_PATH.toString());
462     }
463
464     @Test
465     public void testDeviateNotSupportedMultiLevel() {
466
467         severityCalculator.suppressFinding(ParserFindingType.P162_DEVIATION_TARGET_NODE_IN_SAME_MODULE.toString());
468
469         parseImplementsYangModels(Arrays.asList("deviation-test/deviate-not-supported-multi-level-test-module.yang"), Arrays
470                 .asList(THREEGPP_YANG_EXT_PATH));
471
472         final YModule module = getModule("deviate-not-supported-multi-level-test-module");
473         assertTrue(module != null);
474
475         assertNoFindings();
476
477         final YContainer cont1 = getContainer(module, "cont1");
478         assertTrue(cont1 != null);
479
480         final YContainer cont2 = getContainer(cont1, "cont2");
481         assertTrue(cont2 == null);
482     }
483 }