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
9 package org.opendaylight.yangtools.yang.stmt;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertNull;
15 import com.google.common.collect.ImmutableSet;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.Module;
23 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
25 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
26 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
27 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
28 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
30 public class IfFeatureResolutionTest {
32 private static final StatementStreamSource FOO_MODULE =
33 new YangStatementSourceImpl("/if-feature-resolution-test/foo.yang", false);
34 private static final StatementStreamSource BAR_MODULE =
35 new YangStatementSourceImpl("/if-feature-resolution-test/bar.yang", false);
38 public void testSomeFeaturesSupported() throws ReactorException {
39 final Set<QName> supportedFeatures = ImmutableSet.of(
40 QName.create("foo-namespace", "1970-01-01", "test-feature-1"),
41 QName.create("foo-namespace", "1970-01-01", "test-feature-2"),
42 QName.create("foo-namespace", "1970-01-01", "test-feature-3"),
43 QName.create("bar-namespace", "1970-01-01", "imp-feature"));
45 final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(supportedFeatures);
46 reactor.addSources(FOO_MODULE, BAR_MODULE);
48 final SchemaContext schemaContext = reactor.buildEffective();
49 assertNotNull(schemaContext);
51 final Module testModule = schemaContext.findModuleByName("foo", null);
52 assertNotNull(testModule);
54 assertEquals(9, testModule.getChildNodes().size());
56 final ContainerSchemaNode testContainerA = (ContainerSchemaNode) testModule.getDataChildByName(
57 QName.create(testModule.getQNameModule(), "test-container-a"));
58 assertNull(testContainerA);
60 final ContainerSchemaNode testContainerB = (ContainerSchemaNode) testModule.getDataChildByName(
61 QName.create(testModule.getQNameModule(), "test-container-b"));
62 assertNotNull(testContainerB);
63 final LeafSchemaNode testLeafB = (LeafSchemaNode) testContainerB.getDataChildByName(
64 QName.create(testModule.getQNameModule(), "test-leaf-b"));
65 assertNotNull(testLeafB);
67 final ContainerSchemaNode testContainerC = (ContainerSchemaNode) testModule.getDataChildByName(
68 QName.create(testModule.getQNameModule(), "test-container-c"));
69 assertNotNull(testContainerC);
70 final LeafSchemaNode testLeafC = (LeafSchemaNode) testContainerC.getDataChildByName(
71 QName.create(testModule.getQNameModule(), "test-leaf-c"));
72 assertNotNull(testLeafC);
74 final ContainerSchemaNode testContainerD = (ContainerSchemaNode) testModule.getDataChildByName(
75 QName.create(testModule.getQNameModule(), "test-container-d"));
76 assertNull(testContainerD);
78 final ContainerSchemaNode testContainerE = (ContainerSchemaNode) testModule.getDataChildByName(
79 QName.create(testModule.getQNameModule(), "test-container-e"));
80 assertNotNull(testContainerE);
81 final ContainerSchemaNode testSubContainerE = (ContainerSchemaNode) testContainerE.getDataChildByName(
82 QName.create(testModule.getQNameModule(), "test-subcontainer-e"));
83 assertNotNull(testSubContainerE);
84 final LeafSchemaNode testLeafE = (LeafSchemaNode) testSubContainerE.getDataChildByName(
85 QName.create(testModule.getQNameModule(), "test-leaf-e"));
86 assertNull(testLeafE);
88 final ContainerSchemaNode testContainerF = (ContainerSchemaNode) testModule.getDataChildByName(
89 QName.create(testModule.getQNameModule(), "test-container-f"));
90 assertNotNull(testContainerF);
91 final ContainerSchemaNode testSubContainerF = (ContainerSchemaNode) testContainerF.getDataChildByName(
92 QName.create(testModule.getQNameModule(), "test-subcontainer-f"));
93 assertNull(testSubContainerF);
95 final ContainerSchemaNode testContainerG = (ContainerSchemaNode) testModule.getDataChildByName(
96 QName.create(testModule.getQNameModule(), "test-container-g"));
97 assertNotNull(testContainerG);
98 assertEquals(1, testContainerG.getAvailableAugmentations().size());
99 final LeafSchemaNode testLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
100 QName.create(testModule.getQNameModule(), "test-leaf-g"));
101 assertNotNull(testLeafG);
102 final LeafSchemaNode augmentingTestLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
103 QName.create(testModule.getQNameModule(), "augmenting-test-leaf-g"));
104 assertNull(augmentingTestLeafG);
105 final AnyXmlSchemaNode augmentingTestAnyxmlG = (AnyXmlSchemaNode) testContainerG.getDataChildByName(
106 QName.create(testModule.getQNameModule(), "augmenting-test-anyxml-g"));
107 assertNotNull(augmentingTestAnyxmlG);
109 final ContainerSchemaNode testContainerH = (ContainerSchemaNode) testModule.getDataChildByName(
110 QName.create(testModule.getQNameModule(), "test-container-h"));
111 assertNotNull(testContainerH);
112 assertEquals(0, testContainerH.getChildNodes().size());
113 assertEquals(0, testContainerH.getUses().size());
115 final ContainerSchemaNode testContainerI = (ContainerSchemaNode) testModule.getDataChildByName(
116 QName.create(testModule.getQNameModule(), "test-container-i"));
117 assertNotNull(testContainerI);
118 assertEquals(1, testContainerI.getUses().size());
119 ContainerSchemaNode testGroupingSubContainer = (ContainerSchemaNode) testContainerI.getDataChildByName(
120 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
121 assertNotNull(testGroupingSubContainer);
122 final LeafSchemaNode testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
123 QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
124 assertNull(testGroupingLeaf);
126 final ContainerSchemaNode testContainerJ = (ContainerSchemaNode) testModule.getDataChildByName(
127 QName.create(testModule.getQNameModule(), "test-container-j"));
128 assertNotNull(testContainerJ);
129 final LeafSchemaNode testLeafJ = (LeafSchemaNode) testContainerJ.getDataChildByName(
130 QName.create(testModule.getQNameModule(), "test-leaf-j"));
131 assertNotNull(testLeafJ);
133 final ContainerSchemaNode testContainerK = (ContainerSchemaNode) testModule.getDataChildByName(
134 QName.create(testModule.getQNameModule(), "test-container-k"));
135 assertNotNull(testContainerK);
136 assertEquals(1, testContainerK.getUses().size());
137 testGroupingSubContainer = (ContainerSchemaNode) testContainerK.getDataChildByName(
138 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
139 assertNotNull(testGroupingSubContainer);
140 assertEquals(1, testGroupingSubContainer.getAvailableAugmentations().size());
141 final LeafSchemaNode augmentingTestGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
142 QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf"));
143 assertNotNull(augmentingTestGroupingLeaf);
144 final LeafSchemaNode augmentingTestGroupingLeaf2 = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
145 QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf-2"));
146 assertNull(augmentingTestGroupingLeaf2);
150 public void testAllFeaturesSupported() throws ReactorException {
151 final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
152 reactor.addSources(FOO_MODULE, BAR_MODULE);
154 final SchemaContext schemaContext = reactor.buildEffective();
155 assertNotNull(schemaContext);
157 final Module testModule = schemaContext.findModuleByName("foo", null);
158 assertNotNull(testModule);
160 assertEquals(11, testModule.getChildNodes().size());
162 final ContainerSchemaNode testContainerA = (ContainerSchemaNode) testModule.getDataChildByName(
163 QName.create(testModule.getQNameModule(), "test-container-a"));
164 assertNotNull(testContainerA);
165 final LeafSchemaNode testLeafA = (LeafSchemaNode) testContainerA.getDataChildByName(
166 QName.create(testModule.getQNameModule(), "test-leaf-a"));
167 assertNotNull(testLeafA);
170 final ContainerSchemaNode testContainerB = (ContainerSchemaNode) testModule.getDataChildByName(
171 QName.create(testModule.getQNameModule(), "test-container-b"));
172 assertNotNull(testContainerB);
173 final LeafSchemaNode testLeafB = (LeafSchemaNode) testContainerB.getDataChildByName(
174 QName.create(testModule.getQNameModule(), "test-leaf-b"));
175 assertNotNull(testLeafB);
177 final ContainerSchemaNode testContainerC = (ContainerSchemaNode) testModule.getDataChildByName(
178 QName.create(testModule.getQNameModule(), "test-container-c"));
179 assertNotNull(testContainerC);
180 final LeafSchemaNode testLeafC = (LeafSchemaNode) testContainerC.getDataChildByName(
181 QName.create(testModule.getQNameModule(), "test-leaf-c"));
182 assertNotNull(testLeafC);
184 final ContainerSchemaNode testContainerD = (ContainerSchemaNode) testModule.getDataChildByName(
185 QName.create(testModule.getQNameModule(), "test-container-d"));
186 assertNotNull(testContainerD);
187 final LeafSchemaNode testLeafD = (LeafSchemaNode) testContainerD.getDataChildByName(
188 QName.create(testModule.getQNameModule(), "test-leaf-d"));
189 assertNotNull(testLeafD);
191 final ContainerSchemaNode testContainerE = (ContainerSchemaNode) testModule.getDataChildByName(
192 QName.create(testModule.getQNameModule(), "test-container-e"));
193 assertNotNull(testContainerE);
194 final ContainerSchemaNode testSubContainerE = (ContainerSchemaNode) testContainerE.getDataChildByName(
195 QName.create(testModule.getQNameModule(), "test-subcontainer-e"));
196 assertNotNull(testSubContainerE);
197 final LeafSchemaNode testLeafE = (LeafSchemaNode) testSubContainerE.getDataChildByName(
198 QName.create(testModule.getQNameModule(), "test-leaf-e"));
199 assertNotNull(testLeafE);
201 final ContainerSchemaNode testContainerF = (ContainerSchemaNode) testModule.getDataChildByName(
202 QName.create(testModule.getQNameModule(), "test-container-f"));
203 assertNotNull(testContainerF);
204 final ContainerSchemaNode testSubContainerF = (ContainerSchemaNode) testContainerF.getDataChildByName(
205 QName.create(testModule.getQNameModule(), "test-subcontainer-f"));
206 assertNotNull(testSubContainerF);
207 final ContainerSchemaNode testSubSubContainerF = (ContainerSchemaNode) testSubContainerF.getDataChildByName(
208 QName.create(testModule.getQNameModule(), "test-subsubcontainer-f"));
209 assertNotNull(testSubSubContainerF);
210 final LeafSchemaNode testLeafF = (LeafSchemaNode) testSubSubContainerF.getDataChildByName(
211 QName.create(testModule.getQNameModule(), "test-leaf-f"));
212 assertNotNull(testLeafF);
214 final ContainerSchemaNode testContainerG = (ContainerSchemaNode) testModule.getDataChildByName(
215 QName.create(testModule.getQNameModule(), "test-container-g"));
216 assertNotNull(testContainerG);
217 assertEquals(2, testContainerG.getAvailableAugmentations().size());
218 final LeafSchemaNode testLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
219 QName.create(testModule.getQNameModule(), "test-leaf-g"));
220 assertNotNull(testLeafG);
221 final LeafSchemaNode augmentingTestLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
222 QName.create(testModule.getQNameModule(), "augmenting-test-leaf-g"));
223 assertNotNull(augmentingTestLeafG);
224 final AnyXmlSchemaNode augmentingTestAnyxmlG = (AnyXmlSchemaNode) testContainerG.getDataChildByName(
225 QName.create(testModule.getQNameModule(), "augmenting-test-anyxml-g"));
226 assertNotNull(augmentingTestAnyxmlG);
228 final ContainerSchemaNode testContainerH = (ContainerSchemaNode) testModule.getDataChildByName(
229 QName.create(testModule.getQNameModule(), "test-container-h"));
230 assertNotNull(testContainerH);
231 assertEquals(1, testContainerH.getUses().size());
232 ContainerSchemaNode testGroupingSubContainer = (ContainerSchemaNode) testContainerH.getDataChildByName(
233 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
234 assertNotNull(testGroupingSubContainer);
235 LeafSchemaNode testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
236 QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
237 assertNotNull(testGroupingLeaf);
239 final ContainerSchemaNode testContainerI = (ContainerSchemaNode) testModule.getDataChildByName(
240 QName.create(testModule.getQNameModule(), "test-container-i"));
241 assertNotNull(testContainerI);
242 assertEquals(1, testContainerI.getUses().size());
243 testGroupingSubContainer = (ContainerSchemaNode) testContainerI.getDataChildByName(
244 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
245 assertNotNull(testGroupingSubContainer);
246 testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
247 QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
248 assertNotNull(testGroupingLeaf);
250 final ContainerSchemaNode testContainerJ = (ContainerSchemaNode) testModule.getDataChildByName(
251 QName.create(testModule.getQNameModule(), "test-container-j"));
252 assertNotNull(testContainerJ);
253 final LeafSchemaNode testLeafJ = (LeafSchemaNode) testContainerJ.getDataChildByName(
254 QName.create(testModule.getQNameModule(), "test-leaf-j"));
255 assertNotNull(testLeafJ);
257 final ContainerSchemaNode testContainerK = (ContainerSchemaNode) testModule.getDataChildByName(
258 QName.create(testModule.getQNameModule(), "test-container-k"));
259 assertNotNull(testContainerK);
260 assertEquals(1, testContainerK.getUses().size());
261 testGroupingSubContainer = (ContainerSchemaNode) testContainerK.getDataChildByName(
262 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
263 assertNotNull(testGroupingSubContainer);
264 assertEquals(1, testGroupingSubContainer.getAvailableAugmentations().size());
265 final LeafSchemaNode augmentingTestGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
266 QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf"));
267 assertNotNull(augmentingTestGroupingLeaf);
268 final LeafSchemaNode augmentingTestGroupingLeaf2 = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
269 QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf-2"));
270 assertNotNull(augmentingTestGroupingLeaf2);
271 testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
272 QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
273 assertNotNull(testGroupingLeaf);
277 public void testNoFeaturesSupported() throws ReactorException {
278 final Set<QName> supportedFeatures = ImmutableSet.of();
280 final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(supportedFeatures);
281 reactor.addSources(FOO_MODULE, BAR_MODULE);
283 final SchemaContext schemaContext = reactor.buildEffective();
284 assertNotNull(schemaContext);
286 final Module testModule = schemaContext.findModuleByName("foo", null);
287 assertNotNull(testModule);
289 assertEquals(6, testModule.getChildNodes().size());
291 final ContainerSchemaNode testContainerE = (ContainerSchemaNode) testModule.getDataChildByName(
292 QName.create(testModule.getQNameModule(), "test-container-e"));
293 assertNotNull(testContainerE);
294 final ContainerSchemaNode testSubContainerE = (ContainerSchemaNode) testContainerE.getDataChildByName(
295 QName.create(testModule.getQNameModule(), "test-subcontainer-e"));
296 assertNotNull(testSubContainerE);
297 final LeafSchemaNode testLeafE = (LeafSchemaNode) testSubContainerE.getDataChildByName(
298 QName.create(testModule.getQNameModule(), "test-leaf-e"));
299 assertNull(testLeafE);
301 final ContainerSchemaNode testContainerF = (ContainerSchemaNode) testModule.getDataChildByName(
302 QName.create(testModule.getQNameModule(), "test-container-f"));
303 assertNotNull(testContainerF);
304 final ContainerSchemaNode testSubContainerF = (ContainerSchemaNode) testContainerF.getDataChildByName(
305 QName.create(testModule.getQNameModule(), "test-subcontainer-f"));
306 assertNull(testSubContainerF);
308 final ContainerSchemaNode testContainerG = (ContainerSchemaNode) testModule.getDataChildByName(
309 QName.create(testModule.getQNameModule(), "test-container-g"));
310 assertNotNull(testContainerG);
311 assertEquals(1, testContainerG.getAvailableAugmentations().size());
312 final LeafSchemaNode testLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
313 QName.create(testModule.getQNameModule(), "test-leaf-g"));
314 assertNotNull(testLeafG);
315 final LeafSchemaNode augmentingTestLeafG = (LeafSchemaNode) testContainerG.getDataChildByName(
316 QName.create(testModule.getQNameModule(), "augmenting-test-leaf-g"));
317 assertNull(augmentingTestLeafG);
318 final AnyXmlSchemaNode augmentingTestAnyxmlG = (AnyXmlSchemaNode) testContainerG.getDataChildByName(
319 QName.create(testModule.getQNameModule(), "augmenting-test-anyxml-g"));
320 assertNotNull(augmentingTestAnyxmlG);
322 final ContainerSchemaNode testContainerH = (ContainerSchemaNode) testModule.getDataChildByName(
323 QName.create(testModule.getQNameModule(), "test-container-h"));
324 assertNotNull(testContainerH);
325 assertEquals(0, testContainerH.getChildNodes().size());
326 assertEquals(0, testContainerH.getUses().size());
328 final ContainerSchemaNode testContainerI = (ContainerSchemaNode) testModule.getDataChildByName(
329 QName.create(testModule.getQNameModule(), "test-container-i"));
330 assertNotNull(testContainerI);
331 assertEquals(1, testContainerI.getUses().size());
332 ContainerSchemaNode testGroupingSubContainer = (ContainerSchemaNode) testContainerI.getDataChildByName(
333 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
334 assertNotNull(testGroupingSubContainer);
335 LeafSchemaNode testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
336 QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
337 assertNull(testGroupingLeaf);
339 final ContainerSchemaNode testContainerK = (ContainerSchemaNode) testModule.getDataChildByName(
340 QName.create(testModule.getQNameModule(), "test-container-k"));
341 assertNotNull(testContainerK);
342 assertEquals(1, testContainerK.getUses().size());
343 testGroupingSubContainer = (ContainerSchemaNode) testContainerK.getDataChildByName(
344 QName.create(testModule.getQNameModule(), "test-grouping-subcontainer"));
345 assertNotNull(testGroupingSubContainer);
346 assertEquals(1, testGroupingSubContainer.getAvailableAugmentations().size());
347 final LeafSchemaNode augmentingTestGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
348 QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf"));
349 assertNull(augmentingTestGroupingLeaf);
350 final LeafSchemaNode augmentingTestGroupingLeaf2 = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
351 QName.create(testModule.getQNameModule(), "augmenting-test-grouping-leaf-2"));
352 assertNull(augmentingTestGroupingLeaf2);
353 testGroupingLeaf = (LeafSchemaNode) testGroupingSubContainer.getDataChildByName(
354 QName.create(testModule.getQNameModule(), "test-grouping-leaf"));
355 assertNull(testGroupingLeaf);