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.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
15 import java.io.IOException;
17 import java.net.URISyntaxException;
18 import java.util.ArrayDeque;
19 import java.util.Collection;
20 import java.util.Deque;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.opendaylight.yangtools.yang.common.QName;
24 import org.opendaylight.yangtools.yang.common.QNameModule;
25 import org.opendaylight.yangtools.yang.common.Revision;
26 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
27 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
28 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
29 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
30 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
31 import org.opendaylight.yangtools.yang.model.api.Module;
32 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
33 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
34 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
35 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
36 import org.opendaylight.yangtools.yang.model.api.type.Uint8TypeDefinition;
37 import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
38 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
39 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
40 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
42 public class UsesAugmentTest {
44 private static final QNameModule UG = QNameModule.create(
45 URI.create("urn:opendaylight:params:xml:ns:yang:uses-grouping"), Revision.of("2013-07-30"));
46 private static final QNameModule GD = QNameModule.create(
47 URI.create("urn:opendaylight:params:xml:ns:yang:grouping-definitions"), Revision.of("2013-09-04"));
49 private SchemaContext context;
52 public void init() throws ReactorException, IOException, YangSyntaxErrorException, URISyntaxException {
53 context = TestUtils.loadModules(getClass().getResource("/grouping-test").toURI());
57 * Structure of testing model:
60 * |-- leaf version (U)
63 * |-- |-- container rp
64 * |-- |-- |-- leaf priority (U)
65 * |-- |-- |-- container box (U)
66 * |-- |-- |-- |-- container order (A)
67 * |-- |-- |-- |-- |-- leaf delete (U)
68 * |-- |-- |-- |-- |-- |-- leaf setup (U)
69 * |-- |-- |-- leaf processing-rule (U)
70 * |-- |-- |-- leaf ignore (U)
71 * |-- |-- path-key-expansion
72 * |-- |-- |-- container path-key
73 * |-- |-- |-- |-- list path-keys (U)
74 * |-- |-- |-- |-- |-- leaf version (U)
75 * |-- |-- |-- |-- |-- leaf type (U)
76 * |-- |-- |-- |-- |-- leaf processing-rule (U)
77 * |-- |-- |-- |-- |-- leaf ignore (U)
78 * |-- |-- container segment-computation
79 * |-- |-- |-- container p2p
80 * |-- |-- |-- |-- container endpoints
81 * |-- |-- |-- |-- |-- leaf processing-rule (U)
82 * |-- |-- |-- |-- |-- leaf ignore (U)
83 * |-- |-- |-- |-- |-- container box (U)
84 * |-- |-- |-- |-- |-- choice address-family (U)
85 * |-- |-- |-- |-- |-- |-- case ipv4
86 * |-- |-- |-- |-- |-- |-- |-- leaf source-ipv4-address
87 * |-- |-- |-- |-- |-- |-- case ipv6
88 * |-- |-- |-- |-- |-- |-- |-- leaf source-ipv6-address
89 * |-- |-- |-- |-- container reported-route
90 * |-- |-- |-- |-- |-- container bandwidth
91 * |-- |-- |-- |-- |-- list subobjects(U)
92 * |-- |-- |-- |-- |-- leaf processing-rule (U)
93 * |-- |-- |-- |-- |-- leaf ignore (U)
94 * |-- |-- |-- |-- container bandwidth (U)
95 * |-- |-- |-- |-- |-- container bandwidth (U)
96 * |-- |-- |-- |-- |-- leaf processing-rule (U)
97 * |-- |-- |-- |-- |-- leaf ignore (U)
100 * |-- |-- |-- leaf metric-type (U)
101 * |-- |-- |-- container box (U)
102 * |-- |-- |-- leaf processing-rule (U)
103 * |-- |-- |-- leaf ignore (U)
104 * |-- |-- leaf link-diverse (U)
105 * |-- |-- leaf processing-rule (U)
106 * |-- |-- leaf ignore (U)
108 * U = added by uses A = added by augment
110 * @throws Exception if exception occurs
113 public void testAugmentInUses() throws Exception {
114 final Module testModule = TestUtils.findModule(context, "uses-grouping").get();
116 final Deque<QName> path = new ArrayDeque<>();
118 // * notification pcreq
119 final Collection<? extends NotificationDefinition> notifications = testModule.getNotifications();
120 assertEquals(1, notifications.size());
121 final NotificationDefinition pcreq = notifications.iterator().next();
122 assertNotNull(pcreq);
123 QName expectedQName = QName.create(UG, "pcreq");
124 path.offer(expectedQName);
125 SchemaPath expectedPath = SchemaPath.create(path, true);
126 assertEquals(expectedPath, pcreq.getPath());
127 Collection<? extends DataSchemaNode> childNodes = pcreq.getChildNodes();
128 assertEquals(4, childNodes.size());
129 // * |-- leaf version
130 LeafSchemaNode version = (LeafSchemaNode) pcreq.getDataChildByName(QName.create(testModule.getQNameModule(),
132 assertNotNull(version);
133 expectedQName = QName.create(UG, "version");
134 path.offer(expectedQName);
135 expectedPath = SchemaPath.create(path, true);
136 assertEquals(expectedPath, version.getPath());
137 expectedQName = QName.create(UG, "version");
138 path.offer(expectedQName);
139 expectedPath = SchemaPath.create(true, pcreq.getQName(), expectedQName);
140 assertEquals(expectedPath, version.getType().getPath());
141 assertEquals(BaseTypes.uint8Type(), version.getType().getBaseType().getBaseType());
142 assertTrue(version.isAddedByUses());
144 LeafSchemaNode type = (LeafSchemaNode) pcreq.getDataChildByName(QName.create(testModule.getQNameModule(),
147 expectedQName = QName.create(UG, "type");
148 assertTrue(type.isAddedByUses());
151 path.offer(expectedQName);
152 expectedPath = SchemaPath.create(path, true);
153 assertEquals(expectedPath, type.getPath());
154 expectedQName = QName.create(GD, "int-ext");
155 path.offer(expectedQName);
156 expectedPath = SchemaPath.create(true, expectedQName);
157 assertEquals(expectedPath, type.getType().getPath());
158 final UnionTypeDefinition union = (UnionTypeDefinition) type.getType().getBaseType();
159 assertEquals(SchemaPath.create(true, expectedQName, QName.create(expectedQName, "union")), union.getPath());
160 assertEquals(2, union.getTypes().size());
161 // * |-- list requests
162 final ListSchemaNode requests = (ListSchemaNode) pcreq.getDataChildByName(QName.create(
163 testModule.getQNameModule(), "requests"));
164 assertNotNull(requests);
165 expectedQName = QName.create(UG, "requests");
166 assertEquals(expectedQName, requests.getQName());
169 path.offer(expectedQName);
170 expectedPath = SchemaPath.create(path, true);
171 assertEquals(expectedPath, requests.getPath());
172 assertFalse(requests.isAddedByUses());
173 childNodes = requests.getChildNodes();
174 assertEquals(3, childNodes.size());
175 // * |-- |-- container rp
176 final ContainerSchemaNode rp = (ContainerSchemaNode) requests.getDataChildByName(QName.create(
177 testModule.getQNameModule(), "rp"));
179 expectedQName = QName.create(UG, "rp");
180 path.offer(expectedQName);
181 expectedPath = SchemaPath.create(path, true);
182 assertEquals(expectedPath, rp.getPath());
183 assertFalse(rp.isAddedByUses());
184 childNodes = rp.getChildNodes();
185 assertEquals(4, childNodes.size());
186 // * |-- |-- |-- leaf processing-rule
187 LeafSchemaNode processingRule = (LeafSchemaNode) rp.getDataChildByName(QName.create(
188 testModule.getQNameModule(), "processing-rule"));
189 assertNotNull(processingRule);
190 expectedQName = QName.create(UG, "processing-rule");
191 assertEquals(expectedQName, processingRule.getQName());
192 path.offer(expectedQName);
193 expectedPath = SchemaPath.create(path, true);
194 assertEquals(expectedPath, processingRule.getPath());
195 assertEquals(BaseTypes.booleanType(), processingRule.getType());
196 assertTrue(processingRule.isAddedByUses());
197 // * |-- |-- |-- leaf ignore
198 LeafSchemaNode ignore = (LeafSchemaNode) rp.getDataChildByName(QName.create(testModule.getQNameModule(),
200 assertNotNull(ignore);
201 expectedQName = QName.create(UG, "ignore");
202 assertEquals(expectedQName, ignore.getQName());
204 path.offer(expectedQName);
205 expectedPath = SchemaPath.create(path, true);
206 assertEquals(expectedPath, ignore.getPath());
207 assertEquals(BaseTypes.booleanType(), ignore.getType());
208 assertTrue(ignore.isAddedByUses());
209 // * |-- |-- |-- leaf priority
210 final LeafSchemaNode priority = (LeafSchemaNode) rp.getDataChildByName(QName.create(
211 testModule.getQNameModule(), "priority"));
212 assertNotNull(priority);
213 expectedQName = QName.create(UG, "priority");
214 assertEquals(expectedQName, priority.getQName());
216 path.offer(expectedQName);
217 expectedPath = SchemaPath.create(path, true);
218 assertEquals(expectedPath, priority.getPath());
219 expectedQName = QName.create(UG, "uint8");
220 path.offer(expectedQName);
221 expectedPath = SchemaPath.create(path, true);
223 // assertEquals(expectedPath, priority.getType().getPath());
224 assertEquals(BaseTypes.uint8Type(), priority.getType().getBaseType());
225 assertTrue(priority.isAddedByUses());
226 // * |-- |-- |-- container box
227 ContainerSchemaNode box = (ContainerSchemaNode) rp.getDataChildByName(QName.create(testModule.getQNameModule(),
230 expectedQName = QName.create(UG, "box");
231 assertEquals(expectedQName, box.getQName());
234 path.offer(expectedQName);
235 expectedPath = SchemaPath.create(path, true);
236 assertEquals(expectedPath, box.getPath());
237 assertTrue(box.isAddedByUses());
238 // * |-- |-- |-- |-- container order
239 final ContainerSchemaNode order = (ContainerSchemaNode) box.getDataChildByName(QName.create(
240 testModule.getQNameModule(), "order"));
241 assertNotNull(order);
242 expectedQName = QName.create(UG, "order");
243 assertEquals(expectedQName, order.getQName());
244 path.offer(expectedQName);
245 expectedPath = SchemaPath.create(path, true);
246 assertEquals(expectedPath, order.getPath());
247 assertTrue(order.isAddedByUses());
248 assertTrue(order.isAugmenting());
249 assertEquals(2, order.getChildNodes().size());
250 // * |-- |-- |-- |-- |-- leaf delete
251 final LeafSchemaNode delete = (LeafSchemaNode) order.getDataChildByName(QName.create(
252 testModule.getQNameModule(), "delete"));
253 assertNotNull(delete);
254 expectedQName = QName.create(UG, "delete");
255 assertEquals(expectedQName, delete.getQName());
256 path.offer(expectedQName);
257 expectedPath = SchemaPath.create(path, true);
258 assertEquals(expectedPath, delete.getPath());
259 assertEquals(BaseTypes.uint32Type(), delete.getType());
260 assertTrue(delete.isAddedByUses());
261 // * |-- |-- |-- |-- |-- leaf setup
262 final LeafSchemaNode setup = (LeafSchemaNode) order.getDataChildByName(QName.create(
263 testModule.getQNameModule(), "setup"));
264 assertNotNull(setup);
265 expectedQName = QName.create(UG, "setup");
266 assertEquals(expectedQName, setup.getQName());
268 path.offer(expectedQName);
269 expectedPath = SchemaPath.create(path, true);
270 assertEquals(expectedPath, setup.getPath());
271 assertEquals(BaseTypes.uint32Type(), setup.getType());
272 assertTrue(setup.isAddedByUses());
273 // * |-- |-- path-key-expansion
274 final ContainerSchemaNode pke = (ContainerSchemaNode) requests.getDataChildByName(QName.create(
275 testModule.getQNameModule(), "path-key-expansion"));
277 expectedQName = QName.create(UG, "path-key-expansion");
278 assertEquals(expectedQName, pke.getQName());
283 path.offer(expectedQName);
284 expectedPath = SchemaPath.create(path, true);
285 assertEquals(expectedPath, pke.getPath());
286 assertFalse(pke.isAddedByUses());
287 // * |-- |-- |-- path-key
288 final ContainerSchemaNode pathKey = (ContainerSchemaNode) pke.getDataChildByName(QName.create(
289 testModule.getQNameModule(), "path-key"));
290 assertNotNull(pathKey);
291 expectedQName = QName.create(UG, "path-key");
292 assertEquals(expectedQName, pathKey.getQName());
293 path.offer(expectedQName);
294 expectedPath = SchemaPath.create(path, true);
295 assertEquals(expectedPath, pathKey.getPath());
296 assertFalse(pathKey.isAddedByUses());
297 assertEquals(3, pathKey.getChildNodes().size());
298 // * |-- |-- |-- |-- leaf processing-rule
299 processingRule = (LeafSchemaNode) pathKey.getDataChildByName(QName.create(testModule.getQNameModule(),
301 assertNotNull(processingRule);
302 expectedQName = QName.create(UG, "processing-rule");
303 assertEquals(expectedQName, processingRule.getQName());
304 path.offer(expectedQName);
305 expectedPath = SchemaPath.create(path, true);
306 assertEquals(expectedPath, processingRule.getPath());
307 assertEquals(BaseTypes.booleanType(), processingRule.getType());
308 assertTrue(processingRule.isAddedByUses());
309 // * |-- |-- |-- |-- leaf ignore
310 ignore = (LeafSchemaNode) pathKey.getDataChildByName(QName.create(testModule.getQNameModule(), "ignore"));
311 assertNotNull(ignore);
312 expectedQName = QName.create(UG, "ignore");
313 assertEquals(expectedQName, ignore.getQName());
315 path.offer(expectedQName);
316 expectedPath = SchemaPath.create(path, true);
317 assertEquals(expectedPath, ignore.getPath());
318 assertEquals(BaseTypes.booleanType(), ignore.getType());
319 assertTrue(ignore.isAddedByUses());
320 // * |-- |-- |-- |-- list path-keys
321 final ListSchemaNode pathKeys = (ListSchemaNode) pathKey.getDataChildByName(QName.create(
322 testModule.getQNameModule(), "path-keys"));
323 assertNotNull(pathKeys);
324 expectedQName = QName.create(UG, "path-keys");
325 assertEquals(expectedQName, pathKeys.getQName());
327 path.offer(expectedQName);
328 expectedPath = SchemaPath.create(path, true);
329 assertEquals(expectedPath, pathKeys.getPath());
330 assertTrue(pathKeys.isAddedByUses());
331 childNodes = pathKeys.getChildNodes();
332 assertEquals(2, childNodes.size());
333 // * |-- |-- |-- |-- |-- leaf version
334 version = (LeafSchemaNode) pathKeys.getDataChildByName(QName.create(testModule.getQNameModule(), "version"));
335 assertNotNull(version);
336 expectedQName = QName.create(UG, "version");
337 assertEquals(expectedQName, version.getQName());
338 path.offer(expectedQName);
339 expectedPath = SchemaPath.create(path, true);
340 assertEquals(expectedPath, version.getPath());
341 assertTrue(version.getType() instanceof Uint8TypeDefinition);
342 assertEquals(BaseTypes.uint8Type(), version.getType().getBaseType().getBaseType());
343 assertTrue(version.isAddedByUses());
344 assertTrue(version.isAugmenting());
345 // * |-- |-- |-- |-- |-- leaf type
346 type = (LeafSchemaNode) pathKeys.getDataChildByName(QName.create(testModule.getQNameModule(), "type"));
348 expectedQName = QName.create(UG, "type");
349 assertEquals(expectedQName, type.getQName());
351 path.offer(expectedQName);
352 expectedPath = SchemaPath.create(path, true);
353 assertEquals(expectedPath, type.getPath());
354 assertTrue(type.getType() instanceof UnionTypeDefinition);
355 assertTrue(type.isAddedByUses());
356 assertTrue(type.isAugmenting());
357 // * |-- |-- container segment-computation
358 final ContainerSchemaNode sc = (ContainerSchemaNode) requests.getDataChildByName(QName.create(
359 testModule.getQNameModule(), "segment-computation"));
361 expectedQName = QName.create(UG, "segment-computation");
362 assertEquals(expectedQName, sc.getQName());
367 path.offer(expectedQName);
368 expectedPath = SchemaPath.create(path, true);
369 assertEquals(expectedPath, sc.getPath());
370 assertFalse(sc.isAddedByUses());
371 // * |-- |-- |-- container p2p
372 final ContainerSchemaNode p2p = (ContainerSchemaNode) sc.getDataChildByName(QName.create(
373 testModule.getQNameModule(), "p2p"));
375 expectedQName = QName.create(UG, "p2p");
376 assertEquals(expectedQName, p2p.getQName());
377 path.offer(expectedQName);
378 expectedPath = SchemaPath.create(path, true);
379 assertEquals(expectedPath, p2p.getPath());
380 assertFalse(p2p.isAddedByUses());
381 // * |-- |-- |-- |-- container endpoints
382 final ContainerSchemaNode endpoints = (ContainerSchemaNode) p2p.getDataChildByName(QName.create(
383 testModule.getQNameModule(), "endpoints"));
384 assertNotNull(endpoints);
385 expectedQName = QName.create(UG, "endpoints");
386 assertEquals(expectedQName, endpoints.getQName());
387 path.offer(expectedQName);
388 expectedPath = SchemaPath.create(path, true);
389 assertEquals(expectedPath, endpoints.getPath());
390 assertFalse(endpoints.isAddedByUses());
391 // * |-- |-- |-- |-- |-- leaf processing-rule
392 processingRule = (LeafSchemaNode) endpoints.getDataChildByName(QName.create(testModule.getQNameModule(),
394 assertNotNull(processingRule);
395 expectedQName = QName.create(UG, "processing-rule");
396 assertEquals(expectedQName, processingRule.getQName());
397 path.offer(expectedQName);
398 expectedPath = SchemaPath.create(path, true);
399 assertEquals(expectedPath, processingRule.getPath());
400 assertEquals(BaseTypes.booleanType(), processingRule.getType());
401 assertTrue(processingRule.isAddedByUses());
402 // * |-- |-- |-- |-- |-- leaf ignore
403 ignore = (LeafSchemaNode) endpoints.getDataChildByName(QName.create(testModule.getQNameModule(), "ignore"));
404 assertNotNull(ignore);
405 expectedQName = QName.create(UG, "ignore");
406 assertEquals(expectedQName, ignore.getQName());
408 path.offer(expectedQName);
409 expectedPath = SchemaPath.create(path, true);
410 assertEquals(expectedPath, ignore.getPath());
411 assertEquals(BaseTypes.booleanType(), ignore.getType());
412 assertTrue(ignore.isAddedByUses());
413 // * |-- |-- |-- |-- |-- container box
414 box = (ContainerSchemaNode) endpoints.getDataChildByName(QName.create(testModule.getQNameModule(), "box"));
416 expectedQName = QName.create(UG, "box");
417 assertEquals(expectedQName, box.getQName());
419 path.offer(expectedQName);
420 expectedPath = SchemaPath.create(path, true);
421 assertEquals(expectedPath, box.getPath());
422 assertTrue(box.isAddedByUses());
423 // * |-- |-- |-- |-- |-- choice address-family
424 final ChoiceSchemaNode af = (ChoiceSchemaNode) endpoints.getDataChildByName(QName.create(
425 testModule.getQNameModule(), "address-family"));
427 expectedQName = QName.create(UG, "address-family");
428 assertEquals(expectedQName, af.getQName());
430 path.offer(expectedQName);
431 expectedPath = SchemaPath.create(path, true);
432 assertEquals(expectedPath, af.getPath());
433 assertTrue(af.isAddedByUses());
434 // * |-- |-- |-- |-- container reported-route
435 final ContainerSchemaNode reportedRoute = (ContainerSchemaNode) p2p.getDataChildByName(QName.create(
436 testModule.getQNameModule(), "reported-route"));
437 assertNotNull(reportedRoute);
438 expectedQName = QName.create(UG, "reported-route");
439 assertEquals(expectedQName, reportedRoute.getQName());
442 path.offer(expectedQName);
443 expectedPath = SchemaPath.create(path, true);
444 assertEquals(expectedPath, reportedRoute.getPath());
445 assertFalse(reportedRoute.isAddedByUses());
446 // * |-- |-- |-- |-- |-- leaf processing-rule
447 processingRule = (LeafSchemaNode) reportedRoute.getDataChildByName(QName.create(testModule.getQNameModule(),
449 assertNotNull(processingRule);
450 expectedQName = QName.create(UG, "processing-rule");
451 assertEquals(expectedQName, processingRule.getQName());
452 path.offer(expectedQName);
453 expectedPath = SchemaPath.create(path, true);
454 assertEquals(expectedPath, processingRule.getPath());
455 assertEquals(BaseTypes.booleanType(), processingRule.getType());
456 assertTrue(processingRule.isAddedByUses());
457 // * |-- |-- |-- |-- |-- leaf ignore
458 ignore = (LeafSchemaNode) reportedRoute.getDataChildByName(QName.create(testModule.getQNameModule(), "ignore"));
459 assertNotNull(ignore);
460 expectedQName = QName.create(UG, "ignore");
461 assertEquals(expectedQName, ignore.getQName());
463 path.offer(expectedQName);
464 expectedPath = SchemaPath.create(path, true);
465 assertEquals(expectedPath, ignore.getPath());
466 assertEquals(BaseTypes.booleanType(), ignore.getType());
467 assertTrue(ignore.isAddedByUses());
468 // * |-- |-- |-- |-- |-- list subobjects
469 final ListSchemaNode subobjects = (ListSchemaNode) reportedRoute.getDataChildByName(QName.create(
470 testModule.getQNameModule(), "subobjects"));
471 assertNotNull(subobjects);
472 expectedQName = QName.create(UG, "subobjects");
473 assertEquals(expectedQName, subobjects.getQName());
475 path.offer(expectedQName);
476 expectedPath = SchemaPath.create(path, true);
477 assertEquals(expectedPath, subobjects.getPath());
478 assertTrue(subobjects.isAddedByUses());
479 // * |-- |-- |-- |-- |-- container bandwidth
480 ContainerSchemaNode bandwidth = (ContainerSchemaNode) reportedRoute.getDataChildByName(QName.create(
481 testModule.getQNameModule(), "bandwidth"));
482 assertNotNull(bandwidth);
483 expectedQName = QName.create(UG, "bandwidth");
484 assertEquals(expectedQName, bandwidth.getQName());
486 path.offer(expectedQName);
487 expectedPath = SchemaPath.create(path, true);
488 assertEquals(expectedPath, bandwidth.getPath());
489 assertFalse(bandwidth.isAddedByUses());
490 // * |-- |-- |-- |-- container bandwidth
491 bandwidth = (ContainerSchemaNode) p2p
492 .getDataChildByName(QName.create(testModule.getQNameModule(), "bandwidth"));
493 assertNotNull(bandwidth);
494 expectedQName = QName.create(UG, "bandwidth");
495 assertEquals(expectedQName, bandwidth.getQName());
498 path.offer(expectedQName);
499 expectedPath = SchemaPath.create(path, true);
500 assertEquals(expectedPath, bandwidth.getPath());
501 assertTrue(bandwidth.isAddedByUses());
502 // * |-- |-- |-- |-- |-- leaf processing-rule
503 processingRule = (LeafSchemaNode) bandwidth.getDataChildByName(QName.create(testModule.getQNameModule(),
505 assertNotNull(processingRule);
506 expectedQName = QName.create(UG, "processing-rule");
507 assertEquals(expectedQName, processingRule.getQName());
508 path.offer(expectedQName);
509 expectedPath = SchemaPath.create(path, true);
510 assertEquals(expectedPath, processingRule.getPath());
511 assertEquals(BaseTypes.booleanType(), processingRule.getType());
512 assertTrue(processingRule.isAddedByUses());
513 // * |-- |-- |-- |-- |-- leaf ignore
514 ignore = (LeafSchemaNode) bandwidth.getDataChildByName(QName.create(testModule.getQNameModule(), "ignore"));
515 assertNotNull(ignore);
516 expectedQName = QName.create(UG, "ignore");
517 assertEquals(expectedQName, ignore.getQName());
519 path.offer(expectedQName);
520 expectedPath = SchemaPath.create(path, true);
521 assertEquals(expectedPath, ignore.getPath());
522 assertEquals(BaseTypes.booleanType(), ignore.getType());
523 assertTrue(ignore.isAddedByUses());
524 // * |-- |-- |-- |-- |-- container bandwidth
525 final ContainerSchemaNode bandwidthInner = (ContainerSchemaNode) bandwidth.getDataChildByName(QName.create(
526 testModule.getQNameModule(), "bandwidth"));
527 assertNotNull(bandwidthInner);
528 expectedQName = QName.create(UG, "bandwidth");
529 assertEquals(expectedQName, bandwidth.getQName());
531 path.offer(expectedQName);
532 expectedPath = SchemaPath.create(path, true);
533 assertEquals(expectedPath, bandwidthInner.getPath());
534 assertTrue(bandwidthInner.isAddedByUses());
536 final ListSchemaNode svec = (ListSchemaNode) pcreq.getDataChildByName(QName.create(testModule.getQNameModule(),
539 expectedQName = QName.create(UG, "svec");
540 assertEquals(expectedQName, svec.getQName());
546 path.offer(expectedQName);
547 expectedPath = SchemaPath.create(path, true);
548 assertEquals(expectedPath, svec.getPath());
549 assertFalse(svec.isAddedByUses());
550 // * |-- |-- leaf link-diverse
551 final LeafSchemaNode linkDiverse = (LeafSchemaNode) svec.getDataChildByName(QName.create(
552 testModule.getQNameModule(), "link-diverse"));
553 assertNotNull(linkDiverse);
554 expectedQName = QName.create(UG, "link-diverse");
555 assertEquals(expectedQName, linkDiverse.getQName());
556 path.offer(expectedQName);
557 expectedPath = SchemaPath.create(path, true);
558 assertEquals(expectedPath, linkDiverse.getPath());
559 assertEquals(BaseTypes.booleanType(), linkDiverse.getType().getBaseType());
560 assertTrue(linkDiverse.isAddedByUses());
561 // * |-- |-- leaf processing-rule
562 processingRule = (LeafSchemaNode) svec.getDataChildByName(QName.create(testModule.getQNameModule(),
564 assertNotNull(processingRule);
565 expectedQName = QName.create(UG, "processing-rule");
566 assertEquals(expectedQName, processingRule.getQName());
568 path.offer(expectedQName);
569 expectedPath = SchemaPath.create(path, true);
570 assertEquals(expectedPath, processingRule.getPath());
571 assertEquals(BaseTypes.booleanType(), processingRule.getType());
572 assertTrue(processingRule.isAddedByUses());
573 // * |-- |-- leaf ignore
574 ignore = (LeafSchemaNode) svec.getDataChildByName(QName.create(testModule.getQNameModule(), "ignore"));
575 assertNotNull(ignore);
576 expectedQName = QName.create(UG, "ignore");
577 assertEquals(expectedQName, ignore.getQName());
579 path.offer(expectedQName);
580 expectedPath = SchemaPath.create(path, true);
581 assertEquals(expectedPath, ignore.getPath());
582 assertEquals(BaseTypes.booleanType(), ignore.getType());
583 assertTrue(ignore.isAddedByUses());
584 // * |-- |-- list metric
585 final ListSchemaNode metric = (ListSchemaNode) svec.getDataChildByName(QName.create(
586 testModule.getQNameModule(), "metric"));
587 assertNotNull(metric);
588 expectedQName = QName.create(UG, "metric");
589 assertEquals(expectedQName, metric.getQName());
591 path.offer(expectedQName);
592 expectedPath = SchemaPath.create(path, true);
593 assertEquals(expectedPath, metric.getPath());
594 assertFalse(metric.isAddedByUses());
595 // * |-- |-- |-- leaf metric-type
596 final LeafSchemaNode metricType = (LeafSchemaNode) metric.getDataChildByName(QName.create(
597 testModule.getQNameModule(), "metric-type"));
598 assertNotNull(metricType);
599 expectedQName = QName.create(UG, "metric-type");
600 assertEquals(expectedQName, metricType.getQName());
601 path.offer(expectedQName);
602 expectedPath = SchemaPath.create(path, true);
603 assertEquals(expectedPath, metricType.getPath());
604 assertEquals(BaseTypes.uint8Type(), metricType.getType());
605 assertTrue(metricType.isAddedByUses());
607 box = (ContainerSchemaNode) metric.getDataChildByName(QName.create(testModule.getQNameModule(), "box"));
609 expectedQName = QName.create(UG, "box");
610 assertEquals(expectedQName, box.getQName());
612 path.offer(expectedQName);
613 expectedPath = SchemaPath.create(path, true);
614 assertEquals(expectedPath, box.getPath());
615 assertTrue(box.isAddedByUses());
616 // * |-- |-- |-- leaf processing-rule
617 processingRule = (LeafSchemaNode) metric.getDataChildByName(QName.create(testModule.getQNameModule(),
619 assertNotNull(processingRule);
620 expectedQName = QName.create(UG, "processing-rule");
621 assertEquals(expectedQName, processingRule.getQName());
623 path.offer(expectedQName);
624 expectedPath = SchemaPath.create(path, true);
625 assertEquals(expectedPath, processingRule.getPath());
626 assertEquals(BaseTypes.booleanType(), processingRule.getType());
627 assertTrue(processingRule.isAddedByUses());
628 // * |-- |-- |-- leaf ignore
629 ignore = (LeafSchemaNode) metric.getDataChildByName(QName.create(testModule.getQNameModule(), "ignore"));
630 assertNotNull(ignore);
631 expectedQName = QName.create(UG, "ignore");
632 assertEquals(expectedQName, ignore.getQName());
634 path.offer(expectedQName);
635 expectedPath = SchemaPath.create(path, true);
636 assertEquals(expectedPath, ignore.getPath());
637 assertEquals(BaseTypes.booleanType(), ignore.getType());
638 assertTrue(ignore.isAddedByUses());
642 public void testTypedefs() throws Exception {
643 final Module testModule = TestUtils.findModule(context, "grouping-definitions").get();
644 final Collection<? extends TypeDefinition<?>> types = testModule.getTypeDefinitions();
646 TypeDefinition<?> intExt = null;
647 for (final TypeDefinition<?> td : types) {
648 if ("int-ext".equals(td.getQName().getLocalName())) {
652 assertNotNull(intExt);
654 SchemaPath expectedPath = SchemaPath.create(true, QName.create(GD, "int-ext"));
655 assertEquals(expectedPath, intExt.getPath());
657 final UnionTypeDefinition union = (UnionTypeDefinition) intExt.getBaseType();
659 TypeDefinition<?> uint8 = null;
660 TypeDefinition<?> pv = null;
661 for (final TypeDefinition<?> td : union.getTypes()) {
662 if ("uint8".equals(td.getQName().getLocalName())) {
664 } else if ("protocol-version".equals(td.getQName().getLocalName())) {
668 assertNotNull(uint8);
671 expectedPath = SchemaPath.create(true, QName.create(GD, "int-ext"), QName.create(GD, "union"));
672 assertEquals(expectedPath, union.getPath());