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