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;
20 import org.opendaylight.yangtools.yang.model.api.Module;
22 class IfFeatureResolutionTest extends AbstractYangTest {
24 void testSomeFeaturesSupported() {
25 final var schemaContext = assertEffectiveModelDir("/if-feature-resolution-test",
27 QName.create("foo-namespace", "test-feature-1"),
28 QName.create("foo-namespace", "test-feature-2"),
29 QName.create("foo-namespace", "test-feature-3"),
30 QName.create("bar-namespace", "imp-feature")));
32 final Module testModule = schemaContext.findModule("foo").get();
33 assertEquals(9, testModule.getChildNodes().size());
35 final ContainerSchemaNode testContainerA = (ContainerSchemaNode) testModule.dataChildByName(
36 QName.create(testModule.getQNameModule(), "test-container-a"));
37 assertNull(testContainerA);
39 final ContainerSchemaNode testContainerB = (ContainerSchemaNode) testModule.getDataChildByName(
40 QName.create(testModule.getQNameModule(), "test-container-b"));
41 assertNotNull(testContainerB);
42 final LeafSchemaNode testLeafB = (LeafSchemaNode) testContainerB.getDataChildByName(
43 QName.create(testModule.getQNameModule(), "test-leaf-b"));
44 assertNotNull(testLeafB);
46 final ContainerSchemaNode testContainerC = (ContainerSchemaNode) testModule.getDataChildByName(
47 QName.create(testModule.getQNameModule(), "test-container-c"));
48 assertNotNull(testContainerC);
49 final LeafSchemaNode testLeafC = (LeafSchemaNode) testContainerC.getDataChildByName(
50 QName.create(testModule.getQNameModule(), "test-leaf-c"));
51 assertNotNull(testLeafC);
53 final ContainerSchemaNode testContainerD = (ContainerSchemaNode) testModule.dataChildByName(
54 QName.create(testModule.getQNameModule(), "test-container-d"));
55 assertNull(testContainerD);
57 final ContainerSchemaNode testContainerE = (ContainerSchemaNode) testModule.getDataChildByName(
58 QName.create(testModule.getQNameModule(), "test-container-e"));
59 assertNotNull(testContainerE);
60 final ContainerSchemaNode testSubContainerE = (ContainerSchemaNode) testContainerE.getDataChildByName(
61 QName.create(testModule.getQNameModule(), "test-subcontainer-e"));
62 assertNotNull(testSubContainerE);
63 final LeafSchemaNode testLeafE = (LeafSchemaNode) testSubContainerE.dataChildByName(
64 QName.create(testModule.getQNameModule(), "test-leaf-e"));
65 assertNull(testLeafE);
67 final ContainerSchemaNode testContainerF = (ContainerSchemaNode) testModule.getDataChildByName(
68 QName.create(testModule.getQNameModule(), "test-container-f"));
69 assertNotNull(testContainerF);
70 final ContainerSchemaNode testSubContainerF = (ContainerSchemaNode) testContainerF.dataChildByName(
71 QName.create(testModule.getQNameModule(), "test-subcontainer-f"));
72 assertNull(testSubContainerF);
74 final ContainerSchemaNode testContainerG = (ContainerSchemaNode) testModule.getDataChildByName(
75 QName.create(testModule.getQNameModule(), "test-container-g"));
76 assertNotNull(testContainerG);
77 assertEquals(1, testContainerG.getAvailableAugmentations().size());
78 final LeafSchemaNode testLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
79 QName.create(testModule.getQNameModule(), "test-leaf-g"));
80 assertNotNull(testLeafG);
81 final LeafSchemaNode augmentingTestLeafG = (LeafSchemaNode) testContainerG.dataChildByName(
82 QName.create(testModule.getQNameModule(), "augmenting-test-leaf-g"));
83 assertNull(augmentingTestLeafG);
84 final AnyxmlSchemaNode augmentingTestAnyxmlG = (AnyxmlSchemaNode) testContainerG.getDataChildByName(
85 QName.create(testModule.getQNameModule(), "augmenting-test-anyxml-g"));
86 assertNotNull(augmentingTestAnyxmlG);
88 final ContainerSchemaNode testContainerH = (ContainerSchemaNode) testModule.getDataChildByName(
89 QName.create(testModule.getQNameModule(), "test-container-h"));
90 assertNotNull(testContainerH);
91 assertEquals(0, testContainerH.getChildNodes().size());
92 assertEquals(0, testContainerH.getUses().size());
94 final ContainerSchemaNode testContainerI = (ContainerSchemaNode) testModule.getDataChildByName(
95 QName.create(testModule.getQNameModule(), "test-container-i"));
96 assertNotNull(testContainerI);
97 assertEquals(1, testContainerI.getUses().size());
98 ContainerSchemaNode testGroupingSubContainer = (ContainerSchemaNode) testContainerI.getDataChildByName(
99 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
100 assertNotNull(testGroupingSubContainer);
101 final LeafSchemaNode testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.dataChildByName(
102 QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
103 assertNull(testGroupingLeaf);
105 final ContainerSchemaNode testContainerJ = (ContainerSchemaNode) testModule.getDataChildByName(
106 QName.create(testModule.getQNameModule(), "test-container-j"));
107 assertNotNull(testContainerJ);
108 final LeafSchemaNode testLeafJ = (LeafSchemaNode) testContainerJ.getDataChildByName(
109 QName.create(testModule.getQNameModule(), "test-leaf-j"));
110 assertNotNull(testLeafJ);
112 final ContainerSchemaNode testContainerK = (ContainerSchemaNode) testModule.getDataChildByName(
113 QName.create(testModule.getQNameModule(), "test-container-k"));
114 assertNotNull(testContainerK);
115 assertEquals(1, testContainerK.getUses().size());
116 testGroupingSubContainer = (ContainerSchemaNode) testContainerK.getDataChildByName(
117 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
118 assertNotNull(testGroupingSubContainer);
119 assertEquals(1, testGroupingSubContainer.getAvailableAugmentations().size());
120 final LeafSchemaNode augmentingTestGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
121 QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf"));
122 assertNotNull(augmentingTestGroupingLeaf);
123 final LeafSchemaNode augmentingTestGroupingLeaf2 = (LeafSchemaNode) testGroupingSubContainer.dataChildByName(
124 QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf-2"));
125 assertNull(augmentingTestGroupingLeaf2);
129 void testAllFeaturesSupported() {
130 final var schemaContext = assertEffectiveModelDir("/if-feature-resolution-test");
132 final Module testModule = schemaContext.findModules("foo").iterator().next();
133 assertNotNull(testModule);
135 assertEquals(11, testModule.getChildNodes().size());
137 final ContainerSchemaNode testContainerA = (ContainerSchemaNode) testModule.getDataChildByName(
138 QName.create(testModule.getQNameModule(), "test-container-a"));
139 assertNotNull(testContainerA);
140 final LeafSchemaNode testLeafA = (LeafSchemaNode) testContainerA.getDataChildByName(
141 QName.create(testModule.getQNameModule(), "test-leaf-a"));
142 assertNotNull(testLeafA);
145 final ContainerSchemaNode testContainerB = (ContainerSchemaNode) testModule.getDataChildByName(
146 QName.create(testModule.getQNameModule(), "test-container-b"));
147 assertNotNull(testContainerB);
148 final LeafSchemaNode testLeafB = (LeafSchemaNode) testContainerB.getDataChildByName(
149 QName.create(testModule.getQNameModule(), "test-leaf-b"));
150 assertNotNull(testLeafB);
152 final ContainerSchemaNode testContainerC = (ContainerSchemaNode) testModule.getDataChildByName(
153 QName.create(testModule.getQNameModule(), "test-container-c"));
154 assertNotNull(testContainerC);
155 final LeafSchemaNode testLeafC = (LeafSchemaNode) testContainerC.getDataChildByName(
156 QName.create(testModule.getQNameModule(), "test-leaf-c"));
157 assertNotNull(testLeafC);
159 final ContainerSchemaNode testContainerD = (ContainerSchemaNode) testModule.getDataChildByName(
160 QName.create(testModule.getQNameModule(), "test-container-d"));
161 assertNotNull(testContainerD);
162 final LeafSchemaNode testLeafD = (LeafSchemaNode) testContainerD.getDataChildByName(
163 QName.create(testModule.getQNameModule(), "test-leaf-d"));
164 assertNotNull(testLeafD);
166 final ContainerSchemaNode testContainerE = (ContainerSchemaNode) testModule.getDataChildByName(
167 QName.create(testModule.getQNameModule(), "test-container-e"));
168 assertNotNull(testContainerE);
169 final ContainerSchemaNode testSubContainerE = (ContainerSchemaNode) testContainerE.getDataChildByName(
170 QName.create(testModule.getQNameModule(), "test-subcontainer-e"));
171 assertNotNull(testSubContainerE);
172 final LeafSchemaNode testLeafE = (LeafSchemaNode) testSubContainerE.getDataChildByName(
173 QName.create(testModule.getQNameModule(), "test-leaf-e"));
174 assertNotNull(testLeafE);
176 final ContainerSchemaNode testContainerF = (ContainerSchemaNode) testModule.getDataChildByName(
177 QName.create(testModule.getQNameModule(), "test-container-f"));
178 assertNotNull(testContainerF);
179 final ContainerSchemaNode testSubContainerF = (ContainerSchemaNode) testContainerF.getDataChildByName(
180 QName.create(testModule.getQNameModule(), "test-subcontainer-f"));
181 assertNotNull(testSubContainerF);
182 final ContainerSchemaNode testSubSubContainerF = (ContainerSchemaNode) testSubContainerF.getDataChildByName(
183 QName.create(testModule.getQNameModule(), "test-subsubcontainer-f"));
184 assertNotNull(testSubSubContainerF);
185 final LeafSchemaNode testLeafF = (LeafSchemaNode) testSubSubContainerF.getDataChildByName(
186 QName.create(testModule.getQNameModule(), "test-leaf-f"));
187 assertNotNull(testLeafF);
189 final ContainerSchemaNode testContainerG = (ContainerSchemaNode) testModule.getDataChildByName(
190 QName.create(testModule.getQNameModule(), "test-container-g"));
191 assertNotNull(testContainerG);
192 assertEquals(2, testContainerG.getAvailableAugmentations().size());
193 final LeafSchemaNode testLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
194 QName.create(testModule.getQNameModule(), "test-leaf-g"));
195 assertNotNull(testLeafG);
196 final LeafSchemaNode augmentingTestLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
197 QName.create(testModule.getQNameModule(), "augmenting-test-leaf-g"));
198 assertNotNull(augmentingTestLeafG);
199 final AnyxmlSchemaNode augmentingTestAnyxmlG = (AnyxmlSchemaNode) testContainerG.getDataChildByName(
200 QName.create(testModule.getQNameModule(), "augmenting-test-anyxml-g"));
201 assertNotNull(augmentingTestAnyxmlG);
203 final ContainerSchemaNode testContainerH = (ContainerSchemaNode) testModule.getDataChildByName(
204 QName.create(testModule.getQNameModule(), "test-container-h"));
205 assertNotNull(testContainerH);
206 assertEquals(1, testContainerH.getUses().size());
207 ContainerSchemaNode testGroupingSubContainer = (ContainerSchemaNode) testContainerH.getDataChildByName(
208 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
209 assertNotNull(testGroupingSubContainer);
210 LeafSchemaNode testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
211 QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
212 assertNotNull(testGroupingLeaf);
214 final ContainerSchemaNode testContainerI = (ContainerSchemaNode) testModule.getDataChildByName(
215 QName.create(testModule.getQNameModule(), "test-container-i"));
216 assertNotNull(testContainerI);
217 assertEquals(1, testContainerI.getUses().size());
218 testGroupingSubContainer = (ContainerSchemaNode) testContainerI.getDataChildByName(
219 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
220 assertNotNull(testGroupingSubContainer);
221 testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
222 QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
223 assertNotNull(testGroupingLeaf);
225 final ContainerSchemaNode testContainerJ = (ContainerSchemaNode) testModule.getDataChildByName(
226 QName.create(testModule.getQNameModule(), "test-container-j"));
227 assertNotNull(testContainerJ);
228 final LeafSchemaNode testLeafJ = (LeafSchemaNode) testContainerJ.getDataChildByName(
229 QName.create(testModule.getQNameModule(), "test-leaf-j"));
230 assertNotNull(testLeafJ);
232 final ContainerSchemaNode testContainerK = (ContainerSchemaNode) testModule.getDataChildByName(
233 QName.create(testModule.getQNameModule(), "test-container-k"));
234 assertNotNull(testContainerK);
235 assertEquals(1, testContainerK.getUses().size());
236 testGroupingSubContainer = (ContainerSchemaNode) testContainerK.getDataChildByName(
237 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
238 assertNotNull(testGroupingSubContainer);
239 assertEquals(1, testGroupingSubContainer.getAvailableAugmentations().size());
240 final LeafSchemaNode augmentingTestGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
241 QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf"));
242 assertNotNull(augmentingTestGroupingLeaf);
243 final LeafSchemaNode augmentingTestGroupingLeaf2 = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
244 QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf-2"));
245 assertNotNull(augmentingTestGroupingLeaf2);
246 testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
247 QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
248 assertNotNull(testGroupingLeaf);
252 void testNoFeaturesSupported() {
253 final var schemaContext = assertEffectiveModelDir("/if-feature-resolution-test", Set.of());
255 final Module testModule = schemaContext.findModules("foo").iterator().next();
256 assertNotNull(testModule);
258 assertEquals(6, testModule.getChildNodes().size());
260 final ContainerSchemaNode testContainerE = (ContainerSchemaNode) testModule.getDataChildByName(
261 QName.create(testModule.getQNameModule(), "test-container-e"));
262 assertNotNull(testContainerE);
263 final ContainerSchemaNode testSubContainerE = (ContainerSchemaNode) testContainerE.getDataChildByName(
264 QName.create(testModule.getQNameModule(), "test-subcontainer-e"));
265 assertNotNull(testSubContainerE);
266 final LeafSchemaNode testLeafE = (LeafSchemaNode) testSubContainerE.dataChildByName(
267 QName.create(testModule.getQNameModule(), "test-leaf-e"));
268 assertNull(testLeafE);
270 final ContainerSchemaNode testContainerF = (ContainerSchemaNode) testModule.getDataChildByName(
271 QName.create(testModule.getQNameModule(), "test-container-f"));
272 assertNotNull(testContainerF);
273 final ContainerSchemaNode testSubContainerF = (ContainerSchemaNode) testContainerF.dataChildByName(
274 QName.create(testModule.getQNameModule(), "test-subcontainer-f"));
275 assertNull(testSubContainerF);
277 final ContainerSchemaNode testContainerG = (ContainerSchemaNode) testModule.getDataChildByName(
278 QName.create(testModule.getQNameModule(), "test-container-g"));
279 assertNotNull(testContainerG);
280 assertEquals(1, testContainerG.getAvailableAugmentations().size());
281 final LeafSchemaNode testLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
282 QName.create(testModule.getQNameModule(), "test-leaf-g"));
283 assertNotNull(testLeafG);
284 final LeafSchemaNode augmentingTestLeafG = (LeafSchemaNode) testContainerG.dataChildByName(
285 QName.create(testModule.getQNameModule(), "augmenting-test-leaf-g"));
286 assertNull(augmentingTestLeafG);
287 final AnyxmlSchemaNode augmentingTestAnyxmlG = (AnyxmlSchemaNode) testContainerG.getDataChildByName(
288 QName.create(testModule.getQNameModule(), "augmenting-test-anyxml-g"));
289 assertNotNull(augmentingTestAnyxmlG);
291 final ContainerSchemaNode testContainerH = (ContainerSchemaNode) testModule.getDataChildByName(
292 QName.create(testModule.getQNameModule(), "test-container-h"));
293 assertNotNull(testContainerH);
294 assertEquals(0, testContainerH.getChildNodes().size());
295 assertEquals(0, testContainerH.getUses().size());
297 final ContainerSchemaNode testContainerI = (ContainerSchemaNode) testModule.getDataChildByName(
298 QName.create(testModule.getQNameModule(), "test-container-i"));
299 assertNotNull(testContainerI);
300 assertEquals(1, testContainerI.getUses().size());
301 ContainerSchemaNode testGroupingSubContainer = (ContainerSchemaNode) testContainerI.getDataChildByName(
302 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
303 assertNotNull(testGroupingSubContainer);
304 LeafSchemaNode testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.dataChildByName(
305 QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
306 assertNull(testGroupingLeaf);
308 final ContainerSchemaNode testContainerK = (ContainerSchemaNode) testModule.getDataChildByName(
309 QName.create(testModule.getQNameModule(), "test-container-k"));
310 assertNotNull(testContainerK);
311 assertEquals(1, testContainerK.getUses().size());
312 testGroupingSubContainer = (ContainerSchemaNode) testContainerK.getDataChildByName(
313 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
314 assertNotNull(testGroupingSubContainer);
315 assertEquals(1, testGroupingSubContainer.getAvailableAugmentations().size());
316 final LeafSchemaNode augmentingTestGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.dataChildByName(
317 QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf"));
318 assertNull(augmentingTestGroupingLeaf);
319 final LeafSchemaNode augmentingTestGroupingLeaf2 = (LeafSchemaNode) testGroupingSubContainer.dataChildByName(
320 QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf-2"));
321 assertNull(augmentingTestGroupingLeaf2);
322 testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.dataChildByName(
323 QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
324 assertNull(testGroupingLeaf);