2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.stmt;
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertNotNull;
12 import static org.junit.jupiter.api.Assertions.assertNull;
15 import org.junit.jupiter.api.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
21 class IfFeatureResolutionTest extends AbstractYangTest {
23 void testSomeFeaturesSupported() {
24 final var schemaContext = assertEffectiveModelDir("/if-feature-resolution-test",
26 QName.create("foo-namespace", "test-feature-1"),
27 QName.create("foo-namespace", "test-feature-2"),
28 QName.create("foo-namespace", "test-feature-3"),
29 QName.create("bar-namespace", "imp-feature")));
31 final var testModule = schemaContext.findModule("foo").orElseThrow();
32 assertEquals(9, testModule.getChildNodes().size());
34 final var testContainerA = (ContainerSchemaNode) testModule.dataChildByName(
35 QName.create(testModule.getQNameModule(), "test-container-a"));
36 assertNull(testContainerA);
38 final var testContainerB = (ContainerSchemaNode) testModule.getDataChildByName(
39 QName.create(testModule.getQNameModule(), "test-container-b"));
40 assertNotNull(testContainerB);
41 final var testLeafB = (LeafSchemaNode) testContainerB.getDataChildByName(
42 QName.create(testModule.getQNameModule(), "test-leaf-b"));
43 assertNotNull(testLeafB);
45 final var testContainerC = (ContainerSchemaNode) testModule.getDataChildByName(
46 QName.create(testModule.getQNameModule(), "test-container-c"));
47 assertNotNull(testContainerC);
48 final var testLeafC = (LeafSchemaNode) testContainerC.getDataChildByName(
49 QName.create(testModule.getQNameModule(), "test-leaf-c"));
50 assertNotNull(testLeafC);
52 final var testContainerD = (ContainerSchemaNode) testModule.dataChildByName(
53 QName.create(testModule.getQNameModule(), "test-container-d"));
54 assertNull(testContainerD);
56 final var testContainerE = (ContainerSchemaNode) testModule.getDataChildByName(
57 QName.create(testModule.getQNameModule(), "test-container-e"));
58 assertNotNull(testContainerE);
59 final var testSubContainerE = (ContainerSchemaNode) testContainerE.getDataChildByName(
60 QName.create(testModule.getQNameModule(), "test-subcontainer-e"));
61 assertNotNull(testSubContainerE);
62 final var testLeafE = (LeafSchemaNode) testSubContainerE.dataChildByName(
63 QName.create(testModule.getQNameModule(), "test-leaf-e"));
64 assertNull(testLeafE);
66 final var testContainerF = (ContainerSchemaNode) testModule.getDataChildByName(
67 QName.create(testModule.getQNameModule(), "test-container-f"));
68 assertNotNull(testContainerF);
69 final var testSubContainerF = (ContainerSchemaNode) testContainerF.dataChildByName(
70 QName.create(testModule.getQNameModule(), "test-subcontainer-f"));
71 assertNull(testSubContainerF);
73 final var testContainerG = (ContainerSchemaNode) testModule.getDataChildByName(
74 QName.create(testModule.getQNameModule(), "test-container-g"));
75 assertNotNull(testContainerG);
76 assertEquals(1, testContainerG.getAvailableAugmentations().size());
77 final var testLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
78 QName.create(testModule.getQNameModule(), "test-leaf-g"));
79 assertNotNull(testLeafG);
80 final var augmentingTestLeafG = (LeafSchemaNode) testContainerG.dataChildByName(
81 QName.create(testModule.getQNameModule(), "augmenting-test-leaf-g"));
82 assertNull(augmentingTestLeafG);
83 final var augmentingTestAnyxmlG = (AnyxmlSchemaNode) testContainerG.getDataChildByName(
84 QName.create(testModule.getQNameModule(), "augmenting-test-anyxml-g"));
85 assertNotNull(augmentingTestAnyxmlG);
87 final var testContainerH = (ContainerSchemaNode) testModule.getDataChildByName(
88 QName.create(testModule.getQNameModule(), "test-container-h"));
89 assertNotNull(testContainerH);
90 assertEquals(0, testContainerH.getChildNodes().size());
91 assertEquals(0, testContainerH.getUses().size());
93 final var testContainerI = (ContainerSchemaNode) testModule.getDataChildByName(
94 QName.create(testModule.getQNameModule(), "test-container-i"));
95 assertNotNull(testContainerI);
96 assertEquals(1, testContainerI.getUses().size());
97 var testGroupingSubContainer = (ContainerSchemaNode) testContainerI.getDataChildByName(
98 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
99 assertNotNull(testGroupingSubContainer);
100 final var testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.dataChildByName(
101 QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
102 assertNull(testGroupingLeaf);
104 final var testContainerJ = (ContainerSchemaNode) testModule.getDataChildByName(
105 QName.create(testModule.getQNameModule(), "test-container-j"));
106 assertNotNull(testContainerJ);
107 final var testLeafJ = (LeafSchemaNode) testContainerJ.getDataChildByName(
108 QName.create(testModule.getQNameModule(), "test-leaf-j"));
109 assertNotNull(testLeafJ);
111 final var testContainerK = (ContainerSchemaNode) testModule.getDataChildByName(
112 QName.create(testModule.getQNameModule(), "test-container-k"));
113 assertNotNull(testContainerK);
114 assertEquals(1, testContainerK.getUses().size());
115 testGroupingSubContainer = (ContainerSchemaNode) testContainerK.getDataChildByName(
116 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
117 assertNotNull(testGroupingSubContainer);
118 assertEquals(1, testGroupingSubContainer.getAvailableAugmentations().size());
119 final var augmentingTestGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
120 QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf"));
121 assertNotNull(augmentingTestGroupingLeaf);
122 final var augmentingTestGroupingLeaf2 = (LeafSchemaNode) testGroupingSubContainer.dataChildByName(
123 QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf-2"));
124 assertNull(augmentingTestGroupingLeaf2);
128 void testAllFeaturesSupported() {
129 final var schemaContext = assertEffectiveModelDir("/if-feature-resolution-test");
131 final var testModule = schemaContext.findModules("foo").iterator().next();
132 assertNotNull(testModule);
134 assertEquals(11, testModule.getChildNodes().size());
136 final var testContainerA = (ContainerSchemaNode) testModule.getDataChildByName(
137 QName.create(testModule.getQNameModule(), "test-container-a"));
138 assertNotNull(testContainerA);
139 final var testLeafA = (LeafSchemaNode) testContainerA.getDataChildByName(
140 QName.create(testModule.getQNameModule(), "test-leaf-a"));
141 assertNotNull(testLeafA);
143 final var testContainerB = (ContainerSchemaNode) testModule.getDataChildByName(
144 QName.create(testModule.getQNameModule(), "test-container-b"));
145 assertNotNull(testContainerB);
146 final var testLeafB = (LeafSchemaNode) testContainerB.getDataChildByName(
147 QName.create(testModule.getQNameModule(), "test-leaf-b"));
148 assertNotNull(testLeafB);
150 final var testContainerC = (ContainerSchemaNode) testModule.getDataChildByName(
151 QName.create(testModule.getQNameModule(), "test-container-c"));
152 assertNotNull(testContainerC);
153 final var testLeafC = (LeafSchemaNode) testContainerC.getDataChildByName(
154 QName.create(testModule.getQNameModule(), "test-leaf-c"));
155 assertNotNull(testLeafC);
157 final var testContainerD = (ContainerSchemaNode) testModule.getDataChildByName(
158 QName.create(testModule.getQNameModule(), "test-container-d"));
159 assertNotNull(testContainerD);
160 final var testLeafD = (LeafSchemaNode) testContainerD.getDataChildByName(
161 QName.create(testModule.getQNameModule(), "test-leaf-d"));
162 assertNotNull(testLeafD);
164 final var testContainerE = (ContainerSchemaNode) testModule.getDataChildByName(
165 QName.create(testModule.getQNameModule(), "test-container-e"));
166 assertNotNull(testContainerE);
167 final var testSubContainerE = (ContainerSchemaNode) testContainerE.getDataChildByName(
168 QName.create(testModule.getQNameModule(), "test-subcontainer-e"));
169 assertNotNull(testSubContainerE);
170 final var testLeafE = (LeafSchemaNode) testSubContainerE.getDataChildByName(
171 QName.create(testModule.getQNameModule(), "test-leaf-e"));
172 assertNotNull(testLeafE);
174 final var testContainerF = (ContainerSchemaNode) testModule.getDataChildByName(
175 QName.create(testModule.getQNameModule(), "test-container-f"));
176 assertNotNull(testContainerF);
177 final var testSubContainerF = (ContainerSchemaNode) testContainerF.getDataChildByName(
178 QName.create(testModule.getQNameModule(), "test-subcontainer-f"));
179 assertNotNull(testSubContainerF);
180 final var testSubSubContainerF = (ContainerSchemaNode) testSubContainerF.getDataChildByName(
181 QName.create(testModule.getQNameModule(), "test-subsubcontainer-f"));
182 assertNotNull(testSubSubContainerF);
183 final var testLeafF = (LeafSchemaNode) testSubSubContainerF.getDataChildByName(
184 QName.create(testModule.getQNameModule(), "test-leaf-f"));
185 assertNotNull(testLeafF);
187 final var testContainerG = (ContainerSchemaNode) testModule.getDataChildByName(
188 QName.create(testModule.getQNameModule(), "test-container-g"));
189 assertNotNull(testContainerG);
190 assertEquals(2, testContainerG.getAvailableAugmentations().size());
191 final var testLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
192 QName.create(testModule.getQNameModule(), "test-leaf-g"));
193 assertNotNull(testLeafG);
194 final var augmentingTestLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
195 QName.create(testModule.getQNameModule(), "augmenting-test-leaf-g"));
196 assertNotNull(augmentingTestLeafG);
197 final var augmentingTestAnyxmlG = (AnyxmlSchemaNode) testContainerG.getDataChildByName(
198 QName.create(testModule.getQNameModule(), "augmenting-test-anyxml-g"));
199 assertNotNull(augmentingTestAnyxmlG);
201 final var testContainerH = (ContainerSchemaNode) testModule.getDataChildByName(
202 QName.create(testModule.getQNameModule(), "test-container-h"));
203 assertNotNull(testContainerH);
204 assertEquals(1, testContainerH.getUses().size());
205 var testGroupingSubContainer = (ContainerSchemaNode) testContainerH.getDataChildByName(
206 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
207 assertNotNull(testGroupingSubContainer);
208 var testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
209 QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
210 assertNotNull(testGroupingLeaf);
212 final var testContainerI = (ContainerSchemaNode) testModule.getDataChildByName(
213 QName.create(testModule.getQNameModule(), "test-container-i"));
214 assertNotNull(testContainerI);
215 assertEquals(1, testContainerI.getUses().size());
216 testGroupingSubContainer = (ContainerSchemaNode) testContainerI.getDataChildByName(
217 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
218 assertNotNull(testGroupingSubContainer);
219 testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
220 QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
221 assertNotNull(testGroupingLeaf);
223 final var testContainerJ = (ContainerSchemaNode) testModule.getDataChildByName(
224 QName.create(testModule.getQNameModule(), "test-container-j"));
225 assertNotNull(testContainerJ);
226 final var testLeafJ = (LeafSchemaNode) testContainerJ.getDataChildByName(
227 QName.create(testModule.getQNameModule(), "test-leaf-j"));
228 assertNotNull(testLeafJ);
230 final var testContainerK = (ContainerSchemaNode) testModule.getDataChildByName(
231 QName.create(testModule.getQNameModule(), "test-container-k"));
232 assertNotNull(testContainerK);
233 assertEquals(1, testContainerK.getUses().size());
234 testGroupingSubContainer = (ContainerSchemaNode) testContainerK.getDataChildByName(
235 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
236 assertNotNull(testGroupingSubContainer);
237 assertEquals(1, testGroupingSubContainer.getAvailableAugmentations().size());
238 final var augmentingTestGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
239 QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf"));
240 assertNotNull(augmentingTestGroupingLeaf);
241 final var augmentingTestGroupingLeaf2 = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
242 QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf-2"));
243 assertNotNull(augmentingTestGroupingLeaf2);
244 testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
245 QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
246 assertNotNull(testGroupingLeaf);
250 void testNoFeaturesSupported() {
251 final var schemaContext = assertEffectiveModelDir("/if-feature-resolution-test", Set.of());
253 final var testModule = schemaContext.findModules("foo").iterator().next();
254 assertNotNull(testModule);
256 assertEquals(6, testModule.getChildNodes().size());
258 final var testContainerE = (ContainerSchemaNode) testModule.getDataChildByName(
259 QName.create(testModule.getQNameModule(), "test-container-e"));
260 assertNotNull(testContainerE);
261 final var testSubContainerE = (ContainerSchemaNode) testContainerE.getDataChildByName(
262 QName.create(testModule.getQNameModule(), "test-subcontainer-e"));
263 assertNotNull(testSubContainerE);
264 final var testLeafE = (LeafSchemaNode) testSubContainerE.dataChildByName(
265 QName.create(testModule.getQNameModule(), "test-leaf-e"));
266 assertNull(testLeafE);
268 final var testContainerF = (ContainerSchemaNode) testModule.getDataChildByName(
269 QName.create(testModule.getQNameModule(), "test-container-f"));
270 assertNotNull(testContainerF);
271 final var testSubContainerF = (ContainerSchemaNode) testContainerF.dataChildByName(
272 QName.create(testModule.getQNameModule(), "test-subcontainer-f"));
273 assertNull(testSubContainerF);
275 final var testContainerG = (ContainerSchemaNode) testModule.getDataChildByName(
276 QName.create(testModule.getQNameModule(), "test-container-g"));
277 assertNotNull(testContainerG);
278 assertEquals(1, testContainerG.getAvailableAugmentations().size());
279 final var testLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
280 QName.create(testModule.getQNameModule(), "test-leaf-g"));
281 assertNotNull(testLeafG);
282 final var augmentingTestLeafG = (LeafSchemaNode) testContainerG.dataChildByName(
283 QName.create(testModule.getQNameModule(), "augmenting-test-leaf-g"));
284 assertNull(augmentingTestLeafG);
285 final var augmentingTestAnyxmlG = (AnyxmlSchemaNode) testContainerG.getDataChildByName(
286 QName.create(testModule.getQNameModule(), "augmenting-test-anyxml-g"));
287 assertNotNull(augmentingTestAnyxmlG);
289 final var testContainerH = (ContainerSchemaNode) testModule.getDataChildByName(
290 QName.create(testModule.getQNameModule(), "test-container-h"));
291 assertNotNull(testContainerH);
292 assertEquals(0, testContainerH.getChildNodes().size());
293 assertEquals(0, testContainerH.getUses().size());
295 final var testContainerI = (ContainerSchemaNode) testModule.getDataChildByName(
296 QName.create(testModule.getQNameModule(), "test-container-i"));
297 assertNotNull(testContainerI);
298 assertEquals(1, testContainerI.getUses().size());
299 var testGroupingSubContainer = (ContainerSchemaNode) testContainerI.getDataChildByName(
300 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
301 assertNotNull(testGroupingSubContainer);
302 var testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.dataChildByName(
303 QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
304 assertNull(testGroupingLeaf);
306 final var testContainerK = (ContainerSchemaNode) testModule.getDataChildByName(
307 QName.create(testModule.getQNameModule(), "test-container-k"));
308 assertNotNull(testContainerK);
309 assertEquals(1, testContainerK.getUses().size());
310 testGroupingSubContainer = (ContainerSchemaNode) testContainerK.getDataChildByName(
311 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
312 assertNotNull(testGroupingSubContainer);
313 assertEquals(1, testGroupingSubContainer.getAvailableAugmentations().size());
314 final var augmentingTestGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.dataChildByName(
315 QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf"));
316 assertNull(augmentingTestGroupingLeaf);
317 final var augmentingTestGroupingLeaf2 = (LeafSchemaNode) testGroupingSubContainer.dataChildByName(
318 QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf-2"));
319 assertNull(augmentingTestGroupingLeaf2);
320 testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.dataChildByName(
321 QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
322 assertNull(testGroupingLeaf);