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.FileNotFoundException;
17 import java.net.URISyntaxException;
18 import java.text.DateFormat;
19 import java.text.ParseException;
20 import java.text.SimpleDateFormat;
21 import java.util.ArrayDeque;
22 import java.util.Collection;
23 import java.util.Date;
24 import java.util.Deque;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.opendaylight.yangtools.yang.common.QName;
29 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
30 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
31 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
32 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
33 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
34 import org.opendaylight.yangtools.yang.model.api.Module;
35 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
36 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
37 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
38 import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
39 import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
40 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
41 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
42 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
44 public class UsesAugmentTest {
45 private static final URI UG_NS = URI.create("urn:opendaylight:params:xml:ns:yang:uses-grouping");
46 private static final URI GD_NS = URI.create("urn:opendaylight:params:xml:ns:yang:grouping-definitions");
50 private Set<Module> modules;
53 public void init() throws FileNotFoundException, ParseException {
54 final DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
55 UG_REV = simpleDateFormat.parse("2013-07-30");
56 GD_REV = simpleDateFormat.parse("2013-09-04");
60 * Structure of testing model:
63 * |-- leaf version (U)
66 * |-- |-- container rp
67 * |-- |-- |-- leaf priority (U)
68 * |-- |-- |-- container box (U)
69 * |-- |-- |-- |-- container order (A)
70 * |-- |-- |-- |-- |-- leaf delete (U)
71 * |-- |-- |-- |-- |-- |-- leaf setup (U)
72 * |-- |-- |-- leaf processing-rule (U)
73 * |-- |-- |-- leaf ignore (U)
74 * |-- |-- path-key-expansion
75 * |-- |-- |-- container path-key
76 * |-- |-- |-- |-- list path-keys (U)
77 * |-- |-- |-- |-- |-- leaf version (U)
78 * |-- |-- |-- |-- |-- leaf type (U)
79 * |-- |-- |-- |-- |-- leaf processing-rule (U)
80 * |-- |-- |-- |-- |-- leaf ignore (U)
81 * |-- |-- container segment-computation
82 * |-- |-- |-- container p2p
83 * |-- |-- |-- |-- container endpoints
84 * |-- |-- |-- |-- |-- leaf processing-rule (U)
85 * |-- |-- |-- |-- |-- leaf ignore (U)
86 * |-- |-- |-- |-- |-- container box (U)
87 * |-- |-- |-- |-- |-- choice address-family (U)
88 * |-- |-- |-- |-- |-- |-- case ipv4
89 * |-- |-- |-- |-- |-- |-- |-- leaf source-ipv4-address
90 * |-- |-- |-- |-- |-- |-- case ipv6
91 * |-- |-- |-- |-- |-- |-- |-- leaf source-ipv6-address
92 * |-- |-- |-- |-- container reported-route
93 * |-- |-- |-- |-- |-- container bandwidth
94 * |-- |-- |-- |-- |-- list subobjects(U)
95 * |-- |-- |-- |-- |-- leaf processing-rule (U)
96 * |-- |-- |-- |-- |-- leaf ignore (U)
97 * |-- |-- |-- |-- container bandwidth (U)
98 * |-- |-- |-- |-- |-- container bandwidth (U)
99 * |-- |-- |-- |-- |-- leaf processing-rule (U)
100 * |-- |-- |-- |-- |-- leaf ignore (U)
102 * |-- |-- list metric
103 * |-- |-- |-- leaf metric-type (U)
104 * |-- |-- |-- container box (U)
105 * |-- |-- |-- leaf processing-rule (U)
106 * |-- |-- |-- leaf ignore (U)
107 * |-- |-- leaf link-diverse (U)
108 * |-- |-- leaf processing-rule (U)
109 * |-- |-- leaf ignore (U)
111 * U = added by uses A = added by augment
113 * @throws Exception if exception occurs
116 public void testAugmentInUses() throws Exception {
117 modules = TestUtils.loadModules(getClass().getResource("/grouping-test").toURI());
118 final Module testModule = TestUtils.findModule(modules, "uses-grouping");
120 final Deque<QName> path = new ArrayDeque<>();
122 // * notification pcreq
123 final Set<NotificationDefinition> notifications = testModule.getNotifications();
124 assertEquals(1, notifications.size());
125 final NotificationDefinition pcreq = notifications.iterator().next();
126 assertNotNull(pcreq);
127 QName expectedQName = QName.create(UG_NS, UG_REV, "pcreq");
128 path.offer(expectedQName);
129 SchemaPath expectedPath = SchemaPath.create(path, true);
130 assertEquals(expectedPath, pcreq.getPath());
131 Collection<DataSchemaNode> childNodes = pcreq.getChildNodes();
132 assertEquals(4, childNodes.size());
133 // * |-- leaf version
134 LeafSchemaNode version = (LeafSchemaNode) pcreq.getDataChildByName(QName.create(testModule.getQNameModule(),
136 assertNotNull(version);
137 expectedQName = QName.create(UG_NS, UG_REV, "version");
138 path.offer(expectedQName);
139 expectedPath = SchemaPath.create(path, true);
140 assertEquals(expectedPath, version.getPath());
141 expectedQName = QName.create(UG_NS, UG_REV, "version");
142 path.offer(expectedQName);
143 expectedPath = SchemaPath.create(true, pcreq.getQName(), expectedQName);
144 assertEquals(expectedPath, version.getType().getPath());
145 assertEquals(BaseTypes.uint8Type(), version.getType().getBaseType().getBaseType());
146 assertTrue(version.isAddedByUses());
148 LeafSchemaNode type = (LeafSchemaNode) pcreq.getDataChildByName(QName.create(testModule.getQNameModule(),
151 expectedQName = QName.create(UG_NS, UG_REV, "type");
152 assertTrue(type.isAddedByUses());
155 path.offer(expectedQName);
156 expectedPath = SchemaPath.create(path, true);
157 assertEquals(expectedPath, type.getPath());
158 expectedQName = QName.create(GD_NS, GD_REV, "int-ext");
159 path.offer(expectedQName);
160 expectedPath = SchemaPath.create(true, expectedQName);
161 assertEquals(expectedPath, type.getType().getPath());
162 final UnionTypeDefinition union = (UnionTypeDefinition) type.getType().getBaseType();
163 assertEquals(SchemaPath.create(true, expectedQName, QName.create(expectedQName, "union")), union.getPath());
164 assertEquals(2, union.getTypes().size());
165 // * |-- list requests
166 final ListSchemaNode requests = (ListSchemaNode) pcreq.getDataChildByName(QName.create(
167 testModule.getQNameModule(), "requests"));
168 assertNotNull(requests);
169 expectedQName = QName.create(UG_NS, UG_REV, "requests");
170 assertEquals(expectedQName, requests.getQName());
173 path.offer(expectedQName);
174 expectedPath = SchemaPath.create(path, true);
175 assertEquals(expectedPath, requests.getPath());
176 assertFalse(requests.isAddedByUses());
177 childNodes = requests.getChildNodes();
178 assertEquals(3, childNodes.size());
179 // * |-- |-- container rp
180 final ContainerSchemaNode rp = (ContainerSchemaNode) requests.getDataChildByName(QName.create(
181 testModule.getQNameModule(), "rp"));
183 expectedQName = QName.create(UG_NS, UG_REV, "rp");
184 path.offer(expectedQName);
185 expectedPath = SchemaPath.create(path, true);
186 assertEquals(expectedPath, rp.getPath());
187 assertFalse(rp.isAddedByUses());
188 childNodes = rp.getChildNodes();
189 assertEquals(4, childNodes.size());
190 // * |-- |-- |-- leaf processing-rule
191 LeafSchemaNode processingRule = (LeafSchemaNode) rp.getDataChildByName(QName.create(
192 testModule.getQNameModule(), "processing-rule"));
193 assertNotNull(processingRule);
194 expectedQName = QName.create(UG_NS, UG_REV, "processing-rule");
195 assertEquals(expectedQName, processingRule.getQName());
196 path.offer(expectedQName);
197 expectedPath = SchemaPath.create(path, true);
198 assertEquals(expectedPath, processingRule.getPath());
199 assertEquals(BaseTypes.booleanType(), processingRule.getType());
200 assertTrue(processingRule.isAddedByUses());
201 // * |-- |-- |-- leaf ignore
202 LeafSchemaNode ignore = (LeafSchemaNode) rp.getDataChildByName(QName.create(testModule.getQNameModule(),
204 assertNotNull(ignore);
205 expectedQName = QName.create(UG_NS, UG_REV, "ignore");
206 assertEquals(expectedQName, ignore.getQName());
208 path.offer(expectedQName);
209 expectedPath = SchemaPath.create(path, true);
210 assertEquals(expectedPath, ignore.getPath());
211 assertEquals(BaseTypes.booleanType(), ignore.getType());
212 assertTrue(ignore.isAddedByUses());
213 // * |-- |-- |-- leaf priority
214 final LeafSchemaNode priority = (LeafSchemaNode) rp.getDataChildByName(QName.create(
215 testModule.getQNameModule(), "priority"));
216 assertNotNull(priority);
217 expectedQName = QName.create(UG_NS, UG_REV, "priority");
218 assertEquals(expectedQName, priority.getQName());
220 path.offer(expectedQName);
221 expectedPath = SchemaPath.create(path, true);
222 assertEquals(expectedPath, priority.getPath());
223 expectedQName = QName.create(UG_NS, UG_REV, "uint8");
224 path.offer(expectedQName);
225 expectedPath = SchemaPath.create(path, true);
227 // assertEquals(expectedPath, priority.getType().getPath());
228 assertEquals(BaseTypes.uint8Type(), priority.getType().getBaseType());
229 assertTrue(priority.isAddedByUses());
230 // * |-- |-- |-- container box
231 ContainerSchemaNode box = (ContainerSchemaNode) rp.getDataChildByName(QName.create(testModule.getQNameModule(),
234 expectedQName = QName.create(UG_NS, UG_REV, "box");
235 assertEquals(expectedQName, box.getQName());
238 path.offer(expectedQName);
239 expectedPath = SchemaPath.create(path, true);
240 assertEquals(expectedPath, box.getPath());
241 assertTrue(box.isAddedByUses());
242 // * |-- |-- |-- |-- container order
243 final ContainerSchemaNode order = (ContainerSchemaNode) box.getDataChildByName(QName.create(
244 testModule.getQNameModule(), "order"));
245 assertNotNull(order);
246 expectedQName = QName.create(UG_NS, UG_REV, "order");
247 assertEquals(expectedQName, order.getQName());
248 path.offer(expectedQName);
249 expectedPath = SchemaPath.create(path, true);
250 assertEquals(expectedPath, order.getPath());
251 assertTrue(order.isAddedByUses());
252 assertTrue(order.isAugmenting());
253 assertEquals(2, order.getChildNodes().size());
254 // * |-- |-- |-- |-- |-- leaf delete
255 final LeafSchemaNode delete = (LeafSchemaNode) order.getDataChildByName(QName.create(
256 testModule.getQNameModule(), "delete"));
257 assertNotNull(delete);
258 expectedQName = QName.create(UG_NS, UG_REV, "delete");
259 assertEquals(expectedQName, delete.getQName());
260 path.offer(expectedQName);
261 expectedPath = SchemaPath.create(path, true);
262 assertEquals(expectedPath, delete.getPath());
263 assertEquals(BaseTypes.uint32Type(), delete.getType());
264 assertTrue(delete.isAddedByUses());
265 // * |-- |-- |-- |-- |-- leaf setup
266 final LeafSchemaNode setup = (LeafSchemaNode) order.getDataChildByName(QName.create(
267 testModule.getQNameModule(), "setup"));
268 assertNotNull(setup);
269 expectedQName = QName.create(UG_NS, UG_REV, "setup");
270 assertEquals(expectedQName, setup.getQName());
272 path.offer(expectedQName);
273 expectedPath = SchemaPath.create(path, true);
274 assertEquals(expectedPath, setup.getPath());
275 assertEquals(BaseTypes.uint32Type(), setup.getType());
276 assertTrue(setup.isAddedByUses());
277 // * |-- |-- path-key-expansion
278 final ContainerSchemaNode pke = (ContainerSchemaNode) requests.getDataChildByName(QName.create(
279 testModule.getQNameModule(), "path-key-expansion"));
281 expectedQName = QName.create(UG_NS, UG_REV, "path-key-expansion");
282 assertEquals(expectedQName, pke.getQName());
287 path.offer(expectedQName);
288 expectedPath = SchemaPath.create(path, true);
289 assertEquals(expectedPath, pke.getPath());
290 assertFalse(pke.isAddedByUses());
291 // * |-- |-- |-- path-key
292 final ContainerSchemaNode pathKey = (ContainerSchemaNode) pke.getDataChildByName(QName.create(
293 testModule.getQNameModule(), "path-key"));
294 assertNotNull(pathKey);
295 expectedQName = QName.create(UG_NS, UG_REV, "path-key");
296 assertEquals(expectedQName, pathKey.getQName());
297 path.offer(expectedQName);
298 expectedPath = SchemaPath.create(path, true);
299 assertEquals(expectedPath, pathKey.getPath());
300 assertFalse(pathKey.isAddedByUses());
301 assertEquals(3, pathKey.getChildNodes().size());
302 // * |-- |-- |-- |-- leaf processing-rule
303 processingRule = (LeafSchemaNode) pathKey.getDataChildByName(QName.create(testModule.getQNameModule(),
305 assertNotNull(processingRule);
306 expectedQName = QName.create(UG_NS, UG_REV, "processing-rule");
307 assertEquals(expectedQName, processingRule.getQName());
308 path.offer(expectedQName);
309 expectedPath = SchemaPath.create(path, true);
310 assertEquals(expectedPath, processingRule.getPath());
311 assertEquals(BaseTypes.booleanType(), processingRule.getType());
312 assertTrue(processingRule.isAddedByUses());
313 // * |-- |-- |-- |-- leaf ignore
314 ignore = (LeafSchemaNode) pathKey.getDataChildByName(QName.create(testModule.getQNameModule(), "ignore"));
315 assertNotNull(ignore);
316 expectedQName = QName.create(UG_NS, UG_REV, "ignore");
317 assertEquals(expectedQName, ignore.getQName());
319 path.offer(expectedQName);
320 expectedPath = SchemaPath.create(path, true);
321 assertEquals(expectedPath, ignore.getPath());
322 assertEquals(BaseTypes.booleanType(), ignore.getType());
323 assertTrue(ignore.isAddedByUses());
324 // * |-- |-- |-- |-- list path-keys
325 final ListSchemaNode pathKeys = (ListSchemaNode) pathKey.getDataChildByName(QName.create(
326 testModule.getQNameModule(), "path-keys"));
327 assertNotNull(pathKeys);
328 expectedQName = QName.create(UG_NS, UG_REV, "path-keys");
329 assertEquals(expectedQName, pathKeys.getQName());
331 path.offer(expectedQName);
332 expectedPath = SchemaPath.create(path, true);
333 assertEquals(expectedPath, pathKeys.getPath());
334 assertTrue(pathKeys.isAddedByUses());
335 childNodes = pathKeys.getChildNodes();
336 assertEquals(2, childNodes.size());
337 // * |-- |-- |-- |-- |-- leaf version
338 version = (LeafSchemaNode) pathKeys.getDataChildByName(QName.create(testModule.getQNameModule(), "version"));
339 assertNotNull(version);
340 expectedQName = QName.create(UG_NS, UG_REV, "version");
341 assertEquals(expectedQName, version.getQName());
342 path.offer(expectedQName);
343 expectedPath = SchemaPath.create(path, true);
344 assertEquals(expectedPath, version.getPath());
345 assertTrue(version.getType() instanceof UnsignedIntegerTypeDefinition);
346 assertEquals(BaseTypes.uint8Type(), version.getType().getBaseType().getBaseType());
347 assertTrue(version.isAddedByUses());
348 assertTrue(version.isAugmenting());
349 // * |-- |-- |-- |-- |-- leaf type
350 type = (LeafSchemaNode) pathKeys.getDataChildByName(QName.create(testModule.getQNameModule(), "type"));
352 expectedQName = QName.create(UG_NS, UG_REV, "type");
353 assertEquals(expectedQName, type.getQName());
355 path.offer(expectedQName);
356 expectedPath = SchemaPath.create(path, true);
357 assertEquals(expectedPath, type.getPath());
358 assertTrue(type.getType() instanceof UnionTypeDefinition);
359 assertTrue(type.isAddedByUses());
360 assertTrue(type.isAugmenting());
361 // * |-- |-- container segment-computation
362 final ContainerSchemaNode sc = (ContainerSchemaNode) requests.getDataChildByName(QName.create(
363 testModule.getQNameModule(), "segment-computation"));
365 expectedQName = QName.create(UG_NS, UG_REV, "segment-computation");
366 assertEquals(expectedQName, sc.getQName());
371 path.offer(expectedQName);
372 expectedPath = SchemaPath.create(path, true);
373 assertEquals(expectedPath, sc.getPath());
374 assertFalse(sc.isAddedByUses());
375 // * |-- |-- |-- container p2p
376 final ContainerSchemaNode p2p = (ContainerSchemaNode) sc.getDataChildByName(QName.create(
377 testModule.getQNameModule(), "p2p"));
379 expectedQName = QName.create(UG_NS, UG_REV, "p2p");
380 assertEquals(expectedQName, p2p.getQName());
381 path.offer(expectedQName);
382 expectedPath = SchemaPath.create(path, true);
383 assertEquals(expectedPath, p2p.getPath());
384 assertFalse(p2p.isAddedByUses());
385 // * |-- |-- |-- |-- container endpoints
386 final ContainerSchemaNode endpoints = (ContainerSchemaNode) p2p.getDataChildByName(QName.create(
387 testModule.getQNameModule(), "endpoints"));
388 assertNotNull(endpoints);
389 expectedQName = QName.create(UG_NS, UG_REV, "endpoints");
390 assertEquals(expectedQName, endpoints.getQName());
391 path.offer(expectedQName);
392 expectedPath = SchemaPath.create(path, true);
393 assertEquals(expectedPath, endpoints.getPath());
394 assertFalse(endpoints.isAddedByUses());
395 // * |-- |-- |-- |-- |-- leaf processing-rule
396 processingRule = (LeafSchemaNode) endpoints.getDataChildByName(QName.create(testModule.getQNameModule(),
398 assertNotNull(processingRule);
399 expectedQName = QName.create(UG_NS, UG_REV, "processing-rule");
400 assertEquals(expectedQName, processingRule.getQName());
401 path.offer(expectedQName);
402 expectedPath = SchemaPath.create(path, true);
403 assertEquals(expectedPath, processingRule.getPath());
404 assertEquals(BaseTypes.booleanType(), processingRule.getType());
405 assertTrue(processingRule.isAddedByUses());
406 // * |-- |-- |-- |-- |-- leaf ignore
407 ignore = (LeafSchemaNode) endpoints.getDataChildByName(QName.create(testModule.getQNameModule(), "ignore"));
408 assertNotNull(ignore);
409 expectedQName = QName.create(UG_NS, UG_REV, "ignore");
410 assertEquals(expectedQName, ignore.getQName());
412 path.offer(expectedQName);
413 expectedPath = SchemaPath.create(path, true);
414 assertEquals(expectedPath, ignore.getPath());
415 assertEquals(BaseTypes.booleanType(), ignore.getType());
416 assertTrue(ignore.isAddedByUses());
417 // * |-- |-- |-- |-- |-- container box
418 box = (ContainerSchemaNode) endpoints.getDataChildByName(QName.create(testModule.getQNameModule(), "box"));
420 expectedQName = QName.create(UG_NS, UG_REV, "box");
421 assertEquals(expectedQName, box.getQName());
423 path.offer(expectedQName);
424 expectedPath = SchemaPath.create(path, true);
425 assertEquals(expectedPath, box.getPath());
426 assertTrue(box.isAddedByUses());
427 // * |-- |-- |-- |-- |-- choice address-family
428 final ChoiceSchemaNode af = (ChoiceSchemaNode) endpoints.getDataChildByName(QName.create(
429 testModule.getQNameModule(), "address-family"));
431 expectedQName = QName.create(UG_NS, UG_REV, "address-family");
432 assertEquals(expectedQName, af.getQName());
434 path.offer(expectedQName);
435 expectedPath = SchemaPath.create(path, true);
436 assertEquals(expectedPath, af.getPath());
437 assertTrue(af.isAddedByUses());
438 // * |-- |-- |-- |-- container reported-route
439 final ContainerSchemaNode reportedRoute = (ContainerSchemaNode) p2p.getDataChildByName(QName.create(
440 testModule.getQNameModule(), "reported-route"));
441 assertNotNull(reportedRoute);
442 expectedQName = QName.create(UG_NS, UG_REV, "reported-route");
443 assertEquals(expectedQName, reportedRoute.getQName());
446 path.offer(expectedQName);
447 expectedPath = SchemaPath.create(path, true);
448 assertEquals(expectedPath, reportedRoute.getPath());
449 assertFalse(reportedRoute.isAddedByUses());
450 // * |-- |-- |-- |-- |-- leaf processing-rule
451 processingRule = (LeafSchemaNode) reportedRoute.getDataChildByName(QName.create(testModule.getQNameModule(),
453 assertNotNull(processingRule);
454 expectedQName = QName.create(UG_NS, UG_REV, "processing-rule");
455 assertEquals(expectedQName, processingRule.getQName());
456 path.offer(expectedQName);
457 expectedPath = SchemaPath.create(path, true);
458 assertEquals(expectedPath, processingRule.getPath());
459 assertEquals(BaseTypes.booleanType(), processingRule.getType());
460 assertTrue(processingRule.isAddedByUses());
461 // * |-- |-- |-- |-- |-- leaf ignore
462 ignore = (LeafSchemaNode) reportedRoute.getDataChildByName(QName.create(testModule.getQNameModule(), "ignore"));
463 assertNotNull(ignore);
464 expectedQName = QName.create(UG_NS, UG_REV, "ignore");
465 assertEquals(expectedQName, ignore.getQName());
467 path.offer(expectedQName);
468 expectedPath = SchemaPath.create(path, true);
469 assertEquals(expectedPath, ignore.getPath());
470 assertEquals(BaseTypes.booleanType(), ignore.getType());
471 assertTrue(ignore.isAddedByUses());
472 // * |-- |-- |-- |-- |-- list subobjects
473 final ListSchemaNode subobjects = (ListSchemaNode) reportedRoute.getDataChildByName(QName.create(
474 testModule.getQNameModule(), "subobjects"));
475 assertNotNull(subobjects);
476 expectedQName = QName.create(UG_NS, UG_REV, "subobjects");
477 assertEquals(expectedQName, subobjects.getQName());
479 path.offer(expectedQName);
480 expectedPath = SchemaPath.create(path, true);
481 assertEquals(expectedPath, subobjects.getPath());
482 assertTrue(subobjects.isAddedByUses());
483 // * |-- |-- |-- |-- |-- container bandwidth
484 ContainerSchemaNode bandwidth = (ContainerSchemaNode) reportedRoute.getDataChildByName(QName.create(
485 testModule.getQNameModule(), "bandwidth"));
486 assertNotNull(bandwidth);
487 expectedQName = QName.create(UG_NS, UG_REV, "bandwidth");
488 assertEquals(expectedQName, bandwidth.getQName());
490 path.offer(expectedQName);
491 expectedPath = SchemaPath.create(path, true);
492 assertEquals(expectedPath, bandwidth.getPath());
493 assertFalse(bandwidth.isAddedByUses());
494 // * |-- |-- |-- |-- container bandwidth
495 bandwidth = (ContainerSchemaNode) p2p
496 .getDataChildByName(QName.create(testModule.getQNameModule(), "bandwidth"));
497 assertNotNull(bandwidth);
498 expectedQName = QName.create(UG_NS, UG_REV, "bandwidth");
499 assertEquals(expectedQName, bandwidth.getQName());
502 path.offer(expectedQName);
503 expectedPath = SchemaPath.create(path, true);
504 assertEquals(expectedPath, bandwidth.getPath());
505 assertTrue(bandwidth.isAddedByUses());
506 // * |-- |-- |-- |-- |-- leaf processing-rule
507 processingRule = (LeafSchemaNode) bandwidth.getDataChildByName(QName.create(testModule.getQNameModule(),
509 assertNotNull(processingRule);
510 expectedQName = QName.create(UG_NS, UG_REV, "processing-rule");
511 assertEquals(expectedQName, processingRule.getQName());
512 path.offer(expectedQName);
513 expectedPath = SchemaPath.create(path, true);
514 assertEquals(expectedPath, processingRule.getPath());
515 assertEquals(BaseTypes.booleanType(), processingRule.getType());
516 assertTrue(processingRule.isAddedByUses());
517 // * |-- |-- |-- |-- |-- leaf ignore
518 ignore = (LeafSchemaNode) bandwidth.getDataChildByName(QName.create(testModule.getQNameModule(), "ignore"));
519 assertNotNull(ignore);
520 expectedQName = QName.create(UG_NS, UG_REV, "ignore");
521 assertEquals(expectedQName, ignore.getQName());
523 path.offer(expectedQName);
524 expectedPath = SchemaPath.create(path, true);
525 assertEquals(expectedPath, ignore.getPath());
526 assertEquals(BaseTypes.booleanType(), ignore.getType());
527 assertTrue(ignore.isAddedByUses());
528 // * |-- |-- |-- |-- |-- container bandwidth
529 final ContainerSchemaNode bandwidthInner = (ContainerSchemaNode) bandwidth.getDataChildByName(QName.create(
530 testModule.getQNameModule(), "bandwidth"));
531 assertNotNull(bandwidthInner);
532 expectedQName = QName.create(UG_NS, UG_REV, "bandwidth");
533 assertEquals(expectedQName, bandwidth.getQName());
535 path.offer(expectedQName);
536 expectedPath = SchemaPath.create(path, true);
537 assertEquals(expectedPath, bandwidthInner.getPath());
538 assertTrue(bandwidthInner.isAddedByUses());
540 final ListSchemaNode svec = (ListSchemaNode) pcreq.getDataChildByName(QName.create(testModule.getQNameModule(),
543 expectedQName = QName.create(UG_NS, UG_REV, "svec");
544 assertEquals(expectedQName, svec.getQName());
550 path.offer(expectedQName);
551 expectedPath = SchemaPath.create(path, true);
552 assertEquals(expectedPath, svec.getPath());
553 assertFalse(svec.isAddedByUses());
554 // * |-- |-- leaf link-diverse
555 final LeafSchemaNode linkDiverse = (LeafSchemaNode) svec.getDataChildByName(QName.create(
556 testModule.getQNameModule(), "link-diverse"));
557 assertNotNull(linkDiverse);
558 expectedQName = QName.create(UG_NS, UG_REV, "link-diverse");
559 assertEquals(expectedQName, linkDiverse.getQName());
560 path.offer(expectedQName);
561 expectedPath = SchemaPath.create(path, true);
562 assertEquals(expectedPath, linkDiverse.getPath());
563 assertEquals(BaseTypes.booleanType(), linkDiverse.getType().getBaseType());
564 assertTrue(linkDiverse.isAddedByUses());
565 // * |-- |-- leaf processing-rule
566 processingRule = (LeafSchemaNode) svec.getDataChildByName(QName.create(testModule.getQNameModule(),
568 assertNotNull(processingRule);
569 expectedQName = QName.create(UG_NS, UG_REV, "processing-rule");
570 assertEquals(expectedQName, processingRule.getQName());
572 path.offer(expectedQName);
573 expectedPath = SchemaPath.create(path, true);
574 assertEquals(expectedPath, processingRule.getPath());
575 assertEquals(BaseTypes.booleanType(), processingRule.getType());
576 assertTrue(processingRule.isAddedByUses());
577 // * |-- |-- leaf ignore
578 ignore = (LeafSchemaNode) svec.getDataChildByName(QName.create(testModule.getQNameModule(), "ignore"));
579 assertNotNull(ignore);
580 expectedQName = QName.create(UG_NS, UG_REV, "ignore");
581 assertEquals(expectedQName, ignore.getQName());
583 path.offer(expectedQName);
584 expectedPath = SchemaPath.create(path, true);
585 assertEquals(expectedPath, ignore.getPath());
586 assertEquals(BaseTypes.booleanType(), ignore.getType());
587 assertTrue(ignore.isAddedByUses());
588 // * |-- |-- list metric
589 final ListSchemaNode metric = (ListSchemaNode) svec.getDataChildByName(QName.create(
590 testModule.getQNameModule(), "metric"));
591 assertNotNull(metric);
592 expectedQName = QName.create(UG_NS, UG_REV, "metric");
593 assertEquals(expectedQName, metric.getQName());
595 path.offer(expectedQName);
596 expectedPath = SchemaPath.create(path, true);
597 assertEquals(expectedPath, metric.getPath());
598 assertFalse(metric.isAddedByUses());
599 // * |-- |-- |-- leaf metric-type
600 final LeafSchemaNode metricType = (LeafSchemaNode) metric.getDataChildByName(QName.create(
601 testModule.getQNameModule(), "metric-type"));
602 assertNotNull(metricType);
603 expectedQName = QName.create(UG_NS, UG_REV, "metric-type");
604 assertEquals(expectedQName, metricType.getQName());
605 path.offer(expectedQName);
606 expectedPath = SchemaPath.create(path, true);
607 assertEquals(expectedPath, metricType.getPath());
608 assertEquals(BaseTypes.uint8Type(), metricType.getType());
609 assertTrue(metricType.isAddedByUses());
611 box = (ContainerSchemaNode) metric.getDataChildByName(QName.create(testModule.getQNameModule(), "box"));
613 expectedQName = QName.create(UG_NS, UG_REV, "box");
614 assertEquals(expectedQName, box.getQName());
616 path.offer(expectedQName);
617 expectedPath = SchemaPath.create(path, true);
618 assertEquals(expectedPath, box.getPath());
619 assertTrue(box.isAddedByUses());
620 // * |-- |-- |-- leaf processing-rule
621 processingRule = (LeafSchemaNode) metric.getDataChildByName(QName.create(testModule.getQNameModule(),
623 assertNotNull(processingRule);
624 expectedQName = QName.create(UG_NS, UG_REV, "processing-rule");
625 assertEquals(expectedQName, processingRule.getQName());
627 path.offer(expectedQName);
628 expectedPath = SchemaPath.create(path, true);
629 assertEquals(expectedPath, processingRule.getPath());
630 assertEquals(BaseTypes.booleanType(), processingRule.getType());
631 assertTrue(processingRule.isAddedByUses());
632 // * |-- |-- |-- leaf ignore
633 ignore = (LeafSchemaNode) metric.getDataChildByName(QName.create(testModule.getQNameModule(), "ignore"));
634 assertNotNull(ignore);
635 expectedQName = QName.create(UG_NS, UG_REV, "ignore");
636 assertEquals(expectedQName, ignore.getQName());
638 path.offer(expectedQName);
639 expectedPath = SchemaPath.create(path, true);
640 assertEquals(expectedPath, ignore.getPath());
641 assertEquals(BaseTypes.booleanType(), ignore.getType());
642 assertTrue(ignore.isAddedByUses());
646 public void testTypedefs() throws URISyntaxException, SourceException, ReactorException {
647 modules = TestUtils.loadModules(getClass().getResource("/grouping-test").toURI());
648 final Module testModule = TestUtils.findModule(modules, "grouping-definitions");
649 final Set<TypeDefinition<?>> types = testModule.getTypeDefinitions();
651 TypeDefinition<?> intExt = null;
652 for (final TypeDefinition<?> td : types) {
653 if ("int-ext".equals(td.getQName().getLocalName())) {
657 assertNotNull(intExt);
659 SchemaPath expectedPath = SchemaPath.create(true, QName.create(GD_NS, GD_REV, "int-ext"));
660 assertEquals(expectedPath, intExt.getPath());
662 final UnionTypeDefinition union = (UnionTypeDefinition) intExt.getBaseType();
664 TypeDefinition<?> uint8 = null;
665 TypeDefinition<?> pv = null;
666 for (final TypeDefinition<?> td : union.getTypes()) {
667 if ("uint8".equals(td.getQName().getLocalName())) {
669 } else if ("protocol-version".equals(td.getQName().getLocalName())) {
673 assertNotNull(uint8);
676 expectedPath = SchemaPath.create(true, QName.create(GD_NS, GD_REV, "int-ext"),
677 QName.create(GD_NS, GD_REV, "union"));
678 assertEquals(expectedPath, union.getPath());