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 static org.junit.Assert.assertTrue;
24 import static org.junit.Assert.fail;
26 import java.util.Arrays;
27 import java.util.Collections;
28 import java.util.List;
30 import org.junit.Test;
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;
37 public class StopAfterInitialParseTest extends YangTestCommon {
40 public void test_no_processing_delay() {
42 severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
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");
48 parseAbsoluteYangModels(absoluteImplementsFilePath, Collections.<String> emptyList());
52 final YModule module1 = getModule("module1");
53 assertTrue(module1 != null);
55 final YContainer cont1 = getContainer(module1, "cont1");
56 assertTrue(cont1 != null);
58 assertTrue(getLeaf(cont1, "leaf2") != null);
59 assertTrue(getLeaf(cont1, "leaf99") != null);
63 public void test_processing_delay() {
65 severityCalculator.suppressFinding(ParserFindingType.P133_GROUPING_USED_ONCE_ONLY.toString());
67 // this here is different
69 context.setStopAfterInitialParse(true);
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");
75 parseAbsoluteYangModels(absoluteImplementsFilePath, Collections.<String> emptyList());
79 final YModule module1 = getModule("module1");
80 assertTrue(module1 != null);
82 final YContainer cont1 = getContainer(module1, "cont1");
83 assertTrue(cont1 != null);
85 assertTrue(getLeaf(cont1, "leaf2") != null);
87 // this here is different
89 assertTrue(getLeaf(cont1, "leaf99") == null);
91 yangDeviceModel.getTopLevelSchema().processParsedYangModules(context);
93 assertTrue(getLeaf(cont1, "leaf99") != null);
95 // processing second time should not work:
98 yangDeviceModel.getTopLevelSchema().processParsedYangModules(context);
99 fail("Expected an exception.");
100 } catch (IllegalStateException ex) {
102 } catch (Exception ex) {
103 fail("Expected an IllegalStateException.");