50b761b7f11e3134dc66e18e20783fe311b619d0
[smo/teiv.git] /
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2024 Ericsson
4  *  Modifications Copyright (C) 2024 OpenInfra Foundation Europe
5  *  ================================================================================
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *
18  *  SPDX-License-Identifier: Apache-2.0
19  *  ============LICENSE_END=========================================================
20  */
21 package org.oran.smo.yangtools.parser.model.schema.test;
22
23 import static org.junit.Assert.assertTrue;
24 import static org.junit.Assert.fail;
25
26 import java.util.Arrays;
27 import java.util.Collections;
28 import java.util.List;
29
30 import org.junit.Test;
31
32 import org.oran.smo.yangtools.parser.findings.ParserFindingType;
33 import org.oran.smo.yangtools.parser.model.statements.yang.YContainer;
34 import org.oran.smo.yangtools.parser.model.statements.yang.YModule;
35 import org.oran.smo.yangtools.parser.testutils.YangTestCommon;
36
37 public class StopAfterInitialParseTest extends YangTestCommon {
38
39     @Test
40     public void test_no_processing_delay() {
41
42         severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
43
44         final List<String> absoluteImplementsFilePath = Arrays.asList(
45                 "src/test/resources/model-schema/stop-after-initial-parse-test/module1.yang",
46                 "src/test/resources/model-schema/stop-after-initial-parse-test/module2.yang");
47
48         parseAbsoluteYangModels(absoluteImplementsFilePath, Collections.<String> emptyList());
49
50         assertNoFindings();
51
52         final YModule module1 = getModule("module1");
53         assertTrue(module1 != null);
54
55         final YContainer cont1 = getContainer(module1, "cont1");
56         assertTrue(cont1 != null);
57
58         assertTrue(getLeaf(cont1, "leaf2") != null);
59         assertTrue(getLeaf(cont1, "leaf99") != null);
60     }
61
62     @Test
63     public void test_processing_delay() {
64
65         severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
66
67         // this here is different
68
69         context.setStopAfterInitialParse(true);
70
71         final List<String> absoluteImplementsFilePath = Arrays.asList(
72                 "src/test/resources/model-schema/stop-after-initial-parse-test/module1.yang",
73                 "src/test/resources/model-schema/stop-after-initial-parse-test/module2.yang");
74
75         parseAbsoluteYangModels(absoluteImplementsFilePath, Collections.<String> emptyList());
76
77         assertNoFindings();
78
79         final YModule module1 = getModule("module1");
80         assertTrue(module1 != null);
81
82         final YContainer cont1 = getContainer(module1, "cont1");
83         assertTrue(cont1 != null);
84
85         assertTrue(getLeaf(cont1, "leaf2") != null);
86
87         // this here is different
88
89         assertTrue(getLeaf(cont1, "leaf99") == null);
90
91         yangDeviceModel.getTopLevelSchema().processParsedYangModules(context);
92
93         assertTrue(getLeaf(cont1, "leaf99") != null);
94
95         // processing second time should not work:
96
97         try {
98             yangDeviceModel.getTopLevelSchema().processParsedYangModules(context);
99             fail("Expected an exception.");
100         } catch (IllegalStateException ex) {
101             // expected
102         } catch (Exception ex) {
103             fail("Expected an IllegalStateException.");
104         }
105     }
106
107 }