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.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertNull;
15 import org.junit.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;
21 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
23 public class IfFeatureResolutionTest {
25 public void testSomeFeaturesSupported() throws Exception {
26 final var schemaContext = StmtTestUtils.parseYangSources("/if-feature-resolution-test",
28 QName.create("foo-namespace", "test-feature-1"),
29 QName.create("foo-namespace", "test-feature-2"),
30 QName.create("foo-namespace", "test-feature-3"),
31 QName.create("bar-namespace", "imp-feature")),
32 YangParserConfiguration.DEFAULT);
34 final Module testModule = schemaContext.findModule("foo").get();
35 assertEquals(9, testModule.getChildNodes().size());
37 final ContainerSchemaNode testContainerA = (ContainerSchemaNode) testModule.dataChildByName(
38 QName.create(testModule.getQNameModule(), "test-container-a"));
39 assertNull(testContainerA);
41 final ContainerSchemaNode testContainerB = (ContainerSchemaNode) testModule.getDataChildByName(
42 QName.create(testModule.getQNameModule(), "test-container-b"));
43 assertNotNull(testContainerB);
44 final LeafSchemaNode testLeafB = (LeafSchemaNode) testContainerB.getDataChildByName(
45 QName.create(testModule.getQNameModule(), "test-leaf-b"));
46 assertNotNull(testLeafB);
48 final ContainerSchemaNode testContainerC = (ContainerSchemaNode) testModule.getDataChildByName(
49 QName.create(testModule.getQNameModule(), "test-container-c"));
50 assertNotNull(testContainerC);
51 final LeafSchemaNode testLeafC = (LeafSchemaNode) testContainerC.getDataChildByName(
52 QName.create(testModule.getQNameModule(), "test-leaf-c"));
53 assertNotNull(testLeafC);
55 final ContainerSchemaNode testContainerD = (ContainerSchemaNode) testModule.dataChildByName(
56 QName.create(testModule.getQNameModule(), "test-container-d"));
57 assertNull(testContainerD);
59 final ContainerSchemaNode testContainerE = (ContainerSchemaNode) testModule.getDataChildByName(
60 QName.create(testModule.getQNameModule(), "test-container-e"));
61 assertNotNull(testContainerE);
62 final ContainerSchemaNode testSubContainerE = (ContainerSchemaNode) testContainerE.getDataChildByName(
63 QName.create(testModule.getQNameModule(), "test-subcontainer-e"));
64 assertNotNull(testSubContainerE);
65 final LeafSchemaNode testLeafE = (LeafSchemaNode) testSubContainerE.dataChildByName(
66 QName.create(testModule.getQNameModule(), "test-leaf-e"));
67 assertNull(testLeafE);
69 final ContainerSchemaNode testContainerF = (ContainerSchemaNode) testModule.getDataChildByName(
70 QName.create(testModule.getQNameModule(), "test-container-f"));
71 assertNotNull(testContainerF);
72 final ContainerSchemaNode testSubContainerF = (ContainerSchemaNode) testContainerF.dataChildByName(
73 QName.create(testModule.getQNameModule(), "test-subcontainer-f"));
74 assertNull(testSubContainerF);
76 final ContainerSchemaNode testContainerG = (ContainerSchemaNode) testModule.getDataChildByName(
77 QName.create(testModule.getQNameModule(), "test-container-g"));
78 assertNotNull(testContainerG);
79 assertEquals(1, testContainerG.getAvailableAugmentations().size());
80 final LeafSchemaNode testLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
81 QName.create(testModule.getQNameModule(), "test-leaf-g"));
82 assertNotNull(testLeafG);
83 final LeafSchemaNode augmentingTestLeafG = (LeafSchemaNode) testContainerG.dataChildByName(
84 QName.create(testModule.getQNameModule(), "augmenting-test-leaf-g"));
85 assertNull(augmentingTestLeafG);
86 final AnyxmlSchemaNode augmentingTestAnyxmlG = (AnyxmlSchemaNode) testContainerG.getDataChildByName(
87 QName.create(testModule.getQNameModule(), "augmenting-test-anyxml-g"));
88 assertNotNull(augmentingTestAnyxmlG);
90 final ContainerSchemaNode testContainerH = (ContainerSchemaNode) testModule.getDataChildByName(
91 QName.create(testModule.getQNameModule(), "test-container-h"));
92 assertNotNull(testContainerH);
93 assertEquals(0, testContainerH.getChildNodes().size());
94 assertEquals(0, testContainerH.getUses().size());
96 final ContainerSchemaNode testContainerI = (ContainerSchemaNode) testModule.getDataChildByName(
97 QName.create(testModule.getQNameModule(), "test-container-i"));
98 assertNotNull(testContainerI);
99 assertEquals(1, testContainerI.getUses().size());
100 ContainerSchemaNode testGroupingSubContainer = (ContainerSchemaNode) testContainerI.getDataChildByName(
101 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
102 assertNotNull(testGroupingSubContainer);
103 final LeafSchemaNode testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.dataChildByName(
104 QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
105 assertNull(testGroupingLeaf);
107 final ContainerSchemaNode testContainerJ = (ContainerSchemaNode) testModule.getDataChildByName(
108 QName.create(testModule.getQNameModule(), "test-container-j"));
109 assertNotNull(testContainerJ);
110 final LeafSchemaNode testLeafJ = (LeafSchemaNode) testContainerJ.getDataChildByName(
111 QName.create(testModule.getQNameModule(), "test-leaf-j"));
112 assertNotNull(testLeafJ);
114 final ContainerSchemaNode testContainerK = (ContainerSchemaNode) testModule.getDataChildByName(
115 QName.create(testModule.getQNameModule(), "test-container-k"));
116 assertNotNull(testContainerK);
117 assertEquals(1, testContainerK.getUses().size());
118 testGroupingSubContainer = (ContainerSchemaNode) testContainerK.getDataChildByName(
119 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
120 assertNotNull(testGroupingSubContainer);
121 assertEquals(1, testGroupingSubContainer.getAvailableAugmentations().size());
122 final LeafSchemaNode augmentingTestGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
123 QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf"));
124 assertNotNull(augmentingTestGroupingLeaf);
125 final LeafSchemaNode augmentingTestGroupingLeaf2 = (LeafSchemaNode) testGroupingSubContainer.dataChildByName(
126 QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf-2"));
127 assertNull(augmentingTestGroupingLeaf2);
131 public void testAllFeaturesSupported() throws Exception {
132 final var schemaContext = StmtTestUtils.parseYangSources("/if-feature-resolution-test",
133 YangParserConfiguration.DEFAULT);
135 final Module testModule = schemaContext.findModules("foo").iterator().next();
136 assertNotNull(testModule);
138 assertEquals(11, testModule.getChildNodes().size());
140 final ContainerSchemaNode testContainerA = (ContainerSchemaNode) testModule.getDataChildByName(
141 QName.create(testModule.getQNameModule(), "test-container-a"));
142 assertNotNull(testContainerA);
143 final LeafSchemaNode testLeafA = (LeafSchemaNode) testContainerA.getDataChildByName(
144 QName.create(testModule.getQNameModule(), "test-leaf-a"));
145 assertNotNull(testLeafA);
148 final ContainerSchemaNode testContainerB = (ContainerSchemaNode) testModule.getDataChildByName(
149 QName.create(testModule.getQNameModule(), "test-container-b"));
150 assertNotNull(testContainerB);
151 final LeafSchemaNode testLeafB = (LeafSchemaNode) testContainerB.getDataChildByName(
152 QName.create(testModule.getQNameModule(), "test-leaf-b"));
153 assertNotNull(testLeafB);
155 final ContainerSchemaNode testContainerC = (ContainerSchemaNode) testModule.getDataChildByName(
156 QName.create(testModule.getQNameModule(), "test-container-c"));
157 assertNotNull(testContainerC);
158 final LeafSchemaNode testLeafC = (LeafSchemaNode) testContainerC.getDataChildByName(
159 QName.create(testModule.getQNameModule(), "test-leaf-c"));
160 assertNotNull(testLeafC);
162 final ContainerSchemaNode testContainerD = (ContainerSchemaNode) testModule.getDataChildByName(
163 QName.create(testModule.getQNameModule(), "test-container-d"));
164 assertNotNull(testContainerD);
165 final LeafSchemaNode testLeafD = (LeafSchemaNode) testContainerD.getDataChildByName(
166 QName.create(testModule.getQNameModule(), "test-leaf-d"));
167 assertNotNull(testLeafD);
169 final ContainerSchemaNode testContainerE = (ContainerSchemaNode) testModule.getDataChildByName(
170 QName.create(testModule.getQNameModule(), "test-container-e"));
171 assertNotNull(testContainerE);
172 final ContainerSchemaNode testSubContainerE = (ContainerSchemaNode) testContainerE.getDataChildByName(
173 QName.create(testModule.getQNameModule(), "test-subcontainer-e"));
174 assertNotNull(testSubContainerE);
175 final LeafSchemaNode testLeafE = (LeafSchemaNode) testSubContainerE.getDataChildByName(
176 QName.create(testModule.getQNameModule(), "test-leaf-e"));
177 assertNotNull(testLeafE);
179 final ContainerSchemaNode testContainerF = (ContainerSchemaNode) testModule.getDataChildByName(
180 QName.create(testModule.getQNameModule(), "test-container-f"));
181 assertNotNull(testContainerF);
182 final ContainerSchemaNode testSubContainerF = (ContainerSchemaNode) testContainerF.getDataChildByName(
183 QName.create(testModule.getQNameModule(), "test-subcontainer-f"));
184 assertNotNull(testSubContainerF);
185 final ContainerSchemaNode testSubSubContainerF = (ContainerSchemaNode) testSubContainerF.getDataChildByName(
186 QName.create(testModule.getQNameModule(), "test-subsubcontainer-f"));
187 assertNotNull(testSubSubContainerF);
188 final LeafSchemaNode testLeafF = (LeafSchemaNode) testSubSubContainerF.getDataChildByName(
189 QName.create(testModule.getQNameModule(), "test-leaf-f"));
190 assertNotNull(testLeafF);
192 final ContainerSchemaNode testContainerG = (ContainerSchemaNode) testModule.getDataChildByName(
193 QName.create(testModule.getQNameModule(), "test-container-g"));
194 assertNotNull(testContainerG);
195 assertEquals(2, testContainerG.getAvailableAugmentations().size());
196 final LeafSchemaNode testLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
197 QName.create(testModule.getQNameModule(), "test-leaf-g"));
198 assertNotNull(testLeafG);
199 final LeafSchemaNode augmentingTestLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
200 QName.create(testModule.getQNameModule(), "augmenting-test-leaf-g"));
201 assertNotNull(augmentingTestLeafG);
202 final AnyxmlSchemaNode augmentingTestAnyxmlG = (AnyxmlSchemaNode) testContainerG.getDataChildByName(
203 QName.create(testModule.getQNameModule(), "augmenting-test-anyxml-g"));
204 assertNotNull(augmentingTestAnyxmlG);
206 final ContainerSchemaNode testContainerH = (ContainerSchemaNode) testModule.getDataChildByName(
207 QName.create(testModule.getQNameModule(), "test-container-h"));
208 assertNotNull(testContainerH);
209 assertEquals(1, testContainerH.getUses().size());
210 ContainerSchemaNode testGroupingSubContainer = (ContainerSchemaNode) testContainerH.getDataChildByName(
211 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
212 assertNotNull(testGroupingSubContainer);
213 LeafSchemaNode testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
214 QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
215 assertNotNull(testGroupingLeaf);
217 final ContainerSchemaNode testContainerI = (ContainerSchemaNode) testModule.getDataChildByName(
218 QName.create(testModule.getQNameModule(), "test-container-i"));
219 assertNotNull(testContainerI);
220 assertEquals(1, testContainerI.getUses().size());
221 testGroupingSubContainer = (ContainerSchemaNode) testContainerI.getDataChildByName(
222 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
223 assertNotNull(testGroupingSubContainer);
224 testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
225 QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
226 assertNotNull(testGroupingLeaf);
228 final ContainerSchemaNode testContainerJ = (ContainerSchemaNode) testModule.getDataChildByName(
229 QName.create(testModule.getQNameModule(), "test-container-j"));
230 assertNotNull(testContainerJ);
231 final LeafSchemaNode testLeafJ = (LeafSchemaNode) testContainerJ.getDataChildByName(
232 QName.create(testModule.getQNameModule(), "test-leaf-j"));
233 assertNotNull(testLeafJ);
235 final ContainerSchemaNode testContainerK = (ContainerSchemaNode) testModule.getDataChildByName(
236 QName.create(testModule.getQNameModule(), "test-container-k"));
237 assertNotNull(testContainerK);
238 assertEquals(1, testContainerK.getUses().size());
239 testGroupingSubContainer = (ContainerSchemaNode) testContainerK.getDataChildByName(
240 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
241 assertNotNull(testGroupingSubContainer);
242 assertEquals(1, testGroupingSubContainer.getAvailableAugmentations().size());
243 final LeafSchemaNode augmentingTestGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
244 QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf"));
245 assertNotNull(augmentingTestGroupingLeaf);
246 final LeafSchemaNode augmentingTestGroupingLeaf2 = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
247 QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf-2"));
248 assertNotNull(augmentingTestGroupingLeaf2);
249 testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
250 QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
251 assertNotNull(testGroupingLeaf);
255 public void testNoFeaturesSupported() throws Exception {
256 final var schemaContext = StmtTestUtils.parseYangSources("/if-feature-resolution-test",
257 Set.of(), YangParserConfiguration.DEFAULT);
259 final Module testModule = schemaContext.findModules("foo").iterator().next();
260 assertNotNull(testModule);
262 assertEquals(6, testModule.getChildNodes().size());
264 final ContainerSchemaNode testContainerE = (ContainerSchemaNode) testModule.getDataChildByName(
265 QName.create(testModule.getQNameModule(), "test-container-e"));
266 assertNotNull(testContainerE);
267 final ContainerSchemaNode testSubContainerE = (ContainerSchemaNode) testContainerE.getDataChildByName(
268 QName.create(testModule.getQNameModule(), "test-subcontainer-e"));
269 assertNotNull(testSubContainerE);
270 final LeafSchemaNode testLeafE = (LeafSchemaNode) testSubContainerE.dataChildByName(
271 QName.create(testModule.getQNameModule(), "test-leaf-e"));
272 assertNull(testLeafE);
274 final ContainerSchemaNode testContainerF = (ContainerSchemaNode) testModule.getDataChildByName(
275 QName.create(testModule.getQNameModule(), "test-container-f"));
276 assertNotNull(testContainerF);
277 final ContainerSchemaNode testSubContainerF = (ContainerSchemaNode) testContainerF.dataChildByName(
278 QName.create(testModule.getQNameModule(), "test-subcontainer-f"));
279 assertNull(testSubContainerF);
281 final ContainerSchemaNode testContainerG = (ContainerSchemaNode) testModule.getDataChildByName(
282 QName.create(testModule.getQNameModule(), "test-container-g"));
283 assertNotNull(testContainerG);
284 assertEquals(1, testContainerG.getAvailableAugmentations().size());
285 final LeafSchemaNode testLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
286 QName.create(testModule.getQNameModule(), "test-leaf-g"));
287 assertNotNull(testLeafG);
288 final LeafSchemaNode augmentingTestLeafG = (LeafSchemaNode) testContainerG.dataChildByName(
289 QName.create(testModule.getQNameModule(), "augmenting-test-leaf-g"));
290 assertNull(augmentingTestLeafG);
291 final AnyxmlSchemaNode augmentingTestAnyxmlG = (AnyxmlSchemaNode) testContainerG.getDataChildByName(
292 QName.create(testModule.getQNameModule(), "augmenting-test-anyxml-g"));
293 assertNotNull(augmentingTestAnyxmlG);
295 final ContainerSchemaNode testContainerH = (ContainerSchemaNode) testModule.getDataChildByName(
296 QName.create(testModule.getQNameModule(), "test-container-h"));
297 assertNotNull(testContainerH);
298 assertEquals(0, testContainerH.getChildNodes().size());
299 assertEquals(0, testContainerH.getUses().size());
301 final ContainerSchemaNode testContainerI = (ContainerSchemaNode) testModule.getDataChildByName(
302 QName.create(testModule.getQNameModule(), "test-container-i"));
303 assertNotNull(testContainerI);
304 assertEquals(1, testContainerI.getUses().size());
305 ContainerSchemaNode testGroupingSubContainer = (ContainerSchemaNode) testContainerI.getDataChildByName(
306 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
307 assertNotNull(testGroupingSubContainer);
308 LeafSchemaNode testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.dataChildByName(
309 QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
310 assertNull(testGroupingLeaf);
312 final ContainerSchemaNode testContainerK = (ContainerSchemaNode) testModule.getDataChildByName(
313 QName.create(testModule.getQNameModule(), "test-container-k"));
314 assertNotNull(testContainerK);
315 assertEquals(1, testContainerK.getUses().size());
316 testGroupingSubContainer = (ContainerSchemaNode) testContainerK.getDataChildByName(
317 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
318 assertNotNull(testGroupingSubContainer);
319 assertEquals(1, testGroupingSubContainer.getAvailableAugmentations().size());
320 final LeafSchemaNode augmentingTestGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.dataChildByName(
321 QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf"));
322 assertNull(augmentingTestGroupingLeaf);
323 final LeafSchemaNode augmentingTestGroupingLeaf2 = (LeafSchemaNode) testGroupingSubContainer.dataChildByName(
324 QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf-2"));
325 assertNull(augmentingTestGroupingLeaf2);
326 testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.dataChildByName(
327 QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
328 assertNull(testGroupingLeaf);