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.yang.YContainer;
31 import org.oran.smo.yangtools.parser.model.statements.yang.YLeaf;
32 import org.oran.smo.yangtools.parser.model.statements.yang.YModule;
33 import org.oran.smo.yangtools.parser.testutils.YangTestCommon;
35 public class SubmoduleTest extends YangTestCommon {
38 public void testSubmoduleByExplicitRevisionOk() {
39 parseRelativeImplementsYangModels(Arrays.asList("submodule-test/explicit-revision-ok/module.yang",
40 "submodule-test/explicit-revision-ok/submodule.yang"));
43 final YModule yModule = getModule("submodule-test-module");
44 assertTrue(yModule != null);
46 final YContainer container1 = getContainer(yModule, "cont1");
47 assertTrue(container1 != null);
49 final YContainer container2 = getContainer(yModule, "cont2");
50 assertTrue(container2 != null);
52 final YLeaf leaf31 = getLeaf(yModule, "leaf31");
53 assertTrue(leaf31 != null);
57 public void testSubmoduleByExplicitRevisionWrongRevisionSupplied() {
58 parseRelativeImplementsYangModels(Arrays.asList("submodule-test/explicit-revision-not-found/module.yang",
59 "submodule-test/explicit-revision-not-found/submodule.yang"));
61 assertHasFindingOfType(ParserFindingType.P037_UNRESOLVABLE_INCLUDE.toString());
65 public void testSubmoduleByExplicitRevisionNotSupplied() {
66 parseRelativeImplementsYangModels(Arrays.asList("submodule-test/explicit-revision-not-found/module.yang"));
68 assertHasFindingOfType(ParserFindingType.P037_UNRESOLVABLE_INCLUDE.toString());
72 public void test_multiple_submodules() {
74 severityCalculator.suppressFinding(ParserFindingType.P115_TYPEDEF_USED_ONCE_ONLY.toString());
76 parseRelativeImplementsYangModels(Arrays.asList("submodule-test/multiple-submodules/module.yang",
77 "submodule-test/multiple-submodules/submodule1.yang", "submodule-test/multiple-submodules/submodule2.yang",
78 "submodule-test/multiple-submodules/submodule3.yang",
79 "submodule-test/multiple-submodules/importing-module.yang"));
83 final YModule module = getModule("module");
84 assertTrue(module != null);
86 final YContainer cont1 = getContainer(module, "cont1");
88 assertTrue(cont1 != null);
89 assertTrue(getContainer(cont1, "cont51") == null);
90 assertTrue(getContainer(cont1, "cont52") != null);
91 assertTrue(getLeaf(cont1, "leaf11") != null);
93 final YContainer cont2 = getContainer(module, "cont2");
94 assertTrue(cont2 != null);
95 assertTrue(getLeaf(cont2, "leaf12") != null);
96 assertTrue(getLeaf(cont2, "leaf81") != null);
97 assertTrue(getLeaf(cont2, "leaf81").getEffectiveNamespace().equals("test:importing-module"));
99 final YContainer cont11 = getContainer(module, "cont11");
100 assertTrue(cont11 != null);
101 assertTrue(cont11.getEffectiveNamespace().equals("test:module"));
102 assertTrue(getLeaf(cont11, "leaf24") != null);
104 final YContainer cont12 = getContainer(module, "cont12");
105 assertTrue(cont12 != null);
106 assertTrue(getContainer(cont12, "cont14") == null);
107 assertTrue(getLeaf(cont12, "leaf25") != null);
109 final YContainer cont22 = getContainer(module, "cont22");
110 assertTrue(cont22 != null);
111 assertTrue(cont22.getEffectiveNamespace().equals("test:module"));
112 assertTrue(getContainer(cont22, "cont61") != null);
114 final YContainer cont23 = getContainer(module, "cont23");
115 assertTrue(cont23 != null);
116 assertTrue(getLeaf(cont23, "leaf31") != null);
117 assertTrue(getLeaf(cont23, "leaf82") != null);
118 assertTrue(getLeaf(cont23, "leaf82").getEffectiveNamespace().equals("test:importing-module"));
120 final YContainer cont33 = getContainer(module, "cont33");
121 assertTrue(cont33 != null);
122 assertTrue(cont33.getEffectiveNamespace().equals("test:module"));
124 final YContainer cont34 = getContainer(module, "cont34");
125 assertTrue(cont34 != null);
126 assertTrue(getContainer(cont34, "cont37") == null);
128 final YLeaf leaf1 = getLeaf(module, "leaf1");
129 assertTrue(leaf1 != null);
130 assertTrue(leaf1.getEffectiveNamespace().equals("test:module"));
131 assertTrue(leaf1.getType().getDataType().equals("boolean"));
133 final YLeaf leaf2 = getLeaf(module, "leaf2");
134 assertTrue(leaf2 != null);
135 assertTrue(leaf2.getEffectiveNamespace().equals("test:module"));
136 assertTrue(leaf2.getType().getDataType().equals("boolean"));